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/interpreter/bytecode-generator.h" | 5 #include "src/interpreter/bytecode-generator.h" |
6 | 6 |
7 #include "src/ast/compile-time-value.h" | 7 #include "src/ast/compile-time-value.h" |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/builtins/builtins-constructor.h" | 9 #include "src/builtins/builtins-constructor.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 1075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1086 | 1086 |
1087 void BytecodeGenerator::VisitBreakStatement(BreakStatement* stmt) { | 1087 void BytecodeGenerator::VisitBreakStatement(BreakStatement* stmt) { |
1088 builder()->SetStatementPosition(stmt); | 1088 builder()->SetStatementPosition(stmt); |
1089 execution_control()->Break(stmt->target()); | 1089 execution_control()->Break(stmt->target()); |
1090 } | 1090 } |
1091 | 1091 |
1092 void BytecodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { | 1092 void BytecodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { |
1093 builder()->SetStatementPosition(stmt); | 1093 builder()->SetStatementPosition(stmt); |
1094 VisitForAccumulatorValue(stmt->expression()); | 1094 VisitForAccumulatorValue(stmt->expression()); |
1095 | 1095 |
| 1096 if (stmt->HasTypeProfileSlot()) { |
| 1097 FeedbackSlot collect_type_feedback_slot = stmt->TypeProfileSlot(); |
| 1098 builder()->CollectTypeProfile(stmt->position(), |
| 1099 feedback_index(collect_type_feedback_slot)); |
| 1100 } |
| 1101 |
1096 if (stmt->is_async_return()) { | 1102 if (stmt->is_async_return()) { |
1097 execution_control()->AsyncReturnAccumulator(); | 1103 execution_control()->AsyncReturnAccumulator(); |
1098 } else { | 1104 } else { |
1099 execution_control()->ReturnAccumulator(); | 1105 execution_control()->ReturnAccumulator(); |
1100 } | 1106 } |
1101 } | 1107 } |
1102 | 1108 |
1103 void BytecodeGenerator::VisitWithStatement(WithStatement* stmt) { | 1109 void BytecodeGenerator::VisitWithStatement(WithStatement* stmt) { |
1104 builder()->SetStatementPosition(stmt); | 1110 builder()->SetStatementPosition(stmt); |
1105 VisitForAccumulatorValue(stmt->expression()); | 1111 VisitForAccumulatorValue(stmt->expression()); |
(...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2204 DCHECK(expr->target()->IsValidReferenceExpressionOrThis()); | 2210 DCHECK(expr->target()->IsValidReferenceExpressionOrThis()); |
2205 Register object, key; | 2211 Register object, key; |
2206 RegisterList super_property_args; | 2212 RegisterList super_property_args; |
2207 const AstRawString* name; | 2213 const AstRawString* name; |
2208 | 2214 |
2209 // Left-hand side can only be a property, a global or a variable slot. | 2215 // Left-hand side can only be a property, a global or a variable slot. |
2210 Property* property = expr->target()->AsProperty(); | 2216 Property* property = expr->target()->AsProperty(); |
2211 LhsKind assign_type = Property::GetAssignType(property); | 2217 LhsKind assign_type = Property::GetAssignType(property); |
2212 | 2218 |
2213 // Evaluate LHS expression. | 2219 // Evaluate LHS expression. |
2214 Register lhs_name; | |
2215 if (expr->HasTypeProfileSlot()) { | |
2216 lhs_name = register_allocator()->NewRegister(); | |
2217 } | |
2218 | |
2219 switch (assign_type) { | 2220 switch (assign_type) { |
2220 case VARIABLE: | 2221 case VARIABLE: |
2221 if (expr->HasTypeProfileSlot()) { | |
2222 builder() | |
2223 ->LoadLiteral(expr->target()->AsVariableProxy()->var()->raw_name()) | |
2224 .StoreAccumulatorInRegister(lhs_name); | |
2225 } | |
2226 // Nothing to do to evaluate variable assignment LHS. | 2222 // Nothing to do to evaluate variable assignment LHS. |
2227 break; | 2223 break; |
2228 case NAMED_PROPERTY: { | 2224 case NAMED_PROPERTY: { |
2229 object = VisitForRegisterValue(property->obj()); | 2225 object = VisitForRegisterValue(property->obj()); |
2230 name = property->key()->AsLiteral()->AsRawPropertyName(); | 2226 name = property->key()->AsLiteral()->AsRawPropertyName(); |
2231 if (expr->HasTypeProfileSlot()) { | |
2232 builder()->LoadLiteral(name).StoreAccumulatorInRegister(lhs_name); | |
2233 } | |
2234 break; | 2227 break; |
2235 } | 2228 } |
2236 case KEYED_PROPERTY: { | 2229 case KEYED_PROPERTY: { |
2237 object = VisitForRegisterValue(property->obj()); | 2230 object = VisitForRegisterValue(property->obj()); |
2238 key = VisitForRegisterValue(property->key()); | 2231 key = VisitForRegisterValue(property->key()); |
2239 if (expr->HasTypeProfileSlot()) { | |
2240 builder()->StoreAccumulatorInRegister(lhs_name); | |
2241 } | |
2242 break; | 2232 break; |
2243 } | 2233 } |
2244 case NAMED_SUPER_PROPERTY: { | 2234 case NAMED_SUPER_PROPERTY: { |
2245 super_property_args = register_allocator()->NewRegisterList(4); | 2235 super_property_args = register_allocator()->NewRegisterList(4); |
2246 SuperPropertyReference* super_property = | 2236 SuperPropertyReference* super_property = |
2247 property->obj()->AsSuperPropertyReference(); | 2237 property->obj()->AsSuperPropertyReference(); |
2248 VisitForRegisterValue(super_property->this_var(), super_property_args[0]); | 2238 VisitForRegisterValue(super_property->this_var(), super_property_args[0]); |
2249 VisitForRegisterValue(super_property->home_object(), | 2239 VisitForRegisterValue(super_property->home_object(), |
2250 super_property_args[1]); | 2240 super_property_args[1]); |
2251 builder() | 2241 builder() |
2252 ->LoadLiteral(property->key()->AsLiteral()->AsRawPropertyName()) | 2242 ->LoadLiteral(property->key()->AsLiteral()->AsRawPropertyName()) |
2253 .StoreAccumulatorInRegister(super_property_args[2]); | 2243 .StoreAccumulatorInRegister(super_property_args[2]); |
2254 if (expr->HasTypeProfileSlot()) { | |
2255 builder()->StoreAccumulatorInRegister(lhs_name); | |
2256 } | |
2257 break; | 2244 break; |
2258 } | 2245 } |
2259 case KEYED_SUPER_PROPERTY: { | 2246 case KEYED_SUPER_PROPERTY: { |
2260 super_property_args = register_allocator()->NewRegisterList(4); | 2247 super_property_args = register_allocator()->NewRegisterList(4); |
2261 SuperPropertyReference* super_property = | 2248 SuperPropertyReference* super_property = |
2262 property->obj()->AsSuperPropertyReference(); | 2249 property->obj()->AsSuperPropertyReference(); |
2263 VisitForRegisterValue(super_property->this_var(), super_property_args[0]); | 2250 VisitForRegisterValue(super_property->this_var(), super_property_args[0]); |
2264 VisitForRegisterValue(super_property->home_object(), | 2251 VisitForRegisterValue(super_property->home_object(), |
2265 super_property_args[1]); | 2252 super_property_args[1]); |
2266 VisitForRegisterValue(property->key(), super_property_args[2]); | 2253 VisitForRegisterValue(property->key(), super_property_args[2]); |
2267 if (expr->HasTypeProfileSlot()) { | |
2268 builder()->StoreAccumulatorInRegister(lhs_name); | |
2269 } | |
2270 | |
2271 break; | 2254 break; |
2272 } | 2255 } |
2273 } | 2256 } |
2274 | 2257 |
2275 // Evaluate the value and potentially handle compound assignments by loading | 2258 // Evaluate the value and potentially handle compound assignments by loading |
2276 // the left-hand side value and performing a binary operation. | 2259 // the left-hand side value and performing a binary operation. |
2277 if (expr->is_compound()) { | 2260 if (expr->is_compound()) { |
2278 Register old_value = register_allocator()->NewRegister(); | 2261 Register old_value = register_allocator()->NewRegister(); |
2279 switch (assign_type) { | 2262 switch (assign_type) { |
2280 case VARIABLE: { | 2263 case VARIABLE: { |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2351 } | 2334 } |
2352 case KEYED_SUPER_PROPERTY: { | 2335 case KEYED_SUPER_PROPERTY: { |
2353 builder() | 2336 builder() |
2354 ->StoreAccumulatorInRegister(super_property_args[3]) | 2337 ->StoreAccumulatorInRegister(super_property_args[3]) |
2355 .CallRuntime(StoreKeyedToSuperRuntimeId(), super_property_args); | 2338 .CallRuntime(StoreKeyedToSuperRuntimeId(), super_property_args); |
2356 break; | 2339 break; |
2357 } | 2340 } |
2358 } | 2341 } |
2359 | 2342 |
2360 // Value is in accumulator. | 2343 // Value is in accumulator. |
2361 if (expr->HasTypeProfileSlot()) { | 2344 // TODO(franzih): Collect type profile once we can handle more than just |
| 2345 // return statements. |
| 2346 if (false && expr->HasTypeProfileSlot()) { |
2362 FeedbackSlot collect_type_feedback_slot = expr->TypeProfileSlot(); | 2347 FeedbackSlot collect_type_feedback_slot = expr->TypeProfileSlot(); |
2363 | 2348 |
2364 builder()->CollectTypeProfile(lhs_name, | 2349 builder()->CollectTypeProfile(expr->position(), |
2365 feedback_index(collect_type_feedback_slot)); | 2350 feedback_index(collect_type_feedback_slot)); |
2366 } | 2351 } |
2367 } | 2352 } |
2368 | 2353 |
2369 void BytecodeGenerator::VisitYield(Yield* expr) { | 2354 void BytecodeGenerator::VisitYield(Yield* expr) { |
2370 builder()->SetExpressionPosition(expr); | 2355 builder()->SetExpressionPosition(expr); |
2371 Register value = VisitForRegisterValue(expr->expression()); | 2356 Register value = VisitForRegisterValue(expr->expression()); |
2372 | 2357 |
2373 Register generator = VisitForRegisterValue(expr->generator_object()); | 2358 Register generator = VisitForRegisterValue(expr->generator_object()); |
2374 | 2359 |
(...skipping 1144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3519 } | 3504 } |
3520 | 3505 |
3521 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { | 3506 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { |
3522 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict | 3507 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict |
3523 : Runtime::kStoreKeyedToSuper_Sloppy; | 3508 : Runtime::kStoreKeyedToSuper_Sloppy; |
3524 } | 3509 } |
3525 | 3510 |
3526 } // namespace interpreter | 3511 } // namespace interpreter |
3527 } // namespace internal | 3512 } // namespace internal |
3528 } // namespace v8 | 3513 } // namespace v8 |
OLD | NEW |