blob: 53ace82fe7a28b7bb28b3ba60708b2dfdc5c5070 [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
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +000099void BreakableStatementChecker::VisitSwitchStatement(SwitchStatement* stmt) {
100 // Switch statements breakable if the tag expression is.
101 Visit(stmt->tag());
102}
103
104
105void BreakableStatementChecker::VisitDoWhileStatement(DoWhileStatement* stmt) {
106 // Mark do while as breakable to avoid adding a break slot in front of it.
107 is_breakable_ = true;
108}
109
110
111void BreakableStatementChecker::VisitWhileStatement(WhileStatement* stmt) {
112 // Mark while statements breakable if the condition expression is.
113 Visit(stmt->cond());
114}
115
116
117void BreakableStatementChecker::VisitForStatement(ForStatement* stmt) {
118 // Mark for statements breakable if the condition expression is.
119 if (stmt->cond() != NULL) {
120 Visit(stmt->cond());
121 }
122}
123
124
125void BreakableStatementChecker::VisitForInStatement(ForInStatement* stmt) {
126 // Mark for in statements breakable if the enumerable expression is.
127 Visit(stmt->enumerable());
128}
129
130
131void BreakableStatementChecker::VisitTryCatchStatement(
132 TryCatchStatement* stmt) {
133 // Mark try catch as breakable to avoid adding a break slot in front of it.
134 is_breakable_ = true;
135}
136
137
138void BreakableStatementChecker::VisitTryFinallyStatement(
139 TryFinallyStatement* stmt) {
140 // Mark try finally as breakable to avoid adding a break slot in front of it.
141 is_breakable_ = true;
142}
143
144
145void BreakableStatementChecker::VisitDebuggerStatement(
146 DebuggerStatement* stmt) {
147 // The debugger statement is breakable.
148 is_breakable_ = true;
149}
150
151
152void BreakableStatementChecker::VisitFunctionLiteral(FunctionLiteral* expr) {
153}
154
155
156void BreakableStatementChecker::VisitSharedFunctionInfoLiteral(
157 SharedFunctionInfoLiteral* expr) {
158}
159
160
161void BreakableStatementChecker::VisitConditional(Conditional* expr) {
162}
163
164
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000165void BreakableStatementChecker::VisitVariableProxy(VariableProxy* expr) {
166}
167
168
169void BreakableStatementChecker::VisitLiteral(Literal* expr) {
170}
171
172
173void BreakableStatementChecker::VisitRegExpLiteral(RegExpLiteral* expr) {
174}
175
176
177void BreakableStatementChecker::VisitObjectLiteral(ObjectLiteral* expr) {
178}
179
180
181void BreakableStatementChecker::VisitArrayLiteral(ArrayLiteral* expr) {
182}
183
184
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000185void BreakableStatementChecker::VisitAssignment(Assignment* expr) {
186 // If assigning to a property (including a global property) the assignment is
187 // breakable.
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000188 VariableProxy* proxy = expr->target()->AsVariableProxy();
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000189 Property* prop = expr->target()->AsProperty();
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000190 if (prop != NULL || (proxy != NULL && proxy->var()->IsUnallocated())) {
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000191 is_breakable_ = true;
192 return;
193 }
194
195 // Otherwise the assignment is breakable if the assigned value is.
196 Visit(expr->value());
197}
198
199
200void BreakableStatementChecker::VisitThrow(Throw* expr) {
201 // Throw is breakable if the expression is.
202 Visit(expr->exception());
203}
204
205
206void BreakableStatementChecker::VisitProperty(Property* expr) {
207 // Property load is breakable.
208 is_breakable_ = true;
209}
210
211
212void BreakableStatementChecker::VisitCall(Call* expr) {
213 // Function calls both through IC and call stub are breakable.
214 is_breakable_ = true;
215}
216
217
218void BreakableStatementChecker::VisitCallNew(CallNew* expr) {
219 // Function calls through new are breakable.
220 is_breakable_ = true;
221}
222
223
224void BreakableStatementChecker::VisitCallRuntime(CallRuntime* expr) {
225}
226
227
228void BreakableStatementChecker::VisitUnaryOperation(UnaryOperation* expr) {
229 Visit(expr->expression());
230}
231
232
233void BreakableStatementChecker::VisitCountOperation(CountOperation* expr) {
234 Visit(expr->expression());
235}
236
237
238void BreakableStatementChecker::VisitBinaryOperation(BinaryOperation* expr) {
239 Visit(expr->left());
jkummerow@chromium.orgddda9e82011-07-06 11:27:02 +0000240 if (expr->op() != Token::AND &&
241 expr->op() != Token::OR) {
242 Visit(expr->right());
243 }
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000244}
245
246
ricow@chromium.org65fae842010-08-25 15:26:24 +0000247void BreakableStatementChecker::VisitCompareToNull(CompareToNull* expr) {
248 Visit(expr->expression());
249}
250
251
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000252void BreakableStatementChecker::VisitCompareOperation(CompareOperation* expr) {
253 Visit(expr->left());
254 Visit(expr->right());
255}
256
257
258void BreakableStatementChecker::VisitThisFunction(ThisFunction* expr) {
259}
260
261
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000262#define __ ACCESS_MASM(masm())
263
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000264bool FullCodeGenerator::MakeCode(CompilationInfo* info) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000265 Isolate* isolate = info->isolate();
ager@chromium.org5c838252010-02-19 08:53:10 +0000266 Handle<Script> script = info->script();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000267 if (!script->IsUndefined() && !script->source()->IsUndefined()) {
268 int len = String::cast(script->source())->length();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000269 isolate->counters()->total_full_codegen_source_size()->Increment(len);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000270 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000271 if (FLAG_trace_codegen) {
272 PrintF("Full Compiler - ");
273 }
ager@chromium.org5c838252010-02-19 08:53:10 +0000274 CodeGenerator::MakeCodePrologue(info);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000275 const int kInitialBufferSize = 4 * KB;
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +0000276 MacroAssembler masm(info->isolate(), NULL, kInitialBufferSize);
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000277#ifdef ENABLE_GDB_JIT_INTERFACE
278 masm.positions_recorder()->StartGDBJITLineInfoRecording();
279#endif
ager@chromium.org5c838252010-02-19 08:53:10 +0000280
281 FullCodeGenerator cgen(&masm);
ager@chromium.orgea4f62e2010-08-16 16:28:43 +0000282 cgen.Generate(info);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000283 if (cgen.HasStackOverflow()) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000284 ASSERT(!isolate->has_pending_exception());
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000285 return false;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000286 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000287 unsigned table_offset = cgen.EmitStackCheckTable();
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000288
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000289 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION, NOT_IN_LOOP);
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000290 Handle<Code> code = CodeGenerator::MakeCodeEpilogue(&masm, flags, info);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000291 code->set_optimizable(info->IsOptimizable());
292 cgen.PopulateDeoptimizationData(code);
293 code->set_has_deoptimization_support(info->HasDeoptimizationSupport());
294 code->set_allow_osr_at_loop_nesting_level(0);
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000295 code->set_stack_check_table_offset(table_offset);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000296 CodeGenerator::PrintCode(code, info);
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000297 info->SetCode(code); // may be an empty handle.
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000298#ifdef ENABLE_GDB_JIT_INTERFACE
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000299 if (FLAG_gdbjit && !code.is_null()) {
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000300 GDBJITLineInfo* lineinfo =
301 masm.positions_recorder()->DetachGDBJITLineInfo();
302
303 GDBJIT(RegisterDetailedLineInfo(*code, lineinfo));
304 }
305#endif
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000306 return !code.is_null();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000307}
308
309
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000310unsigned FullCodeGenerator::EmitStackCheckTable() {
311 // The stack check table consists of a length (in number of entries)
312 // field, and then a sequence of entries. Each entry is a pair of AST id
313 // and code-relative pc offset.
314 masm()->Align(kIntSize);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000315 unsigned offset = masm()->pc_offset();
316 unsigned length = stack_checks_.length();
317 __ dd(length);
318 for (unsigned i = 0; i < length; ++i) {
319 __ dd(stack_checks_[i].id);
320 __ dd(stack_checks_[i].pc_and_state);
321 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000322 return offset;
323}
324
325
326void FullCodeGenerator::PopulateDeoptimizationData(Handle<Code> code) {
327 // Fill in the deoptimization information.
328 ASSERT(info_->HasDeoptimizationSupport() || bailout_entries_.is_empty());
329 if (!info_->HasDeoptimizationSupport()) return;
330 int length = bailout_entries_.length();
331 Handle<DeoptimizationOutputData> data =
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000332 isolate()->factory()->
333 NewDeoptimizationOutputData(length, TENURED);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000334 for (int i = 0; i < length; i++) {
335 data->SetAstId(i, Smi::FromInt(bailout_entries_[i].id));
336 data->SetPcAndState(i, Smi::FromInt(bailout_entries_[i].pc_and_state));
337 }
338 code->set_deoptimization_data(*data);
339}
340
341
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000342void FullCodeGenerator::PrepareForBailout(Expression* node, State state) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000343 PrepareForBailoutForId(node->id(), state);
344}
345
346
347void FullCodeGenerator::RecordJSReturnSite(Call* call) {
348 // We record the offset of the function return so we can rebuild the frame
349 // if the function was inlined, i.e., this is the return address in the
350 // inlined function's frame.
351 //
352 // The state is ignored. We defensively set it to TOS_REG, which is the
353 // real state of the unoptimized code at the return site.
354 PrepareForBailoutForId(call->ReturnId(), TOS_REG);
355#ifdef DEBUG
356 // In debug builds, mark the return so we can verify that this function
357 // was called.
358 ASSERT(!call->return_is_recorded_);
359 call->return_is_recorded_ = true;
360#endif
361}
362
363
364void FullCodeGenerator::PrepareForBailoutForId(int id, State state) {
365 // There's no need to prepare this code for bailouts from already optimized
366 // code or code that can't be optimized.
367 if (!FLAG_deopt || !info_->HasDeoptimizationSupport()) return;
368 unsigned pc_and_state =
369 StateField::encode(state) | PcField::encode(masm_->pc_offset());
370 BailoutEntry entry = { id, pc_and_state };
371#ifdef DEBUG
372 // Assert that we don't have multiple bailout entries for the same node.
373 for (int i = 0; i < bailout_entries_.length(); i++) {
374 if (bailout_entries_.at(i).id == entry.id) {
375 AstPrinter printer;
376 PrintF("%s", printer.PrintProgram(info_->function()));
377 UNREACHABLE();
378 }
379 }
380#endif // DEBUG
381 bailout_entries_.Add(entry);
382}
383
384
385void FullCodeGenerator::RecordStackCheck(int ast_id) {
386 // The pc offset does not need to be encoded and packed together with a
387 // state.
388 BailoutEntry entry = { ast_id, masm_->pc_offset() };
389 stack_checks_.Add(entry);
390}
391
392
ricow@chromium.org65fae842010-08-25 15:26:24 +0000393bool FullCodeGenerator::ShouldInlineSmiCase(Token::Value op) {
ricow@chromium.org65fae842010-08-25 15:26:24 +0000394 // Inline smi case inside loops, but not division and modulo which
395 // are too complicated and take up too much space.
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000396 if (op == Token::DIV ||op == Token::MOD) return false;
397 if (FLAG_always_inline_smi_code) return true;
398 return loop_depth_ > 0;
ricow@chromium.org65fae842010-08-25 15:26:24 +0000399}
400
401
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000402void FullCodeGenerator::EffectContext::Plug(Register reg) const {
403}
404
405
406void FullCodeGenerator::AccumulatorValueContext::Plug(Register reg) const {
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000407 __ Move(result_register(), reg);
408}
409
410
411void FullCodeGenerator::StackValueContext::Plug(Register reg) const {
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000412 __ push(reg);
vegorov@chromium.org7943d462011-08-01 11:41:52 +0000413 codegen()->increment_stack_height();
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000414}
415
416
417void FullCodeGenerator::TestContext::Plug(Register reg) const {
418 // For simplicity we always test the accumulator register.
419 __ Move(result_register(), reg);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000420 codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL);
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000421 codegen()->DoTest(this);
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000422}
423
424
425void FullCodeGenerator::EffectContext::PlugTOS() const {
426 __ Drop(1);
vegorov@chromium.org7943d462011-08-01 11:41:52 +0000427 codegen()->decrement_stack_height();
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000428}
429
430
431void FullCodeGenerator::AccumulatorValueContext::PlugTOS() const {
432 __ pop(result_register());
vegorov@chromium.org7943d462011-08-01 11:41:52 +0000433 codegen()->decrement_stack_height();
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000434}
435
436
437void FullCodeGenerator::StackValueContext::PlugTOS() const {
438}
439
440
441void FullCodeGenerator::TestContext::PlugTOS() const {
442 // For simplicity we always test the accumulator register.
443 __ pop(result_register());
vegorov@chromium.org7943d462011-08-01 11:41:52 +0000444 codegen()->decrement_stack_height();
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000445 codegen()->PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL);
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000446 codegen()->DoTest(this);
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000447}
448
449
450void FullCodeGenerator::EffectContext::PrepareTest(
451 Label* materialize_true,
452 Label* materialize_false,
453 Label** if_true,
454 Label** if_false,
455 Label** fall_through) const {
456 // In an effect context, the true and the false case branch to the
457 // same label.
458 *if_true = *if_false = *fall_through = materialize_true;
459}
460
461
462void FullCodeGenerator::AccumulatorValueContext::PrepareTest(
463 Label* materialize_true,
464 Label* materialize_false,
465 Label** if_true,
466 Label** if_false,
467 Label** fall_through) const {
468 *if_true = *fall_through = materialize_true;
469 *if_false = materialize_false;
470}
471
472
473void FullCodeGenerator::StackValueContext::PrepareTest(
474 Label* materialize_true,
475 Label* materialize_false,
476 Label** if_true,
477 Label** if_false,
478 Label** fall_through) const {
479 *if_true = *fall_through = materialize_true;
480 *if_false = materialize_false;
481}
482
483
484void FullCodeGenerator::TestContext::PrepareTest(
485 Label* materialize_true,
486 Label* materialize_false,
487 Label** if_true,
488 Label** if_false,
489 Label** fall_through) const {
490 *if_true = true_label_;
491 *if_false = false_label_;
492 *fall_through = fall_through_;
ricow@chromium.org65fae842010-08-25 15:26:24 +0000493}
494
495
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000496void FullCodeGenerator::DoTest(const TestContext* context) {
497 DoTest(context->condition(),
498 context->true_label(),
499 context->false_label(),
500 context->fall_through());
501}
502
503
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000504void FullCodeGenerator::VisitDeclarations(
505 ZoneList<Declaration*>* declarations) {
506 int length = declarations->length();
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000507 int global_count = 0;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000508 for (int i = 0; i < length; i++) {
509 Declaration* decl = declarations->at(i);
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000510 EmitDeclaration(decl->proxy(), decl->mode(), decl->fun(), &global_count);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000511 }
512
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000513 // Batch declare global functions and variables.
514 if (global_count > 0) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000515 Handle<FixedArray> array =
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000516 isolate()->factory()->NewFixedArray(2 * global_count, TENURED);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000517 for (int j = 0, i = 0; i < length; i++) {
518 Declaration* decl = declarations->at(i);
519 Variable* var = decl->proxy()->var();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000520
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000521 if (var->IsUnallocated()) {
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000522 array->set(j++, *(var->name()));
523 if (decl->fun() == NULL) {
524 if (var->mode() == Variable::CONST) {
525 // In case this is const property use the hole.
526 array->set_the_hole(j++);
527 } else {
528 array->set_undefined(j++);
529 }
530 } else {
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000531 Handle<SharedFunctionInfo> function =
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000532 Compiler::BuildFunctionInfo(decl->fun(), script());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000533 // Check for stack-overflow exception.
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000534 if (function.is_null()) {
535 SetStackOverflow();
536 return;
537 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000538 array->set(j++, *function);
539 }
540 }
541 }
542 // Invoke the platform-dependent code generator to do the actual
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000543 // declaration the global functions and variables.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000544 DeclareGlobals(array);
545 }
546}
547
548
fschneider@chromium.org1805e212011-09-05 10:49:12 +0000549int FullCodeGenerator::DeclareGlobalsFlags() {
550 int flags = 0;
551 if (is_eval()) flags |= kDeclareGlobalsEvalFlag;
552 if (is_strict_mode()) flags |= kDeclareGlobalsStrictModeFlag;
553 if (is_native()) flags |= kDeclareGlobalsNativeFlag;
554 return flags;
555}
556
557
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000558void FullCodeGenerator::SetFunctionPosition(FunctionLiteral* fun) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000559 CodeGenerator::RecordPositions(masm_, fun->start_position());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000560}
561
562
563void FullCodeGenerator::SetReturnPosition(FunctionLiteral* fun) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000564 CodeGenerator::RecordPositions(masm_, fun->end_position() - 1);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000565}
566
567
568void FullCodeGenerator::SetStatementPosition(Statement* stmt) {
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000569#ifdef ENABLE_DEBUGGER_SUPPORT
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000570 if (!isolate()->debugger()->IsDebuggerActive()) {
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000571 CodeGenerator::RecordPositions(masm_, stmt->statement_pos());
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000572 } else {
573 // Check if the statement will be breakable without adding a debug break
574 // slot.
575 BreakableStatementChecker checker;
576 checker.Check(stmt);
577 // Record the statement position right here if the statement is not
578 // breakable. For breakable statements the actual recording of the
579 // position will be postponed to the breakable code (typically an IC).
580 bool position_recorded = CodeGenerator::RecordPositions(
581 masm_, stmt->statement_pos(), !checker.is_breakable());
582 // If the position recording did record a new position generate a debug
583 // break slot to make the statement breakable.
584 if (position_recorded) {
585 Debug::GenerateSlot(masm_);
586 }
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000587 }
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000588#else
589 CodeGenerator::RecordPositions(masm_, stmt->statement_pos());
590#endif
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000591}
592
593
594void FullCodeGenerator::SetExpressionPosition(Expression* expr, int pos) {
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000595#ifdef ENABLE_DEBUGGER_SUPPORT
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000596 if (!isolate()->debugger()->IsDebuggerActive()) {
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000597 CodeGenerator::RecordPositions(masm_, pos);
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000598 } else {
599 // Check if the expression will be breakable without adding a debug break
600 // slot.
601 BreakableStatementChecker checker;
602 checker.Check(expr);
603 // Record a statement position right here if the expression is not
604 // breakable. For breakable expressions the actual recording of the
605 // position will be postponed to the breakable code (typically an IC).
606 // NOTE this will record a statement position for something which might
607 // not be a statement. As stepping in the debugger will only stop at
608 // statement positions this is used for e.g. the condition expression of
609 // a do while loop.
610 bool position_recorded = CodeGenerator::RecordPositions(
611 masm_, pos, !checker.is_breakable());
612 // If the position recording did record a new position generate a debug
613 // break slot to make the statement breakable.
614 if (position_recorded) {
615 Debug::GenerateSlot(masm_);
616 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000617 }
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000618#else
619 CodeGenerator::RecordPositions(masm_, pos);
620#endif
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000621}
622
623
624void FullCodeGenerator::SetStatementPosition(int pos) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000625 CodeGenerator::RecordPositions(masm_, pos);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000626}
627
628
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000629void FullCodeGenerator::SetSourcePosition(int pos) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000630 if (pos != RelocInfo::kNoPosition) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000631 masm_->positions_recorder()->RecordPosition(pos);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000632 }
633}
634
635
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000636// Lookup table for code generators for special runtime calls which are
637// generated inline.
638#define INLINE_FUNCTION_GENERATOR_ADDRESS(Name, argc, ressize) \
639 &FullCodeGenerator::Emit##Name,
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000640
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000641const FullCodeGenerator::InlineFunctionGenerator
642 FullCodeGenerator::kInlineFunctionGenerators[] = {
643 INLINE_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS)
644 INLINE_RUNTIME_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS)
645 };
646#undef INLINE_FUNCTION_GENERATOR_ADDRESS
647
648
649FullCodeGenerator::InlineFunctionGenerator
650 FullCodeGenerator::FindInlineFunctionGenerator(Runtime::FunctionId id) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000651 int lookup_index =
652 static_cast<int>(id) - static_cast<int>(Runtime::kFirstInlineFunction);
653 ASSERT(lookup_index >= 0);
654 ASSERT(static_cast<size_t>(lookup_index) <
655 ARRAY_SIZE(kInlineFunctionGenerators));
656 return kInlineFunctionGenerators[lookup_index];
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000657}
658
659
660void FullCodeGenerator::EmitInlineRuntimeCall(CallRuntime* node) {
661 ZoneList<Expression*>* args = node->arguments();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000662 const Runtime::Function* function = node->function();
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000663 ASSERT(function != NULL);
664 ASSERT(function->intrinsic_type == Runtime::INLINE);
665 InlineFunctionGenerator generator =
666 FindInlineFunctionGenerator(function->function_id);
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000667 ((*this).*(generator))(args);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000668}
669
670
671void FullCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) {
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000672 switch (expr->op()) {
ricow@chromium.org65fae842010-08-25 15:26:24 +0000673 case Token::COMMA:
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000674 return VisitComma(expr);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000675 case Token::OR:
676 case Token::AND:
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000677 return VisitLogicalExpression(expr);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000678 default:
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000679 return VisitArithmeticExpression(expr);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000680 }
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000681}
682
683
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000684void FullCodeGenerator::VisitComma(BinaryOperation* expr) {
685 Comment cmnt(masm_, "[ Comma");
686 VisitForEffect(expr->left());
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000687 if (context()->IsTest()) ForwardBailoutToChild(expr);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000688 VisitInCurrentContext(expr->right());
689}
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000690
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000691
692void FullCodeGenerator::VisitLogicalExpression(BinaryOperation* expr) {
693 bool is_logical_and = expr->op() == Token::AND;
694 Comment cmnt(masm_, is_logical_and ? "[ Logical AND" : "[ Logical OR");
695 Expression* left = expr->left();
696 Expression* right = expr->right();
697 int right_id = expr->RightId();
698 Label done;
699
700 if (context()->IsTest()) {
701 Label eval_right;
702 const TestContext* test = TestContext::cast(context());
703 if (is_logical_and) {
704 VisitForControl(left, &eval_right, test->false_label(), &eval_right);
705 } else {
706 VisitForControl(left, test->true_label(), &eval_right, &eval_right);
707 }
708 PrepareForBailoutForId(right_id, NO_REGISTERS);
709 __ bind(&eval_right);
710 ForwardBailoutToChild(expr);
711
712 } else if (context()->IsAccumulatorValue()) {
713 VisitForAccumulatorValue(left);
714 // We want the value in the accumulator for the test, and on the stack in
715 // case we need it.
716 __ push(result_register());
717 Label discard, restore;
718 PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL);
719 if (is_logical_and) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000720 DoTest(left, &discard, &restore, &restore);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000721 } else {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000722 DoTest(left, &restore, &discard, &restore);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000723 }
724 __ bind(&restore);
725 __ pop(result_register());
726 __ jmp(&done);
727 __ bind(&discard);
728 __ Drop(1);
729 PrepareForBailoutForId(right_id, NO_REGISTERS);
730
731 } else if (context()->IsStackValue()) {
732 VisitForAccumulatorValue(left);
733 // We want the value in the accumulator for the test, and on the stack in
734 // case we need it.
735 __ push(result_register());
736 Label discard;
737 PrepareForBailoutBeforeSplit(TOS_REG, false, NULL, NULL);
738 if (is_logical_and) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000739 DoTest(left, &discard, &done, &discard);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000740 } else {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000741 DoTest(left, &done, &discard, &discard);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000742 }
743 __ bind(&discard);
744 __ Drop(1);
745 PrepareForBailoutForId(right_id, NO_REGISTERS);
746
747 } else {
748 ASSERT(context()->IsEffect());
749 Label eval_right;
750 if (is_logical_and) {
751 VisitForControl(left, &eval_right, &done, &eval_right);
752 } else {
753 VisitForControl(left, &done, &eval_right, &eval_right);
754 }
755 PrepareForBailoutForId(right_id, NO_REGISTERS);
756 __ bind(&eval_right);
757 }
758
759 VisitInCurrentContext(right);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000760 __ bind(&done);
761}
762
763
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000764void FullCodeGenerator::VisitArithmeticExpression(BinaryOperation* expr) {
765 Token::Value op = expr->op();
766 Comment cmnt(masm_, "[ ArithmeticExpression");
767 Expression* left = expr->left();
768 Expression* right = expr->right();
769 OverwriteMode mode =
770 left->ResultOverwriteAllowed()
771 ? OVERWRITE_LEFT
772 : (right->ResultOverwriteAllowed() ? OVERWRITE_RIGHT : NO_OVERWRITE);
773
774 VisitForStackValue(left);
775 VisitForAccumulatorValue(right);
776
777 SetSourcePosition(expr->position());
778 if (ShouldInlineSmiCase(op)) {
779 EmitInlineSmiBinaryOp(expr, op, mode, left, right);
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000780 } else {
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000781 EmitBinaryOp(expr, op, mode);
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000782 }
783}
784
785
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000786void FullCodeGenerator::ForwardBailoutToChild(Expression* expr) {
787 if (!info_->HasDeoptimizationSupport()) return;
788 ASSERT(context()->IsTest());
789 ASSERT(expr == forward_bailout_stack_->expr());
790 forward_bailout_pending_ = forward_bailout_stack_;
791}
792
793
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000794void FullCodeGenerator::VisitInCurrentContext(Expression* expr) {
795 if (context()->IsTest()) {
796 ForwardBailoutStack stack(expr, forward_bailout_pending_);
797 ForwardBailoutStack* saved = forward_bailout_stack_;
798 forward_bailout_pending_ = NULL;
799 forward_bailout_stack_ = &stack;
800 Visit(expr);
801 forward_bailout_stack_ = saved;
802 } else {
803 ASSERT(forward_bailout_pending_ == NULL);
804 Visit(expr);
805 State state = context()->IsAccumulatorValue() ? TOS_REG : NO_REGISTERS;
806 PrepareForBailout(expr, state);
807 // Forwarding bailouts to children is a one shot operation. It should have
808 // been processed at this point.
809 ASSERT(forward_bailout_pending_ == NULL);
810 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000811}
812
813
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000814void FullCodeGenerator::VisitBlock(Block* stmt) {
815 Comment cmnt(masm_, "[ Block");
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000816 NestedBlock nested_block(this, stmt);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000817 SetStatementPosition(stmt);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000818
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000819 Scope* saved_scope = scope();
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000820 // Push a block context when entering a block with block scoped variables.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000821 if (stmt->block_scope() != NULL) {
822 { Comment cmnt(masm_, "[ Extend block context");
823 scope_ = stmt->block_scope();
824 __ Push(scope_->GetSerializedScopeInfo());
825 PushFunctionArgumentForContextAllocation();
826 __ CallRuntime(Runtime::kPushBlockContext, 2);
827 StoreToFrameField(StandardFrameConstants::kContextOffset,
828 context_register());
829 }
830 { Comment cmnt(masm_, "[ Declarations");
831 VisitDeclarations(scope_->declarations());
832 }
833 }
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +0000834 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000835 VisitStatements(stmt->statements());
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000836 scope_ = saved_scope;
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000837 __ bind(nested_block.break_label());
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000838 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000839
840 // Pop block context if necessary.
841 if (stmt->block_scope() != NULL) {
842 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
843 // Update local stack frame context field.
844 StoreToFrameField(StandardFrameConstants::kContextOffset,
845 context_register());
846 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000847}
848
849
850void FullCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) {
851 Comment cmnt(masm_, "[ ExpressionStatement");
852 SetStatementPosition(stmt);
853 VisitForEffect(stmt->expression());
854}
855
856
857void FullCodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) {
858 Comment cmnt(masm_, "[ EmptyStatement");
859 SetStatementPosition(stmt);
860}
861
862
863void FullCodeGenerator::VisitIfStatement(IfStatement* stmt) {
864 Comment cmnt(masm_, "[ IfStatement");
865 SetStatementPosition(stmt);
866 Label then_part, else_part, done;
867
ricow@chromium.org65fae842010-08-25 15:26:24 +0000868 if (stmt->HasElseStatement()) {
869 VisitForControl(stmt->condition(), &then_part, &else_part, &then_part);
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000870 PrepareForBailoutForId(stmt->ThenId(), NO_REGISTERS);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000871 __ bind(&then_part);
872 Visit(stmt->then_statement());
873 __ jmp(&done);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000874
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000875 PrepareForBailoutForId(stmt->ElseId(), NO_REGISTERS);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000876 __ bind(&else_part);
877 Visit(stmt->else_statement());
878 } else {
879 VisitForControl(stmt->condition(), &then_part, &done, &then_part);
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000880 PrepareForBailoutForId(stmt->ThenId(), NO_REGISTERS);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000881 __ bind(&then_part);
882 Visit(stmt->then_statement());
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000883
884 PrepareForBailoutForId(stmt->ElseId(), NO_REGISTERS);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000885 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000886 __ bind(&done);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000887 PrepareForBailoutForId(stmt->IfId(), NO_REGISTERS);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000888}
889
890
891void FullCodeGenerator::VisitContinueStatement(ContinueStatement* stmt) {
892 Comment cmnt(masm_, "[ ContinueStatement");
893 SetStatementPosition(stmt);
894 NestedStatement* current = nesting_stack_;
895 int stack_depth = 0;
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000896 int context_length = 0;
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000897 // When continuing, we clobber the unpredictable value in the accumulator
898 // with one that's safe for GC. If we hit an exit from the try block of
899 // try...finally on our way out, we will unconditionally preserve the
900 // accumulator on the stack.
901 ClearAccumulator();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000902 while (!current->IsContinueTarget(stmt->target())) {
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000903 current = current->Exit(&stack_depth, &context_length);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000904 }
905 __ Drop(stack_depth);
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000906 if (context_length > 0) {
907 while (context_length > 0) {
908 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
909 --context_length;
910 }
911 StoreToFrameField(StandardFrameConstants::kContextOffset,
912 context_register());
913 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000914
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000915 __ jmp(current->AsIteration()->continue_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000916}
917
918
919void FullCodeGenerator::VisitBreakStatement(BreakStatement* stmt) {
920 Comment cmnt(masm_, "[ BreakStatement");
921 SetStatementPosition(stmt);
922 NestedStatement* current = nesting_stack_;
923 int stack_depth = 0;
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000924 int context_length = 0;
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000925 // When breaking, we clobber the unpredictable value in the accumulator
926 // with one that's safe for GC. If we hit an exit from the try block of
927 // try...finally on our way out, we will unconditionally preserve the
928 // accumulator on the stack.
929 ClearAccumulator();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000930 while (!current->IsBreakTarget(stmt->target())) {
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000931 current = current->Exit(&stack_depth, &context_length);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000932 }
933 __ Drop(stack_depth);
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000934 if (context_length > 0) {
935 while (context_length > 0) {
936 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
937 --context_length;
938 }
939 StoreToFrameField(StandardFrameConstants::kContextOffset,
940 context_register());
941 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000942
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000943 __ jmp(current->AsBreakable()->break_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000944}
945
946
947void FullCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) {
948 Comment cmnt(masm_, "[ ReturnStatement");
949 SetStatementPosition(stmt);
950 Expression* expr = stmt->expression();
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000951 VisitForAccumulatorValue(expr);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000952
953 // Exit all nested statements.
954 NestedStatement* current = nesting_stack_;
955 int stack_depth = 0;
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000956 int context_length = 0;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000957 while (current != NULL) {
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000958 current = current->Exit(&stack_depth, &context_length);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000959 }
960 __ Drop(stack_depth);
961
ager@chromium.org2cc82ae2010-06-14 07:35:38 +0000962 EmitReturnSequence();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000963}
964
965
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000966void FullCodeGenerator::VisitWithStatement(WithStatement* stmt) {
967 Comment cmnt(masm_, "[ WithStatement");
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000968 SetStatementPosition(stmt);
969
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000970 VisitForStackValue(stmt->expression());
vegorov@chromium.org3cf47312011-06-29 13:20:01 +0000971 PushFunctionArgumentForContextAllocation();
972 __ CallRuntime(Runtime::kPushWithContext, 2);
vegorov@chromium.org7943d462011-08-01 11:41:52 +0000973 decrement_stack_height();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000974 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register());
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000975
976 { WithOrCatch body(this);
977 Visit(stmt->statement());
978 }
979
980 // Pop context.
981 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
982 // Update local stack frame context field.
983 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000984}
985
986
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000987void FullCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) {
988 Comment cmnt(masm_, "[ DoWhileStatement");
989 SetStatementPosition(stmt);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000990 Label body, stack_check;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000991
992 Iteration loop_statement(this, stmt);
993 increment_loop_depth();
994
995 __ bind(&body);
996 Visit(stmt->body());
997
ricow@chromium.org65fae842010-08-25 15:26:24 +0000998 // Record the position of the do while condition and make sure it is
999 // possible to break on the condition.
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001000 __ bind(loop_statement.continue_label());
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001001 PrepareForBailoutForId(stmt->ContinueId(), NO_REGISTERS);
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001002 SetExpressionPosition(stmt->cond(), stmt->condition_position());
ricow@chromium.org65fae842010-08-25 15:26:24 +00001003 VisitForControl(stmt->cond(),
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001004 &stack_check,
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001005 loop_statement.break_label(),
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001006 &stack_check);
1007
1008 // Check stack before looping.
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001009 PrepareForBailoutForId(stmt->BackEdgeId(), NO_REGISTERS);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001010 __ bind(&stack_check);
1011 EmitStackCheck(stmt);
1012 __ jmp(&body);
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001013
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001014 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001015 __ bind(loop_statement.break_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001016 decrement_loop_depth();
1017}
1018
1019
1020void FullCodeGenerator::VisitWhileStatement(WhileStatement* stmt) {
1021 Comment cmnt(masm_, "[ WhileStatement");
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001022 Label test, body;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001023
1024 Iteration loop_statement(this, stmt);
1025 increment_loop_depth();
1026
1027 // Emit the test at the bottom of the loop.
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001028 __ jmp(&test);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001029
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001030 PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001031 __ bind(&body);
1032 Visit(stmt->body());
ricow@chromium.org65fae842010-08-25 15:26:24 +00001033
1034 // Emit the statement position here as this is where the while
1035 // statement code starts.
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001036 __ bind(loop_statement.continue_label());
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001037 SetStatementPosition(stmt);
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00001038
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001039 // Check stack before looping.
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001040 EmitStackCheck(stmt);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001041
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001042 __ bind(&test);
ricow@chromium.org65fae842010-08-25 15:26:24 +00001043 VisitForControl(stmt->cond(),
1044 &body,
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001045 loop_statement.break_label(),
1046 loop_statement.break_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001047
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001048 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001049 __ bind(loop_statement.break_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001050 decrement_loop_depth();
1051}
1052
1053
1054void FullCodeGenerator::VisitForStatement(ForStatement* stmt) {
1055 Comment cmnt(masm_, "[ ForStatement");
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001056 Label test, body;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001057
1058 Iteration loop_statement(this, stmt);
1059 if (stmt->init() != NULL) {
1060 Visit(stmt->init());
1061 }
1062
1063 increment_loop_depth();
1064 // Emit the test at the bottom of the loop (even if empty).
1065 __ jmp(&test);
1066
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001067 PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001068 __ bind(&body);
1069 Visit(stmt->body());
1070
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001071 PrepareForBailoutForId(stmt->ContinueId(), NO_REGISTERS);
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001072 __ bind(loop_statement.continue_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001073 SetStatementPosition(stmt);
1074 if (stmt->next() != NULL) {
1075 Visit(stmt->next());
1076 }
1077
ricow@chromium.org65fae842010-08-25 15:26:24 +00001078 // Emit the statement position here as this is where the for
1079 // statement code starts.
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001080 SetStatementPosition(stmt);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001081
1082 // Check stack before looping.
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001083 EmitStackCheck(stmt);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001084
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001085 __ bind(&test);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001086 if (stmt->cond() != NULL) {
ricow@chromium.org65fae842010-08-25 15:26:24 +00001087 VisitForControl(stmt->cond(),
1088 &body,
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001089 loop_statement.break_label(),
1090 loop_statement.break_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001091 } else {
1092 __ jmp(&body);
1093 }
1094
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001095 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001096 __ bind(loop_statement.break_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001097 decrement_loop_depth();
1098}
1099
1100
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001101void FullCodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) {
1102 Comment cmnt(masm_, "[ TryCatchStatement");
1103 SetStatementPosition(stmt);
1104 // The try block adds a handler to the exception handler chain
1105 // before entering, and removes it again when exiting normally.
1106 // If an exception is thrown during execution of the try block,
1107 // control is passed to the handler, which also consumes the handler.
1108 // At this point, the exception is in a register, and store it in
1109 // the temporary local variable (prints as ".catch-var") before
1110 // executing the catch block. The catch block has been rewritten
1111 // to introduce a new scope to bind the catch variable and to remove
1112 // that scope again afterwards.
1113
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001114 Label try_handler_setup, done;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001115 __ Call(&try_handler_setup);
1116 // Try handler code, exception in result register.
1117
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001118 // Extend the context before executing the catch block.
1119 { Comment cmnt(masm_, "[ Extend catch context");
ricow@chromium.org4f693d62011-07-04 14:01:31 +00001120 __ Push(stmt->variable()->name());
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001121 __ push(result_register());
vegorov@chromium.org3cf47312011-06-29 13:20:01 +00001122 PushFunctionArgumentForContextAllocation();
1123 __ CallRuntime(Runtime::kPushCatchContext, 3);
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001124 StoreToFrameField(StandardFrameConstants::kContextOffset,
1125 context_register());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001126 }
1127
ricow@chromium.org4f693d62011-07-04 14:01:31 +00001128 Scope* saved_scope = scope();
1129 scope_ = stmt->scope();
1130 ASSERT(scope_->declarations()->is_empty());
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00001131 { WithOrCatch body(this);
1132 Visit(stmt->catch_block());
1133 }
ricow@chromium.org55ee8072011-09-08 16:33:10 +00001134 // Restore the context.
1135 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
1136 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register());
ricow@chromium.org4f693d62011-07-04 14:01:31 +00001137 scope_ = saved_scope;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001138 __ jmp(&done);
1139
1140 // Try block code. Sets up the exception handler chain.
1141 __ bind(&try_handler_setup);
1142 {
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001143 const int delta = StackHandlerConstants::kSize / kPointerSize;
1144 TryCatch try_block(this);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001145 __ PushTryHandler(IN_JAVASCRIPT, TRY_CATCH_HANDLER);
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001146 increment_stack_height(delta);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001147 Visit(stmt->try_block());
1148 __ PopTryHandler();
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001149 decrement_stack_height(delta);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001150 }
1151 __ bind(&done);
1152}
1153
1154
1155void FullCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
1156 Comment cmnt(masm_, "[ TryFinallyStatement");
1157 SetStatementPosition(stmt);
1158 // Try finally is compiled by setting up a try-handler on the stack while
1159 // executing the try body, and removing it again afterwards.
1160 //
1161 // The try-finally construct can enter the finally block in three ways:
1162 // 1. By exiting the try-block normally. This removes the try-handler and
1163 // calls the finally block code before continuing.
1164 // 2. By exiting the try-block with a function-local control flow transfer
1165 // (break/continue/return). The site of the, e.g., break removes the
1166 // try handler and calls the finally block code before continuing
1167 // its outward control transfer.
1168 // 3. by exiting the try-block with a thrown exception.
1169 // This can happen in nested function calls. It traverses the try-handler
1170 // chain and consumes the try-handler entry before jumping to the
1171 // handler code. The handler code then calls the finally-block before
1172 // rethrowing the exception.
1173 //
1174 // The finally block must assume a return address on top of the stack
1175 // (or in the link register on ARM chips) and a value (return value or
1176 // exception) in the result register (rax/eax/r0), both of which must
1177 // be preserved. The return address isn't GC-safe, so it should be
1178 // cooked before GC.
1179 Label finally_entry;
1180 Label try_handler_setup;
vegorov@chromium.org7943d462011-08-01 11:41:52 +00001181 const int original_stack_height = stack_height();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001182
1183 // Setup the try-handler chain. Use a call to
1184 // Jump to try-handler setup and try-block code. Use call to put try-handler
1185 // address on stack.
1186 __ Call(&try_handler_setup);
1187 // Try handler code. Return address of call is pushed on handler stack.
1188 {
1189 // This code is only executed during stack-handler traversal when an
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001190 // exception is thrown. The exception is in the result register, which
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001191 // is retained by the finally block.
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001192 // Call the finally block and then rethrow the exception if it returns.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001193 __ Call(&finally_entry);
1194 __ push(result_register());
1195 __ CallRuntime(Runtime::kReThrow, 1);
1196 }
1197
1198 __ bind(&finally_entry);
1199 {
1200 // Finally block implementation.
1201 Finally finally_block(this);
1202 EnterFinallyBlock();
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001203 set_stack_height(original_stack_height + Finally::kElementCount);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001204 Visit(stmt->finally_block());
1205 ExitFinallyBlock(); // Return to the calling code.
1206 }
1207
1208 __ bind(&try_handler_setup);
1209 {
1210 // Setup try handler (stack pointer registers).
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001211 const int delta = StackHandlerConstants::kSize / kPointerSize;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001212 TryFinally try_block(this, &finally_entry);
1213 __ PushTryHandler(IN_JAVASCRIPT, TRY_FINALLY_HANDLER);
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001214 set_stack_height(original_stack_height + delta);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001215 Visit(stmt->try_block());
1216 __ PopTryHandler();
vegorov@chromium.org7943d462011-08-01 11:41:52 +00001217 set_stack_height(original_stack_height);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001218 }
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001219 // Execute the finally block on the way out. Clobber the unpredictable
1220 // value in the accumulator with one that's safe for GC. The finally
1221 // block will unconditionally preserve the accumulator on the stack.
1222 ClearAccumulator();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001223 __ Call(&finally_entry);
1224}
1225
1226
1227void FullCodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) {
1228#ifdef ENABLE_DEBUGGER_SUPPORT
1229 Comment cmnt(masm_, "[ DebuggerStatement");
1230 SetStatementPosition(stmt);
1231
ager@chromium.org5c838252010-02-19 08:53:10 +00001232 __ DebugBreak();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001233 // Ignore the return value.
1234#endif
1235}
1236
1237
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001238void FullCodeGenerator::VisitConditional(Conditional* expr) {
1239 Comment cmnt(masm_, "[ Conditional");
1240 Label true_case, false_case, done;
ricow@chromium.org65fae842010-08-25 15:26:24 +00001241 VisitForControl(expr->condition(), &true_case, &false_case, &true_case);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001242
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001243 PrepareForBailoutForId(expr->ThenId(), NO_REGISTERS);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001244 __ bind(&true_case);
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001245 SetExpressionPosition(expr->then_expression(),
1246 expr->then_expression_position());
vegorov@chromium.org7943d462011-08-01 11:41:52 +00001247 int start_stack_height = stack_height();
ager@chromium.orgb61a0d12010-10-13 08:35:23 +00001248 if (context()->IsTest()) {
1249 const TestContext* for_test = TestContext::cast(context());
1250 VisitForControl(expr->then_expression(),
1251 for_test->true_label(),
1252 for_test->false_label(),
1253 NULL);
1254 } else {
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001255 VisitInCurrentContext(expr->then_expression());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001256 __ jmp(&done);
1257 }
1258
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001259 PrepareForBailoutForId(expr->ElseId(), NO_REGISTERS);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001260 __ bind(&false_case);
vegorov@chromium.org7943d462011-08-01 11:41:52 +00001261 set_stack_height(start_stack_height);
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001262 if (context()->IsTest()) ForwardBailoutToChild(expr);
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001263 SetExpressionPosition(expr->else_expression(),
1264 expr->else_expression_position());
ricow@chromium.orgd2be9012011-06-01 06:00:58 +00001265 VisitInCurrentContext(expr->else_expression());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001266 // If control flow falls through Visit, merge it with true case here.
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00001267 if (!context()->IsTest()) {
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001268 __ bind(&done);
1269 }
1270}
1271
1272
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001273void FullCodeGenerator::VisitLiteral(Literal* expr) {
1274 Comment cmnt(masm_, "[ Literal");
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00001275 context()->Plug(expr->handle());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001276}
1277
1278
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00001279void FullCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) {
1280 Comment cmnt(masm_, "[ FunctionLiteral");
1281
1282 // Build the function boilerplate and instantiate it.
1283 Handle<SharedFunctionInfo> function_info =
ager@chromium.orgb61a0d12010-10-13 08:35:23 +00001284 Compiler::BuildFunctionInfo(expr, script());
1285 if (function_info.is_null()) {
1286 SetStackOverflow();
1287 return;
1288 }
vegorov@chromium.org21b5e952010-11-23 10:24:40 +00001289 EmitNewClosure(function_info, expr->pretenure());
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00001290}
1291
1292
1293void FullCodeGenerator::VisitSharedFunctionInfoLiteral(
1294 SharedFunctionInfoLiteral* expr) {
1295 Comment cmnt(masm_, "[ SharedFunctionInfoLiteral");
vegorov@chromium.org21b5e952010-11-23 10:24:40 +00001296 EmitNewClosure(expr->shared_function_info(), false);
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00001297}
1298
1299
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001300void FullCodeGenerator::VisitThrow(Throw* expr) {
1301 Comment cmnt(masm_, "[ Throw");
vegorov@chromium.org7943d462011-08-01 11:41:52 +00001302 // Throw has no effect on the stack height or the current expression context.
1303 // Usually the expression context is null, because throw is a statement.
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00001304 VisitForStackValue(expr->exception());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001305 __ CallRuntime(Runtime::kThrow, 1);
vegorov@chromium.org7943d462011-08-01 11:41:52 +00001306 decrement_stack_height();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001307 // Never returns here.
1308}
1309
1310
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00001311FullCodeGenerator::NestedStatement* FullCodeGenerator::TryCatch::Exit(
1312 int* stack_depth,
1313 int* context_length) {
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001314 // The macros used here must preserve the result register.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00001315 __ Drop(*stack_depth);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001316 __ PopTryHandler();
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00001317 *stack_depth = 0;
1318 return previous_;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001319}
1320
ricow@chromium.org65fae842010-08-25 15:26:24 +00001321
ager@chromium.org04921a82011-06-27 13:21:41 +00001322bool FullCodeGenerator::TryLiteralCompare(CompareOperation* compare,
1323 Label* if_true,
1324 Label* if_false,
1325 Label* fall_through) {
1326 Expression *expr;
1327 Handle<String> check;
1328 if (compare->IsLiteralCompareTypeof(&expr, &check)) {
1329 EmitLiteralCompareTypeof(expr, check, if_true, if_false, fall_through);
1330 return true;
1331 }
1332
1333 if (compare->IsLiteralCompareUndefined(&expr)) {
1334 EmitLiteralCompareUndefined(expr, if_true, if_false, fall_through);
1335 return true;
1336 }
1337
1338 return false;
1339}
1340
1341
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001342#undef __
1343
1344
1345} } // namespace v8::internal