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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 LoopBuilder* loop_builder_; | 294 LoopBuilder* loop_builder_; |
295 }; | 295 }; |
296 | 296 |
297 | 297 |
298 // Scoped class for enabling 'throw' in try-catch constructs. | 298 // Scoped class for enabling 'throw' in try-catch constructs. |
299 class BytecodeGenerator::ControlScopeForTryCatch final | 299 class BytecodeGenerator::ControlScopeForTryCatch final |
300 : public BytecodeGenerator::ControlScope { | 300 : public BytecodeGenerator::ControlScope { |
301 public: | 301 public: |
302 ControlScopeForTryCatch(BytecodeGenerator* generator, | 302 ControlScopeForTryCatch(BytecodeGenerator* generator, |
303 TryCatchBuilder* try_catch_builder) | 303 TryCatchBuilder* try_catch_builder) |
304 : ControlScope(generator) { | 304 : ControlScope(generator) {} |
305 generator->try_catch_nesting_level_++; | |
306 } | |
307 virtual ~ControlScopeForTryCatch() { | |
308 generator()->try_catch_nesting_level_--; | |
309 } | |
310 | 305 |
311 protected: | 306 protected: |
312 bool Execute(Command command, Statement* statement) override { | 307 bool Execute(Command command, Statement* statement) override { |
313 switch (command) { | 308 switch (command) { |
314 case CMD_BREAK: | 309 case CMD_BREAK: |
315 case CMD_CONTINUE: | 310 case CMD_CONTINUE: |
316 case CMD_RETURN: | 311 case CMD_RETURN: |
317 break; | 312 break; |
318 case CMD_RETHROW: | 313 case CMD_RETHROW: |
319 generator()->builder()->ReThrow(); | 314 generator()->builder()->ReThrow(); |
320 return true; | 315 return true; |
321 } | 316 } |
322 return false; | 317 return false; |
323 } | 318 } |
324 }; | 319 }; |
325 | 320 |
326 | 321 |
327 // Scoped class for enabling control flow through try-finally constructs. | 322 // Scoped class for enabling control flow through try-finally constructs. |
328 class BytecodeGenerator::ControlScopeForTryFinally final | 323 class BytecodeGenerator::ControlScopeForTryFinally final |
329 : public BytecodeGenerator::ControlScope { | 324 : public BytecodeGenerator::ControlScope { |
330 public: | 325 public: |
331 ControlScopeForTryFinally(BytecodeGenerator* generator, | 326 ControlScopeForTryFinally(BytecodeGenerator* generator, |
332 TryFinallyBuilder* try_finally_builder, | 327 TryFinallyBuilder* try_finally_builder, |
333 DeferredCommands* commands) | 328 DeferredCommands* commands) |
334 : ControlScope(generator), | 329 : ControlScope(generator), |
335 try_finally_builder_(try_finally_builder), | 330 try_finally_builder_(try_finally_builder), |
336 commands_(commands) { | 331 commands_(commands) {} |
337 generator->try_finally_nesting_level_++; | |
338 } | |
339 virtual ~ControlScopeForTryFinally() { | |
340 generator()->try_finally_nesting_level_--; | |
341 } | |
342 | 332 |
343 protected: | 333 protected: |
344 bool Execute(Command command, Statement* statement) override { | 334 bool Execute(Command command, Statement* statement) override { |
345 switch (command) { | 335 switch (command) { |
346 case CMD_BREAK: | 336 case CMD_BREAK: |
347 case CMD_CONTINUE: | 337 case CMD_CONTINUE: |
348 case CMD_RETURN: | 338 case CMD_RETURN: |
349 case CMD_RETHROW: | 339 case CMD_RETHROW: |
350 commands_->RecordCommand(command, statement); | 340 commands_->RecordCommand(command, statement); |
351 try_finally_builder_->LeaveTry(); | 341 try_finally_builder_->LeaveTry(); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
546 BytecodeGenerator::BytecodeGenerator(Isolate* isolate, Zone* zone) | 536 BytecodeGenerator::BytecodeGenerator(Isolate* isolate, Zone* zone) |
547 : isolate_(isolate), | 537 : isolate_(isolate), |
548 zone_(zone), | 538 zone_(zone), |
549 builder_(nullptr), | 539 builder_(nullptr), |
550 info_(nullptr), | 540 info_(nullptr), |
551 scope_(nullptr), | 541 scope_(nullptr), |
552 globals_(0, zone), | 542 globals_(0, zone), |
553 execution_control_(nullptr), | 543 execution_control_(nullptr), |
554 execution_context_(nullptr), | 544 execution_context_(nullptr), |
555 execution_result_(nullptr), | 545 execution_result_(nullptr), |
556 register_allocator_(nullptr), | 546 register_allocator_(nullptr) { |
557 try_catch_nesting_level_(0), | |
558 try_finally_nesting_level_(0) { | |
559 InitializeAstVisitor(isolate); | 547 InitializeAstVisitor(isolate); |
560 } | 548 } |
561 | 549 |
562 | 550 |
563 Handle<BytecodeArray> BytecodeGenerator::MakeBytecode(CompilationInfo* info) { | 551 Handle<BytecodeArray> BytecodeGenerator::MakeBytecode(CompilationInfo* info) { |
564 set_info(info); | 552 set_info(info); |
565 set_scope(info->scope()); | 553 set_scope(info->scope()); |
566 | 554 |
567 // Initialize bytecode array builder. | 555 // Initialize bytecode array builder. |
568 set_builder(new (zone()) BytecodeArrayBuilder( | 556 set_builder(new (zone()) BytecodeArrayBuilder( |
(...skipping 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 // Load the catch context into the accumulator. | 1143 // Load the catch context into the accumulator. |
1156 builder()->LoadAccumulatorWithRegister(context); | 1144 builder()->LoadAccumulatorWithRegister(context); |
1157 | 1145 |
1158 // Evaluate the catch-block. | 1146 // Evaluate the catch-block. |
1159 VisitInScope(stmt->catch_block(), stmt->scope()); | 1147 VisitInScope(stmt->catch_block(), stmt->scope()); |
1160 try_control_builder.EndCatch(); | 1148 try_control_builder.EndCatch(); |
1161 } | 1149 } |
1162 | 1150 |
1163 | 1151 |
1164 void BytecodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { | 1152 void BytecodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { |
1165 TryFinallyBuilder try_control_builder(builder(), IsInsideTryCatch()); | 1153 TryFinallyBuilder try_control_builder(builder()); |
1166 Register no_reg; | 1154 Register no_reg; |
1167 | 1155 |
1168 // We keep a record of all paths that enter the finally-block to be able to | 1156 // We keep a record of all paths that enter the finally-block to be able to |
1169 // dispatch to the correct continuation point after the statements in the | 1157 // dispatch to the correct continuation point after the statements in the |
1170 // finally-block have been evaluated. | 1158 // finally-block have been evaluated. |
1171 // | 1159 // |
1172 // The try-finally construct can enter the finally-block in three ways: | 1160 // The try-finally construct can enter the finally-block in three ways: |
1173 // 1. By exiting the try-block normally, falling through at the end. | 1161 // 1. By exiting the try-block normally, falling through at the end. |
1174 // 2. By exiting the try-block with a function-local control flow transfer | 1162 // 2. By exiting the try-block with a function-local control flow transfer |
1175 // (i.e. through break/continue/return statements). | 1163 // (i.e. through break/continue/return statements). |
(...skipping 1707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2883 } | 2871 } |
2884 | 2872 |
2885 | 2873 |
2886 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 2874 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
2887 return info()->feedback_vector()->GetIndex(slot); | 2875 return info()->feedback_vector()->GetIndex(slot); |
2888 } | 2876 } |
2889 | 2877 |
2890 } // namespace interpreter | 2878 } // namespace interpreter |
2891 } // namespace internal | 2879 } // namespace internal |
2892 } // namespace v8 | 2880 } // namespace v8 |
OLD | NEW |