| 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 <stack> | 7 #include <stack> |
| 8 | 8 |
| 9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
| 10 #include "src/objects.h" | 10 #include "src/objects.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 BytecodeGenerator::~BytecodeGenerator() {} | 24 BytecodeGenerator::~BytecodeGenerator() {} |
| 25 | 25 |
| 26 | 26 |
| 27 Handle<BytecodeArray> BytecodeGenerator::MakeBytecode(CompilationInfo* info) { | 27 Handle<BytecodeArray> BytecodeGenerator::MakeBytecode(CompilationInfo* info) { |
| 28 set_scope(info->scope()); | 28 set_scope(info->scope()); |
| 29 | 29 |
| 30 // This a temporary guard (oth). | 30 // This a temporary guard (oth). |
| 31 DCHECK(scope()->is_function_scope()); | 31 DCHECK(scope()->is_function_scope()); |
| 32 | 32 |
| 33 builder().set_parameter_count(info->num_parameters_including_this()); |
| 33 builder().set_locals_count(scope()->num_stack_slots()); | 34 builder().set_locals_count(scope()->num_stack_slots()); |
| 34 | 35 |
| 35 // Visit implicit declaration of the function name. | 36 // Visit implicit declaration of the function name. |
| 36 if (scope()->is_function_scope() && scope()->function() != NULL) { | 37 if (scope()->is_function_scope() && scope()->function() != NULL) { |
| 37 VisitVariableDeclaration(scope()->function()); | 38 VisitVariableDeclaration(scope()->function()); |
| 38 } | 39 } |
| 39 | 40 |
| 40 // Visit declarations within the function scope. | 41 // Visit declarations within the function scope. |
| 41 VisitDeclarations(scope()->declarations()); | 42 VisitDeclarations(scope()->declarations()); |
| 42 | 43 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 65 | 66 |
| 66 | 67 |
| 67 void BytecodeGenerator::VisitVariableDeclaration(VariableDeclaration* decl) { | 68 void BytecodeGenerator::VisitVariableDeclaration(VariableDeclaration* decl) { |
| 68 Variable* variable = decl->proxy()->var(); | 69 Variable* variable = decl->proxy()->var(); |
| 69 switch (variable->location()) { | 70 switch (variable->location()) { |
| 70 case VariableLocation::GLOBAL: | 71 case VariableLocation::GLOBAL: |
| 71 case VariableLocation::UNALLOCATED: | 72 case VariableLocation::UNALLOCATED: |
| 72 UNIMPLEMENTED(); | 73 UNIMPLEMENTED(); |
| 73 break; | 74 break; |
| 74 case VariableLocation::PARAMETER: | 75 case VariableLocation::PARAMETER: |
| 75 UNIMPLEMENTED(); | |
| 76 break; | |
| 77 case VariableLocation::LOCAL: | 76 case VariableLocation::LOCAL: |
| 78 // Details stored in scope, i.e. variable index. | 77 // Details stored in scope, i.e. variable index. |
| 79 break; | 78 break; |
| 80 case VariableLocation::CONTEXT: | 79 case VariableLocation::CONTEXT: |
| 81 case VariableLocation::LOOKUP: | 80 case VariableLocation::LOOKUP: |
| 82 UNIMPLEMENTED(); | 81 UNIMPLEMENTED(); |
| 83 break; | 82 break; |
| 84 } | 83 } |
| 85 } | 84 } |
| 86 | 85 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 | 240 |
| 242 | 241 |
| 243 void BytecodeGenerator::VisitVariableProxy(VariableProxy* proxy) { | 242 void BytecodeGenerator::VisitVariableProxy(VariableProxy* proxy) { |
| 244 Variable* variable = proxy->var(); | 243 Variable* variable = proxy->var(); |
| 245 switch (variable->location()) { | 244 switch (variable->location()) { |
| 246 case VariableLocation::LOCAL: { | 245 case VariableLocation::LOCAL: { |
| 247 Register source(variable->index()); | 246 Register source(variable->index()); |
| 248 builder().LoadAccumulatorWithRegister(source); | 247 builder().LoadAccumulatorWithRegister(source); |
| 249 break; | 248 break; |
| 250 } | 249 } |
| 250 case VariableLocation::PARAMETER: { |
| 251 // The parameter indices are shifted by 1 (receiver is variable |
| 252 // index -1 but is parameter index 0 in BytecodeArrayBuilder). |
| 253 Register source(builder().Parameter(variable->index() + 1)); |
| 254 builder().LoadAccumulatorWithRegister(source); |
| 255 break; |
| 256 } |
| 251 case VariableLocation::GLOBAL: | 257 case VariableLocation::GLOBAL: |
| 252 case VariableLocation::UNALLOCATED: | 258 case VariableLocation::UNALLOCATED: |
| 253 case VariableLocation::PARAMETER: | |
| 254 case VariableLocation::CONTEXT: | 259 case VariableLocation::CONTEXT: |
| 255 case VariableLocation::LOOKUP: | 260 case VariableLocation::LOOKUP: |
| 256 UNIMPLEMENTED(); | 261 UNIMPLEMENTED(); |
| 257 } | 262 } |
| 258 } | 263 } |
| 259 | 264 |
| 260 | 265 |
| 261 void BytecodeGenerator::VisitAssignment(Assignment* expr) { | 266 void BytecodeGenerator::VisitAssignment(Assignment* expr) { |
| 262 DCHECK(expr->target()->IsValidReferenceExpression()); | 267 DCHECK(expr->target()->IsValidReferenceExpression()); |
| 263 | 268 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 | 371 |
| 367 Visit(left); | 372 Visit(left); |
| 368 builder().StoreAccumulatorInRegister(temporary); | 373 builder().StoreAccumulatorInRegister(temporary); |
| 369 Visit(right); | 374 Visit(right); |
| 370 builder().BinaryOperation(op, temporary); | 375 builder().BinaryOperation(op, temporary); |
| 371 } | 376 } |
| 372 | 377 |
| 373 } // namespace interpreter | 378 } // namespace interpreter |
| 374 } // namespace internal | 379 } // namespace internal |
| 375 } // namespace v8 | 380 } // namespace v8 |
| OLD | NEW |