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/compiler.h" | 7 #include "src/compiler.h" |
8 #include "src/interpreter/control-flow-builders.h" | 8 #include "src/interpreter/control-flow-builders.h" |
9 #include "src/objects.h" | 9 #include "src/objects.h" |
10 #include "src/parser.h" | 10 #include "src/parser.h" |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 | 489 |
490 | 490 |
491 void BytecodeGenerator::VisitIfStatement(IfStatement* stmt) { | 491 void BytecodeGenerator::VisitIfStatement(IfStatement* stmt) { |
492 // TODO(oth): Spot easy cases where there code would not need to | 492 // TODO(oth): Spot easy cases where there code would not need to |
493 // emit the then block or the else block, e.g. condition is | 493 // emit the then block or the else block, e.g. condition is |
494 // obviously true/1/false/0. | 494 // obviously true/1/false/0. |
495 | 495 |
496 BytecodeLabel else_label, end_label; | 496 BytecodeLabel else_label, end_label; |
497 | 497 |
498 VisitForAccumulatorValue(stmt->condition()); | 498 VisitForAccumulatorValue(stmt->condition()); |
499 builder()->CastAccumulatorToBoolean(); | |
500 builder()->JumpIfFalse(&else_label); | 499 builder()->JumpIfFalse(&else_label); |
501 Visit(stmt->then_statement()); | 500 Visit(stmt->then_statement()); |
502 if (stmt->HasElseStatement()) { | 501 if (stmt->HasElseStatement()) { |
503 builder()->Jump(&end_label); | 502 builder()->Jump(&end_label); |
504 builder()->Bind(&else_label); | 503 builder()->Bind(&else_label); |
505 Visit(stmt->else_statement()); | 504 Visit(stmt->else_statement()); |
506 } else { | 505 } else { |
507 builder()->Bind(&else_label); | 506 builder()->Bind(&else_label); |
508 } | 507 } |
509 builder()->Bind(&end_label); | 508 builder()->Bind(&end_label); |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 | 785 |
787 | 786 |
788 void BytecodeGenerator::VisitConditional(Conditional* expr) { | 787 void BytecodeGenerator::VisitConditional(Conditional* expr) { |
789 // TODO(rmcilroy): Spot easy cases where there code would not need to | 788 // TODO(rmcilroy): Spot easy cases where there code would not need to |
790 // emit the then block or the else block, e.g. condition is | 789 // emit the then block or the else block, e.g. condition is |
791 // obviously true/1/false/0. | 790 // obviously true/1/false/0. |
792 | 791 |
793 BytecodeLabel else_label, end_label; | 792 BytecodeLabel else_label, end_label; |
794 | 793 |
795 VisitForAccumulatorValue(expr->condition()); | 794 VisitForAccumulatorValue(expr->condition()); |
796 builder()->CastAccumulatorToBoolean(); | |
797 builder()->JumpIfFalse(&else_label); | 795 builder()->JumpIfFalse(&else_label); |
798 | 796 |
799 VisitForAccumulatorValue(expr->then_expression()); | 797 VisitForAccumulatorValue(expr->then_expression()); |
800 builder()->Jump(&end_label); | 798 builder()->Jump(&end_label); |
801 | 799 |
802 builder()->Bind(&else_label); | 800 builder()->Bind(&else_label); |
803 VisitForAccumulatorValue(expr->else_expression()); | 801 VisitForAccumulatorValue(expr->else_expression()); |
804 builder()->Bind(&end_label); | 802 builder()->Bind(&end_label); |
805 | 803 |
806 execution_result()->SetResultInAccumulator(); | 804 execution_result()->SetResultInAccumulator(); |
(...skipping 979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1786 Expression* left = binop->left(); | 1784 Expression* left = binop->left(); |
1787 Expression* right = binop->right(); | 1785 Expression* right = binop->right(); |
1788 | 1786 |
1789 // Short-circuit evaluation- If it is known that left is always true, | 1787 // Short-circuit evaluation- If it is known that left is always true, |
1790 // no need to visit right | 1788 // no need to visit right |
1791 if (left->ToBooleanIsTrue()) { | 1789 if (left->ToBooleanIsTrue()) { |
1792 VisitForAccumulatorValue(left); | 1790 VisitForAccumulatorValue(left); |
1793 } else { | 1791 } else { |
1794 BytecodeLabel end_label; | 1792 BytecodeLabel end_label; |
1795 VisitForAccumulatorValue(left); | 1793 VisitForAccumulatorValue(left); |
1796 builder()->JumpIfToBooleanTrue(&end_label); | 1794 builder()->JumpIfTrue(&end_label); |
1797 VisitForAccumulatorValue(right); | 1795 VisitForAccumulatorValue(right); |
1798 builder()->Bind(&end_label); | 1796 builder()->Bind(&end_label); |
1799 } | 1797 } |
1800 execution_result()->SetResultInAccumulator(); | 1798 execution_result()->SetResultInAccumulator(); |
1801 } | 1799 } |
1802 | 1800 |
1803 | 1801 |
1804 void BytecodeGenerator::VisitLogicalAndExpression(BinaryOperation* binop) { | 1802 void BytecodeGenerator::VisitLogicalAndExpression(BinaryOperation* binop) { |
1805 Expression* left = binop->left(); | 1803 Expression* left = binop->left(); |
1806 Expression* right = binop->right(); | 1804 Expression* right = binop->right(); |
1807 | 1805 |
1808 // Short-circuit evaluation- If it is known that left is always false, | 1806 // Short-circuit evaluation- If it is known that left is always false, |
1809 // no need to visit right | 1807 // no need to visit right |
1810 if (left->ToBooleanIsFalse()) { | 1808 if (left->ToBooleanIsFalse()) { |
1811 VisitForAccumulatorValue(left); | 1809 VisitForAccumulatorValue(left); |
1812 } else { | 1810 } else { |
1813 BytecodeLabel end_label; | 1811 BytecodeLabel end_label; |
1814 VisitForAccumulatorValue(left); | 1812 VisitForAccumulatorValue(left); |
1815 builder()->JumpIfToBooleanFalse(&end_label); | 1813 builder()->JumpIfFalse(&end_label); |
1816 VisitForAccumulatorValue(right); | 1814 VisitForAccumulatorValue(right); |
1817 builder()->Bind(&end_label); | 1815 builder()->Bind(&end_label); |
1818 } | 1816 } |
1819 execution_result()->SetResultInAccumulator(); | 1817 execution_result()->SetResultInAccumulator(); |
1820 } | 1818 } |
1821 | 1819 |
1822 | 1820 |
1823 void BytecodeGenerator::VisitNewLocalFunctionContext() { | 1821 void BytecodeGenerator::VisitNewLocalFunctionContext() { |
1824 AccumulatorResultScope accumulator_execution_result(this); | 1822 AccumulatorResultScope accumulator_execution_result(this); |
1825 Scope* scope = this->scope(); | 1823 Scope* scope = this->scope(); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2055 } | 2053 } |
2056 | 2054 |
2057 | 2055 |
2058 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 2056 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
2059 return info()->feedback_vector()->GetIndex(slot); | 2057 return info()->feedback_vector()->GetIndex(slot); |
2060 } | 2058 } |
2061 | 2059 |
2062 } // namespace interpreter | 2060 } // namespace interpreter |
2063 } // namespace internal | 2061 } // namespace internal |
2064 } // namespace v8 | 2062 } // namespace v8 |
OLD | NEW |