OLD | NEW |
---|---|
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
8 #include "src/interpreter/bytecode-array-iterator.h" | 8 #include "src/interpreter/bytecode-array-iterator.h" |
9 #include "src/interpreter/bytecode-generator.h" | 9 #include "src/interpreter/bytecode-generator.h" |
10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
104 #define U16(x) static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff), \ | 104 #define U16(x) static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff), \ |
105 static_cast<uint8_t>((x) & 0xff) | 105 static_cast<uint8_t>((x) & 0xff) |
106 #define U16I(x) static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff), \ | 106 #define U16I(x) static_cast<uint8_t>(((x) >> kBitsPerByte) & 0xff), \ |
107 static_cast<uint8_t>((x++) & 0xff) | 107 static_cast<uint8_t>((x++) & 0xff) |
108 #else | 108 #else |
109 #error Unknown byte ordering | 109 #error Unknown byte ordering |
110 #endif | 110 #endif |
111 | 111 |
112 #define COMMA() , | 112 #define COMMA() , |
113 #define SPACE() | 113 #define SPACE() |
114 #define UNIQUE_VAR() "var a" XSTR(__COUNTER__) " = 0;\n" | |
oth
2016/01/11 11:31:11
Does this need to be flagged with the core v8 team
rmcilroy
2016/01/11 15:47:19
I think this is OK (assuming it passes the bots) -
| |
114 | 115 |
115 #define REPEAT_2(SEP, ...) \ | 116 #define REPEAT_2(SEP, ...) \ |
116 __VA_ARGS__ SEP() __VA_ARGS__ | 117 __VA_ARGS__ SEP() __VA_ARGS__ |
117 #define REPEAT_4(SEP, ...) \ | 118 #define REPEAT_4(SEP, ...) \ |
118 REPEAT_2(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__) | 119 REPEAT_2(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__) |
119 #define REPEAT_8(SEP, ...) \ | 120 #define REPEAT_8(SEP, ...) \ |
120 REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_4(SEP, __VA_ARGS__) | 121 REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_4(SEP, __VA_ARGS__) |
121 #define REPEAT_16(SEP, ...) \ | 122 #define REPEAT_16(SEP, ...) \ |
122 REPEAT_8(SEP, __VA_ARGS__) SEP() REPEAT_8(SEP, __VA_ARGS__) | 123 REPEAT_8(SEP, __VA_ARGS__) SEP() REPEAT_8(SEP, __VA_ARGS__) |
123 #define REPEAT_32(SEP, ...) \ | 124 #define REPEAT_32(SEP, ...) \ |
124 REPEAT_16(SEP, __VA_ARGS__) SEP() REPEAT_16(SEP, __VA_ARGS__) | 125 REPEAT_16(SEP, __VA_ARGS__) SEP() REPEAT_16(SEP, __VA_ARGS__) |
125 #define REPEAT_64(SEP, ...) \ | 126 #define REPEAT_64(SEP, ...) \ |
126 REPEAT_32(SEP, __VA_ARGS__) SEP() REPEAT_32(SEP, __VA_ARGS__) | 127 REPEAT_32(SEP, __VA_ARGS__) SEP() REPEAT_32(SEP, __VA_ARGS__) |
127 #define REPEAT_128(SEP, ...) \ | 128 #define REPEAT_128(SEP, ...) \ |
128 REPEAT_64(SEP, __VA_ARGS__) SEP() REPEAT_64(SEP, __VA_ARGS__) | 129 REPEAT_64(SEP, __VA_ARGS__) SEP() REPEAT_64(SEP, __VA_ARGS__) |
129 #define REPEAT_256(SEP, ...) \ | 130 #define REPEAT_256(SEP, ...) \ |
130 REPEAT_128(SEP, __VA_ARGS__) SEP() REPEAT_128(SEP, __VA_ARGS__) | 131 REPEAT_128(SEP, __VA_ARGS__) SEP() REPEAT_128(SEP, __VA_ARGS__) |
131 | 132 |
132 #define REPEAT_127(SEP, ...) \ | 133 #define REPEAT_127(SEP, ...) \ |
133 REPEAT_64(SEP, __VA_ARGS__) SEP() REPEAT_32(SEP, __VA_ARGS__) SEP() \ | 134 REPEAT_64(SEP, __VA_ARGS__) SEP() REPEAT_32(SEP, __VA_ARGS__) SEP() \ |
134 REPEAT_16(SEP, __VA_ARGS__) SEP() REPEAT_8(SEP, __VA_ARGS__) SEP() \ | 135 REPEAT_16(SEP, __VA_ARGS__) SEP() REPEAT_8(SEP, __VA_ARGS__) SEP() \ |
135 REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__) SEP() \ | 136 REPEAT_4(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__) SEP() \ |
136 __VA_ARGS__ | 137 __VA_ARGS__ |
137 | 138 |
139 #define REPEAT_249(SEP, ...) \ | |
140 REPEAT_127(SEP, __VA_ARGS__) SEP() REPEAT_64(SEP, __VA_ARGS__) SEP() \ | |
141 REPEAT_32(SEP, __VA_ARGS__) SEP() REPEAT_16(SEP, __VA_ARGS__) SEP() \ | |
142 REPEAT_8(SEP, __VA_ARGS__) SEP() REPEAT_2(SEP, __VA_ARGS__) | |
143 | |
144 #define REPEAT_249_UNIQUE_VARS() \ | |
145 UNIQUE_VAR() REPEAT_127(UNIQUE_VAR) UNIQUE_VAR() REPEAT_64(UNIQUE_VAR) \ | |
146 UNIQUE_VAR() REPEAT_32(UNIQUE_VAR) UNIQUE_VAR() REPEAT_16(UNIQUE_VAR) \ | |
147 UNIQUE_VAR() REPEAT_8(UNIQUE_VAR) UNIQUE_VAR() REPEAT_2(UNIQUE_VAR) | |
148 | |
138 // Structure for containing expected bytecode snippets. | 149 // Structure for containing expected bytecode snippets. |
139 template<typename T, int C = 6> | 150 template<typename T, int C = 6> |
140 struct ExpectedSnippet { | 151 struct ExpectedSnippet { |
141 const char* code_snippet; | 152 const char* code_snippet; |
142 int frame_size; | 153 int frame_size; |
143 int parameter_count; | 154 int parameter_count; |
144 int bytecode_length; | 155 int bytecode_length; |
145 const uint8_t bytecode[2048]; | 156 const uint8_t bytecode[2048]; |
146 int constant_count; | 157 int constant_count; |
147 T constants[C]; | 158 T constants[C]; |
(...skipping 3861 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4009 BytecodeGeneratorHelper helper; | 4020 BytecodeGeneratorHelper helper; |
4010 Zone zone; | 4021 Zone zone; |
4011 | 4022 |
4012 FeedbackVectorSpec feedback_spec(&zone); | 4023 FeedbackVectorSpec feedback_spec(&zone); |
4013 FeedbackVectorSlot slot = feedback_spec.AddCallICSlot(); | 4024 FeedbackVectorSlot slot = feedback_spec.AddCallICSlot(); |
4014 | 4025 |
4015 Handle<i::TypeFeedbackVector> vector = | 4026 Handle<i::TypeFeedbackVector> vector = |
4016 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); | 4027 i::NewTypeFeedbackVector(helper.isolate(), &feedback_spec); |
4017 | 4028 |
4018 int closure = Register::function_closure().index(); | 4029 int closure = Register::function_closure().index(); |
4030 int new_target = Register::new_target().index(); | |
4019 int first_context_slot = Context::MIN_CONTEXT_SLOTS; | 4031 int first_context_slot = Context::MIN_CONTEXT_SLOTS; |
4032 | |
4033 int wide_slot = first_context_slot + 3; | |
oth
2016/01/11 11:31:11
This code could STATIC_ASSERT that the limit of wi
rmcilroy
2016/01/11 15:47:19
Done.
| |
4020 ExpectedSnippet<InstanceType> snippets[] = { | 4034 ExpectedSnippet<InstanceType> snippets[] = { |
4021 {"var a; return function() { a = 1; };", | 4035 {"var a; return function() { a = 1; };", |
4022 1 * kPointerSize, | 4036 1 * kPointerSize, |
4023 1, | 4037 1, |
4024 11, | 4038 11, |
4025 { | 4039 { |
4026 B(CallRuntime), U16(Runtime::kNewFunctionContext), // | 4040 B(CallRuntime), U16(Runtime::kNewFunctionContext), // |
4027 R(closure), U8(1), // | 4041 R(closure), U8(1), // |
4028 B(PushContext), R(0), // | 4042 B(PushContext), R(0), // |
4029 B(CreateClosure), U8(0), U8(0), // | 4043 B(CreateClosure), U8(0), U8(0), // |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4102 B(LdaTheHole), // | 4116 B(LdaTheHole), // |
4103 B(StaContextSlot), R(1), U8(first_context_slot), // | 4117 B(StaContextSlot), R(1), U8(first_context_slot), // |
4104 B(LdaSmi8), U8(2), // | 4118 B(LdaSmi8), U8(2), // |
4105 B(StaContextSlot), R(1), U8(first_context_slot), // | 4119 B(StaContextSlot), R(1), U8(first_context_slot), // |
4106 B(CreateClosure), U8(1), U8(0), // | 4120 B(CreateClosure), U8(1), U8(0), // |
4107 B(Return), // | 4121 B(Return), // |
4108 }, | 4122 }, |
4109 2, | 4123 2, |
4110 {InstanceType::FIXED_ARRAY_TYPE, | 4124 {InstanceType::FIXED_ARRAY_TYPE, |
4111 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, | 4125 InstanceType::SHARED_FUNCTION_INFO_TYPE}}, |
4126 {"'use strict';\n" | |
4127 REPEAT_249_UNIQUE_VARS() | |
4128 "eval();" | |
4129 "var b = 100;" | |
4130 "return b", | |
4131 3 * kPointerSize, | |
4132 1, | |
4133 1041, | |
4134 { | |
4135 B(CallRuntime), U16(Runtime::kNewFunctionContext), R(closure), // | |
4136 U8(1), // | |
4137 B(PushContext), R(0), // | |
4138 B(Ldar), THIS(1), // | |
4139 B(StaContextSlot), R(0), U8(first_context_slot), // | |
4140 B(CreateUnmappedArguments), // | |
4141 B(StaContextSlot), R(0), U8(first_context_slot + 1), // | |
4142 B(Ldar), R(new_target), // | |
4143 B(StaContextSlot), R(0), U8(first_context_slot + 2), // | |
4144 REPEAT_249(COMMA, // | |
4145 B(LdaZero), // | |
4146 B(StaContextSlot), R(0), U8(wide_slot++)), // | |
4147 B(LdaUndefined), // | |
4148 B(Star), R(2), // | |
4149 B(LdaGlobalStrict), U8(0), U8(1), // | |
4150 B(Star), R(1), // | |
4151 B(Call), R(1), R(2), U8(0), U8(0), // | |
4152 B(LdaSmi8), U8(100), // | |
4153 B(StaContextSlotWide), R(0), U16(256), // | |
4154 B(LdaContextSlotWide), R(0), U16(256), // | |
4155 B(Return), // | |
4156 }, | |
4157 1, | |
4158 {InstanceType::ONE_BYTE_INTERNALIZED_STRING_TYPE}}, | |
4112 }; | 4159 }; |
4113 | 4160 |
4114 for (size_t i = 0; i < arraysize(snippets); i++) { | 4161 for (size_t i = 0; i < arraysize(snippets); i++) { |
4115 Handle<BytecodeArray> bytecode_array = | 4162 Handle<BytecodeArray> bytecode_array = |
4116 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); | 4163 helper.MakeBytecodeForFunctionBody(snippets[i].code_snippet); |
4117 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 4164 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
4118 } | 4165 } |
4119 } | 4166 } |
4120 | 4167 |
4121 | 4168 |
(...skipping 2144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6266 std::string(function_epilogue); | 6313 std::string(function_epilogue); |
6267 Handle<BytecodeArray> bytecode_array = | 6314 Handle<BytecodeArray> bytecode_array = |
6268 helper.MakeBytecode(script.c_str(), "t", "f"); | 6315 helper.MakeBytecode(script.c_str(), "t", "f"); |
6269 CheckBytecodeArrayEqual(snippets[i], bytecode_array); | 6316 CheckBytecodeArrayEqual(snippets[i], bytecode_array); |
6270 } | 6317 } |
6271 } | 6318 } |
6272 | 6319 |
6273 } // namespace interpreter | 6320 } // namespace interpreter |
6274 } // namespace internal | 6321 } // namespace internal |
6275 } // namespace v8 | 6322 } // namespace v8 |
OLD | NEW |