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 1737 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1748 | 1748 |
1749 if (!literal_in_accumulator) { | 1749 if (!literal_in_accumulator) { |
1750 // Restore literal array into accumulator. | 1750 // Restore literal array into accumulator. |
1751 builder()->LoadAccumulatorWithRegister(literal); | 1751 builder()->LoadAccumulatorWithRegister(literal); |
1752 } | 1752 } |
1753 execution_result()->SetResultInAccumulator(); | 1753 execution_result()->SetResultInAccumulator(); |
1754 } | 1754 } |
1755 | 1755 |
1756 | 1756 |
1757 void BytecodeGenerator::VisitVariableProxy(VariableProxy* proxy) { | 1757 void BytecodeGenerator::VisitVariableProxy(VariableProxy* proxy) { |
| 1758 builder()->SetExpressionPosition(proxy); |
1758 VisitVariableLoad(proxy->var(), proxy->VariableFeedbackSlot()); | 1759 VisitVariableLoad(proxy->var(), proxy->VariableFeedbackSlot()); |
1759 } | 1760 } |
1760 | 1761 |
1761 void BytecodeGenerator::BuildHoleCheckForVariableLoad(VariableMode mode, | 1762 void BytecodeGenerator::BuildHoleCheckForVariableLoad(VariableMode mode, |
1762 Handle<String> name) { | 1763 Handle<String> name) { |
1763 if (mode == CONST_LEGACY) { | 1764 if (mode == CONST_LEGACY) { |
1764 BytecodeLabel end_label; | 1765 BytecodeLabel end_label; |
1765 builder()->JumpIfNotHole(&end_label).LoadUndefined().Bind(&end_label); | 1766 builder()->JumpIfNotHole(&end_label).LoadUndefined().Bind(&end_label); |
1766 } else if (mode == LET || mode == CONST) { | 1767 } else if (mode == LET || mode == CONST) { |
1767 BuildThrowIfHole(name); | 1768 BuildThrowIfHole(name); |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2192 break; | 2193 break; |
2193 } | 2194 } |
2194 } | 2195 } |
2195 VisitForAccumulatorValue(expr->value()); | 2196 VisitForAccumulatorValue(expr->value()); |
2196 builder()->BinaryOperation(expr->binary_op(), old_value); | 2197 builder()->BinaryOperation(expr->binary_op(), old_value); |
2197 } else { | 2198 } else { |
2198 VisitForAccumulatorValue(expr->value()); | 2199 VisitForAccumulatorValue(expr->value()); |
2199 } | 2200 } |
2200 | 2201 |
2201 // Store the value. | 2202 // Store the value. |
| 2203 builder()->SetExpressionPosition(expr); |
2202 FeedbackVectorSlot slot = expr->AssignmentSlot(); | 2204 FeedbackVectorSlot slot = expr->AssignmentSlot(); |
2203 switch (assign_type) { | 2205 switch (assign_type) { |
2204 case VARIABLE: { | 2206 case VARIABLE: { |
2205 // TODO(oth): The VisitVariableAssignment() call is hard to reason about. | 2207 // TODO(oth): The VisitVariableAssignment() call is hard to reason about. |
2206 // Is the value in the accumulator safe? Yes, but scary. | 2208 // Is the value in the accumulator safe? Yes, but scary. |
2207 Variable* variable = expr->target()->AsVariableProxy()->var(); | 2209 Variable* variable = expr->target()->AsVariableProxy()->var(); |
2208 VisitVariableAssignment(variable, expr->op(), slot); | 2210 VisitVariableAssignment(variable, expr->op(), slot); |
2209 break; | 2211 break; |
2210 } | 2212 } |
2211 case NAMED_PROPERTY: | 2213 case NAMED_PROPERTY: |
(...skipping 17 matching lines...) Expand all Loading... |
2229 } | 2231 } |
2230 execution_result()->SetResultInAccumulator(); | 2232 execution_result()->SetResultInAccumulator(); |
2231 } | 2233 } |
2232 | 2234 |
2233 | 2235 |
2234 void BytecodeGenerator::VisitYield(Yield* expr) { UNIMPLEMENTED(); } | 2236 void BytecodeGenerator::VisitYield(Yield* expr) { UNIMPLEMENTED(); } |
2235 | 2237 |
2236 | 2238 |
2237 void BytecodeGenerator::VisitThrow(Throw* expr) { | 2239 void BytecodeGenerator::VisitThrow(Throw* expr) { |
2238 VisitForAccumulatorValue(expr->exception()); | 2240 VisitForAccumulatorValue(expr->exception()); |
| 2241 builder()->SetExpressionPosition(expr); |
2239 builder()->Throw(); | 2242 builder()->Throw(); |
2240 // Throw statments are modeled as expression instead of statments. These are | 2243 // Throw statments are modeled as expression instead of statments. These are |
2241 // converted from assignment statements in Rewriter::ReWrite pass. An | 2244 // converted from assignment statements in Rewriter::ReWrite pass. An |
2242 // assignment statement expects a value in the accumulator. This is a hack to | 2245 // assignment statement expects a value in the accumulator. This is a hack to |
2243 // avoid DCHECK fails assert accumulator has been set. | 2246 // avoid DCHECK fails assert accumulator has been set. |
2244 execution_result()->SetResultInAccumulator(); | 2247 execution_result()->SetResultInAccumulator(); |
2245 } | 2248 } |
2246 | 2249 |
2247 | 2250 |
2248 void BytecodeGenerator::VisitPropertyLoad(Register obj, Property* expr) { | 2251 void BytecodeGenerator::VisitPropertyLoad(Register obj, Property* expr) { |
2249 LhsKind property_kind = Property::GetAssignType(expr); | 2252 LhsKind property_kind = Property::GetAssignType(expr); |
2250 FeedbackVectorSlot slot = expr->PropertyFeedbackSlot(); | 2253 FeedbackVectorSlot slot = expr->PropertyFeedbackSlot(); |
| 2254 builder()->SetExpressionPosition(expr); |
2251 switch (property_kind) { | 2255 switch (property_kind) { |
2252 case VARIABLE: | 2256 case VARIABLE: |
2253 UNREACHABLE(); | 2257 UNREACHABLE(); |
2254 case NAMED_PROPERTY: { | 2258 case NAMED_PROPERTY: { |
2255 builder()->LoadNamedProperty(obj, | 2259 builder()->LoadNamedProperty(obj, |
2256 expr->key()->AsLiteral()->AsPropertyName(), | 2260 expr->key()->AsLiteral()->AsPropertyName(), |
2257 feedback_index(slot)); | 2261 feedback_index(slot)); |
2258 break; | 2262 break; |
2259 } | 2263 } |
2260 case KEYED_PROPERTY: { | 2264 case KEYED_PROPERTY: { |
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2749 // Save result for postfix expressions. | 2753 // Save result for postfix expressions. |
2750 if (is_postfix) { | 2754 if (is_postfix) { |
2751 old_value = register_allocator()->outer()->NewRegister(); | 2755 old_value = register_allocator()->outer()->NewRegister(); |
2752 builder()->StoreAccumulatorInRegister(old_value); | 2756 builder()->StoreAccumulatorInRegister(old_value); |
2753 } | 2757 } |
2754 | 2758 |
2755 // Perform +1/-1 operation. | 2759 // Perform +1/-1 operation. |
2756 builder()->CountOperation(expr->binary_op()); | 2760 builder()->CountOperation(expr->binary_op()); |
2757 | 2761 |
2758 // Store the value. | 2762 // Store the value. |
| 2763 builder()->SetExpressionPosition(expr); |
2759 FeedbackVectorSlot feedback_slot = expr->CountSlot(); | 2764 FeedbackVectorSlot feedback_slot = expr->CountSlot(); |
2760 switch (assign_type) { | 2765 switch (assign_type) { |
2761 case VARIABLE: { | 2766 case VARIABLE: { |
2762 Variable* variable = expr->expression()->AsVariableProxy()->var(); | 2767 Variable* variable = expr->expression()->AsVariableProxy()->var(); |
2763 VisitVariableAssignment(variable, expr->op(), feedback_slot); | 2768 VisitVariableAssignment(variable, expr->op(), feedback_slot); |
2764 break; | 2769 break; |
2765 } | 2770 } |
2766 case NAMED_PROPERTY: { | 2771 case NAMED_PROPERTY: { |
2767 builder()->StoreNamedProperty(object, name, feedback_index(feedback_slot), | 2772 builder()->StoreNamedProperty(object, name, feedback_index(feedback_slot), |
2768 language_mode()); | 2773 language_mode()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2808 default: | 2813 default: |
2809 VisitArithmeticExpression(binop); | 2814 VisitArithmeticExpression(binop); |
2810 break; | 2815 break; |
2811 } | 2816 } |
2812 } | 2817 } |
2813 | 2818 |
2814 | 2819 |
2815 void BytecodeGenerator::VisitCompareOperation(CompareOperation* expr) { | 2820 void BytecodeGenerator::VisitCompareOperation(CompareOperation* expr) { |
2816 Register lhs = VisitForRegisterValue(expr->left()); | 2821 Register lhs = VisitForRegisterValue(expr->left()); |
2817 VisitForAccumulatorValue(expr->right()); | 2822 VisitForAccumulatorValue(expr->right()); |
| 2823 builder()->SetExpressionPosition(expr); |
2818 builder()->CompareOperation(expr->op(), lhs); | 2824 builder()->CompareOperation(expr->op(), lhs); |
2819 execution_result()->SetResultInAccumulator(); | 2825 execution_result()->SetResultInAccumulator(); |
2820 } | 2826 } |
2821 | 2827 |
2822 | 2828 |
2823 void BytecodeGenerator::VisitArithmeticExpression(BinaryOperation* expr) { | 2829 void BytecodeGenerator::VisitArithmeticExpression(BinaryOperation* expr) { |
2824 Register lhs = VisitForRegisterValue(expr->left()); | 2830 Register lhs = VisitForRegisterValue(expr->left()); |
2825 VisitForAccumulatorValue(expr->right()); | 2831 VisitForAccumulatorValue(expr->right()); |
2826 builder()->BinaryOperation(expr->op(), lhs); | 2832 builder()->BinaryOperation(expr->op(), lhs); |
2827 execution_result()->SetResultInAccumulator(); | 2833 execution_result()->SetResultInAccumulator(); |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3157 } | 3163 } |
3158 | 3164 |
3159 | 3165 |
3160 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 3166 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
3161 return info()->feedback_vector()->GetIndex(slot); | 3167 return info()->feedback_vector()->GetIndex(slot); |
3162 } | 3168 } |
3163 | 3169 |
3164 } // namespace interpreter | 3170 } // namespace interpreter |
3165 } // namespace internal | 3171 } // namespace internal |
3166 } // namespace v8 | 3172 } // namespace v8 |
OLD | NEW |