| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 Label ok; | 68 Label ok; |
| 69 ExternalReference stack_guard_limit = | 69 ExternalReference stack_guard_limit = |
| 70 ExternalReference::address_of_stack_guard_limit(); | 70 ExternalReference::address_of_stack_guard_limit(); |
| 71 __ cmp(esp, Operand::StaticVariable(stack_guard_limit)); | 71 __ cmp(esp, Operand::StaticVariable(stack_guard_limit)); |
| 72 __ j(above_equal, &ok, taken); | 72 __ j(above_equal, &ok, taken); |
| 73 StackCheckStub stub; | 73 StackCheckStub stub; |
| 74 __ CallStub(&stub); | 74 __ CallStub(&stub); |
| 75 __ bind(&ok); | 75 __ bind(&ok); |
| 76 } | 76 } |
| 77 | 77 |
| 78 { Comment cmnt(masm_, "[ Declarations"); |
| 79 VisitDeclarations(fun->scope()->declarations()); |
| 80 } |
| 81 |
| 78 { Comment cmnt(masm_, "[ Body"); | 82 { Comment cmnt(masm_, "[ Body"); |
| 79 VisitStatements(fun->body()); | 83 VisitStatements(fun->body()); |
| 80 } | 84 } |
| 81 | 85 |
| 82 { Comment cmnt(masm_, "[ return <undefined>;"); | 86 { Comment cmnt(masm_, "[ return <undefined>;"); |
| 83 // Emit a 'return undefined' in case control fell off the end of the | 87 // Emit a 'return undefined' in case control fell off the end of the |
| 84 // body. | 88 // body. |
| 85 __ mov(eax, Factory::undefined_value()); | 89 __ mov(eax, Factory::undefined_value()); |
| 86 SetReturnPosition(fun); | 90 SetReturnPosition(fun); |
| 87 __ RecordJSReturn(); | 91 __ RecordJSReturn(); |
| 88 // Do not use the leave instruction here because it is too short to | 92 // Do not use the leave instruction here because it is too short to |
| 89 // patch with the code required by the debugger. | 93 // patch with the code required by the debugger. |
| 90 __ mov(esp, ebp); | 94 __ mov(esp, ebp); |
| 91 __ pop(ebp); | 95 __ pop(ebp); |
| 92 __ ret((fun->scope()->num_parameters() + 1) * kPointerSize); | 96 __ ret((fun->scope()->num_parameters() + 1) * kPointerSize); |
| 93 } | 97 } |
| 94 } | 98 } |
| 95 | 99 |
| 96 | 100 |
| 101 void FastCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
| 102 // Call the runtime to declare the globals. |
| 103 __ push(Immediate(pairs)); |
| 104 __ push(esi); // The context is the second argument. |
| 105 __ push(Immediate(Smi::FromInt(is_eval_ ? 1 : 0))); |
| 106 __ CallRuntime(Runtime::kDeclareGlobals, 3); |
| 107 // Return value is ignored. |
| 108 } |
| 109 |
| 110 |
| 111 void FastCodeGenerator::VisitBlock(Block* stmt) { |
| 112 Comment cmnt(masm_, "[ Block"); |
| 113 SetStatementPosition(stmt); |
| 114 VisitStatements(stmt->statements()); |
| 115 } |
| 116 |
| 117 |
| 97 void FastCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { | 118 void FastCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { |
| 98 Comment cmnt(masm_, "[ ExpressionStatement"); | 119 Comment cmnt(masm_, "[ ExpressionStatement"); |
| 99 SetStatementPosition(stmt); | 120 SetStatementPosition(stmt); |
| 100 Visit(stmt->expression()); | 121 Visit(stmt->expression()); |
| 101 } | 122 } |
| 102 | 123 |
| 103 | 124 |
| 104 void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { | 125 void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { |
| 105 Comment cmnt(masm_, "[ ReturnStatement"); | 126 Comment cmnt(masm_, "[ ReturnStatement"); |
| 106 SetStatementPosition(stmt); | 127 SetStatementPosition(stmt); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 119 } | 140 } |
| 120 __ RecordJSReturn(); | 141 __ RecordJSReturn(); |
| 121 // Do not use the leave instruction here because it is too short to | 142 // Do not use the leave instruction here because it is too short to |
| 122 // patch with the code required by the debugger. | 143 // patch with the code required by the debugger. |
| 123 __ mov(esp, ebp); | 144 __ mov(esp, ebp); |
| 124 __ pop(ebp); | 145 __ pop(ebp); |
| 125 __ ret((function_->scope()->num_parameters() + 1) * kPointerSize); | 146 __ ret((function_->scope()->num_parameters() + 1) * kPointerSize); |
| 126 } | 147 } |
| 127 | 148 |
| 128 | 149 |
| 150 void FastCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { |
| 151 Comment cmnt(masm_, "[ FunctionLiteral"); |
| 152 |
| 153 // Build the function boilerplate and instantiate it. |
| 154 Handle<JSFunction> boilerplate = BuildBoilerplate(expr); |
| 155 if (HasStackOverflow()) return; |
| 156 |
| 157 ASSERT(boilerplate->IsBoilerplate()); |
| 158 |
| 159 // Create a new closure. |
| 160 __ push(Immediate(boilerplate)); |
| 161 __ push(esi); |
| 162 __ CallRuntime(Runtime::kNewClosure, 2); |
| 163 |
| 164 if (expr->location().is_temporary()) { |
| 165 __ push(eax); |
| 166 } else { |
| 167 ASSERT(expr->location().is_nowhere()); |
| 168 } |
| 169 } |
| 170 |
| 171 |
| 129 void FastCodeGenerator::VisitVariableProxy(VariableProxy* expr) { | 172 void FastCodeGenerator::VisitVariableProxy(VariableProxy* expr) { |
| 130 Comment cmnt(masm_, "[ VariableProxy"); | 173 Comment cmnt(masm_, "[ VariableProxy"); |
| 131 Expression* rewrite = expr->var()->rewrite(); | 174 Expression* rewrite = expr->var()->rewrite(); |
| 132 ASSERT(rewrite != NULL); | 175 ASSERT(rewrite != NULL); |
| 133 | 176 |
| 134 Slot* slot = rewrite->AsSlot(); | 177 Slot* slot = rewrite->AsSlot(); |
| 135 ASSERT(slot != NULL); | 178 ASSERT(slot != NULL); |
| 136 { Comment cmnt(masm_, "[ Slot"); | 179 { Comment cmnt(masm_, "[ Slot"); |
| 137 if (expr->location().is_temporary()) { | 180 if (expr->location().is_temporary()) { |
| 138 __ push(Operand(ebp, SlotOffset(slot))); | 181 __ push(Operand(ebp, SlotOffset(slot))); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 __ mov(Operand(ebp, SlotOffset(var->slot())), eax); | 249 __ mov(Operand(ebp, SlotOffset(var->slot())), eax); |
| 207 if (destination.is_temporary()) { | 250 if (destination.is_temporary()) { |
| 208 // Case 'temp <- (var = constant)'. Save result. | 251 // Case 'temp <- (var = constant)'. Save result. |
| 209 __ push(eax); | 252 __ push(eax); |
| 210 } | 253 } |
| 211 } | 254 } |
| 212 } | 255 } |
| 213 } | 256 } |
| 214 | 257 |
| 215 | 258 |
| 259 void FastCodeGenerator::VisitCall(Call* expr) { |
| 260 Expression* fun = expr->expression(); |
| 261 ZoneList<Expression*>* args = expr->arguments(); |
| 262 Variable* var = fun->AsVariableProxy()->AsVariable(); |
| 263 ASSERT(var != NULL && !var->is_this() && var->is_global()); |
| 264 ASSERT(!var->is_possibly_eval()); |
| 265 |
| 266 __ push(Immediate(var->name())); |
| 267 // Push global object (receiver). |
| 268 __ push(CodeGenerator::GlobalObject()); |
| 269 int arg_count = args->length(); |
| 270 for (int i = 0; i < arg_count; i++) { |
| 271 Visit(args->at(i)); |
| 272 ASSERT(!args->at(i)->location().is_nowhere()); |
| 273 if (args->at(i)->location().is_constant()) { |
| 274 ASSERT(args->at(i)->AsLiteral() != NULL); |
| 275 __ push(Immediate(args->at(i)->AsLiteral()->handle())); |
| 276 } |
| 277 } |
| 278 // Record source position for debugger |
| 279 SetSourcePosition(expr->position()); |
| 280 // Call the IC initialization code. |
| 281 Handle<Code> ic = CodeGenerator::ComputeCallInitialize(arg_count, |
| 282 NOT_IN_LOOP); |
| 283 __ call(ic, RelocInfo::CODE_TARGET_CONTEXT); |
| 284 // Restore context register. |
| 285 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 286 // Discard the function left on TOS. |
| 287 if (expr->location().is_temporary()) { |
| 288 __ mov(Operand(esp, 0), eax); |
| 289 } else { |
| 290 ASSERT(expr->location().is_nowhere()); |
| 291 __ pop(eax); |
| 292 } |
| 293 } |
| 294 |
| 295 |
| 296 void FastCodeGenerator::VisitCallRuntime(CallRuntime* expr) { |
| 297 Comment cmnt(masm_, "[ CallRuntime"); |
| 298 ZoneList<Expression*>* args = expr->arguments(); |
| 299 Runtime::Function* function = expr->function(); |
| 300 |
| 301 ASSERT(function != NULL); |
| 302 |
| 303 // Push the arguments ("left-to-right"). |
| 304 int arg_count = args->length(); |
| 305 for (int i = 0; i < arg_count; i++) { |
| 306 Visit(args->at(i)); |
| 307 ASSERT(!args->at(i)->location().is_nowhere()); |
| 308 if (args->at(i)->location().is_constant()) { |
| 309 ASSERT(args->at(i)->AsLiteral() != NULL); |
| 310 __ push(Immediate(args->at(i)->AsLiteral()->handle())); |
| 311 } |
| 312 } |
| 313 |
| 314 __ CallRuntime(function, arg_count); |
| 315 if (expr->location().is_temporary()) { |
| 316 __ push(eax); |
| 317 } else { |
| 318 ASSERT(expr->location().is_nowhere()); |
| 319 } |
| 320 } |
| 321 |
| 322 |
| 216 } } // namespace v8::internal | 323 } } // namespace v8::internal |
| OLD | NEW |