| 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/code-stubs.h" | 8 #include "src/code-stubs.h" |
| 9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
| 10 #include "src/interpreter/bytecode-flags.h" | 10 #include "src/interpreter/bytecode-flags.h" |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 info->SourcePositionRecordingMode())), | 542 info->SourcePositionRecordingMode())), |
| 543 info_(info), | 543 info_(info), |
| 544 scope_(info->scope()), | 544 scope_(info->scope()), |
| 545 globals_(0, info->zone()), | 545 globals_(0, info->zone()), |
| 546 execution_control_(nullptr), | 546 execution_control_(nullptr), |
| 547 execution_context_(nullptr), | 547 execution_context_(nullptr), |
| 548 execution_result_(nullptr), | 548 execution_result_(nullptr), |
| 549 register_allocator_(nullptr), | 549 register_allocator_(nullptr), |
| 550 generator_resume_points_(info->literal()->yield_count(), info->zone()), | 550 generator_resume_points_(info->literal()->yield_count(), info->zone()), |
| 551 generator_state_() { | 551 generator_state_() { |
| 552 InitializeAstVisitor(isolate()); | 552 InitializeAstVisitor(isolate()->stack_guard()->real_climit()); |
| 553 } | 553 } |
| 554 | 554 |
| 555 Handle<BytecodeArray> BytecodeGenerator::MakeBytecode() { | 555 Handle<BytecodeArray> BytecodeGenerator::MakeBytecode() { |
| 556 // Initialize the incoming context. | 556 // Initialize the incoming context. |
| 557 ContextScope incoming_context(this, scope(), false); | 557 ContextScope incoming_context(this, scope(), false); |
| 558 | 558 |
| 559 // Initialize control scope. | 559 // Initialize control scope. |
| 560 ControlScopeForTopLevel control(this); | 560 ControlScopeForTopLevel control(this); |
| 561 | 561 |
| 562 RegisterAllocationScope register_scope(this); | 562 RegisterAllocationScope register_scope(this); |
| (...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1478 | 1478 |
| 1479 builder()->Bind(&else_label); | 1479 builder()->Bind(&else_label); |
| 1480 VisitForAccumulatorValue(expr->else_expression()); | 1480 VisitForAccumulatorValue(expr->else_expression()); |
| 1481 builder()->Bind(&end_label); | 1481 builder()->Bind(&end_label); |
| 1482 | 1482 |
| 1483 execution_result()->SetResultInAccumulator(); | 1483 execution_result()->SetResultInAccumulator(); |
| 1484 } | 1484 } |
| 1485 | 1485 |
| 1486 void BytecodeGenerator::VisitLiteral(Literal* expr) { | 1486 void BytecodeGenerator::VisitLiteral(Literal* expr) { |
| 1487 if (!execution_result()->IsEffect()) { | 1487 if (!execution_result()->IsEffect()) { |
| 1488 Handle<Object> value = expr->value(); | 1488 const AstValue* raw_value = expr->raw_value(); |
| 1489 if (value->IsSmi()) { | 1489 if (raw_value->IsSmi()) { |
| 1490 builder()->LoadLiteral(Smi::cast(*value)); | 1490 builder()->LoadLiteral(raw_value->AsSmi()); |
| 1491 } else if (value->IsUndefined(isolate())) { | 1491 } else if (raw_value->IsUndefined()) { |
| 1492 builder()->LoadUndefined(); | 1492 builder()->LoadUndefined(); |
| 1493 } else if (value->IsTrue(isolate())) { | 1493 } else if (raw_value->IsTrue()) { |
| 1494 builder()->LoadTrue(); | 1494 builder()->LoadTrue(); |
| 1495 } else if (value->IsFalse(isolate())) { | 1495 } else if (raw_value->IsFalse()) { |
| 1496 builder()->LoadFalse(); | 1496 builder()->LoadFalse(); |
| 1497 } else if (value->IsNull(isolate())) { | 1497 } else if (raw_value->IsNull()) { |
| 1498 builder()->LoadNull(); | 1498 builder()->LoadNull(); |
| 1499 } else if (value->IsTheHole(isolate())) { | 1499 } else if (raw_value->IsTheHole()) { |
| 1500 builder()->LoadTheHole(); | 1500 builder()->LoadTheHole(); |
| 1501 } else { | 1501 } else { |
| 1502 builder()->LoadLiteral(value); | 1502 builder()->LoadLiteral(raw_value->value()); |
| 1503 } | 1503 } |
| 1504 execution_result()->SetResultInAccumulator(); | 1504 execution_result()->SetResultInAccumulator(); |
| 1505 } | 1505 } |
| 1506 } | 1506 } |
| 1507 | 1507 |
| 1508 void BytecodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) { | 1508 void BytecodeGenerator::VisitRegExpLiteral(RegExpLiteral* expr) { |
| 1509 // Materialize a regular expression literal. | 1509 // Materialize a regular expression literal. |
| 1510 builder()->CreateRegExpLiteral(expr->pattern(), expr->literal_index(), | 1510 builder()->CreateRegExpLiteral(expr->pattern(), expr->literal_index(), |
| 1511 expr->flags()); | 1511 expr->flags()); |
| 1512 execution_result()->SetResultInAccumulator(); | 1512 execution_result()->SetResultInAccumulator(); |
| (...skipping 1342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2855 | 2855 |
| 2856 void BytecodeGenerator::VisitCompareOperation(CompareOperation* expr) { | 2856 void BytecodeGenerator::VisitCompareOperation(CompareOperation* expr) { |
| 2857 Register lhs = VisitForRegisterValue(expr->left()); | 2857 Register lhs = VisitForRegisterValue(expr->left()); |
| 2858 VisitForAccumulatorValue(expr->right()); | 2858 VisitForAccumulatorValue(expr->right()); |
| 2859 builder()->SetExpressionPosition(expr); | 2859 builder()->SetExpressionPosition(expr); |
| 2860 builder()->CompareOperation(expr->op(), lhs); | 2860 builder()->CompareOperation(expr->op(), lhs); |
| 2861 execution_result()->SetResultInAccumulator(); | 2861 execution_result()->SetResultInAccumulator(); |
| 2862 } | 2862 } |
| 2863 | 2863 |
| 2864 void BytecodeGenerator::VisitArithmeticExpression(BinaryOperation* expr) { | 2864 void BytecodeGenerator::VisitArithmeticExpression(BinaryOperation* expr) { |
| 2865 // TODO(rmcilroy): Special case "x * 1.0" and "x * -1" which are generated for |
| 2866 // +x and -x by the parser. |
| 2865 Register lhs = VisitForRegisterValue(expr->left()); | 2867 Register lhs = VisitForRegisterValue(expr->left()); |
| 2866 VisitForAccumulatorValue(expr->right()); | 2868 VisitForAccumulatorValue(expr->right()); |
| 2867 builder()->BinaryOperation(expr->op(), lhs); | 2869 builder()->BinaryOperation(expr->op(), lhs); |
| 2868 execution_result()->SetResultInAccumulator(); | 2870 execution_result()->SetResultInAccumulator(); |
| 2869 } | 2871 } |
| 2870 | 2872 |
| 2871 void BytecodeGenerator::VisitSpread(Spread* expr) { UNREACHABLE(); } | 2873 void BytecodeGenerator::VisitSpread(Spread* expr) { UNREACHABLE(); } |
| 2872 | 2874 |
| 2873 void BytecodeGenerator::VisitEmptyParentheses(EmptyParentheses* expr) { | 2875 void BytecodeGenerator::VisitEmptyParentheses(EmptyParentheses* expr) { |
| 2874 UNREACHABLE(); | 2876 UNREACHABLE(); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3178 return execution_context()->scope()->language_mode(); | 3180 return execution_context()->scope()->language_mode(); |
| 3179 } | 3181 } |
| 3180 | 3182 |
| 3181 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 3183 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
| 3182 return TypeFeedbackVector::GetIndex(slot); | 3184 return TypeFeedbackVector::GetIndex(slot); |
| 3183 } | 3185 } |
| 3184 | 3186 |
| 3185 } // namespace interpreter | 3187 } // namespace interpreter |
| 3186 } // namespace internal | 3188 } // namespace internal |
| 3187 } // namespace v8 | 3189 } // namespace v8 |
| OLD | NEW |