blob: d810bb3dc0823a661d740708408c34e98462e332 [file] [log] [blame]
karlklose@chromium.org44bc7082011-04-11 12:33:05 +00001// Copyright 2011 the V8 project authors. All rights reserved.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00002// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#include "v8.h"
29
karlklose@chromium.org44bc7082011-04-11 12:33:05 +000030#include "codegen.h"
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +000031#include "compiler.h"
kasperl@chromium.orga5551262010-12-07 12:49:48 +000032#include "debug.h"
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +000033#include "full-codegen.h"
kasperl@chromium.orga5551262010-12-07 12:49:48 +000034#include "liveedit.h"
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +000035#include "macro-assembler.h"
kasperl@chromium.orga5551262010-12-07 12:49:48 +000036#include "prettyprinter.h"
sgjesse@chromium.org833cdd72010-02-26 10:06:16 +000037#include "scopes.h"
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +000038#include "scopeinfo.h"
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +000039#include "stub-cache.h"
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +000040
41namespace v8 {
42namespace internal {
43
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +000044void BreakableStatementChecker::Check(Statement* stmt) {
45 Visit(stmt);
46}
47
48
49void BreakableStatementChecker::Check(Expression* expr) {
50 Visit(expr);
51}
52
53
54void BreakableStatementChecker::VisitDeclaration(Declaration* decl) {
55}
56
57
58void BreakableStatementChecker::VisitBlock(Block* stmt) {
59}
60
61
62void BreakableStatementChecker::VisitExpressionStatement(
63 ExpressionStatement* stmt) {
64 // Check if expression is breakable.
65 Visit(stmt->expression());
66}
67
68
69void BreakableStatementChecker::VisitEmptyStatement(EmptyStatement* stmt) {
70}
71
72
73void BreakableStatementChecker::VisitIfStatement(IfStatement* stmt) {
74 // If the condition is breakable the if statement is breakable.
75 Visit(stmt->condition());
76}
77
78
79void BreakableStatementChecker::VisitContinueStatement(
80 ContinueStatement* stmt) {
81}
82
83
84void BreakableStatementChecker::VisitBreakStatement(BreakStatement* stmt) {
85}
86
87
88void BreakableStatementChecker::VisitReturnStatement(ReturnStatement* stmt) {
89 // Return is breakable if the expression is.
90 Visit(stmt->expression());
91}
92
93
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +000094void BreakableStatementChecker::VisitWithStatement(WithStatement* stmt) {
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +000095 Visit(stmt->expression());
96}
97
98
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +000099void BreakableStatementChecker::VisitExitContextStatement(
100 ExitContextStatement* stmt) {
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000101}
102
103
104void BreakableStatementChecker::VisitSwitchStatement(SwitchStatement* stmt) {
105 // Switch statements breakable if the tag expression is.
106 Visit(stmt->tag());
107}
108
109
110void BreakableStatementChecker::VisitDoWhileStatement(DoWhileStatement* stmt) {
111 // Mark do while as breakable to avoid adding a break slot in front of it.
112 is_breakable_ = true;
113}
114
115
116void BreakableStatementChecker::VisitWhileStatement(WhileStatement* stmt) {
117 // Mark while statements breakable if the condition expression is.
118 Visit(stmt->cond());
119}
120
121
122void BreakableStatementChecker::VisitForStatement(ForStatement* stmt) {
123 // Mark for statements breakable if the condition expression is.
124 if (stmt->cond() != NULL) {
125 Visit(stmt->cond());
126 }
127}
128
129
130void BreakableStatementChecker::VisitForInStatement(ForInStatement* stmt) {
131 // Mark for in statements breakable if the enumerable expression is.
132 Visit(stmt->enumerable());
133}
134
135
136void BreakableStatementChecker::VisitTryCatchStatement(
137 TryCatchStatement* stmt) {
138 // Mark try catch as breakable to avoid adding a break slot in front of it.
139 is_breakable_ = true;
140}
141
142
143void BreakableStatementChecker::VisitTryFinallyStatement(
144 TryFinallyStatement* stmt) {
145 // Mark try finally as breakable to avoid adding a break slot in front of it.
146 is_breakable_ = true;
147}
148
149
150void BreakableStatementChecker::VisitDebuggerStatement(
151 DebuggerStatement* stmt) {
152 // The debugger statement is breakable.
153 is_breakable_ = true;
154}
155
156
157void BreakableStatementChecker::VisitFunctionLiteral(FunctionLiteral* expr) {
158}
159
160
161void BreakableStatementChecker::VisitSharedFunctionInfoLiteral(
162 SharedFunctionInfoLiteral* expr) {
163}
164
165
166void BreakableStatementChecker::VisitConditional(Conditional* expr) {
167}
168
169
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000170void BreakableStatementChecker::VisitVariableProxy(VariableProxy* expr) {
171}
172
173
174void BreakableStatementChecker::VisitLiteral(Literal* expr) {
175}
176
177
178void BreakableStatementChecker::VisitRegExpLiteral(RegExpLiteral* expr) {
179}
180
181
182void BreakableStatementChecker::VisitObjectLiteral(ObjectLiteral* expr) {
183}
184
185
186void BreakableStatementChecker::VisitArrayLiteral(ArrayLiteral* expr) {
187}
188
189
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000190void BreakableStatementChecker::VisitAssignment(Assignment* expr) {
191 // If assigning to a property (including a global property) the assignment is
192 // breakable.
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000193 VariableProxy* proxy = expr->target()->AsVariableProxy();
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000194 Property* prop = expr->target()->AsProperty();
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000195 if (prop != NULL || (proxy != NULL && proxy->var()->IsUnallocated())) {
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000196 is_breakable_ = true;
197 return;
198 }
199
200 // Otherwise the assignment is breakable if the assigned value is.
201 Visit(expr->value());
202}
203
204
205void BreakableStatementChecker::VisitThrow(Throw* expr) {
206 // Throw is breakable if the expression is.
207 Visit(expr->exception());
208}
209
210
211void BreakableStatementChecker::VisitProperty(Property* expr) {
212 // Property load is breakable.
213 is_breakable_ = true;
214}
215
216
217void BreakableStatementChecker::VisitCall(Call* expr) {
218 // Function calls both through IC and call stub are breakable.
219 is_breakable_ = true;
220}
221
222
223void BreakableStatementChecker::VisitCallNew(CallNew* expr) {
224 // Function calls through new are breakable.
225 is_breakable_ = true;
226}
227
228
229void BreakableStatementChecker::VisitCallRuntime(CallRuntime* expr) {
230}
231
232
233void BreakableStatementChecker::VisitUnaryOperation(UnaryOperation* expr) {
234 Visit(expr->expression());
235}
236
237
238void BreakableStatementChecker::VisitCountOperation(CountOperation* expr) {
239 Visit(expr->expression());
240}
241
242
243void BreakableStatementChecker::VisitBinaryOperation(BinaryOperation* expr) {
244 Visit(expr->left());
jkummerow@chromium.orgddda9e82011-07-06 11:27:02 +0000245 if (expr->op() != Token::AND &&
246 expr->op() != Token::OR) {
247 Visit(expr->right());
248 }
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000249}
250
251
ricow@chromium.org65fae842010-08-25 15:26:24 +0000252void BreakableStatementChecker::VisitCompareToNull(CompareToNull* expr) {
253 Visit(expr->expression());
254}
255
256
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000257void BreakableStatementChecker::VisitCompareOperation(CompareOperation* expr) {
258 Visit(expr->left());
259 Visit(expr->right());
260}
261
262
263void BreakableStatementChecker::VisitThisFunction(ThisFunction* expr) {
264}
265
266
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000267#define __ ACCESS_MASM(masm())
268
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000269bool FullCodeGenerator::MakeCode(CompilationInfo* info) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000270 Isolate* isolate = info->isolate();
ager@chromium.org5c838252010-02-19 08:53:10 +0000271 Handle<Script> script = info->script();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000272 if (!script->IsUndefined() && !script->source()->IsUndefined()) {
273 int len = String::cast(script->source())->length();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000274 isolate->counters()->total_full_codegen_source_size()->Increment(len);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000275 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000276 if (FLAG_trace_codegen) {
277 PrintF("Full Compiler - ");
278 }
ager@chromium.org5c838252010-02-19 08:53:10 +0000279 CodeGenerator::MakeCodePrologue(info);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000280 const int kInitialBufferSize = 4 * KB;
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +0000281 MacroAssembler masm(info->isolate(), NULL, kInitialBufferSize);
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000282#ifdef ENABLE_GDB_JIT_INTERFACE
283 masm.positions_recorder()->StartGDBJITLineInfoRecording();
284#endif
ager@chromium.org5c838252010-02-19 08:53:10 +0000285
286 FullCodeGenerator cgen(&masm);
ager@chromium.orgea4f62e2010-08-16 16:28:43 +0000287 cgen.Generate(info);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000288 if (cgen.HasStackOverflow()) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000289 ASSERT(!isolate->has_pending_exception());
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000290 return false;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000291 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000292 unsigned table_offset = cgen.EmitStackCheckTable();
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000293
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000294 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION, NOT_IN_LOOP);
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000295 Handle<Code> code = CodeGenerator::MakeCodeEpilogue(&masm, flags, info);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000296 code->set_optimizable(info->IsOptimizable());
297 cgen.PopulateDeoptimizationData(code);
298 code->set_has_deoptimization_support(info->HasDeoptimizationSupport());
299 code->set_allow_osr_at_loop_nesting_level(0);
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000300 code->set_stack_check_table_offset(table_offset);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000301 CodeGenerator::PrintCode(code, info);
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000302 info->SetCode(code); // may be an empty handle.
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000303#ifdef ENABLE_GDB_JIT_INTERFACE
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000304 if (FLAG_gdbjit && !code.is_null()) {
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000305 GDBJITLineInfo* lineinfo =
306 masm.positions_recorder()->DetachGDBJITLineInfo();
307
308 GDBJIT(RegisterDetailedLineInfo(*code, lineinfo));
309 }
310#endif
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000311 return !code.is_null();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000312}
313
314
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000315unsigned FullCodeGenerator::EmitStackCheckTable() {
316 // The stack check table consists of a length (in number of entries)
317 // field, and then a sequence of entries. Each entry is a pair of AST id
318 // and code-relative pc offset.
319 masm()->Align(kIntSize);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000320 unsigned offset = masm()->pc_offset();
321 unsigned length = stack_checks_.length();
322 __ dd(length);
323 for (unsigned i = 0; i < length; ++i) {
324 __ dd(stack_checks_[i].id);
325 __ dd(stack_checks_[i].pc_and_state);
326 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000327 return offset;
328}
329
330
331void FullCodeGenerator::PopulateDeoptimizationData(Handle<Code> code) {
332 // Fill in the deoptimization information.
333 ASSERT(info_->HasDeoptimizationSupport() || bailout_entries_.is_empty());
334 if (!info_->HasDeoptimizationSupport()) return;
335 int length = bailout_entries_.length();
336 Handle<DeoptimizationOutputData> data =
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000337 isolate()->factory()->
338 NewDeoptimizationOutputData(length, TENURED);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000339 for (int i = 0; i < length; i++) {
340 data->SetAstId(i, Smi::FromInt(bailout_entries_[i].id));
341 data->SetPcAndState(i, Smi::FromInt(bailout_entries_[i].pc_and_state));
342 }
343 code->set_deoptimization_data(*data);
344}
345
346
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000347void FullCodeGenerator::PrepareForBailout(Expression* node, State state) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000348 PrepareForBailoutForId(node->id(), state);
349}
350
351
352void FullCodeGenerator::RecordJSReturnSite(Call* call) {
353 // We record the offset of the function return so we can rebuild the frame
354 // if the function was inlined, i.e., this is the return address in the
355 // inlined function's frame.
356 //
357 // The state is ignored. We defensively set it to TOS_REG, which is the
358 // real state of the unoptimized code at the return site.
359 PrepareForBailoutForId(call->ReturnId(), TOS_REG);
360#ifdef DEBUG
361 // In debug builds, mark the return so we can verify that this function
362 // was called.
363 ASSERT(!call->return_is_recorded_);
364 call->return_is_recorded_ = true;
365#endif
366}
367
368
369void FullCodeGenerator::PrepareForBailoutForId(int id, State state) {
370 // There's no need to prepare this code for bailouts from already optimized
371 // code or code that can't be optimized.
372 if (!FLAG_deopt || !info_->HasDeoptimizationSupport()) return;
373 unsigned pc_and_state =
374 StateField::encode(state) | PcField::encode(masm_->pc_offset());
375 BailoutEntry entry = { id, pc_and_state };
376#ifdef DEBUG
377 // Assert that we don't have multiple bailout entries for the same node.
378 for (int i = 0; i < bailout_entries_.length(); i++) {
379 if (bailout_entries_.at(i).id == entry.id) {
380 AstPrinter printer;
381 PrintF("%s", printer.PrintProgram(info_->function()));
382 UNREACHABLE();
383 }
384 }
385#endif // DEBUG
386 bailout_entries_.Add(entry);
387}
388
389
390void FullCodeGenerator::RecordStackCheck(int ast_id) {
391 // The pc offset does not need to be encoded and packed together with a
392 // state.
393 BailoutEntry entry = { ast_id, masm_->pc_offset() };
394 stack_checks_.Add(entry);
395}
396
397
ricow@chromium.org65fae842010-08-25 15:26:24 +0000398bool FullCodeGenerator::ShouldInlineSmiCase(Token::Value op) {
ricow@chromium.org65fae842010-08-25 15:26:24 +0000399 // Inline smi case inside loops, but not division and modulo which
400 // are too complicated and take up too much space.
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000401 if (op == Token::DIV ||op == Token::MOD) return false;
402 if (FLAG_always_inline_smi_code) return true;
403 return loop_depth_ > 0;
ricow@chromium.org65fae842010-08-25 15:26:24 +0000404}
405
406
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000407void FullCodeGenerator::EffectContext::Plug(Register reg) const {
408}
409
410
411void FullCodeGenerator::AccumulatorValueContext::Plug(Register reg) const {
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000412 __ Move(result_register(), reg);
413}
414
415
416void FullCodeGenerator::StackValueContext::Plug(Register reg) const {
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000417 __ push(reg);
vegorov@chromium.org7943d462011-08-01 11:41:52 +0000418 codegen()->increment_stack_height();
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000419}
420
421
422void FullCodeGenerator::TestContext::Plug(Register reg) const {
423 // For simplicity we always test the accumulator register.
424 __ Move(result_register(), reg);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000425 codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL);
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000426 codegen()->DoTest(this);
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000427}
428
429
430void FullCodeGenerator::EffectContext::PlugTOS() const {
431 __ Drop(1);
vegorov@chromium.org7943d462011-08-01 11:41:52 +0000432 codegen()->decrement_stack_height();
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000433}
434
435
436void FullCodeGenerator::AccumulatorValueContext::PlugTOS() const {
437 __ pop(result_register());
vegorov@chromium.org7943d462011-08-01 11:41:52 +0000438 codegen()->decrement_stack_height();
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000439}
440
441
442void FullCodeGenerator::StackValueContext::PlugTOS() const {
443}
444
445
446void FullCodeGenerator::TestContext::PlugTOS() const {
447 // For simplicity we always test the accumulator register.
448 __ pop(result_register());
vegorov@chromium.org7943d462011-08-01 11:41:52 +0000449 codegen()->decrement_stack_height();
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000450 codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL);
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000451 codegen()->DoTest(this);
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000452}
453
454
455void FullCodeGenerator::EffectContext::PrepareTest(
456 Label* materialize_true,
457 Label* materialize_false,
458 Label** if_true,
459 Label** if_false,
460 Label** fall_through) const {
461 // In an effect context, the true and the false case branch to the
462 // same label.
463 *if_true = *if_false = *fall_through = materialize_true;
464}
465
466
467void FullCodeGenerator::AccumulatorValueContext::PrepareTest(
468 Label* materialize_true,
469 Label* materialize_false,
470 Label** if_true,
471 Label** if_false,
472 Label** fall_through) const {
473 *if_true = *fall_through = materialize_true;
474 *if_false = materialize_false;
475}
476
477
478void FullCodeGenerator::StackValueContext::PrepareTest(
479 Label* materialize_true,
480 Label* materialize_false,
481 Label** if_true,
482 Label** if_false,
483 Label** fall_through) const {
484 *if_true = *fall_through = materialize_true;
485 *if_false = materialize_false;
486}
487
488
489void FullCodeGenerator::TestContext::PrepareTest(
490 Label* materialize_true,
491 Label* materialize_false,
492 Label** if_true,
493 Label** if_false,
494 Label** fall_through) const {
495 *if_true = true_label_;
496 *if_false = false_label_;
497 *fall_through = fall_through_;
ricow@chromium.org65fae842010-08-25 15:26:24 +0000498}
499
500
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000501void FullCodeGenerator::DoTest(const TestContext* context) {
502 DoTest(context->condition(),
503 context->true_label(),
504 context->false_label(),
505 context->fall_through());
506}
507
508
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000509void FullCodeGenerator::VisitDeclarations(
510 ZoneList<Declaration*>* declarations) {
511 int length = declarations->length();
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000512 int global_count = 0;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000513 for (int i = 0; i < length; i++) {
514 Declaration* decl = declarations->at(i);
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000515 EmitDeclaration(decl->proxy(), decl->mode(), decl->fun(), &global_count);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000516 }
517
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000518 // Batch declare global functions and variables.
519 if (global_count > 0) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000520 Handle<FixedArray> array =
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000521 isolate()->factory()->NewFixedArray(2 * global_count, TENURED);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000522 for (int j = 0, i = 0; i < length; i++) {
523 Declaration* decl = declarations->at(i);
524 Variable* var = decl->proxy()->var();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000525
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000526 if (var->IsUnallocated()) {
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000527 array->set(j++, *(var->name()));
528 if (decl->fun() == NULL) {
529 if (var->mode() == Variable::CONST) {
530 // In case this is const property use the hole.
531 array->set_the_hole(j++);
532 } else {
533 array->set_undefined(j++);
534 }
535 } else {
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000536 Handle<SharedFunctionInfo> function =
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000537 Compiler::BuildFunctionInfo(decl->fun(), script());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000538 // Check for stack-overflow exception.
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000539 if (function.is_null()) {
540 SetStackOverflow();
541 return;
542 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000543 array->set(j++, *function);
544 }
545 }
546 }
547 // Invoke the platform-dependent code generator to do the actual
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000548 // declaration the global functions and variables.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000549 DeclareGlobals(array);
550 }
551}
552
553
fschneider@chromium.org1805e212011-09-05 10:49:12 +0000554int FullCodeGenerator::DeclareGlobalsFlags() {
555 int flags = 0;
556 if (is_eval()) flags |= kDeclareGlobalsEvalFlag;
557 if (is_strict_mode()) flags |= kDeclareGlobalsStrictModeFlag;
558 if (is_native()) flags |= kDeclareGlobalsNativeFlag;
559 return flags;
560}
561
562
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000563void FullCodeGenerator::SetFunctionPosition(FunctionLiteral* fun) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000564 CodeGenerator::RecordPositions(masm_, fun->start_position());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000565}
566
567
568void FullCodeGenerator::SetReturnPosition(FunctionLiteral* fun) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000569 CodeGenerator::RecordPositions(masm_, fun->end_position() - 1);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000570}
571
572
573void FullCodeGenerator::SetStatementPosition(Statement* stmt) {
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000574#ifdef ENABLE_DEBUGGER_SUPPORT
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000575 if (!isolate()->debugger()->IsDebuggerActive()) {
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000576 CodeGenerator::RecordPositions(masm_, stmt->statement_pos());
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000577 } else {
578 // Check if the statement will be breakable without adding a debug break
579 // slot.
580 BreakableStatementChecker checker;
581 checker.Check(stmt);
582 // Record the statement position right here if the statement is not
583 // breakable. For breakable statements the actual recording of the
584 // position will be postponed to the breakable code (typically an IC).
585 bool position_recorded = CodeGenerator::RecordPositions(
586 masm_, stmt->statement_pos(), !checker.is_breakable());
587 // If the position recording did record a new position generate a debug
588 // break slot to make the statement breakable.
589 if (position_recorded) {
590 Debug::GenerateSlot(masm_);
591 }
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000592 }
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000593#else
594 CodeGenerator::RecordPositions(masm_, stmt->statement_pos());
595#endif
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000596}
597
598
599void FullCodeGenerator::SetExpressionPosition(Expression* expr, int pos) {
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000600#ifdef ENABLE_DEBUGGER_SUPPORT
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000601 if (!isolate()->debugger()->IsDebuggerActive()) {
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000602 CodeGenerator::RecordPositions(masm_, pos);
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000603 } else {
604 // Check if the expression will be breakable without adding a debug break
605 // slot.
606 BreakableStatementChecker checker;
607 checker.Check(expr);
608 // Record a statement position right here if the expression is not
609 // breakable. For breakable expressions the actual recording of the
610 // position will be postponed to the breakable code (typically an IC).
611 // NOTE this will record a statement position for something which might
612 // not be a statement. As stepping in the debugger will only stop at
613 // statement positions this is used for e.g. the condition expression of
614 // a do while loop.
615 bool position_recorded = CodeGenerator::RecordPositions(
616 masm_, pos, !checker.is_breakable());
617 // If the position recording did record a new position generate a debug
618 // break slot to make the statement breakable.
619 if (position_recorded) {
620 Debug::GenerateSlot(masm_);
621 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000622 }
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000623#else
624 CodeGenerator::RecordPositions(masm_, pos);
625#endif
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000626}
627
628
629void FullCodeGenerator::SetStatementPosition(int pos) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000630 CodeGenerator::RecordPositions(masm_, pos);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000631}
632
633
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000634void FullCodeGenerator::SetSourcePosition(int pos) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000635 if (pos != RelocInfo::kNoPosition) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000636 masm_->positions_recorder()->RecordPosition(pos);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000637 }
638}
639
640
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000641// Lookup table for code generators for special runtime calls which are
642// generated inline.
643#define INLINE_FUNCTION_GENERATOR_ADDRESS(Name, argc, ressize) \
644 &FullCodeGenerator::Emit##Name,
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000645
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000646const FullCodeGenerator::InlineFunctionGenerator
647 FullCodeGenerator::kInlineFunctionGenerators[] = {
648 INLINE_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS)
649 INLINE_RUNTIME_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS)
650 };
651#undef INLINE_FUNCTION_GENERATOR_ADDRESS
652
653
654FullCodeGenerator::InlineFunctionGenerator
655 FullCodeGenerator::FindInlineFunctionGenerator(Runtime::FunctionId id) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000656 int lookup_index =
657 static_cast<int>(id) - static_cast<int>(Runtime::kFirstInlineFunction);
658 ASSERT(lookup_index >= 0);
659 ASSERT(static_cast<size_t>(lookup_index) <
660 ARRAY_SIZE(kInlineFunctionGenerators));
661 return kInlineFunctionGenerators[lookup_index];
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000662}
663
664
665void FullCodeGenerator::EmitInlineRuntimeCall(CallRuntime* node) {
666 ZoneList<Expression*>* args = node->arguments();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000667 const Runtime::Function* function = node->function();
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000668 ASSERT(function != NULL);
669 ASSERT(function->intrinsic_type == Runtime::INLINE);
670 InlineFunctionGenerator generator =
671 FindInlineFunctionGenerator(function->function_id);
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000672 ((*this).*(generator))(args);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000673}
674
675
676void FullCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) {
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000677 switch (expr->op()) {
ricow@chromium.org65fae842010-08-25 15:26:24 +0000678 case Token::COMMA:
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000679 return VisitComma(expr);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000680 case Token::OR:
681 case Token::AND:
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000682 return VisitLogicalExpression(expr);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000683 default:
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000684 return VisitArithmeticExpression(expr);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000685 }
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000686}
687
688
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000689void FullCodeGenerator::VisitComma(BinaryOperation* expr) {
690 Comment cmnt(masm_, "[ Comma");
691 VisitForEffect(expr->left());
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000692 if (context()->IsTest()) ForwardBailoutToChild(expr);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000693 VisitInCurrentContext(expr->right());
694}
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000695
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000696
697void FullCodeGenerator::VisitLogicalExpression(BinaryOperation* expr) {
698 bool is_logical_and = expr->op() == Token::AND;
699 Comment cmnt(masm_, is_logical_and ? "[ Logical AND" : "[ Logical OR");
700 Expression* left = expr->left();
701 Expression* right = expr->right();
702 int right_id = expr->RightId();
703 Label done;
704
705 if (context()->IsTest()) {
706 Label eval_right;
707 const TestContext* test = TestContext::cast(context());
708 if (is_logical_and) {
709 VisitForControl(left, &eval_right, test->false_label(), &eval_right);
710 } else {
711 VisitForControl(left, test->true_label(), &eval_right, &eval_right);
712 }
713 PrepareForBailoutForId(right_id, NO_REGISTERS);
714 __ bind(&eval_right);
715 ForwardBailoutToChild(expr);
716
717 } else if (context()->IsAccumulatorValue()) {
718 VisitForAccumulatorValue(left);
719 // We want the value in the accumulator for the test, and on the stack in
720 // case we need it.
721 __ push(result_register());
722 Label discard, restore;
723 PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL);
724 if (is_logical_and) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000725 DoTest(left, &discard, &restore, &restore);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000726 } else {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000727 DoTest(left, &restore, &discard, &restore);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000728 }
729 __ bind(&restore);
730 __ pop(result_register());
731 __ jmp(&done);
732 __ bind(&discard);
733 __ Drop(1);
734 PrepareForBailoutForId(right_id, NO_REGISTERS);
735
736 } else if (context()->IsStackValue()) {
737 VisitForAccumulatorValue(left);
738 // We want the value in the accumulator for the test, and on the stack in
739 // case we need it.
740 __ push(result_register());
741 Label discard;
742 PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL);
743 if (is_logical_and) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000744 DoTest(left, &discard, &done, &discard);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000745 } else {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000746 DoTest(left, &done, &discard, &discard);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000747 }
748 __ bind(&discard);
749 __ Drop(1);
750 PrepareForBailoutForId(right_id, NO_REGISTERS);
751
752 } else {
753 ASSERT(context()->IsEffect());
754 Label eval_right;
755 if (is_logical_and) {
756 VisitForControl(left, &eval_right, &done, &eval_right);
757 } else {
758 VisitForControl(left, &done, &eval_right, &eval_right);
759 }
760 PrepareForBailoutForId(right_id, NO_REGISTERS);
761 __ bind(&eval_right);
762 }
763
764 VisitInCurrentContext(right);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000765 __ bind(&done);
766}
767
768
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000769void FullCodeGenerator::VisitArithmeticExpression(BinaryOperation* expr) {
770 Token::Value op = expr->op();
771 Comment cmnt(masm_, "[ ArithmeticExpression");
772 Expression* left = expr->left();
773 Expression* right = expr->right();
774 OverwriteMode mode =
775 left->ResultOverwriteAllowed()
776 ? OVERWRITE_LEFT
777 : (right->ResultOverwriteAllowed() ? OVERWRITE_RIGHT : NO_OVERWRITE);
778
779 VisitForStackValue(left);
780 VisitForAccumulatorValue(right);
781
782 SetSourcePosition(expr->position());
783 if (ShouldInlineSmiCase(op)) {
784 EmitInlineSmiBinaryOp(expr, op, mode, left, right);
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000785 } else {
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000786 EmitBinaryOp(expr, op, mode);
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000787 }
788}
789
790
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000791void FullCodeGenerator::ForwardBailoutToChild(Expression* expr) {
792 if (!info_->HasDeoptimizationSupport()) return;
793 ASSERT(context()->IsTest());
794 ASSERT(expr == forward_bailout_stack_->expr());
795 forward_bailout_pending_ = forward_bailout_stack_;
796}
797
798
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000799void FullCodeGenerator::VisitInCurrentContext(Expression* expr) {
800 if (context()->IsTest()) {
801 ForwardBailoutStack stack(expr, forward_bailout_pending_);
802 ForwardBailoutStack* saved = forward_bailout_stack_;
803 forward_bailout_pending_ = NULL;
804 forward_bailout_stack_ = &stack;
805 Visit(expr);
806 forward_bailout_stack_ = saved;
807 } else {
808 ASSERT(forward_bailout_pending_ == NULL);
809 Visit(expr);
810 State state = context()->IsAccumulatorValue() ? TOS_REG : NO_REGISTERS;
811 PrepareForBailout(expr, state);
812 // Forwarding bailouts to children is a one shot operation. It should have
813 // been processed at this point.
814 ASSERT(forward_bailout_pending_ == NULL);
815 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000816}
817
818
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000819void FullCodeGenerator::VisitBlock(Block* stmt) {
820 Comment cmnt(masm_, "[ Block");
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000821 NestedBlock nested_block(this, stmt);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000822 SetStatementPosition(stmt);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000823
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000824 Scope* saved_scope = scope();
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000825 // Push a block context when entering a block with block scoped variables.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000826 if (stmt->block_scope() != NULL) {
827 { Comment cmnt(masm_, "[ Extend block context");
828 scope_ = stmt->block_scope();
829 __ Push(scope_->GetSerializedScopeInfo());
830 PushFunctionArgumentForContextAllocation();
831 __ CallRuntime(Runtime::kPushBlockContext, 2);
832 StoreToFrameField(StandardFrameConstants::kContextOffset,
833 context_register());
834 }
835 { Comment cmnt(masm_, "[ Declarations");
836 VisitDeclarations(scope_->declarations());
837 }
838 }
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +0000839 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000840 VisitStatements(stmt->statements());
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000841 scope_ = saved_scope;
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000842 __ bind(nested_block.break_label());
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000843 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000844
845 // Pop block context if necessary.
846 if (stmt->block_scope() != NULL) {
847 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
848 // Update local stack frame context field.
849 StoreToFrameField(StandardFrameConstants::kContextOffset,
850 context_register());
851 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000852}
853
854
855void FullCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) {
856 Comment cmnt(masm_, "[ ExpressionStatement");
857 SetStatementPosition(stmt);
858 VisitForEffect(stmt->expression());
859}
860
861
862void FullCodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) {
863 Comment cmnt(masm_, "[ EmptyStatement");
864 SetStatementPosition(stmt);
865}
866
867
868void FullCodeGenerator::VisitIfStatement(IfStatement* stmt) {
869 Comment cmnt(masm_, "[ IfStatement");
870 SetStatementPosition(stmt);
871 Label then_part, else_part, done;
872
ricow@chromium.org65fae842010-08-25 15:26:24 +0000873 if (stmt->HasElseStatement()) {
874 VisitForControl(stmt->condition(), &then_part, &else_part, &then_part);
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000875 PrepareForBailoutForId(stmt->ThenId(), NO_REGISTERS);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000876 __ bind(&then_part);
877 Visit(stmt->then_statement());
878 __ jmp(&done);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000879
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000880 PrepareForBailoutForId(stmt->ElseId(), NO_REGISTERS);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000881 __ bind(&else_part);
882 Visit(stmt->else_statement());
883 } else {
884 VisitForControl(stmt->condition(), &then_part, &done, &then_part);
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000885 PrepareForBailoutForId(stmt->ThenId(), NO_REGISTERS);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000886 __ bind(&then_part);
887 Visit(stmt->then_statement());
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000888
889 PrepareForBailoutForId(stmt->ElseId(), NO_REGISTERS);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000890 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000891 __ bind(&done);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000892 PrepareForBailoutForId(stmt->IfId(), NO_REGISTERS);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000893}
894
895
896void FullCodeGenerator::VisitContinueStatement(ContinueStatement* stmt) {
897 Comment cmnt(masm_, "[ ContinueStatement");
898 SetStatementPosition(stmt);
899 NestedStatement* current = nesting_stack_;
900 int stack_depth = 0;
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000901 int context_length = 0;
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000902 // When continuing, we clobber the unpredictable value in the accumulator
903 // with one that's safe for GC. If we hit an exit from the try block of
904 // try...finally on our way out, we will unconditionally preserve the
905 // accumulator on the stack.
906 ClearAccumulator();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000907 while (!current->IsContinueTarget(stmt->target())) {
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000908 current = current->Exit(&stack_depth, &context_length);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000909 }
910 __ Drop(stack_depth);
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000911 if (context_length > 0) {
912 while (context_length > 0) {
913 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
914 --context_length;
915 }
916 StoreToFrameField(StandardFrameConstants::kContextOffset,
917 context_register());
918 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000919
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000920 __ jmp(current->AsIteration()->continue_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000921}
922
923
924void FullCodeGenerator::VisitBreakStatement(BreakStatement* stmt) {
925 Comment cmnt(masm_, "[ BreakStatement");
926 SetStatementPosition(stmt);
927 NestedStatement* current = nesting_stack_;
928 int stack_depth = 0;
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000929 int context_length = 0;
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000930 // When breaking, we clobber the unpredictable value in the accumulator
931 // with one that's safe for GC. If we hit an exit from the try block of
932 // try...finally on our way out, we will unconditionally preserve the
933 // accumulator on the stack.
934 ClearAccumulator();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000935 while (!current->IsBreakTarget(stmt->target())) {
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000936 current = current->Exit(&stack_depth, &context_length);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000937 }
938 __ Drop(stack_depth);
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000939 if (context_length > 0) {
940 while (context_length > 0) {
941 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
942 --context_length;
943 }
944 StoreToFrameField(StandardFrameConstants::kContextOffset,
945 context_register());
946 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000947
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000948 __ jmp(current->AsBreakable()->break_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000949}
950
951
952void FullCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) {
953 Comment cmnt(masm_, "[ ReturnStatement");
954 SetStatementPosition(stmt);
955 Expression* expr = stmt->expression();
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000956 VisitForAccumulatorValue(expr);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000957
958 // Exit all nested statements.
959 NestedStatement* current = nesting_stack_;
960 int stack_depth = 0;
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000961 int context_length = 0;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000962 while (current != NULL) {
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000963 current = current->Exit(&stack_depth, &context_length);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000964 }
965 __ Drop(stack_depth);
966
ager@chromium.org2cc82ae2010-06-14 07:35:38 +0000967 EmitReturnSequence();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000968}
969
970
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000971void FullCodeGenerator::VisitWithStatement(WithStatement* stmt) {
972 Comment cmnt(masm_, "[ WithStatement");
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000973 SetStatementPosition(stmt);
974
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000975 VisitForStackValue(stmt->expression());
vegorov@chromium.org3cf47312011-06-29 13:20:01 +0000976 PushFunctionArgumentForContextAllocation();
977 __ CallRuntime(Runtime::kPushWithContext, 2);
vegorov@chromium.org7943d462011-08-01 11:41:52 +0000978 decrement_stack_height();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000979 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register());
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000980
981 { WithOrCatch body(this);
982 Visit(stmt->statement());
983 }
984
985 // Pop context.
986 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
987 // Update local stack frame context field.
988 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000989}
990
991
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000992void FullCodeGenerator::VisitExitContextStatement(ExitContextStatement* stmt) {
993 Comment cmnt(masm_, "[ ExitContextStatement");
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000994 SetStatementPosition(stmt);
995
996 // Pop context.
997 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
998 // Update local stack frame context field.
999 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register());
1000}
1001
1002
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001003void FullCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) {
1004 Comment cmnt(masm_, "[ DoWhileStatement");
1005 SetStatementPosition(stmt);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001006 Label body, stack_check;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001007
1008 Iteration loop_statement(this, stmt);
1009 increment_loop_depth();
1010
1011 __ bind(&body);
1012 Visit(stmt->body());
1013
ricow@chromium.org65fae842010-08-25 15:26:24 +00001014 // Record the position of the do while condition and make sure it is
1015 // possible to break on the condition.
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001016 __ bind(loop_statement.continue_label());
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001017 PrepareForBailoutForId(stmt->ContinueId(), NO_REGISTERS);
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001018 SetExpressionPosition(stmt->cond(), stmt->condition_position());
ricow@chromium.org65fae842010-08-25 15:26:24 +00001019 VisitForControl(stmt->cond(),
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001020 &stack_check,
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001021 loop_statement.break_label(),
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001022 &stack_check);
1023
1024 // Check stack before looping.
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001025 PrepareForBailoutForId(stmt->BackEdgeId(), NO_REGISTERS);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001026 __ bind(&stack_check);
1027 EmitStackCheck(stmt);
1028 __ jmp(&body);
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001029
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001030 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001031 __ bind(loop_statement.break_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001032 decrement_loop_depth();
1033}
1034
1035
1036void FullCodeGenerator::VisitWhileStatement(WhileStatement* stmt) {
1037 Comment cmnt(masm_, "[ WhileStatement");
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001038 Label test, body;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001039
1040 Iteration loop_statement(this, stmt);
1041 increment_loop_depth();
1042
1043 // Emit the test at the bottom of the loop.
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001044 __ jmp(&test);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001045
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001046 PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001047 __ bind(&body);
1048 Visit(stmt->body());
ricow@chromium.org65fae842010-08-25 15:26:24 +00001049
1050 // Emit the statement position here as this is where the while
1051 // statement code starts.
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001052 __ bind(loop_statement.continue_label());
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001053 SetStatementPosition(stmt);
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00001054
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001055 // Check stack before looping.
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001056 EmitStackCheck(stmt);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001057
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001058 __ bind(&test);
ricow@chromium.org65fae842010-08-25 15:26:24 +00001059 VisitForControl(stmt->cond(),
1060 &body,
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001061 loop_statement.break_label(),
1062 loop_statement.break_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001063
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001064 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001065 __ bind(loop_statement.break_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001066 decrement_loop_depth();
1067}
1068
1069
1070void FullCodeGenerator::VisitForStatement(ForStatement* stmt) {
1071 Comment cmnt(masm_, "[ ForStatement");
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001072 Label test, body;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001073
1074 Iteration loop_statement(this, stmt);
1075 if (stmt->init() != NULL) {
1076 Visit(stmt->init());
1077 }
1078
1079 increment_loop_depth();
1080 // Emit the test at the bottom of the loop (even if empty).
1081 __ jmp(&test);
1082
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001083 PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001084 __ bind(&body);
1085 Visit(stmt->body());
1086
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001087 PrepareForBailoutForId(stmt->ContinueId(), NO_REGISTERS);
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001088 __ bind(loop_statement.continue_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001089 SetStatementPosition(stmt);
1090 if (stmt->next() != NULL) {
1091 Visit(stmt->next());
1092 }
1093
ricow@chromium.org65fae842010-08-25 15:26:24 +00001094 // Emit the statement position here as this is where the for
1095 // statement code starts.
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001096 SetStatementPosition(stmt);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001097
1098 // Check stack before looping.
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001099 EmitStackCheck(stmt);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001100
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001101 __ bind(&test);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001102 if (stmt->cond() != NULL) {
ricow@chromium.org65fae842010-08-25 15:26:24 +00001103 VisitForControl(stmt->cond(),
1104 &body,
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001105 loop_statement.break_label(),
1106 loop_statement.break_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001107 } else {
1108 __ jmp(&body);
1109 }
1110
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001111 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001112 __ bind(loop_statement.break_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001113 decrement_loop_depth();
1114}
1115
1116
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001117void FullCodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) {
1118 Comment cmnt(masm_, "[ TryCatchStatement");
1119 SetStatementPosition(stmt);
1120 // The try block adds a handler to the exception handler chain
1121 // before entering, and removes it again when exiting normally.
1122 // If an exception is thrown during execution of the try block,
1123 // control is passed to the handler, which also consumes the handler.
1124 // At this point, the exception is in a register, and store it in
1125 // the temporary local variable (prints as ".catch-var") before
1126 // executing the catch block. The catch block has been rewritten
1127 // to introduce a new scope to bind the catch variable and to remove
1128 // that scope again afterwards.
1129
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001130 Label try_handler_setup, done;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001131 __ Call(&try_handler_setup);
1132 // Try handler code, exception in result register.
1133
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001134 // Extend the context before executing the catch block.
1135 { Comment cmnt(masm_, "[ Extend catch context");
ricow@chromium.org4f693d62011-07-04 14:01:31 +00001136 __ Push(stmt->variable()->name());
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001137 __ push(result_register());
vegorov@chromium.org3cf47312011-06-29 13:20:01 +00001138 PushFunctionArgumentForContextAllocation();
1139 __ CallRuntime(Runtime::kPushCatchContext, 3);
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001140 StoreToFrameField(StandardFrameConstants::kContextOffset,
1141 context_register());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001142 }
1143
ricow@chromium.org4f693d62011-07-04 14:01:31 +00001144 Scope* saved_scope = scope();
1145 scope_ = stmt->scope();
1146 ASSERT(scope_->declarations()->is_empty());
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00001147 { WithOrCatch body(this);
1148 Visit(stmt->catch_block());
1149 }
ricow@chromium.org4f693d62011-07-04 14:01:31 +00001150 scope_ = saved_scope;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001151 __ jmp(&done);
1152
1153 // Try block code. Sets up the exception handler chain.
1154 __ bind(&try_handler_setup);
1155 {
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001156 const int delta = StackHandlerConstants::kSize / kPointerSize;
1157 TryCatch try_block(this);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001158 __ PushTryHandler(IN_JAVASCRIPT, TRY_CATCH_HANDLER);
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001159 increment_stack_height(delta);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001160 Visit(stmt->try_block());
1161 __ PopTryHandler();
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001162 decrement_stack_height(delta);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001163 }
1164 __ bind(&done);
1165}
1166
1167
1168void FullCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
1169 Comment cmnt(masm_, "[ TryFinallyStatement");
1170 SetStatementPosition(stmt);
1171 // Try finally is compiled by setting up a try-handler on the stack while
1172 // executing the try body, and removing it again afterwards.
1173 //
1174 // The try-finally construct can enter the finally block in three ways:
1175 // 1. By exiting the try-block normally. This removes the try-handler and
1176 // calls the finally block code before continuing.
1177 // 2. By exiting the try-block with a function-local control flow transfer
1178 // (break/continue/return). The site of the, e.g., break removes the
1179 // try handler and calls the finally block code before continuing
1180 // its outward control transfer.
1181 // 3. by exiting the try-block with a thrown exception.
1182 // This can happen in nested function calls. It traverses the try-handler
1183 // chain and consumes the try-handler entry before jumping to the
1184 // handler code. The handler code then calls the finally-block before
1185 // rethrowing the exception.
1186 //
1187 // The finally block must assume a return address on top of the stack
1188 // (or in the link register on ARM chips) and a value (return value or
1189 // exception) in the result register (rax/eax/r0), both of which must
1190 // be preserved. The return address isn't GC-safe, so it should be
1191 // cooked before GC.
1192 Label finally_entry;
1193 Label try_handler_setup;
vegorov@chromium.org7943d462011-08-01 11:41:52 +00001194 const int original_stack_height = stack_height();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001195
1196 // Setup the try-handler chain. Use a call to
1197 // Jump to try-handler setup and try-block code. Use call to put try-handler
1198 // address on stack.
1199 __ Call(&try_handler_setup);
1200 // Try handler code. Return address of call is pushed on handler stack.
1201 {
1202 // This code is only executed during stack-handler traversal when an
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001203 // exception is thrown. The exception is in the result register, which
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001204 // is retained by the finally block.
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001205 // Call the finally block and then rethrow the exception if it returns.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001206 __ Call(&finally_entry);
1207 __ push(result_register());
1208 __ CallRuntime(Runtime::kReThrow, 1);
1209 }
1210
1211 __ bind(&finally_entry);
1212 {
1213 // Finally block implementation.
1214 Finally finally_block(this);
1215 EnterFinallyBlock();
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001216 set_stack_height(original_stack_height + Finally::kElementCount);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001217 Visit(stmt->finally_block());
1218 ExitFinallyBlock(); // Return to the calling code.
1219 }
1220
1221 __ bind(&try_handler_setup);
1222 {
1223 // Setup try handler (stack pointer registers).
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001224 const int delta = StackHandlerConstants::kSize / kPointerSize;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001225 TryFinally try_block(this, &finally_entry);
1226 __ PushTryHandler(IN_JAVASCRIPT, TRY_FINALLY_HANDLER);
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001227 set_stack_height(original_stack_height + delta);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001228 Visit(stmt->try_block());
1229 __ PopTryHandler();
vegorov@chromium.org7943d462011-08-01 11:41:52 +00001230 set_stack_height(original_stack_height);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001231 }
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001232 // Execute the finally block on the way out. Clobber the unpredictable
1233 // value in the accumulator with one that's safe for GC. The finally
1234 // block will unconditionally preserve the accumulator on the stack.
1235 ClearAccumulator();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001236 __ Call(&finally_entry);
1237}
1238
1239
1240void FullCodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) {
1241#ifdef ENABLE_DEBUGGER_SUPPORT
1242 Comment cmnt(masm_, "[ DebuggerStatement");
1243 SetStatementPosition(stmt);
1244
ager@chromium.org5c838252010-02-19 08:53:10 +00001245 __ DebugBreak();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001246 // Ignore the return value.
1247#endif
1248}
1249
1250
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001251void FullCodeGenerator::VisitConditional(Conditional* expr) {
1252 Comment cmnt(masm_, "[ Conditional");
1253 Label true_case, false_case, done;
ricow@chromium.org65fae842010-08-25 15:26:24 +00001254 VisitForControl(expr->condition(), &true_case, &false_case, &true_case);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001255
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001256 PrepareForBailoutForId(expr->ThenId(), NO_REGISTERS);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001257 __ bind(&true_case);
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001258 SetExpressionPosition(expr->then_expression(),
1259 expr->then_expression_position());
vegorov@chromium.org7943d462011-08-01 11:41:52 +00001260 int start_stack_height = stack_height();
ager@chromium.orgb61a0d12010-10-13 08:35:23 +00001261 if (context()->IsTest()) {
1262 const TestContext* for_test = TestContext::cast(context());
1263 VisitForControl(expr->then_expression(),
1264 for_test->true_label(),
1265 for_test->false_label(),
1266 NULL);
1267 } else {
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001268 VisitInCurrentContext(expr->then_expression());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001269 __ jmp(&done);
1270 }
1271
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001272 PrepareForBailoutForId(expr->ElseId(), NO_REGISTERS);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001273 __ bind(&false_case);
vegorov@chromium.org7943d462011-08-01 11:41:52 +00001274 set_stack_height(start_stack_height);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001275 if (context()->IsTest()) ForwardBailoutToChild(expr);
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001276 SetExpressionPosition(expr->else_expression(),
1277 expr->else_expression_position());
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001278 VisitInCurrentContext(expr->else_expression());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001279 // If control flow falls through Visit, merge it with true case here.
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00001280 if (!context()->IsTest()) {
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001281 __ bind(&done);
1282 }
1283}
1284
1285
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001286void FullCodeGenerator::VisitLiteral(Literal* expr) {
1287 Comment cmnt(masm_, "[ Literal");
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00001288 context()->Plug(expr->handle());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001289}
1290
1291
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00001292void FullCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) {
1293 Comment cmnt(masm_, "[ FunctionLiteral");
1294
1295 // Build the function boilerplate and instantiate it.
1296 Handle<SharedFunctionInfo> function_info =
ager@chromium.orgb61a0d12010-10-13 08:35:23 +00001297 Compiler::BuildFunctionInfo(expr, script());
1298 if (function_info.is_null()) {
1299 SetStackOverflow();
1300 return;
1301 }
vegorov@chromium.org21b5e952010-11-23 10:24:40 +00001302 EmitNewClosure(function_info, expr->pretenure());
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00001303}
1304
1305
1306void FullCodeGenerator::VisitSharedFunctionInfoLiteral(
1307 SharedFunctionInfoLiteral* expr) {
1308 Comment cmnt(masm_, "[ SharedFunctionInfoLiteral");
vegorov@chromium.org21b5e952010-11-23 10:24:40 +00001309 EmitNewClosure(expr->shared_function_info(), false);
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00001310}
1311
1312
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001313void FullCodeGenerator::VisitThrow(Throw* expr) {
1314 Comment cmnt(masm_, "[ Throw");
vegorov@chromium.org7943d462011-08-01 11:41:52 +00001315 // Throw has no effect on the stack height or the current expression context.
1316 // Usually the expression context is null, because throw is a statement.
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00001317 VisitForStackValue(expr->exception());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001318 __ CallRuntime(Runtime::kThrow, 1);
vegorov@chromium.org7943d462011-08-01 11:41:52 +00001319 decrement_stack_height();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001320 // Never returns here.
1321}
1322
1323
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00001324FullCodeGenerator::NestedStatement* FullCodeGenerator::TryCatch::Exit(
1325 int* stack_depth,
1326 int* context_length) {
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001327 // The macros used here must preserve the result register.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00001328 __ Drop(*stack_depth);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001329 __ PopTryHandler();
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00001330 *stack_depth = 0;
1331 return previous_;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001332}
1333
ricow@chromium.org65fae842010-08-25 15:26:24 +00001334
ager@chromium.org04921a82011-06-27 13:21:41 +00001335bool FullCodeGenerator::TryLiteralCompare(CompareOperation* compare,
1336 Label* if_true,
1337 Label* if_false,
1338 Label* fall_through) {
1339 Expression *expr;
1340 Handle<String> check;
1341 if (compare->IsLiteralCompareTypeof(&expr, &check)) {
1342 EmitLiteralCompareTypeof(expr, check, if_true, if_false, fall_through);
1343 return true;
1344 }
1345
1346 if (compare->IsLiteralCompareUndefined(&expr)) {
1347 EmitLiteralCompareUndefined(expr, if_true, if_false, fall_through);
1348 return true;
1349 }
1350
1351 return false;
1352}
1353
1354
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001355#undef __
1356
1357
1358} } // namespace v8::internal