Chromium Code Reviews| 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/compiler.h" | 8 #include "src/compiler.h" |
| 9 #include "src/interpreter/bytecode-register-allocator.h" | 9 #include "src/interpreter/bytecode-register-allocator.h" |
| 10 #include "src/interpreter/control-flow-builders.h" | 10 #include "src/interpreter/control-flow-builders.h" |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 : generator_(generator), | 443 : generator_(generator), |
| 444 kind_(kind), | 444 kind_(kind), |
| 445 outer_(generator->execution_result()), | 445 outer_(generator->execution_result()), |
| 446 allocator_(generator), | 446 allocator_(generator), |
| 447 result_identified_(false) { | 447 result_identified_(false) { |
| 448 generator_->set_execution_result(this); | 448 generator_->set_execution_result(this); |
| 449 } | 449 } |
| 450 | 450 |
| 451 virtual ~ExpressionResultScope() { | 451 virtual ~ExpressionResultScope() { |
| 452 generator_->set_execution_result(outer_); | 452 generator_->set_execution_result(outer_); |
| 453 DCHECK(result_identified()); | 453 DCHECK(result_identified() || generator_->HasStackOverflow()); |
| 454 } | 454 } |
| 455 | 455 |
| 456 bool IsEffect() const { return kind_ == Expression::kEffect; } | 456 bool IsEffect() const { return kind_ == Expression::kEffect; } |
| 457 bool IsValue() const { return kind_ == Expression::kValue; } | 457 bool IsValue() const { return kind_ == Expression::kValue; } |
| 458 bool HasStackOverflow() const { return generator_->HasStackOverflow(); } | |
|
rmcilroy
2016/02/25 10:35:13
Could you just expose generator() as a protected m
mythria
2016/02/25 11:02:03
Done.
| |
| 458 | 459 |
| 459 virtual void SetResultInAccumulator() = 0; | 460 virtual void SetResultInAccumulator() = 0; |
| 460 virtual void SetResultInRegister(Register reg) = 0; | 461 virtual void SetResultInRegister(Register reg) = 0; |
| 461 | 462 |
| 462 protected: | 463 protected: |
| 463 ExpressionResultScope* outer() const { return outer_; } | 464 ExpressionResultScope* outer() const { return outer_; } |
| 464 BytecodeArrayBuilder* builder() const { return generator_->builder(); } | 465 BytecodeArrayBuilder* builder() const { return generator_->builder(); } |
| 465 const RegisterAllocationScope* allocator() const { return &allocator_; } | 466 const RegisterAllocationScope* allocator() const { return &allocator_; } |
| 466 | 467 |
| 467 void set_result_identified() { | 468 void set_result_identified() { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 } | 530 } |
| 530 | 531 |
| 531 virtual void SetResultInRegister(Register reg) { | 532 virtual void SetResultInRegister(Register reg) { |
| 532 DCHECK(builder()->RegisterIsParameterOrLocal(reg) || | 533 DCHECK(builder()->RegisterIsParameterOrLocal(reg) || |
| 533 (builder()->TemporaryRegisterIsLive(reg) && | 534 (builder()->TemporaryRegisterIsLive(reg) && |
| 534 !allocator()->RegisterIsAllocatedInThisScope(reg))); | 535 !allocator()->RegisterIsAllocatedInThisScope(reg))); |
| 535 result_register_ = reg; | 536 result_register_ = reg; |
| 536 set_result_identified(); | 537 set_result_identified(); |
| 537 } | 538 } |
| 538 | 539 |
| 539 Register ResultRegister() const { return result_register_; } | 540 Register ResultRegister() { |
| 541 if (HasStackOverflow() && !result_identified()) SetResultInAccumulator(); | |
| 542 return result_register_; | |
| 543 } | |
| 540 | 544 |
| 541 private: | 545 private: |
| 542 Register result_register_; | 546 Register result_register_; |
| 543 }; | 547 }; |
| 544 | 548 |
| 545 BytecodeGenerator::BytecodeGenerator(Isolate* isolate, Zone* zone) | 549 BytecodeGenerator::BytecodeGenerator(Isolate* isolate, Zone* zone) |
| 546 : isolate_(isolate), | 550 : isolate_(isolate), |
| 547 zone_(zone), | 551 zone_(zone), |
| 548 builder_(nullptr), | 552 builder_(nullptr), |
| 549 info_(nullptr), | 553 info_(nullptr), |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1260 void BytecodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) { | 1264 void BytecodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) { |
| 1261 builder()->SetStatementPosition(stmt); | 1265 builder()->SetStatementPosition(stmt); |
| 1262 builder()->Debugger(); | 1266 builder()->Debugger(); |
| 1263 } | 1267 } |
| 1264 | 1268 |
| 1265 | 1269 |
| 1266 void BytecodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { | 1270 void BytecodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { |
| 1267 // Find or build a shared function info. | 1271 // Find or build a shared function info. |
| 1268 Handle<SharedFunctionInfo> shared_info = | 1272 Handle<SharedFunctionInfo> shared_info = |
| 1269 Compiler::GetSharedFunctionInfo(expr, info()->script(), info()); | 1273 Compiler::GetSharedFunctionInfo(expr, info()->script(), info()); |
| 1270 CHECK(!shared_info.is_null()); // TODO(rmcilroy): Set stack overflow? | 1274 if (shared_info.is_null()) { |
| 1275 return SetStackOverflow(); | |
| 1276 } | |
| 1271 builder()->CreateClosure(shared_info, | 1277 builder()->CreateClosure(shared_info, |
| 1272 expr->pretenure() ? TENURED : NOT_TENURED); | 1278 expr->pretenure() ? TENURED : NOT_TENURED); |
| 1273 execution_result()->SetResultInAccumulator(); | 1279 execution_result()->SetResultInAccumulator(); |
| 1274 } | 1280 } |
| 1275 | 1281 |
| 1276 | 1282 |
| 1277 void BytecodeGenerator::VisitClassLiteral(ClassLiteral* expr) { | 1283 void BytecodeGenerator::VisitClassLiteral(ClassLiteral* expr) { |
| 1278 if (expr->scope()->ContextLocalCount() > 0) { | 1284 if (expr->scope()->ContextLocalCount() > 0) { |
| 1279 VisitNewLocalBlockContext(expr->scope()); | 1285 VisitNewLocalBlockContext(expr->scope()); |
| 1280 ContextScope scope(this, expr->scope()); | 1286 ContextScope scope(this, expr->scope()); |
| (...skipping 1852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3133 } | 3139 } |
| 3134 | 3140 |
| 3135 | 3141 |
| 3136 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 3142 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
| 3137 return info()->feedback_vector()->GetIndex(slot); | 3143 return info()->feedback_vector()->GetIndex(slot); |
| 3138 } | 3144 } |
| 3139 | 3145 |
| 3140 } // namespace interpreter | 3146 } // namespace interpreter |
| 3141 } // namespace internal | 3147 } // namespace internal |
| 3142 } // namespace v8 | 3148 } // namespace v8 |
| OLD | NEW |