| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 } | 430 } |
| 431 | 431 |
| 432 | 432 |
| 433 void FullCodeGenerator::AccumulatorValueContext::Plug(Register reg) const { | 433 void FullCodeGenerator::AccumulatorValueContext::Plug(Register reg) const { |
| 434 __ Move(result_register(), reg); | 434 __ Move(result_register(), reg); |
| 435 } | 435 } |
| 436 | 436 |
| 437 | 437 |
| 438 void FullCodeGenerator::StackValueContext::Plug(Register reg) const { | 438 void FullCodeGenerator::StackValueContext::Plug(Register reg) const { |
| 439 __ push(reg); | 439 __ push(reg); |
| 440 codegen()->increment_stack_height(); |
| 440 } | 441 } |
| 441 | 442 |
| 442 | 443 |
| 443 void FullCodeGenerator::TestContext::Plug(Register reg) const { | 444 void FullCodeGenerator::TestContext::Plug(Register reg) const { |
| 444 // For simplicity we always test the accumulator register. | 445 // For simplicity we always test the accumulator register. |
| 445 __ Move(result_register(), reg); | 446 __ Move(result_register(), reg); |
| 446 codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); | 447 codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); |
| 447 codegen()->DoTest(this); | 448 codegen()->DoTest(this); |
| 448 } | 449 } |
| 449 | 450 |
| 450 | 451 |
| 451 void FullCodeGenerator::EffectContext::PlugTOS() const { | 452 void FullCodeGenerator::EffectContext::PlugTOS() const { |
| 452 __ Drop(1); | 453 __ Drop(1); |
| 454 codegen()->decrement_stack_height(); |
| 453 } | 455 } |
| 454 | 456 |
| 455 | 457 |
| 456 void FullCodeGenerator::AccumulatorValueContext::PlugTOS() const { | 458 void FullCodeGenerator::AccumulatorValueContext::PlugTOS() const { |
| 457 __ pop(result_register()); | 459 __ pop(result_register()); |
| 460 codegen()->decrement_stack_height(); |
| 458 } | 461 } |
| 459 | 462 |
| 460 | 463 |
| 461 void FullCodeGenerator::StackValueContext::PlugTOS() const { | 464 void FullCodeGenerator::StackValueContext::PlugTOS() const { |
| 462 } | 465 } |
| 463 | 466 |
| 464 | 467 |
| 465 void FullCodeGenerator::TestContext::PlugTOS() const { | 468 void FullCodeGenerator::TestContext::PlugTOS() const { |
| 466 // For simplicity we always test the accumulator register. | 469 // For simplicity we always test the accumulator register. |
| 467 __ pop(result_register()); | 470 __ pop(result_register()); |
| 471 codegen()->decrement_stack_height(); |
| 468 codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); | 472 codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL); |
| 469 codegen()->DoTest(this); | 473 codegen()->DoTest(this); |
| 470 } | 474 } |
| 471 | 475 |
| 472 | 476 |
| 473 void FullCodeGenerator::EffectContext::PrepareTest( | 477 void FullCodeGenerator::EffectContext::PrepareTest( |
| 474 Label* materialize_true, | 478 Label* materialize_true, |
| 475 Label* materialize_false, | 479 Label* materialize_false, |
| 476 Label** if_true, | 480 Label** if_true, |
| 477 Label** if_false, | 481 Label** if_false, |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 | 957 |
| 954 | 958 |
| 955 void FullCodeGenerator::VisitEnterWithContextStatement( | 959 void FullCodeGenerator::VisitEnterWithContextStatement( |
| 956 EnterWithContextStatement* stmt) { | 960 EnterWithContextStatement* stmt) { |
| 957 Comment cmnt(masm_, "[ EnterWithContextStatement"); | 961 Comment cmnt(masm_, "[ EnterWithContextStatement"); |
| 958 SetStatementPosition(stmt); | 962 SetStatementPosition(stmt); |
| 959 | 963 |
| 960 VisitForStackValue(stmt->expression()); | 964 VisitForStackValue(stmt->expression()); |
| 961 PushFunctionArgumentForContextAllocation(); | 965 PushFunctionArgumentForContextAllocation(); |
| 962 __ CallRuntime(Runtime::kPushWithContext, 2); | 966 __ CallRuntime(Runtime::kPushWithContext, 2); |
| 967 decrement_stack_height(); |
| 963 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); | 968 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register()); |
| 964 } | 969 } |
| 965 | 970 |
| 966 | 971 |
| 967 void FullCodeGenerator::VisitExitContextStatement(ExitContextStatement* stmt) { | 972 void FullCodeGenerator::VisitExitContextStatement(ExitContextStatement* stmt) { |
| 968 Comment cmnt(masm_, "[ ExitContextStatement"); | 973 Comment cmnt(masm_, "[ ExitContextStatement"); |
| 969 SetStatementPosition(stmt); | 974 SetStatementPosition(stmt); |
| 970 | 975 |
| 971 // Pop context. | 976 // Pop context. |
| 972 LoadContextField(context_register(), Context::PREVIOUS_INDEX); | 977 LoadContextField(context_register(), Context::PREVIOUS_INDEX); |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1121 ASSERT(scope_->declarations()->is_empty()); | 1126 ASSERT(scope_->declarations()->is_empty()); |
| 1122 Visit(stmt->catch_block()); | 1127 Visit(stmt->catch_block()); |
| 1123 scope_ = saved_scope; | 1128 scope_ = saved_scope; |
| 1124 __ jmp(&done); | 1129 __ jmp(&done); |
| 1125 | 1130 |
| 1126 // Try block code. Sets up the exception handler chain. | 1131 // Try block code. Sets up the exception handler chain. |
| 1127 __ bind(&try_handler_setup); | 1132 __ bind(&try_handler_setup); |
| 1128 { | 1133 { |
| 1129 TryCatch try_block(this, &catch_entry); | 1134 TryCatch try_block(this, &catch_entry); |
| 1130 __ PushTryHandler(IN_JAVASCRIPT, TRY_CATCH_HANDLER); | 1135 __ PushTryHandler(IN_JAVASCRIPT, TRY_CATCH_HANDLER); |
| 1136 increment_stack_height(StackHandlerConstants::kSize / kPointerSize); |
| 1131 Visit(stmt->try_block()); | 1137 Visit(stmt->try_block()); |
| 1132 __ PopTryHandler(); | 1138 __ PopTryHandler(); |
| 1139 decrement_stack_height(StackHandlerConstants::kSize / kPointerSize); |
| 1133 } | 1140 } |
| 1134 __ bind(&done); | 1141 __ bind(&done); |
| 1135 } | 1142 } |
| 1136 | 1143 |
| 1137 | 1144 |
| 1138 void FullCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { | 1145 void FullCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) { |
| 1139 Comment cmnt(masm_, "[ TryFinallyStatement"); | 1146 Comment cmnt(masm_, "[ TryFinallyStatement"); |
| 1140 SetStatementPosition(stmt); | 1147 SetStatementPosition(stmt); |
| 1141 // Try finally is compiled by setting up a try-handler on the stack while | 1148 // Try finally is compiled by setting up a try-handler on the stack while |
| 1142 // executing the try body, and removing it again afterwards. | 1149 // executing the try body, and removing it again afterwards. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1154 // handler code. The handler code then calls the finally-block before | 1161 // handler code. The handler code then calls the finally-block before |
| 1155 // rethrowing the exception. | 1162 // rethrowing the exception. |
| 1156 // | 1163 // |
| 1157 // The finally block must assume a return address on top of the stack | 1164 // The finally block must assume a return address on top of the stack |
| 1158 // (or in the link register on ARM chips) and a value (return value or | 1165 // (or in the link register on ARM chips) and a value (return value or |
| 1159 // exception) in the result register (rax/eax/r0), both of which must | 1166 // exception) in the result register (rax/eax/r0), both of which must |
| 1160 // be preserved. The return address isn't GC-safe, so it should be | 1167 // be preserved. The return address isn't GC-safe, so it should be |
| 1161 // cooked before GC. | 1168 // cooked before GC. |
| 1162 Label finally_entry; | 1169 Label finally_entry; |
| 1163 Label try_handler_setup; | 1170 Label try_handler_setup; |
| 1171 const int original_stack_height = stack_height(); |
| 1172 const int finally_block_stack_height = original_stack_height + 2; |
| 1173 const int try_block_stack_height = original_stack_height + 4; |
| 1174 STATIC_ASSERT(StackHandlerConstants::kSize / kPointerSize == 4); |
| 1164 | 1175 |
| 1165 // Setup the try-handler chain. Use a call to | 1176 // Setup the try-handler chain. Use a call to |
| 1166 // Jump to try-handler setup and try-block code. Use call to put try-handler | 1177 // Jump to try-handler setup and try-block code. Use call to put try-handler |
| 1167 // address on stack. | 1178 // address on stack. |
| 1168 __ Call(&try_handler_setup); | 1179 __ Call(&try_handler_setup); |
| 1169 // Try handler code. Return address of call is pushed on handler stack. | 1180 // Try handler code. Return address of call is pushed on handler stack. |
| 1170 { | 1181 { |
| 1171 // This code is only executed during stack-handler traversal when an | 1182 // This code is only executed during stack-handler traversal when an |
| 1172 // exception is thrown. The execption is in the result register, which | 1183 // exception is thrown. The execption is in the result register, which |
| 1173 // is retained by the finally block. | 1184 // is retained by the finally block. |
| 1174 // Call the finally block and then rethrow the exception. | 1185 // Call the finally block and then rethrow the exception. |
| 1175 __ Call(&finally_entry); | 1186 __ Call(&finally_entry); |
| 1176 __ push(result_register()); | 1187 __ push(result_register()); |
| 1177 __ CallRuntime(Runtime::kReThrow, 1); | 1188 __ CallRuntime(Runtime::kReThrow, 1); |
| 1178 } | 1189 } |
| 1179 | 1190 |
| 1180 __ bind(&finally_entry); | 1191 __ bind(&finally_entry); |
| 1181 { | 1192 { |
| 1182 // Finally block implementation. | 1193 // Finally block implementation. |
| 1183 Finally finally_block(this); | 1194 Finally finally_block(this); |
| 1184 EnterFinallyBlock(); | 1195 EnterFinallyBlock(); |
| 1196 set_stack_height(finally_block_stack_height); |
| 1185 Visit(stmt->finally_block()); | 1197 Visit(stmt->finally_block()); |
| 1186 ExitFinallyBlock(); // Return to the calling code. | 1198 ExitFinallyBlock(); // Return to the calling code. |
| 1187 } | 1199 } |
| 1188 | 1200 |
| 1189 __ bind(&try_handler_setup); | 1201 __ bind(&try_handler_setup); |
| 1190 { | 1202 { |
| 1191 // Setup try handler (stack pointer registers). | 1203 // Setup try handler (stack pointer registers). |
| 1192 TryFinally try_block(this, &finally_entry); | 1204 TryFinally try_block(this, &finally_entry); |
| 1193 __ PushTryHandler(IN_JAVASCRIPT, TRY_FINALLY_HANDLER); | 1205 __ PushTryHandler(IN_JAVASCRIPT, TRY_FINALLY_HANDLER); |
| 1206 set_stack_height(try_block_stack_height); |
| 1194 Visit(stmt->try_block()); | 1207 Visit(stmt->try_block()); |
| 1195 __ PopTryHandler(); | 1208 __ PopTryHandler(); |
| 1209 set_stack_height(original_stack_height); |
| 1196 } | 1210 } |
| 1197 // Execute the finally block on the way out. Clobber the unpredictable | 1211 // Execute the finally block on the way out. Clobber the unpredictable |
| 1198 // value in the accumulator with one that's safe for GC. The finally | 1212 // value in the accumulator with one that's safe for GC. The finally |
| 1199 // block will unconditionally preserve the accumulator on the stack. | 1213 // block will unconditionally preserve the accumulator on the stack. |
| 1200 ClearAccumulator(); | 1214 ClearAccumulator(); |
| 1201 __ Call(&finally_entry); | 1215 __ Call(&finally_entry); |
| 1202 } | 1216 } |
| 1203 | 1217 |
| 1204 | 1218 |
| 1205 void FullCodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) { | 1219 void FullCodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) { |
| 1206 #ifdef ENABLE_DEBUGGER_SUPPORT | 1220 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1207 Comment cmnt(masm_, "[ DebuggerStatement"); | 1221 Comment cmnt(masm_, "[ DebuggerStatement"); |
| 1208 SetStatementPosition(stmt); | 1222 SetStatementPosition(stmt); |
| 1209 | 1223 |
| 1210 __ DebugBreak(); | 1224 __ DebugBreak(); |
| 1211 // Ignore the return value. | 1225 // Ignore the return value. |
| 1212 #endif | 1226 #endif |
| 1213 } | 1227 } |
| 1214 | 1228 |
| 1215 | 1229 |
| 1216 void FullCodeGenerator::VisitConditional(Conditional* expr) { | 1230 void FullCodeGenerator::VisitConditional(Conditional* expr) { |
| 1217 Comment cmnt(masm_, "[ Conditional"); | 1231 Comment cmnt(masm_, "[ Conditional"); |
| 1218 Label true_case, false_case, done; | 1232 Label true_case, false_case, done; |
| 1219 VisitForControl(expr->condition(), &true_case, &false_case, &true_case); | 1233 VisitForControl(expr->condition(), &true_case, &false_case, &true_case); |
| 1220 | 1234 |
| 1221 PrepareForBailoutForId(expr->ThenId(), NO_REGISTERS); | 1235 PrepareForBailoutForId(expr->ThenId(), NO_REGISTERS); |
| 1222 __ bind(&true_case); | 1236 __ bind(&true_case); |
| 1223 SetExpressionPosition(expr->then_expression(), | 1237 SetExpressionPosition(expr->then_expression(), |
| 1224 expr->then_expression_position()); | 1238 expr->then_expression_position()); |
| 1239 int start_stack_height = stack_height(); |
| 1225 if (context()->IsTest()) { | 1240 if (context()->IsTest()) { |
| 1226 const TestContext* for_test = TestContext::cast(context()); | 1241 const TestContext* for_test = TestContext::cast(context()); |
| 1227 VisitForControl(expr->then_expression(), | 1242 VisitForControl(expr->then_expression(), |
| 1228 for_test->true_label(), | 1243 for_test->true_label(), |
| 1229 for_test->false_label(), | 1244 for_test->false_label(), |
| 1230 NULL); | 1245 NULL); |
| 1231 } else { | 1246 } else { |
| 1232 VisitInCurrentContext(expr->then_expression()); | 1247 VisitInCurrentContext(expr->then_expression()); |
| 1233 __ jmp(&done); | 1248 __ jmp(&done); |
| 1234 } | 1249 } |
| 1235 | 1250 |
| 1236 PrepareForBailoutForId(expr->ElseId(), NO_REGISTERS); | 1251 PrepareForBailoutForId(expr->ElseId(), NO_REGISTERS); |
| 1237 __ bind(&false_case); | 1252 __ bind(&false_case); |
| 1253 set_stack_height(start_stack_height); |
| 1238 if (context()->IsTest()) ForwardBailoutToChild(expr); | 1254 if (context()->IsTest()) ForwardBailoutToChild(expr); |
| 1239 SetExpressionPosition(expr->else_expression(), | 1255 SetExpressionPosition(expr->else_expression(), |
| 1240 expr->else_expression_position()); | 1256 expr->else_expression_position()); |
| 1241 VisitInCurrentContext(expr->else_expression()); | 1257 VisitInCurrentContext(expr->else_expression()); |
| 1242 // If control flow falls through Visit, merge it with true case here. | 1258 // If control flow falls through Visit, merge it with true case here. |
| 1243 if (!context()->IsTest()) { | 1259 if (!context()->IsTest()) { |
| 1244 __ bind(&done); | 1260 __ bind(&done); |
| 1245 } | 1261 } |
| 1246 } | 1262 } |
| 1247 | 1263 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1268 | 1284 |
| 1269 void FullCodeGenerator::VisitSharedFunctionInfoLiteral( | 1285 void FullCodeGenerator::VisitSharedFunctionInfoLiteral( |
| 1270 SharedFunctionInfoLiteral* expr) { | 1286 SharedFunctionInfoLiteral* expr) { |
| 1271 Comment cmnt(masm_, "[ SharedFunctionInfoLiteral"); | 1287 Comment cmnt(masm_, "[ SharedFunctionInfoLiteral"); |
| 1272 EmitNewClosure(expr->shared_function_info(), false); | 1288 EmitNewClosure(expr->shared_function_info(), false); |
| 1273 } | 1289 } |
| 1274 | 1290 |
| 1275 | 1291 |
| 1276 void FullCodeGenerator::VisitThrow(Throw* expr) { | 1292 void FullCodeGenerator::VisitThrow(Throw* expr) { |
| 1277 Comment cmnt(masm_, "[ Throw"); | 1293 Comment cmnt(masm_, "[ Throw"); |
| 1294 // Throw has no effect on the stack height or the current expression context. |
| 1295 // Usually the expression context is null, because throw is a statement. |
| 1278 VisitForStackValue(expr->exception()); | 1296 VisitForStackValue(expr->exception()); |
| 1279 __ CallRuntime(Runtime::kThrow, 1); | 1297 __ CallRuntime(Runtime::kThrow, 1); |
| 1298 decrement_stack_height(); |
| 1280 // Never returns here. | 1299 // Never returns here. |
| 1281 } | 1300 } |
| 1282 | 1301 |
| 1283 | 1302 |
| 1284 int FullCodeGenerator::TryFinally::Exit(int stack_depth) { | 1303 int FullCodeGenerator::TryFinally::Exit(int stack_depth) { |
| 1285 // The macros used here must preserve the result register. | 1304 // The macros used here must preserve the result register. |
| 1286 __ Drop(stack_depth); | 1305 __ Drop(stack_depth); |
| 1287 __ PopTryHandler(); | 1306 __ PopTryHandler(); |
| 1288 __ Call(finally_entry_); | 1307 __ Call(finally_entry_); |
| 1289 return 0; | 1308 return 0; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1315 } | 1334 } |
| 1316 | 1335 |
| 1317 return false; | 1336 return false; |
| 1318 } | 1337 } |
| 1319 | 1338 |
| 1320 | 1339 |
| 1321 #undef __ | 1340 #undef __ |
| 1322 | 1341 |
| 1323 | 1342 |
| 1324 } } // namespace v8::internal | 1343 } } // namespace v8::internal |
| OLD | NEW |