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 965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 | 976 |
977 void BytecodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { | 977 void BytecodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { |
978 builder()->SetStatementPosition(stmt); | 978 builder()->SetStatementPosition(stmt); |
979 VisitForAccumulatorValue(stmt->expression()); | 979 VisitForAccumulatorValue(stmt->expression()); |
980 execution_control()->ReturnAccumulator(); | 980 execution_control()->ReturnAccumulator(); |
981 } | 981 } |
982 | 982 |
983 void BytecodeGenerator::VisitWithStatement(WithStatement* stmt) { | 983 void BytecodeGenerator::VisitWithStatement(WithStatement* stmt) { |
984 builder()->SetStatementPosition(stmt); | 984 builder()->SetStatementPosition(stmt); |
985 VisitForAccumulatorValue(stmt->expression()); | 985 VisitForAccumulatorValue(stmt->expression()); |
986 builder()->CastAccumulatorToJSObject(); | |
987 VisitNewLocalWithContext(); | 986 VisitNewLocalWithContext(); |
988 VisitInScope(stmt->statement(), stmt->scope()); | 987 VisitInScope(stmt->statement(), stmt->scope()); |
989 } | 988 } |
990 | 989 |
991 void BytecodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { | 990 void BytecodeGenerator::VisitSwitchStatement(SwitchStatement* stmt) { |
992 // We need this scope because we visit for register values. We have to | 991 // We need this scope because we visit for register values. We have to |
993 // maintain a execution result scope where registers can be allocated. | 992 // maintain a execution result scope where registers can be allocated. |
994 ZoneList<CaseClause*>* clauses = stmt->cases(); | 993 ZoneList<CaseClause*>* clauses = stmt->cases(); |
995 SwitchBuilder switch_builder(builder(), clauses->length()); | 994 SwitchBuilder switch_builder(builder(), clauses->length()); |
996 ControlScopeForBreakable scope(this, stmt, &switch_builder); | 995 ControlScopeForBreakable scope(this, stmt, &switch_builder); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1194 | 1193 |
1195 LoopBuilder loop_builder(builder()); | 1194 LoopBuilder loop_builder(builder()); |
1196 BytecodeLabel subject_null_label, subject_undefined_label; | 1195 BytecodeLabel subject_null_label, subject_undefined_label; |
1197 | 1196 |
1198 // Prepare the state for executing ForIn. | 1197 // Prepare the state for executing ForIn. |
1199 builder()->SetExpressionAsStatementPosition(stmt->subject()); | 1198 builder()->SetExpressionAsStatementPosition(stmt->subject()); |
1200 VisitForAccumulatorValue(stmt->subject()); | 1199 VisitForAccumulatorValue(stmt->subject()); |
1201 builder()->JumpIfUndefined(&subject_undefined_label); | 1200 builder()->JumpIfUndefined(&subject_undefined_label); |
1202 builder()->JumpIfNull(&subject_null_label); | 1201 builder()->JumpIfNull(&subject_null_label); |
1203 Register receiver = register_allocator()->NewRegister(); | 1202 Register receiver = register_allocator()->NewRegister(); |
1204 builder()->CastAccumulatorToJSObject(); | 1203 builder()->CastAccumulatorToJSObject(receiver); |
1205 builder()->StoreAccumulatorInRegister(receiver); | |
1206 | 1204 |
1207 register_allocator()->PrepareForConsecutiveAllocations(3); | 1205 register_allocator()->PrepareForConsecutiveAllocations(3); |
1208 Register cache_type = register_allocator()->NextConsecutiveRegister(); | 1206 Register cache_type = register_allocator()->NextConsecutiveRegister(); |
1209 Register cache_array = register_allocator()->NextConsecutiveRegister(); | 1207 Register cache_array = register_allocator()->NextConsecutiveRegister(); |
1210 Register cache_length = register_allocator()->NextConsecutiveRegister(); | 1208 Register cache_length = register_allocator()->NextConsecutiveRegister(); |
1211 // Used as kRegTriple and kRegPair in ForInPrepare and ForInNext. | 1209 // Used as kRegTriple and kRegPair in ForInPrepare and ForInNext. |
1212 USE(cache_array); | 1210 USE(cache_array); |
1213 builder()->ForInPrepare(cache_type); | 1211 builder()->ForInPrepare(receiver, cache_type); |
1214 | 1212 |
1215 // Set up loop counter | 1213 // Set up loop counter |
1216 Register index = register_allocator()->NewRegister(); | 1214 Register index = register_allocator()->NewRegister(); |
1217 builder()->LoadLiteral(Smi::FromInt(0)); | 1215 builder()->LoadLiteral(Smi::FromInt(0)); |
1218 builder()->StoreAccumulatorInRegister(index); | 1216 builder()->StoreAccumulatorInRegister(index); |
1219 | 1217 |
1220 // The loop | 1218 // The loop |
1221 VisitIterationHeader(stmt, &loop_builder); | 1219 VisitIterationHeader(stmt, &loop_builder); |
1222 builder()->SetExpressionAsStatementPosition(stmt->each()); | 1220 builder()->SetExpressionAsStatementPosition(stmt->each()); |
1223 builder()->ForInDone(index, cache_length); | 1221 builder()->ForInDone(index, cache_length); |
(...skipping 1840 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3064 execution_result()->SetResultInAccumulator(); | 3062 execution_result()->SetResultInAccumulator(); |
3065 } | 3063 } |
3066 | 3064 |
3067 void BytecodeGenerator::VisitNewLocalWithContext() { | 3065 void BytecodeGenerator::VisitNewLocalWithContext() { |
3068 AccumulatorResultScope accumulator_execution_result(this); | 3066 AccumulatorResultScope accumulator_execution_result(this); |
3069 | 3067 |
3070 register_allocator()->PrepareForConsecutiveAllocations(2); | 3068 register_allocator()->PrepareForConsecutiveAllocations(2); |
3071 Register extension_object = register_allocator()->NextConsecutiveRegister(); | 3069 Register extension_object = register_allocator()->NextConsecutiveRegister(); |
3072 Register closure = register_allocator()->NextConsecutiveRegister(); | 3070 Register closure = register_allocator()->NextConsecutiveRegister(); |
3073 | 3071 |
3074 builder()->StoreAccumulatorInRegister(extension_object); | 3072 builder()->CastAccumulatorToJSObject(extension_object); |
3075 VisitFunctionClosureForContext(); | 3073 VisitFunctionClosureForContext(); |
3076 builder()->StoreAccumulatorInRegister(closure).CallRuntime( | 3074 builder()->StoreAccumulatorInRegister(closure).CallRuntime( |
3077 Runtime::kPushWithContext, extension_object, 2); | 3075 Runtime::kPushWithContext, extension_object, 2); |
3078 execution_result()->SetResultInAccumulator(); | 3076 execution_result()->SetResultInAccumulator(); |
3079 } | 3077 } |
3080 | 3078 |
3081 void BytecodeGenerator::VisitNewLocalCatchContext(Variable* variable) { | 3079 void BytecodeGenerator::VisitNewLocalCatchContext(Variable* variable) { |
3082 AccumulatorResultScope accumulator_execution_result(this); | 3080 AccumulatorResultScope accumulator_execution_result(this); |
3083 DCHECK(variable->IsContextSlot()); | 3081 DCHECK(variable->IsContextSlot()); |
3084 | 3082 |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3238 return execution_context()->scope()->language_mode(); | 3236 return execution_context()->scope()->language_mode(); |
3239 } | 3237 } |
3240 | 3238 |
3241 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 3239 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
3242 return TypeFeedbackVector::GetIndex(slot); | 3240 return TypeFeedbackVector::GetIndex(slot); |
3243 } | 3241 } |
3244 | 3242 |
3245 } // namespace interpreter | 3243 } // namespace interpreter |
3246 } // namespace internal | 3244 } // namespace internal |
3247 } // namespace v8 | 3245 } // namespace v8 |
OLD | NEW |