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/scopes.h" | 7 #include "src/ast/scopes.h" |
8 #include "src/compiler.h" | 8 #include "src/compiler.h" |
9 #include "src/interpreter/bytecode-register-allocator.h" | 9 #include "src/interpreter/bytecode-register-allocator.h" |
10 #include "src/interpreter/control-flow-builders.h" | 10 #include "src/interpreter/control-flow-builders.h" |
(...skipping 1294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1305 VisitClassLiteralForRuntimeDefinition(expr); | 1305 VisitClassLiteralForRuntimeDefinition(expr); |
1306 | 1306 |
1307 // Load the "prototype" from the constructor. | 1307 // Load the "prototype" from the constructor. |
1308 register_allocator()->PrepareForConsecutiveAllocations(2); | 1308 register_allocator()->PrepareForConsecutiveAllocations(2); |
1309 Register literal = register_allocator()->NextConsecutiveRegister(); | 1309 Register literal = register_allocator()->NextConsecutiveRegister(); |
1310 Register prototype = register_allocator()->NextConsecutiveRegister(); | 1310 Register prototype = register_allocator()->NextConsecutiveRegister(); |
1311 Handle<String> name = isolate()->factory()->prototype_string(); | 1311 Handle<String> name = isolate()->factory()->prototype_string(); |
1312 FeedbackVectorSlot slot = expr->PrototypeSlot(); | 1312 FeedbackVectorSlot slot = expr->PrototypeSlot(); |
1313 builder() | 1313 builder() |
1314 ->StoreAccumulatorInRegister(literal) | 1314 ->StoreAccumulatorInRegister(literal) |
1315 .LoadNamedProperty(literal, name, feedback_index(slot), language_mode()) | 1315 .LoadNamedProperty(literal, name, feedback_index(slot)) |
1316 .StoreAccumulatorInRegister(prototype); | 1316 .StoreAccumulatorInRegister(prototype); |
1317 | 1317 |
1318 VisitClassLiteralProperties(expr, literal, prototype); | 1318 VisitClassLiteralProperties(expr, literal, prototype); |
1319 builder()->CallRuntime(Runtime::kFinalizeClassDefinition, literal, 2); | 1319 builder()->CallRuntime(Runtime::kFinalizeClassDefinition, literal, 2); |
1320 // Assign to class variable. | 1320 // Assign to class variable. |
1321 if (expr->class_variable_proxy() != nullptr) { | 1321 if (expr->class_variable_proxy() != nullptr) { |
1322 Variable* var = expr->class_variable_proxy()->var(); | 1322 Variable* var = expr->class_variable_proxy()->var(); |
1323 FeedbackVectorSlot slot = expr->NeedsProxySlot() | 1323 FeedbackVectorSlot slot = expr->NeedsProxySlot() |
1324 ? expr->ProxySlot() | 1324 ? expr->ProxySlot() |
1325 : FeedbackVectorSlot::Invalid(); | 1325 : FeedbackVectorSlot::Invalid(); |
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1774 // index -1 but is parameter index 0 in BytecodeArrayBuilder). | 1774 // index -1 but is parameter index 0 in BytecodeArrayBuilder). |
1775 Register source = builder()->Parameter(variable->index() + 1); | 1775 Register source = builder()->Parameter(variable->index() + 1); |
1776 builder()->LoadAccumulatorWithRegister(source); | 1776 builder()->LoadAccumulatorWithRegister(source); |
1777 BuildHoleCheckForVariableLoad(mode, variable->name()); | 1777 BuildHoleCheckForVariableLoad(mode, variable->name()); |
1778 execution_result()->SetResultInAccumulator(); | 1778 execution_result()->SetResultInAccumulator(); |
1779 break; | 1779 break; |
1780 } | 1780 } |
1781 case VariableLocation::GLOBAL: | 1781 case VariableLocation::GLOBAL: |
1782 case VariableLocation::UNALLOCATED: { | 1782 case VariableLocation::UNALLOCATED: { |
1783 builder()->LoadGlobal(variable->name(), feedback_index(slot), | 1783 builder()->LoadGlobal(variable->name(), feedback_index(slot), |
1784 language_mode(), typeof_mode); | 1784 typeof_mode); |
1785 execution_result()->SetResultInAccumulator(); | 1785 execution_result()->SetResultInAccumulator(); |
1786 break; | 1786 break; |
1787 } | 1787 } |
1788 case VariableLocation::CONTEXT: { | 1788 case VariableLocation::CONTEXT: { |
1789 int depth = execution_context()->ContextChainDepth(variable->scope()); | 1789 int depth = execution_context()->ContextChainDepth(variable->scope()); |
1790 ContextScope* context = execution_context()->Previous(depth); | 1790 ContextScope* context = execution_context()->Previous(depth); |
1791 Register context_reg; | 1791 Register context_reg; |
1792 if (context) { | 1792 if (context) { |
1793 context_reg = context->reg(); | 1793 context_reg = context->reg(); |
1794 } else { | 1794 } else { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1857 VisitForAccumulatorValue(super_property->this_var()); | 1857 VisitForAccumulatorValue(super_property->this_var()); |
1858 builder()->StoreAccumulatorInRegister(super_args->receiver()); | 1858 builder()->StoreAccumulatorInRegister(super_args->receiver()); |
1859 VisitForAccumulatorValue(super_property->home_object()); | 1859 VisitForAccumulatorValue(super_property->home_object()); |
1860 builder()->StoreAccumulatorInRegister(super_args->home_object()); | 1860 builder()->StoreAccumulatorInRegister(super_args->home_object()); |
1861 VisitForAccumulatorValue(key); | 1861 VisitForAccumulatorValue(key); |
1862 builder()->StoreAccumulatorInRegister(super_args->name_or_key()); | 1862 builder()->StoreAccumulatorInRegister(super_args->name_or_key()); |
1863 } | 1863 } |
1864 | 1864 |
1865 void BytecodeGenerator::BuildNamedSuperPropertyLoad( | 1865 void BytecodeGenerator::BuildNamedSuperPropertyLoad( |
1866 SuperPropertyArguments* super_args) { | 1866 SuperPropertyArguments* super_args) { |
1867 builder() | 1867 // TODO(oth): Abstraction not suitable for 3 args, will over-allocate regs. |
1868 ->LoadLiteral(Smi::FromInt(static_cast<int>(language_mode()))) | 1868 builder()->CallRuntime(Runtime::kLoadFromSuper, super_args->receiver(), 3); |
1869 .StoreAccumulatorInRegister(super_args->language_mode()); | |
1870 builder()->CallRuntime(Runtime::kLoadFromSuper, super_args->receiver(), | |
1871 super_args->count()); | |
1872 } | 1869 } |
1873 | 1870 |
1874 void BytecodeGenerator::BuildKeyedSuperPropertyLoad( | 1871 void BytecodeGenerator::BuildKeyedSuperPropertyLoad( |
1875 SuperPropertyArguments* super_args) { | 1872 SuperPropertyArguments* super_args) { |
1876 builder() | 1873 // TODO(oth): Abstraction not suitable for 3 args, will over-allocate regs. |
1877 ->LoadLiteral(Smi::FromInt(static_cast<int>(language_mode()))) | |
1878 .StoreAccumulatorInRegister(super_args->language_mode()); | |
1879 builder()->CallRuntime(Runtime::kLoadKeyedFromSuper, super_args->receiver(), | 1874 builder()->CallRuntime(Runtime::kLoadKeyedFromSuper, super_args->receiver(), |
1880 super_args->count()); | 1875 3); |
1881 } | 1876 } |
1882 | 1877 |
1883 void BytecodeGenerator::BuildNamedSuperPropertyStore( | 1878 void BytecodeGenerator::BuildNamedSuperPropertyStore( |
1884 SuperPropertyArguments* super_args) { | 1879 SuperPropertyArguments* super_args) { |
1885 builder()->StoreAccumulatorInRegister(super_args->store_value()); | 1880 builder()->StoreAccumulatorInRegister(super_args->store_value()); |
1886 Runtime::FunctionId function_id = is_strict(language_mode()) | 1881 Runtime::FunctionId function_id = is_strict(language_mode()) |
1887 ? Runtime::kStoreToSuper_Strict | 1882 ? Runtime::kStoreToSuper_Strict |
1888 : Runtime::kStoreToSuper_Sloppy; | 1883 : Runtime::kStoreToSuper_Sloppy; |
1889 builder()->CallRuntime(function_id, super_args->receiver(), | 1884 builder()->CallRuntime(function_id, super_args->receiver(), |
1890 super_args->count()); | 1885 super_args->count()); |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2161 case VARIABLE: { | 2156 case VARIABLE: { |
2162 VariableProxy* proxy = expr->target()->AsVariableProxy(); | 2157 VariableProxy* proxy = expr->target()->AsVariableProxy(); |
2163 old_value = VisitVariableLoadForRegisterValue( | 2158 old_value = VisitVariableLoadForRegisterValue( |
2164 proxy->var(), proxy->VariableFeedbackSlot()); | 2159 proxy->var(), proxy->VariableFeedbackSlot()); |
2165 break; | 2160 break; |
2166 } | 2161 } |
2167 case NAMED_PROPERTY: { | 2162 case NAMED_PROPERTY: { |
2168 FeedbackVectorSlot slot = property->PropertyFeedbackSlot(); | 2163 FeedbackVectorSlot slot = property->PropertyFeedbackSlot(); |
2169 old_value = register_allocator()->NewRegister(); | 2164 old_value = register_allocator()->NewRegister(); |
2170 builder() | 2165 builder() |
2171 ->LoadNamedProperty(object, name, feedback_index(slot), | 2166 ->LoadNamedProperty(object, name, feedback_index(slot)) |
2172 language_mode()) | |
2173 .StoreAccumulatorInRegister(old_value); | 2167 .StoreAccumulatorInRegister(old_value); |
2174 break; | 2168 break; |
2175 } | 2169 } |
2176 case KEYED_PROPERTY: { | 2170 case KEYED_PROPERTY: { |
2177 // Key is already in accumulator at this point due to evaluating the | 2171 // Key is already in accumulator at this point due to evaluating the |
2178 // LHS above. | 2172 // LHS above. |
2179 FeedbackVectorSlot slot = property->PropertyFeedbackSlot(); | 2173 FeedbackVectorSlot slot = property->PropertyFeedbackSlot(); |
2180 old_value = register_allocator()->NewRegister(); | 2174 old_value = register_allocator()->NewRegister(); |
2181 builder() | 2175 builder() |
2182 ->LoadKeyedProperty(object, feedback_index(slot), language_mode()) | 2176 ->LoadKeyedProperty(object, feedback_index(slot)) |
2183 .StoreAccumulatorInRegister(old_value); | 2177 .StoreAccumulatorInRegister(old_value); |
2184 break; | 2178 break; |
2185 } | 2179 } |
2186 case NAMED_SUPER_PROPERTY: { | 2180 case NAMED_SUPER_PROPERTY: { |
2187 old_value = register_allocator()->NewRegister(); | 2181 old_value = register_allocator()->NewRegister(); |
2188 BuildNamedSuperPropertyLoad(&super_args); | 2182 BuildNamedSuperPropertyLoad(&super_args); |
2189 builder()->StoreAccumulatorInRegister(old_value); | 2183 builder()->StoreAccumulatorInRegister(old_value); |
2190 break; | 2184 break; |
2191 } | 2185 } |
2192 case KEYED_SUPER_PROPERTY: { | 2186 case KEYED_SUPER_PROPERTY: { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2249 | 2243 |
2250 void BytecodeGenerator::VisitPropertyLoad(Register obj, Property* expr) { | 2244 void BytecodeGenerator::VisitPropertyLoad(Register obj, Property* expr) { |
2251 LhsKind property_kind = Property::GetAssignType(expr); | 2245 LhsKind property_kind = Property::GetAssignType(expr); |
2252 FeedbackVectorSlot slot = expr->PropertyFeedbackSlot(); | 2246 FeedbackVectorSlot slot = expr->PropertyFeedbackSlot(); |
2253 switch (property_kind) { | 2247 switch (property_kind) { |
2254 case VARIABLE: | 2248 case VARIABLE: |
2255 UNREACHABLE(); | 2249 UNREACHABLE(); |
2256 case NAMED_PROPERTY: { | 2250 case NAMED_PROPERTY: { |
2257 builder()->LoadNamedProperty(obj, | 2251 builder()->LoadNamedProperty(obj, |
2258 expr->key()->AsLiteral()->AsPropertyName(), | 2252 expr->key()->AsLiteral()->AsPropertyName(), |
2259 feedback_index(slot), language_mode()); | 2253 feedback_index(slot)); |
2260 break; | 2254 break; |
2261 } | 2255 } |
2262 case KEYED_PROPERTY: { | 2256 case KEYED_PROPERTY: { |
2263 VisitForAccumulatorValue(expr->key()); | 2257 VisitForAccumulatorValue(expr->key()); |
2264 builder()->LoadKeyedProperty(obj, feedback_index(slot), language_mode()); | 2258 builder()->LoadKeyedProperty(obj, feedback_index(slot)); |
2265 break; | 2259 break; |
2266 } | 2260 } |
2267 case NAMED_SUPER_PROPERTY: | 2261 case NAMED_SUPER_PROPERTY: |
2268 VisitNamedSuperPropertyLoad(expr, Register::invalid_value()); | 2262 VisitNamedSuperPropertyLoad(expr, Register::invalid_value()); |
2269 break; | 2263 break; |
2270 case KEYED_SUPER_PROPERTY: | 2264 case KEYED_SUPER_PROPERTY: |
2271 VisitKeyedSuperPropertyLoad(expr, Register::invalid_value()); | 2265 VisitKeyedSuperPropertyLoad(expr, Register::invalid_value()); |
2272 break; | 2266 break; |
2273 } | 2267 } |
2274 execution_result()->SetResultInAccumulator(); | 2268 execution_result()->SetResultInAccumulator(); |
(...skipping 398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2673 case VARIABLE: { | 2667 case VARIABLE: { |
2674 VariableProxy* proxy = expr->expression()->AsVariableProxy(); | 2668 VariableProxy* proxy = expr->expression()->AsVariableProxy(); |
2675 VisitVariableLoadForAccumulatorValue(proxy->var(), | 2669 VisitVariableLoadForAccumulatorValue(proxy->var(), |
2676 proxy->VariableFeedbackSlot()); | 2670 proxy->VariableFeedbackSlot()); |
2677 break; | 2671 break; |
2678 } | 2672 } |
2679 case NAMED_PROPERTY: { | 2673 case NAMED_PROPERTY: { |
2680 FeedbackVectorSlot slot = property->PropertyFeedbackSlot(); | 2674 FeedbackVectorSlot slot = property->PropertyFeedbackSlot(); |
2681 object = VisitForRegisterValue(property->obj()); | 2675 object = VisitForRegisterValue(property->obj()); |
2682 name = property->key()->AsLiteral()->AsPropertyName(); | 2676 name = property->key()->AsLiteral()->AsPropertyName(); |
2683 builder()->LoadNamedProperty(object, name, feedback_index(slot), | 2677 builder()->LoadNamedProperty(object, name, feedback_index(slot)); |
2684 language_mode()); | |
2685 break; | 2678 break; |
2686 } | 2679 } |
2687 case KEYED_PROPERTY: { | 2680 case KEYED_PROPERTY: { |
2688 FeedbackVectorSlot slot = property->PropertyFeedbackSlot(); | 2681 FeedbackVectorSlot slot = property->PropertyFeedbackSlot(); |
2689 object = VisitForRegisterValue(property->obj()); | 2682 object = VisitForRegisterValue(property->obj()); |
2690 // Use visit for accumulator here since we need the key in the accumulator | 2683 // Use visit for accumulator here since we need the key in the accumulator |
2691 // for the LoadKeyedProperty. | 2684 // for the LoadKeyedProperty. |
2692 key = register_allocator()->NewRegister(); | 2685 key = register_allocator()->NewRegister(); |
2693 VisitForAccumulatorValue(property->key()); | 2686 VisitForAccumulatorValue(property->key()); |
2694 builder()->StoreAccumulatorInRegister(key).LoadKeyedProperty( | 2687 builder()->StoreAccumulatorInRegister(key).LoadKeyedProperty( |
2695 object, feedback_index(slot), language_mode()); | 2688 object, feedback_index(slot)); |
2696 break; | 2689 break; |
2697 } | 2690 } |
2698 case NAMED_SUPER_PROPERTY: { | 2691 case NAMED_SUPER_PROPERTY: { |
2699 PrepareNamedSuperPropertyArguments( | 2692 PrepareNamedSuperPropertyArguments( |
2700 property->obj()->AsSuperPropertyReference(), | 2693 property->obj()->AsSuperPropertyReference(), |
2701 property->key()->AsLiteral()->AsPropertyName(), &super_args); | 2694 property->key()->AsLiteral()->AsPropertyName(), &super_args); |
2702 BuildNamedSuperPropertyLoad(&super_args); | 2695 BuildNamedSuperPropertyLoad(&super_args); |
2703 break; | 2696 break; |
2704 } | 2697 } |
2705 case KEYED_SUPER_PROPERTY: { | 2698 case KEYED_SUPER_PROPERTY: { |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3118 } | 3111 } |
3119 | 3112 |
3120 | 3113 |
3121 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 3114 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
3122 return info()->feedback_vector()->GetIndex(slot); | 3115 return info()->feedback_vector()->GetIndex(slot); |
3123 } | 3116 } |
3124 | 3117 |
3125 } // namespace interpreter | 3118 } // namespace interpreter |
3126 } // namespace internal | 3119 } // namespace internal |
3127 } // namespace v8 | 3120 } // namespace v8 |
OLD | NEW |