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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 __ add(lr, pc, Operand(Assembler::kInstrSize)); | 78 __ add(lr, pc, Operand(Assembler::kInstrSize)); |
79 __ cmp(sp, Operand(r2)); | 79 __ cmp(sp, Operand(r2)); |
80 StackCheckStub stub; | 80 StackCheckStub stub; |
81 __ mov(pc, | 81 __ mov(pc, |
82 Operand(reinterpret_cast<intptr_t>(stub.GetCode().location()), | 82 Operand(reinterpret_cast<intptr_t>(stub.GetCode().location()), |
83 RelocInfo::CODE_TARGET), | 83 RelocInfo::CODE_TARGET), |
84 LeaveCC, | 84 LeaveCC, |
85 lo); | 85 lo); |
86 } | 86 } |
87 | 87 |
| 88 { Comment cmnt(masm_, "[ Declarations"); |
| 89 VisitDeclarations(fun->scope()->declarations()); |
| 90 } |
| 91 |
88 { Comment cmnt(masm_, "[ Body"); | 92 { Comment cmnt(masm_, "[ Body"); |
89 VisitStatements(fun->body()); | 93 VisitStatements(fun->body()); |
90 } | 94 } |
91 | 95 |
92 { Comment cmnt(masm_, "[ return <undefined>;"); | 96 { Comment cmnt(masm_, "[ return <undefined>;"); |
93 // Emit a 'return undefined' in case control fell off the end of the | 97 // Emit a 'return undefined' in case control fell off the end of the |
94 // body. | 98 // body. |
95 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); | 99 __ LoadRoot(r0, Heap::kUndefinedValueRootIndex); |
96 SetReturnPosition(fun); | 100 SetReturnPosition(fun); |
97 __ RecordJSReturn(); | 101 __ RecordJSReturn(); |
98 __ mov(sp, fp); | 102 __ mov(sp, fp); |
99 __ ldm(ia_w, sp, fp.bit() | lr.bit()); | 103 __ ldm(ia_w, sp, fp.bit() | lr.bit()); |
100 int num_parameters = function_->scope()->num_parameters(); | 104 int num_parameters = function_->scope()->num_parameters(); |
101 __ add(sp, sp, Operand((num_parameters + 1) * kPointerSize)); | 105 __ add(sp, sp, Operand((num_parameters + 1) * kPointerSize)); |
102 __ Jump(lr); | 106 __ Jump(lr); |
103 } | 107 } |
104 } | 108 } |
105 | 109 |
106 | 110 |
| 111 void FastCodeGenerator::DeclareGlobals(Handle<FixedArray> pairs) { |
| 112 // Call the runtime to declare the globals. |
| 113 __ mov(r0, Operand(pairs)); |
| 114 __ push(r0); |
| 115 __ push(cp); // The context is the second argument. |
| 116 __ mov(r0, Operand(Smi::FromInt(is_eval_ ? 1 : 0))); |
| 117 __ push(r0); |
| 118 __ CallRuntime(Runtime::kDeclareGlobals, 3); |
| 119 // Return value is ignored. |
| 120 } |
| 121 |
| 122 |
| 123 void FastCodeGenerator::VisitBlock(Block* stmt) { |
| 124 Comment cmnt(masm_, "[ Block"); |
| 125 SetStatementPosition(stmt); |
| 126 VisitStatements(stmt->statements()); |
| 127 } |
| 128 |
| 129 |
107 void FastCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { | 130 void FastCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) { |
108 Comment cmnt(masm_, "[ ExpressionStatement"); | 131 Comment cmnt(masm_, "[ ExpressionStatement"); |
109 SetStatementPosition(stmt); | 132 SetStatementPosition(stmt); |
110 Visit(stmt->expression()); | 133 Visit(stmt->expression()); |
111 } | 134 } |
112 | 135 |
113 | 136 |
114 void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { | 137 void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { |
115 Comment cmnt(masm_, "[ ReturnStatement"); | 138 Comment cmnt(masm_, "[ ReturnStatement"); |
116 SetStatementPosition(stmt); | 139 SetStatementPosition(stmt); |
(...skipping 12 matching lines...) Expand all Loading... |
129 } | 152 } |
130 __ RecordJSReturn(); | 153 __ RecordJSReturn(); |
131 __ mov(sp, fp); | 154 __ mov(sp, fp); |
132 __ ldm(ia_w, sp, fp.bit() | lr.bit()); | 155 __ ldm(ia_w, sp, fp.bit() | lr.bit()); |
133 int num_parameters = function_->scope()->num_parameters(); | 156 int num_parameters = function_->scope()->num_parameters(); |
134 __ add(sp, sp, Operand((num_parameters + 1) * kPointerSize)); | 157 __ add(sp, sp, Operand((num_parameters + 1) * kPointerSize)); |
135 __ Jump(lr); | 158 __ Jump(lr); |
136 } | 159 } |
137 | 160 |
138 | 161 |
| 162 void FastCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) { |
| 163 Comment cmnt(masm_, "[ FunctionLiteral"); |
| 164 |
| 165 // Build the function boilerplate and instantiate it. |
| 166 Handle<JSFunction> boilerplate = BuildBoilerplate(expr); |
| 167 if (HasStackOverflow()) return; |
| 168 |
| 169 ASSERT(boilerplate->IsBoilerplate()); |
| 170 |
| 171 // Create a new closure. |
| 172 __ mov(r0, Operand(boilerplate)); |
| 173 __ push(r0); |
| 174 __ push(cp); |
| 175 __ CallRuntime(Runtime::kNewClosure, 2); |
| 176 |
| 177 if (expr->location().is_temporary()) { |
| 178 __ push(r0); |
| 179 } else { |
| 180 ASSERT(expr->location().is_nowhere()); |
| 181 } |
| 182 } |
| 183 |
| 184 |
139 void FastCodeGenerator::VisitVariableProxy(VariableProxy* expr) { | 185 void FastCodeGenerator::VisitVariableProxy(VariableProxy* expr) { |
140 Comment cmnt(masm_, "[ VariableProxy"); | 186 Comment cmnt(masm_, "[ VariableProxy"); |
141 Expression* rewrite = expr->var()->rewrite(); | 187 Expression* rewrite = expr->var()->rewrite(); |
142 ASSERT(rewrite != NULL); | 188 ASSERT(rewrite != NULL); |
143 | 189 |
144 Slot* slot = rewrite->AsSlot(); | 190 Slot* slot = rewrite->AsSlot(); |
145 ASSERT(slot != NULL); | 191 ASSERT(slot != NULL); |
146 { Comment cmnt(masm_, "[ Slot"); | 192 { Comment cmnt(masm_, "[ Slot"); |
147 if (expr->location().is_temporary()) { | 193 if (expr->location().is_temporary()) { |
148 __ ldr(ip, MemOperand(fp, SlotOffset(slot))); | 194 __ ldr(ip, MemOperand(fp, SlotOffset(slot))); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 __ str(ip, MemOperand(fp, SlotOffset(var->slot()))); | 263 __ str(ip, MemOperand(fp, SlotOffset(var->slot()))); |
218 if (destination.is_temporary()) { | 264 if (destination.is_temporary()) { |
219 // Case 'temp <- (var = constant)'. Save result. | 265 // Case 'temp <- (var = constant)'. Save result. |
220 __ push(ip); | 266 __ push(ip); |
221 } | 267 } |
222 } | 268 } |
223 } | 269 } |
224 } | 270 } |
225 | 271 |
226 | 272 |
| 273 void FastCodeGenerator::VisitCall(Call* expr) { |
| 274 Comment cmnt(masm_, "[ Call"); |
| 275 Expression* fun = expr->expression(); |
| 276 ZoneList<Expression*>* args = expr->arguments(); |
| 277 Variable* var = fun->AsVariableProxy()->AsVariable(); |
| 278 ASSERT(var != NULL && !var->is_this() && var->is_global()); |
| 279 ASSERT(!var->is_possibly_eval()); |
| 280 |
| 281 __ mov(r0, Operand(var->name())); |
| 282 __ push(r0); |
| 283 // Push global object (receiver) |
| 284 __ ldr(r0, CodeGenerator::GlobalObject()); |
| 285 __ push(r0); |
| 286 int arg_count = args->length(); |
| 287 for (int i = 0; i < arg_count; i++) { |
| 288 Visit(args->at(i)); |
| 289 ASSERT(!args->at(i)->location().is_nowhere()); |
| 290 if (args->at(i)->location().is_constant()) { |
| 291 ASSERT(args->at(i)->AsLiteral() != NULL); |
| 292 __ mov(r0, Operand(args->at(i)->AsLiteral()->handle())); |
| 293 __ push(r0); |
| 294 } |
| 295 } |
| 296 // Record source position for debugger |
| 297 SetSourcePosition(expr->position()); |
| 298 // Call the IC initialization code. |
| 299 Handle<Code> ic = CodeGenerator::ComputeCallInitialize(arg_count, |
| 300 NOT_IN_LOOP); |
| 301 __ Call(ic, RelocInfo::CODE_TARGET_CONTEXT); |
| 302 // Restore context register. |
| 303 __ ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 304 if (expr->location().is_temporary()) { |
| 305 __ str(r0, MemOperand(sp)); |
| 306 } else { |
| 307 ASSERT(expr->location().is_nowhere()); |
| 308 __ pop(); |
| 309 } |
| 310 } |
| 311 |
| 312 |
| 313 void FastCodeGenerator::VisitCallRuntime(CallRuntime* expr) { |
| 314 Comment cmnt(masm_, "[ CallRuntime"); |
| 315 ZoneList<Expression*>* args = expr->arguments(); |
| 316 Runtime::Function* function = expr->function(); |
| 317 |
| 318 ASSERT(function != NULL); |
| 319 |
| 320 // Push the arguments ("left-to-right"). |
| 321 int arg_count = args->length(); |
| 322 for (int i = 0; i < arg_count; i++) { |
| 323 Visit(args->at(i)); |
| 324 ASSERT(!args->at(i)->location().is_nowhere()); |
| 325 if (args->at(i)->location().is_constant()) { |
| 326 ASSERT(args->at(i)->AsLiteral() != NULL); |
| 327 __ mov(r0, Operand(args->at(i)->AsLiteral()->handle())); |
| 328 __ push(r0); |
| 329 } |
| 330 } |
| 331 |
| 332 __ CallRuntime(function, arg_count); |
| 333 if (expr->location().is_temporary()) { |
| 334 __ push(r0); |
| 335 } else { |
| 336 ASSERT(expr->location().is_nowhere()); |
| 337 } |
| 338 } |
| 339 |
| 340 |
227 } } // namespace v8::internal | 341 } } // namespace v8::internal |
OLD | NEW |