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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 __ CallRuntime(Runtime::kTraceEnter, 0); | 84 __ CallRuntime(Runtime::kTraceEnter, 0); |
85 } | 85 } |
86 | 86 |
87 { Comment cmnt(masm_, "[ Body"); | 87 { Comment cmnt(masm_, "[ Body"); |
88 ASSERT(loop_depth() == 0); | 88 ASSERT(loop_depth() == 0); |
89 VisitStatements(fun->body()); | 89 VisitStatements(fun->body()); |
90 ASSERT(loop_depth() == 0); | 90 ASSERT(loop_depth() == 0); |
91 } | 91 } |
92 | 92 |
93 { Comment cmnt(masm_, "[ return <undefined>;"); | 93 { Comment cmnt(masm_, "[ return <undefined>;"); |
94 // Emit a 'return undefined' in case control fell off the end of the | 94 // Emit a 'return undefined' in case control fell off the end of the body. |
95 // body. | |
96 __ mov(eax, Factory::undefined_value()); | 95 __ mov(eax, Factory::undefined_value()); |
97 } | 96 EmitReturnSequence(function_->end_position()); |
98 { Comment cmnt(masm_, "[ Return sequence"); | |
99 SetReturnPosition(fun); | |
100 | |
101 if (return_label_.is_bound()) { | |
102 __ jmp(&return_label_); | |
103 } else { | |
104 // Common return label | |
105 __ bind(&return_label_); | |
106 | |
107 if (FLAG_trace) { | |
108 __ push(eax); | |
109 __ CallRuntime(Runtime::kTraceExit, 1); | |
110 } | |
111 __ RecordJSReturn(); | |
112 // Do not use the leave instruction here because it is too short to | |
113 // patch with the code required by the debugger. | |
114 __ mov(esp, ebp); | |
115 __ pop(ebp); | |
116 __ ret((fun->scope()->num_parameters() + 1) * kPointerSize); | |
117 } | |
118 } | 97 } |
119 } | 98 } |
120 | 99 |
| 100 |
| 101 void FastCodeGenerator::EmitReturnSequence(int position) { |
| 102 Comment cmnt(masm_, "[ Return sequence"); |
| 103 if (return_label_.is_bound()) { |
| 104 __ jmp(&return_label_); |
| 105 } else { |
| 106 // Common return label |
| 107 __ bind(&return_label_); |
| 108 if (FLAG_trace) { |
| 109 __ push(eax); |
| 110 __ CallRuntime(Runtime::kTraceExit, 1); |
| 111 } |
| 112 #ifdef DEBUG |
| 113 // Add a label for checking the size of the code used for returning. |
| 114 Label check_exit_codesize; |
| 115 masm_->bind(&check_exit_codesize); |
| 116 #endif |
| 117 CodeGenerator::RecordPositions(masm_, position); |
| 118 __ RecordJSReturn(); |
| 119 // Do not use the leave instruction here because it is too short to |
| 120 // patch with the code required by the debugger. |
| 121 __ mov(esp, ebp); |
| 122 __ pop(ebp); |
| 123 __ ret((function_->scope()->num_parameters() + 1) * kPointerSize); |
| 124 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 125 // Check that the size of the code used for returning matches what is |
| 126 // expected by the debugger. |
| 127 ASSERT_EQ(Debug::kIa32JSReturnSequenceLength, |
| 128 masm_->SizeOfCodeGeneratedSince(&check_exit_codesize)); |
| 129 #endif |
| 130 } |
| 131 } |
| 132 |
121 | 133 |
122 void FastCodeGenerator::Move(Expression::Context context, Register source) { | 134 void FastCodeGenerator::Move(Expression::Context context, Register source) { |
123 switch (context) { | 135 switch (context) { |
124 case Expression::kUninitialized: | 136 case Expression::kUninitialized: |
125 UNREACHABLE(); | 137 UNREACHABLE(); |
126 case Expression::kEffect: | 138 case Expression::kEffect: |
127 break; | 139 break; |
128 case Expression::kValue: | 140 case Expression::kValue: |
129 __ push(source); | 141 __ push(source); |
130 break; | 142 break; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 __ push(esi); // The context is the first argument. | 275 __ push(esi); // The context is the first argument. |
264 __ push(Immediate(pairs)); | 276 __ push(Immediate(pairs)); |
265 __ push(Immediate(Smi::FromInt(is_eval_ ? 1 : 0))); | 277 __ push(Immediate(Smi::FromInt(is_eval_ ? 1 : 0))); |
266 __ CallRuntime(Runtime::kDeclareGlobals, 3); | 278 __ CallRuntime(Runtime::kDeclareGlobals, 3); |
267 // Return value is ignored. | 279 // Return value is ignored. |
268 } | 280 } |
269 | 281 |
270 | 282 |
271 void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { | 283 void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { |
272 Comment cmnt(masm_, "[ ReturnStatement"); | 284 Comment cmnt(masm_, "[ ReturnStatement"); |
273 SetStatementPosition(stmt); | |
274 Expression* expr = stmt->expression(); | 285 Expression* expr = stmt->expression(); |
275 if (expr->AsLiteral() != NULL) { | 286 if (expr->AsLiteral() != NULL) { |
276 __ mov(eax, expr->AsLiteral()->handle()); | 287 __ mov(eax, expr->AsLiteral()->handle()); |
277 } else { | 288 } else { |
278 ASSERT_EQ(Expression::kValue, expr->context()); | 289 ASSERT_EQ(Expression::kValue, expr->context()); |
279 Visit(expr); | 290 Visit(expr); |
280 __ pop(eax); | 291 __ pop(eax); |
281 } | 292 } |
282 | 293 EmitReturnSequence(stmt->statement_pos()); |
283 if (return_label_.is_bound()) { | |
284 __ jmp(&return_label_); | |
285 } else { | |
286 __ bind(&return_label_); | |
287 | |
288 if (FLAG_trace) { | |
289 __ push(eax); | |
290 __ CallRuntime(Runtime::kTraceExit, 1); | |
291 } | |
292 | |
293 __ RecordJSReturn(); | |
294 | |
295 // Do not use the leave instruction here because it is too short to | |
296 // patch with the code required by the debugger. | |
297 __ mov(esp, ebp); | |
298 __ pop(ebp); | |
299 __ ret((function_->scope()->num_parameters() + 1) * kPointerSize); | |
300 } | |
301 } | 294 } |
302 | 295 |
303 | 296 |
304 void FastCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { | 297 void FastCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { |
305 Comment cmnt(masm_, "[ FunctionLiteral"); | 298 Comment cmnt(masm_, "[ FunctionLiteral"); |
306 | 299 |
307 // Build the function boilerplate and instantiate it. | 300 // Build the function boilerplate and instantiate it. |
308 Handle<JSFunction> boilerplate = BuildBoilerplate(expr); | 301 Handle<JSFunction> boilerplate = BuildBoilerplate(expr); |
309 if (HasStackOverflow()) return; | 302 if (HasStackOverflow()) return; |
310 | 303 |
(...skipping 975 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1286 true_label_ = saved_true; | 1279 true_label_ = saved_true; |
1287 false_label_ = saved_false; | 1280 false_label_ = saved_false; |
1288 // Convert current context to test context: End post-test code. | 1281 // Convert current context to test context: End post-test code. |
1289 } | 1282 } |
1290 | 1283 |
1291 | 1284 |
1292 #undef __ | 1285 #undef __ |
1293 | 1286 |
1294 | 1287 |
1295 } } // namespace v8::internal | 1288 } } // namespace v8::internal |
OLD | NEW |