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/interpreter/control-flow-builders.h" | 10 #include "src/interpreter/control-flow-builders.h" |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
184 MakeBytecodeBody(); | 184 MakeBytecodeBody(); |
185 } | 185 } |
186 | 186 |
187 set_scope(nullptr); | 187 set_scope(nullptr); |
188 set_info(nullptr); | 188 set_info(nullptr); |
189 return builder_.ToBytecodeArray(); | 189 return builder_.ToBytecodeArray(); |
190 } | 190 } |
191 | 191 |
192 | 192 |
193 void BytecodeGenerator::MakeBytecodeBody() { | 193 void BytecodeGenerator::MakeBytecodeBody() { |
194 // Build the arguments object if it is used. | |
195 VisitArgumentsObject(scope()->arguments()); | |
196 | |
197 // Build assignment to {.this_function} variable if it is used. | |
198 VisitThisFunctionVariable(scope()->this_function_var()); | |
199 | |
200 // Build assignment to {new.target} variable if it is used. | |
201 VisitNewTargetVariable(scope()->new_target_var()); | |
202 | |
203 // TODO(rmcilroy): Emit tracing call if requested to do so. | |
204 if (FLAG_trace) { | |
205 UNIMPLEMENTED(); | |
206 } | |
207 | |
208 // Visit illegal re-declaration and bail out if it exists. | |
209 if (scope()->HasIllegalRedeclaration()) { | |
210 Visit(scope()->GetIllegalRedeclaration()); | |
211 return; | |
212 } | |
213 | |
194 // Visit declarations within the function scope. | 214 // Visit declarations within the function scope. |
195 VisitDeclarations(scope()->declarations()); | 215 VisitDeclarations(scope()->declarations()); |
196 | 216 |
197 // Visit statements in the function body. | 217 // Visit statements in the function body. |
198 VisitStatements(info()->literal()->body()); | 218 VisitStatements(info()->literal()->body()); |
199 } | 219 } |
200 | 220 |
201 | 221 |
202 void BytecodeGenerator::VisitBlock(Block* stmt) { | 222 void BytecodeGenerator::VisitBlock(Block* stmt) { |
203 builder()->EnterBlock(); | 223 builder()->EnterBlock(); |
(...skipping 1171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1375 isolate()->factory()->home_object_symbol(); | 1395 isolate()->factory()->home_object_symbol(); |
1376 builder() | 1396 builder() |
1377 ->LoadLiteral(isolate()->factory()->home_object_symbol()) | 1397 ->LoadLiteral(isolate()->factory()->home_object_symbol()) |
1378 .StoreAccumulatorInRegister(name) | 1398 .StoreAccumulatorInRegister(name) |
1379 .StoreNamedProperty(home_object, name, | 1399 .StoreNamedProperty(home_object, name, |
1380 feedback_index(property->GetSlot(slot_number)), | 1400 feedback_index(property->GetSlot(slot_number)), |
1381 language_mode()); | 1401 language_mode()); |
1382 } | 1402 } |
1383 | 1403 |
1384 | 1404 |
1405 void BytecodeGenerator::VisitArgumentsObject(Variable* arguments) { | |
1406 if (arguments == NULL) return; | |
Michael Starzinger
2015/10/21 18:42:17
nit: s/NULL/nullptr/
rmcilroy
2015/10/22 15:19:52
Done.
| |
1407 | |
1408 DCHECK(arguments->IsContextSlot() || arguments->IsStackAllocated()); | |
1409 | |
1410 // Allocate and initialize a new arguments object and assign to the | |
1411 // {arguments} variable. | |
1412 bool use_strict = | |
1413 is_strict(language_mode()) || !info()->has_simple_parameters(); | |
1414 builder()->CreateArguments(use_strict); | |
1415 VisitVariableAssignment(arguments, FeedbackVectorSlot::Invalid()); | |
1416 } | |
1417 | |
1418 | |
1419 void BytecodeGenerator::VisitThisFunctionVariable(Variable* this_function_var) { | |
1420 if (this_function_var == nullptr) return; | |
1421 | |
1422 // TODO(rmcilroy): Remove once we have tests which exercise this code path. | |
1423 UNIMPLEMENTED(); | |
1424 | |
1425 // Store the closure we were called with in the this_function_var. | |
1426 builder()->LoadAccumulatorWithRegister(Register::function_closure()); | |
1427 VisitVariableAssignment(this_function_var, FeedbackVectorSlot::Invalid()); | |
1428 } | |
1429 | |
1430 | |
1431 void BytecodeGenerator::VisitNewTargetVariable(Variable* new_target_var) { | |
1432 if (new_target_var == nullptr) return; | |
1433 | |
1434 // TODO(rmcilroy): Remove once we have tests which exercise this code path. | |
1435 UNIMPLEMENTED(); | |
1436 | |
1437 // Store the closure we were called with in the this_function_var. | |
1438 builder()->CallRuntime(Runtime::kGetOriginalConstructor, Register(), 0); | |
1439 VisitVariableAssignment(new_target_var, FeedbackVectorSlot::Invalid()); | |
1440 } | |
1441 | |
1442 | |
1385 void BytecodeGenerator::VisitFunctionClosureForContext() { | 1443 void BytecodeGenerator::VisitFunctionClosureForContext() { |
1386 Scope* closure_scope = execution_context()->scope()->ClosureScope(); | 1444 Scope* closure_scope = execution_context()->scope()->ClosureScope(); |
1387 if (closure_scope->is_script_scope() || | 1445 if (closure_scope->is_script_scope() || |
1388 closure_scope->is_module_scope()) { | 1446 closure_scope->is_module_scope()) { |
1389 // Contexts nested in the native context have a canonical empty function as | 1447 // Contexts nested in the native context have a canonical empty function as |
1390 // their closure, not the anonymous closure containing the global code. | 1448 // their closure, not the anonymous closure containing the global code. |
1391 // Pass a SMI sentinel and let the runtime look up the empty function. | 1449 // Pass a SMI sentinel and let the runtime look up the empty function. |
1392 builder()->LoadLiteral(Smi::FromInt(0)); | 1450 builder()->LoadLiteral(Smi::FromInt(0)); |
1393 } else { | 1451 } else { |
1394 DCHECK(closure_scope->is_function_scope()); | 1452 DCHECK(closure_scope->is_function_scope()); |
(...skipping 30 matching lines...) Expand all Loading... | |
1425 } | 1483 } |
1426 | 1484 |
1427 | 1485 |
1428 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 1486 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
1429 return info()->feedback_vector()->GetIndex(slot); | 1487 return info()->feedback_vector()->GetIndex(slot); |
1430 } | 1488 } |
1431 | 1489 |
1432 } // namespace interpreter | 1490 } // namespace interpreter |
1433 } // namespace internal | 1491 } // namespace internal |
1434 } // namespace v8 | 1492 } // namespace v8 |
OLD | NEW |