| OLD | NEW |
| 1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 __ CallRuntime(Runtime::kTraceEnter, 0); | 83 __ CallRuntime(Runtime::kTraceEnter, 0); |
| 84 } | 84 } |
| 85 | 85 |
| 86 { Comment cmnt(masm_, "[ Body"); | 86 { Comment cmnt(masm_, "[ Body"); |
| 87 ASSERT(loop_depth() == 0); | 87 ASSERT(loop_depth() == 0); |
| 88 VisitStatements(fun->body()); | 88 VisitStatements(fun->body()); |
| 89 ASSERT(loop_depth() == 0); | 89 ASSERT(loop_depth() == 0); |
| 90 } | 90 } |
| 91 | 91 |
| 92 { Comment cmnt(masm_, "[ return <undefined>;"); | 92 { Comment cmnt(masm_, "[ return <undefined>;"); |
| 93 // Emit a 'return undefined' in case control fell off the end of the | 93 // Emit a 'return undefined' in case control fell off the end of the body. |
| 94 // body. | |
| 95 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); | 94 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
| 96 } | 95 EmitReturnSequence(function_->end_position()); |
| 97 { Comment cmnt(masm_, "Return sequence"); | |
| 98 SetReturnPosition(fun); | |
| 99 | |
| 100 if (return_label_.is_bound()) { | |
| 101 __ jmp(&return_label_); | |
| 102 } else { | |
| 103 __ bind(&return_label_); | |
| 104 | |
| 105 if (FLAG_trace) { | |
| 106 __ push(rax); | |
| 107 __ CallRuntime(Runtime::kTraceExit, 1); | |
| 108 } | |
| 109 __ RecordJSReturn(); | |
| 110 | |
| 111 // Do not use the leave instruction here because it is too short to | |
| 112 // patch with the code required by the debugger. | |
| 113 __ movq(rsp, rbp); | |
| 114 __ pop(rbp); | |
| 115 __ ret((fun->scope()->num_parameters() + 1) * kPointerSize); | |
| 116 #ifdef ENABLE_DEBUGGER_SUPPORT | |
| 117 // Add padding that will be overwritten by a debugger breakpoint. We | |
| 118 // have just generated "movq rsp, rbp; pop rbp; ret k" with length 7 | |
| 119 // (3 + 1 + 3). | |
| 120 const int kPadding = Debug::kX64JSReturnSequenceLength - 7; | |
| 121 for (int i = 0; i < kPadding; ++i) { | |
| 122 masm_->int3(); | |
| 123 } | |
| 124 #endif | |
| 125 } | |
| 126 } | 96 } |
| 127 } | 97 } |
| 128 | 98 |
| 129 | 99 |
| 100 void FastCodeGenerator::EmitReturnSequence(int position) { |
| 101 Comment cmnt(masm_, "[ Return sequence"); |
| 102 if (return_label_.is_bound()) { |
| 103 __ jmp(&return_label_); |
| 104 } else { |
| 105 __ bind(&return_label_); |
| 106 if (FLAG_trace) { |
| 107 __ push(rax); |
| 108 __ CallRuntime(Runtime::kTraceExit, 1); |
| 109 } |
| 110 #ifdef DEBUG |
| 111 // Add a label for checking the size of the code used for returning. |
| 112 Label check_exit_codesize; |
| 113 masm_->bind(&check_exit_codesize); |
| 114 #endif |
| 115 CodeGenerator::RecordPositions(masm_, position); |
| 116 __ RecordJSReturn(); |
| 117 // Do not use the leave instruction here because it is too short to |
| 118 // patch with the code required by the debugger. |
| 119 __ movq(rsp, rbp); |
| 120 __ pop(rbp); |
| 121 __ ret((function_->scope()->num_parameters() + 1) * kPointerSize); |
| 122 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 123 // Add padding that will be overwritten by a debugger breakpoint. We |
| 124 // have just generated "movq rsp, rbp; pop rbp; ret k" with length 7 |
| 125 // (3 + 1 + 3). |
| 126 const int kPadding = Debug::kX64JSReturnSequenceLength - 7; |
| 127 for (int i = 0; i < kPadding; ++i) { |
| 128 masm_->int3(); |
| 129 } |
| 130 // Check that the size of the code used for returning matches what is |
| 131 // expected by the debugger. |
| 132 ASSERT_EQ(Debug::Debug::kX64JSReturnSequenceLength, |
| 133 masm_->SizeOfCodeGeneratedSince(&check_exit_codesize)); |
| 134 #endif |
| 135 } |
| 136 } |
| 137 |
| 130 | 138 |
| 131 void FastCodeGenerator::Move(Expression::Context context, Register source) { | 139 void FastCodeGenerator::Move(Expression::Context context, Register source) { |
| 132 switch (context) { | 140 switch (context) { |
| 133 case Expression::kUninitialized: | 141 case Expression::kUninitialized: |
| 134 UNREACHABLE(); | 142 UNREACHABLE(); |
| 135 case Expression::kEffect: | 143 case Expression::kEffect: |
| 136 break; | 144 break; |
| 137 case Expression::kValue: | 145 case Expression::kValue: |
| 138 __ push(source); | 146 __ push(source); |
| 139 break; | 147 break; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 __ push(rsi); // The context is the first argument. | 283 __ push(rsi); // The context is the first argument. |
| 276 __ Push(pairs); | 284 __ Push(pairs); |
| 277 __ Push(Smi::FromInt(is_eval_ ? 1 : 0)); | 285 __ Push(Smi::FromInt(is_eval_ ? 1 : 0)); |
| 278 __ CallRuntime(Runtime::kDeclareGlobals, 3); | 286 __ CallRuntime(Runtime::kDeclareGlobals, 3); |
| 279 // Return value is ignored. | 287 // Return value is ignored. |
| 280 } | 288 } |
| 281 | 289 |
| 282 | 290 |
| 283 void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { | 291 void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { |
| 284 Comment cmnt(masm_, "[ ReturnStatement"); | 292 Comment cmnt(masm_, "[ ReturnStatement"); |
| 285 SetStatementPosition(stmt); | |
| 286 Expression* expr = stmt->expression(); | 293 Expression* expr = stmt->expression(); |
| 287 if (expr->AsLiteral() != NULL) { | 294 if (expr->AsLiteral() != NULL) { |
| 288 __ Move(rax, expr->AsLiteral()->handle()); | 295 __ Move(rax, expr->AsLiteral()->handle()); |
| 289 } else { | 296 } else { |
| 290 Visit(expr); | 297 Visit(expr); |
| 291 ASSERT_EQ(Expression::kValue, expr->context()); | 298 ASSERT_EQ(Expression::kValue, expr->context()); |
| 292 __ pop(rax); | 299 __ pop(rax); |
| 293 } | 300 } |
| 294 | 301 EmitReturnSequence(stmt->statement_pos()); |
| 295 if (return_label_.is_bound()) { | |
| 296 __ jmp(&return_label_); | |
| 297 } else { | |
| 298 __ bind(&return_label_); | |
| 299 | |
| 300 if (FLAG_trace) { | |
| 301 __ push(rax); | |
| 302 __ CallRuntime(Runtime::kTraceExit, 1); | |
| 303 } | |
| 304 | |
| 305 __ RecordJSReturn(); | |
| 306 // Do not use the leave instruction here because it is too short to | |
| 307 // patch with the code required by the debugger. | |
| 308 __ movq(rsp, rbp); | |
| 309 __ pop(rbp); | |
| 310 __ ret((function_->scope()->num_parameters() + 1) * kPointerSize); | |
| 311 #ifdef ENABLE_DEBUGGER_SUPPORT | |
| 312 // Add padding that will be overwritten by a debugger breakpoint. We | |
| 313 // have just generated "movq rsp, rbp; pop rbp; ret k" with length 7 | |
| 314 // (3 + 1 + 3). | |
| 315 const int kPadding = Debug::kX64JSReturnSequenceLength - 7; | |
| 316 for (int i = 0; i < kPadding; ++i) { | |
| 317 masm_->int3(); | |
| 318 } | |
| 319 #endif | |
| 320 } | |
| 321 } | 302 } |
| 322 | 303 |
| 323 | 304 |
| 324 void FastCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { | 305 void FastCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { |
| 325 Comment cmnt(masm_, "[ FunctionLiteral"); | 306 Comment cmnt(masm_, "[ FunctionLiteral"); |
| 326 | 307 |
| 327 // Build the function boilerplate and instantiate it. | 308 // Build the function boilerplate and instantiate it. |
| 328 Handle<JSFunction> boilerplate = BuildBoilerplate(expr); | 309 Handle<JSFunction> boilerplate = BuildBoilerplate(expr); |
| 329 if (HasStackOverflow()) return; | 310 if (HasStackOverflow()) return; |
| 330 | 311 |
| (...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1298 true_label_ = saved_true; | 1279 true_label_ = saved_true; |
| 1299 false_label_ = saved_false; | 1280 false_label_ = saved_false; |
| 1300 // Convert current context to test context: End post-test code. | 1281 // Convert current context to test context: End post-test code. |
| 1301 } | 1282 } |
| 1302 | 1283 |
| 1303 | 1284 |
| 1304 #undef __ | 1285 #undef __ |
| 1305 | 1286 |
| 1306 | 1287 |
| 1307 } } // namespace v8::internal | 1288 } } // namespace v8::internal |
| OLD | NEW |