| 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 899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 // that is intercepting 'throw' control commands. | 910 // that is intercepting 'throw' control commands. |
| 911 try_control_builder.BeginTry(context); | 911 try_control_builder.BeginTry(context); |
| 912 // TODO(mstarzinger): Control scope is missing! | 912 // TODO(mstarzinger): Control scope is missing! |
| 913 Visit(stmt->try_block()); | 913 Visit(stmt->try_block()); |
| 914 try_control_builder.EndTry(); | 914 try_control_builder.EndTry(); |
| 915 | 915 |
| 916 // Clear message object as we enter the catch block. | 916 // Clear message object as we enter the catch block. |
| 917 // TODO(mstarzinger): Implement this! | 917 // TODO(mstarzinger): Implement this! |
| 918 | 918 |
| 919 // Create a catch scope that binds the exception. | 919 // Create a catch scope that binds the exception. |
| 920 register_allocator()->PrepareForConsecutiveAllocations(3); | 920 VisitNewLocalCatchContext(stmt->variable()); |
| 921 Register name = register_allocator()->NextConsecutiveRegister(); | |
| 922 Register exception = register_allocator()->NextConsecutiveRegister(); | |
| 923 Register closure = register_allocator()->NextConsecutiveRegister(); | |
| 924 builder() | |
| 925 ->StoreAccumulatorInRegister(exception) | |
| 926 .LoadLiteral(stmt->variable()->name()) | |
| 927 .StoreAccumulatorInRegister(name); | |
| 928 VisitFunctionClosureForContext(); | |
| 929 builder()->StoreAccumulatorInRegister(closure).CallRuntime( | |
| 930 Runtime::kPushCatchContext, name, 3); | |
| 931 | 921 |
| 932 // Evaluate the catch-block. | 922 // Evaluate the catch-block. |
| 933 Visit(stmt->catch_block()); | 923 VisitInScope(stmt->catch_block(), stmt->scope()); |
| 934 try_control_builder.EndCatch(); | 924 try_control_builder.EndCatch(); |
| 935 } | 925 } |
| 936 | 926 |
| 937 | 927 |
| 938 void BytecodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { | 928 void BytecodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { |
| 939 TryFinallyBuilder try_control_builder(builder()); | 929 TryFinallyBuilder try_control_builder(builder()); |
| 940 | 930 |
| 941 // Preserve the context in a dedicated register, so that it can be restored | 931 // Preserve the context in a dedicated register, so that it can be restored |
| 942 // when the handler is entered by the stack-unwinding machinery. | 932 // when the handler is entered by the stack-unwinding machinery. |
| 943 // TODO(mstarzinger): Be smarter about register allocation. | 933 // TODO(mstarzinger): Be smarter about register allocation. |
| (...skipping 1177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2121 ->LoadLiteral(scope->GetScopeInfo(isolate())) | 2111 ->LoadLiteral(scope->GetScopeInfo(isolate())) |
| 2122 .StoreAccumulatorInRegister(scope_info); | 2112 .StoreAccumulatorInRegister(scope_info); |
| 2123 VisitFunctionClosureForContext(); | 2113 VisitFunctionClosureForContext(); |
| 2124 builder() | 2114 builder() |
| 2125 ->StoreAccumulatorInRegister(closure) | 2115 ->StoreAccumulatorInRegister(closure) |
| 2126 .CallRuntime(Runtime::kPushBlockContext, scope_info, 2); | 2116 .CallRuntime(Runtime::kPushBlockContext, scope_info, 2); |
| 2127 execution_result()->SetResultInAccumulator(); | 2117 execution_result()->SetResultInAccumulator(); |
| 2128 } | 2118 } |
| 2129 | 2119 |
| 2130 | 2120 |
| 2121 void BytecodeGenerator::VisitNewLocalCatchContext(Variable* variable) { |
| 2122 AccumulatorResultScope accumulator_execution_result(this); |
| 2123 DCHECK(variable->IsContextSlot()); |
| 2124 |
| 2125 // Allocate a new local block context. |
| 2126 register_allocator()->PrepareForConsecutiveAllocations(3); |
| 2127 Register name = register_allocator()->NextConsecutiveRegister(); |
| 2128 Register exception = register_allocator()->NextConsecutiveRegister(); |
| 2129 Register closure = register_allocator()->NextConsecutiveRegister(); |
| 2130 |
| 2131 builder() |
| 2132 ->StoreAccumulatorInRegister(exception) |
| 2133 .LoadLiteral(variable->name()) |
| 2134 .StoreAccumulatorInRegister(name); |
| 2135 VisitFunctionClosureForContext(); |
| 2136 builder()->StoreAccumulatorInRegister(closure).CallRuntime( |
| 2137 Runtime::kPushCatchContext, name, 3); |
| 2138 execution_result()->SetResultInAccumulator(); |
| 2139 } |
| 2140 |
| 2141 |
| 2131 void BytecodeGenerator::VisitObjectLiteralAccessor( | 2142 void BytecodeGenerator::VisitObjectLiteralAccessor( |
| 2132 Register home_object, ObjectLiteralProperty* property, Register value_out) { | 2143 Register home_object, ObjectLiteralProperty* property, Register value_out) { |
| 2133 // TODO(rmcilroy): Replace value_out with VisitForRegister(); | 2144 // TODO(rmcilroy): Replace value_out with VisitForRegister(); |
| 2134 if (property == nullptr) { | 2145 if (property == nullptr) { |
| 2135 builder()->LoadNull().StoreAccumulatorInRegister(value_out); | 2146 builder()->LoadNull().StoreAccumulatorInRegister(value_out); |
| 2136 } else { | 2147 } else { |
| 2137 VisitForAccumulatorValue(property->value()); | 2148 VisitForAccumulatorValue(property->value()); |
| 2138 builder()->StoreAccumulatorInRegister(value_out); | 2149 builder()->StoreAccumulatorInRegister(value_out); |
| 2139 VisitSetHomeObject(value_out, home_object, property); | 2150 VisitSetHomeObject(value_out, home_object, property); |
| 2140 } | 2151 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2225 | 2236 |
| 2226 // Visits the expression |expr| and returns the register containing | 2237 // Visits the expression |expr| and returns the register containing |
| 2227 // the expression result. | 2238 // the expression result. |
| 2228 Register BytecodeGenerator::VisitForRegisterValue(Expression* expr) { | 2239 Register BytecodeGenerator::VisitForRegisterValue(Expression* expr) { |
| 2229 RegisterResultScope register_scope(this); | 2240 RegisterResultScope register_scope(this); |
| 2230 Visit(expr); | 2241 Visit(expr); |
| 2231 return register_scope.ResultRegister(); | 2242 return register_scope.ResultRegister(); |
| 2232 } | 2243 } |
| 2233 | 2244 |
| 2234 | 2245 |
| 2246 void BytecodeGenerator::VisitInScope(Statement* stmt, Scope* scope) { |
| 2247 ContextScope context_scope(this, scope); |
| 2248 DCHECK(scope->declarations()->is_empty()); |
| 2249 Visit(stmt); |
| 2250 } |
| 2251 |
| 2252 |
| 2235 Register BytecodeGenerator::NextContextRegister() const { | 2253 Register BytecodeGenerator::NextContextRegister() const { |
| 2236 if (execution_context() == nullptr) { | 2254 if (execution_context() == nullptr) { |
| 2237 // Return the incoming function context for the outermost execution context. | 2255 // Return the incoming function context for the outermost execution context. |
| 2238 return Register::function_context(); | 2256 return Register::function_context(); |
| 2239 } | 2257 } |
| 2240 Register previous = execution_context()->reg(); | 2258 Register previous = execution_context()->reg(); |
| 2241 if (previous == Register::function_context()) { | 2259 if (previous == Register::function_context()) { |
| 2242 // If the previous context was the incoming function context, then the next | 2260 // If the previous context was the incoming function context, then the next |
| 2243 // context register is the first local context register. | 2261 // context register is the first local context register. |
| 2244 return builder_.first_context_register(); | 2262 return builder_.first_context_register(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2260 } | 2278 } |
| 2261 | 2279 |
| 2262 | 2280 |
| 2263 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { | 2281 int BytecodeGenerator::feedback_index(FeedbackVectorSlot slot) const { |
| 2264 return info()->feedback_vector()->GetIndex(slot); | 2282 return info()->feedback_vector()->GetIndex(slot); |
| 2265 } | 2283 } |
| 2266 | 2284 |
| 2267 } // namespace interpreter | 2285 } // namespace interpreter |
| 2268 } // namespace internal | 2286 } // namespace internal |
| 2269 } // namespace v8 | 2287 } // namespace v8 |
| OLD | NEW |