blob: 79427524860b3c1d99e26a443f606969ff9deb0a [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
247void BreakableStatementChecker::VisitCompareOperation(CompareOperation* expr) {
248 Visit(expr->left());
249 Visit(expr->right());
250}
251
252
253void BreakableStatementChecker::VisitThisFunction(ThisFunction* expr) {
254}
255
256
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000257#define __ ACCESS_MASM(masm())
258
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000259bool FullCodeGenerator::MakeCode(CompilationInfo* info) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000260 Isolate* isolate = info->isolate();
ager@chromium.org5c838252010-02-19 08:53:10 +0000261 Handle<Script> script = info->script();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000262 if (!script->IsUndefined() && !script->source()->IsUndefined()) {
263 int len = String::cast(script->source())->length();
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000264 isolate->counters()->total_full_codegen_source_size()->Increment(len);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000265 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000266 if (FLAG_trace_codegen) {
267 PrintF("Full Compiler - ");
268 }
ager@chromium.org5c838252010-02-19 08:53:10 +0000269 CodeGenerator::MakeCodePrologue(info);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000270 const int kInitialBufferSize = 4 * KB;
kmillikin@chromium.orgc36ce6e2011-04-04 08:25:31 +0000271 MacroAssembler masm(info->isolate(), NULL, kInitialBufferSize);
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000272#ifdef ENABLE_GDB_JIT_INTERFACE
273 masm.positions_recorder()->StartGDBJITLineInfoRecording();
274#endif
ager@chromium.org5c838252010-02-19 08:53:10 +0000275
276 FullCodeGenerator cgen(&masm);
ager@chromium.orgea4f62e2010-08-16 16:28:43 +0000277 cgen.Generate(info);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000278 if (cgen.HasStackOverflow()) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000279 ASSERT(!isolate->has_pending_exception());
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000280 return false;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000281 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000282 unsigned table_offset = cgen.EmitStackCheckTable();
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000283
lrn@chromium.org34e60782011-09-15 07:25:40 +0000284 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION);
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000285 Handle<Code> code = CodeGenerator::MakeCodeEpilogue(&masm, flags, info);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000286 code->set_optimizable(info->IsOptimizable());
287 cgen.PopulateDeoptimizationData(code);
288 code->set_has_deoptimization_support(info->HasDeoptimizationSupport());
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +0000289 code->set_handler_table(*cgen.handler_table());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000290#ifdef ENABLE_DEBUGGER_SUPPORT
lrn@chromium.org34e60782011-09-15 07:25:40 +0000291 code->set_has_debug_break_slots(
292 info->isolate()->debugger()->IsDebuggerActive());
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000293 code->set_compiled_optimizable(info->IsOptimizable());
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000294#endif // ENABLE_DEBUGGER_SUPPORT
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000295 code->set_allow_osr_at_loop_nesting_level(0);
ricow@chromium.org83aa5492011-02-07 12:42:56 +0000296 code->set_stack_check_table_offset(table_offset);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000297 CodeGenerator::PrintCode(code, info);
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000298 info->SetCode(code); // May be an empty handle.
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000299#ifdef ENABLE_GDB_JIT_INTERFACE
vegorov@chromium.org0a4e9012011-01-24 12:33:13 +0000300 if (FLAG_gdbjit && !code.is_null()) {
erik.corry@gmail.com0511e242011-01-19 11:11:08 +0000301 GDBJITLineInfo* lineinfo =
302 masm.positions_recorder()->DetachGDBJITLineInfo();
303
304 GDBJIT(RegisterDetailedLineInfo(*code, lineinfo));
305 }
306#endif
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000307 return !code.is_null();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000308}
309
310
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000311unsigned FullCodeGenerator::EmitStackCheckTable() {
312 // The stack check table consists of a length (in number of entries)
313 // field, and then a sequence of entries. Each entry is a pair of AST id
314 // and code-relative pc offset.
315 masm()->Align(kIntSize);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000316 unsigned offset = masm()->pc_offset();
317 unsigned length = stack_checks_.length();
318 __ dd(length);
319 for (unsigned i = 0; i < length; ++i) {
320 __ dd(stack_checks_[i].id);
321 __ dd(stack_checks_[i].pc_and_state);
322 }
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000323 return offset;
324}
325
326
327void FullCodeGenerator::PopulateDeoptimizationData(Handle<Code> code) {
328 // Fill in the deoptimization information.
329 ASSERT(info_->HasDeoptimizationSupport() || bailout_entries_.is_empty());
330 if (!info_->HasDeoptimizationSupport()) return;
331 int length = bailout_entries_.length();
332 Handle<DeoptimizationOutputData> data =
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000333 isolate()->factory()->
334 NewDeoptimizationOutputData(length, TENURED);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000335 for (int i = 0; i < length; i++) {
336 data->SetAstId(i, Smi::FromInt(bailout_entries_[i].id));
337 data->SetPcAndState(i, Smi::FromInt(bailout_entries_[i].pc_and_state));
338 }
339 code->set_deoptimization_data(*data);
340}
341
342
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000343void FullCodeGenerator::PrepareForBailout(Expression* node, State state) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000344 PrepareForBailoutForId(node->id(), state);
345}
346
347
348void FullCodeGenerator::RecordJSReturnSite(Call* call) {
349 // We record the offset of the function return so we can rebuild the frame
350 // if the function was inlined, i.e., this is the return address in the
351 // inlined function's frame.
352 //
353 // The state is ignored. We defensively set it to TOS_REG, which is the
354 // real state of the unoptimized code at the return site.
355 PrepareForBailoutForId(call->ReturnId(), TOS_REG);
356#ifdef DEBUG
357 // In debug builds, mark the return so we can verify that this function
358 // was called.
359 ASSERT(!call->return_is_recorded_);
360 call->return_is_recorded_ = true;
361#endif
362}
363
364
365void FullCodeGenerator::PrepareForBailoutForId(int id, State state) {
366 // There's no need to prepare this code for bailouts from already optimized
367 // code or code that can't be optimized.
368 if (!FLAG_deopt || !info_->HasDeoptimizationSupport()) return;
369 unsigned pc_and_state =
370 StateField::encode(state) | PcField::encode(masm_->pc_offset());
371 BailoutEntry entry = { id, pc_and_state };
372#ifdef DEBUG
373 // Assert that we don't have multiple bailout entries for the same node.
374 for (int i = 0; i < bailout_entries_.length(); i++) {
375 if (bailout_entries_.at(i).id == entry.id) {
376 AstPrinter printer;
377 PrintF("%s", printer.PrintProgram(info_->function()));
378 UNREACHABLE();
379 }
380 }
381#endif // DEBUG
382 bailout_entries_.Add(entry);
383}
384
385
386void FullCodeGenerator::RecordStackCheck(int ast_id) {
387 // The pc offset does not need to be encoded and packed together with a
388 // state.
389 BailoutEntry entry = { ast_id, masm_->pc_offset() };
390 stack_checks_.Add(entry);
391}
392
393
ricow@chromium.org65fae842010-08-25 15:26:24 +0000394bool FullCodeGenerator::ShouldInlineSmiCase(Token::Value op) {
ricow@chromium.org65fae842010-08-25 15:26:24 +0000395 // Inline smi case inside loops, but not division and modulo which
396 // are too complicated and take up too much space.
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000397 if (op == Token::DIV ||op == Token::MOD) return false;
398 if (FLAG_always_inline_smi_code) return true;
399 return loop_depth_ > 0;
ricow@chromium.org65fae842010-08-25 15:26:24 +0000400}
401
402
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000403void FullCodeGenerator::EffectContext::Plug(Register reg) const {
404}
405
406
407void FullCodeGenerator::AccumulatorValueContext::Plug(Register reg) const {
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000408 __ Move(result_register(), reg);
409}
410
411
412void FullCodeGenerator::StackValueContext::Plug(Register reg) const {
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000413 __ push(reg);
414}
415
416
417void FullCodeGenerator::TestContext::Plug(Register reg) const {
418 // For simplicity we always test the accumulator register.
419 __ Move(result_register(), reg);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000420 codegen()->PrepareForBailoutBeforeSplit(condition(), 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);
427}
428
429
430void FullCodeGenerator::AccumulatorValueContext::PlugTOS() const {
431 __ pop(result_register());
432}
433
434
435void FullCodeGenerator::StackValueContext::PlugTOS() const {
436}
437
438
439void FullCodeGenerator::TestContext::PlugTOS() const {
440 // For simplicity we always test the accumulator register.
441 __ pop(result_register());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000442 codegen()->PrepareForBailoutBeforeSplit(condition(), false, NULL, NULL);
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000443 codegen()->DoTest(this);
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000444}
445
446
447void FullCodeGenerator::EffectContext::PrepareTest(
448 Label* materialize_true,
449 Label* materialize_false,
450 Label** if_true,
451 Label** if_false,
452 Label** fall_through) const {
453 // In an effect context, the true and the false case branch to the
454 // same label.
455 *if_true = *if_false = *fall_through = materialize_true;
456}
457
458
459void FullCodeGenerator::AccumulatorValueContext::PrepareTest(
460 Label* materialize_true,
461 Label* materialize_false,
462 Label** if_true,
463 Label** if_false,
464 Label** fall_through) const {
465 *if_true = *fall_through = materialize_true;
466 *if_false = materialize_false;
467}
468
469
470void FullCodeGenerator::StackValueContext::PrepareTest(
471 Label* materialize_true,
472 Label* materialize_false,
473 Label** if_true,
474 Label** if_false,
475 Label** fall_through) const {
476 *if_true = *fall_through = materialize_true;
477 *if_false = materialize_false;
478}
479
480
481void FullCodeGenerator::TestContext::PrepareTest(
482 Label* materialize_true,
483 Label* materialize_false,
484 Label** if_true,
485 Label** if_false,
486 Label** fall_through) const {
487 *if_true = true_label_;
488 *if_false = false_label_;
489 *fall_through = fall_through_;
ricow@chromium.org65fae842010-08-25 15:26:24 +0000490}
491
492
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000493void FullCodeGenerator::DoTest(const TestContext* context) {
494 DoTest(context->condition(),
495 context->true_label(),
496 context->false_label(),
497 context->fall_through());
498}
499
500
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000501void FullCodeGenerator::VisitDeclarations(
502 ZoneList<Declaration*>* declarations) {
503 int length = declarations->length();
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000504 int global_count = 0;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000505 for (int i = 0; i < length; i++) {
506 Declaration* decl = declarations->at(i);
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000507 EmitDeclaration(decl->proxy(), decl->mode(), decl->fun(), &global_count);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000508 }
509
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000510 // Batch declare global functions and variables.
511 if (global_count > 0) {
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000512 Handle<FixedArray> array =
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000513 isolate()->factory()->NewFixedArray(2 * global_count, TENURED);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000514 for (int j = 0, i = 0; i < length; i++) {
515 Declaration* decl = declarations->at(i);
516 Variable* var = decl->proxy()->var();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000517
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000518 if (var->IsUnallocated()) {
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000519 array->set(j++, *(var->name()));
520 if (decl->fun() == NULL) {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000521 if (var->binding_needs_init()) {
522 // In case this binding needs initialization use the hole.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000523 array->set_the_hole(j++);
524 } else {
525 array->set_undefined(j++);
526 }
527 } else {
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000528 Handle<SharedFunctionInfo> function =
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000529 Compiler::BuildFunctionInfo(decl->fun(), script());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000530 // Check for stack-overflow exception.
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000531 if (function.is_null()) {
532 SetStackOverflow();
533 return;
534 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000535 array->set(j++, *function);
536 }
537 }
538 }
539 // Invoke the platform-dependent code generator to do the actual
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000540 // declaration the global functions and variables.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000541 DeclareGlobals(array);
542 }
543}
544
545
fschneider@chromium.org1805e212011-09-05 10:49:12 +0000546int FullCodeGenerator::DeclareGlobalsFlags() {
erik.corry@gmail.com394dbcf2011-10-27 07:38:48 +0000547 ASSERT(DeclareGlobalsStrictModeFlag::is_valid(strict_mode_flag()));
548 return DeclareGlobalsEvalFlag::encode(is_eval()) |
549 DeclareGlobalsStrictModeFlag::encode(strict_mode_flag()) |
550 DeclareGlobalsNativeFlag::encode(is_native());
fschneider@chromium.org1805e212011-09-05 10:49:12 +0000551}
552
553
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000554void FullCodeGenerator::SetFunctionPosition(FunctionLiteral* fun) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000555 CodeGenerator::RecordPositions(masm_, fun->start_position());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000556}
557
558
559void FullCodeGenerator::SetReturnPosition(FunctionLiteral* fun) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000560 CodeGenerator::RecordPositions(masm_, fun->end_position() - 1);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000561}
562
563
564void FullCodeGenerator::SetStatementPosition(Statement* stmt) {
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000565#ifdef ENABLE_DEBUGGER_SUPPORT
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000566 if (!isolate()->debugger()->IsDebuggerActive()) {
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000567 CodeGenerator::RecordPositions(masm_, stmt->statement_pos());
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000568 } else {
569 // Check if the statement will be breakable without adding a debug break
570 // slot.
571 BreakableStatementChecker checker;
572 checker.Check(stmt);
573 // Record the statement position right here if the statement is not
574 // breakable. For breakable statements the actual recording of the
575 // position will be postponed to the breakable code (typically an IC).
576 bool position_recorded = CodeGenerator::RecordPositions(
577 masm_, stmt->statement_pos(), !checker.is_breakable());
578 // If the position recording did record a new position generate a debug
579 // break slot to make the statement breakable.
580 if (position_recorded) {
581 Debug::GenerateSlot(masm_);
582 }
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000583 }
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000584#else
585 CodeGenerator::RecordPositions(masm_, stmt->statement_pos());
586#endif
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000587}
588
589
590void FullCodeGenerator::SetExpressionPosition(Expression* expr, int pos) {
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000591#ifdef ENABLE_DEBUGGER_SUPPORT
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000592 if (!isolate()->debugger()->IsDebuggerActive()) {
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000593 CodeGenerator::RecordPositions(masm_, pos);
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000594 } else {
595 // Check if the expression will be breakable without adding a debug break
596 // slot.
597 BreakableStatementChecker checker;
598 checker.Check(expr);
599 // Record a statement position right here if the expression is not
600 // breakable. For breakable expressions the actual recording of the
601 // position will be postponed to the breakable code (typically an IC).
602 // NOTE this will record a statement position for something which might
603 // not be a statement. As stepping in the debugger will only stop at
604 // statement positions this is used for e.g. the condition expression of
605 // a do while loop.
606 bool position_recorded = CodeGenerator::RecordPositions(
607 masm_, pos, !checker.is_breakable());
608 // If the position recording did record a new position generate a debug
609 // break slot to make the statement breakable.
610 if (position_recorded) {
611 Debug::GenerateSlot(masm_);
612 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000613 }
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000614#else
615 CodeGenerator::RecordPositions(masm_, pos);
616#endif
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000617}
618
619
620void FullCodeGenerator::SetStatementPosition(int pos) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000621 CodeGenerator::RecordPositions(masm_, pos);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000622}
623
624
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000625void FullCodeGenerator::SetSourcePosition(int pos) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000626 if (pos != RelocInfo::kNoPosition) {
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000627 masm_->positions_recorder()->RecordPosition(pos);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000628 }
629}
630
631
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000632// Lookup table for code generators for special runtime calls which are
633// generated inline.
634#define INLINE_FUNCTION_GENERATOR_ADDRESS(Name, argc, ressize) \
635 &FullCodeGenerator::Emit##Name,
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000636
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000637const FullCodeGenerator::InlineFunctionGenerator
638 FullCodeGenerator::kInlineFunctionGenerators[] = {
639 INLINE_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS)
640 INLINE_RUNTIME_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS)
641 };
642#undef INLINE_FUNCTION_GENERATOR_ADDRESS
643
644
645FullCodeGenerator::InlineFunctionGenerator
646 FullCodeGenerator::FindInlineFunctionGenerator(Runtime::FunctionId id) {
whesse@chromium.org023421e2010-12-21 12:19:12 +0000647 int lookup_index =
648 static_cast<int>(id) - static_cast<int>(Runtime::kFirstInlineFunction);
649 ASSERT(lookup_index >= 0);
650 ASSERT(static_cast<size_t>(lookup_index) <
651 ARRAY_SIZE(kInlineFunctionGenerators));
652 return kInlineFunctionGenerators[lookup_index];
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000653}
654
655
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000656void FullCodeGenerator::EmitInlineRuntimeCall(CallRuntime* expr) {
657 const Runtime::Function* function = expr->function();
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000658 ASSERT(function != NULL);
659 ASSERT(function->intrinsic_type == Runtime::INLINE);
660 InlineFunctionGenerator generator =
661 FindInlineFunctionGenerator(function->function_id);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000662 ((*this).*(generator))(expr);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000663}
664
665
666void FullCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) {
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000667 switch (expr->op()) {
ricow@chromium.org65fae842010-08-25 15:26:24 +0000668 case Token::COMMA:
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000669 return VisitComma(expr);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000670 case Token::OR:
671 case Token::AND:
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000672 return VisitLogicalExpression(expr);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000673 default:
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000674 return VisitArithmeticExpression(expr);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000675 }
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000676}
677
678
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000679void FullCodeGenerator::VisitInDuplicateContext(Expression* expr) {
680 if (context()->IsEffect()) {
681 VisitForEffect(expr);
682 } else if (context()->IsAccumulatorValue()) {
683 VisitForAccumulatorValue(expr);
684 } else if (context()->IsStackValue()) {
685 VisitForStackValue(expr);
686 } else if (context()->IsTest()) {
687 const TestContext* test = TestContext::cast(context());
688 VisitForControl(expr, test->true_label(), test->false_label(),
689 test->fall_through());
690 }
691}
692
693
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000694void FullCodeGenerator::VisitComma(BinaryOperation* expr) {
695 Comment cmnt(masm_, "[ Comma");
696 VisitForEffect(expr->left());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000697 VisitInDuplicateContext(expr->right());
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000698}
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000699
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000700
701void FullCodeGenerator::VisitLogicalExpression(BinaryOperation* expr) {
702 bool is_logical_and = expr->op() == Token::AND;
703 Comment cmnt(masm_, is_logical_and ? "[ Logical AND" : "[ Logical OR");
704 Expression* left = expr->left();
705 Expression* right = expr->right();
706 int right_id = expr->RightId();
707 Label done;
708
709 if (context()->IsTest()) {
710 Label eval_right;
711 const TestContext* test = TestContext::cast(context());
712 if (is_logical_and) {
713 VisitForControl(left, &eval_right, test->false_label(), &eval_right);
714 } else {
715 VisitForControl(left, test->true_label(), &eval_right, &eval_right);
716 }
717 PrepareForBailoutForId(right_id, NO_REGISTERS);
718 __ bind(&eval_right);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000719
720 } else if (context()->IsAccumulatorValue()) {
721 VisitForAccumulatorValue(left);
722 // We want the value in the accumulator for the test, and on the stack in
723 // case we need it.
724 __ push(result_register());
725 Label discard, restore;
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000726 if (is_logical_and) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000727 DoTest(left, &discard, &restore, &restore);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000728 } else {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000729 DoTest(left, &restore, &discard, &restore);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000730 }
731 __ bind(&restore);
732 __ pop(result_register());
733 __ jmp(&done);
734 __ bind(&discard);
735 __ Drop(1);
736 PrepareForBailoutForId(right_id, NO_REGISTERS);
737
738 } else if (context()->IsStackValue()) {
739 VisitForAccumulatorValue(left);
740 // We want the value in the accumulator for the test, and on the stack in
741 // case we need it.
742 __ push(result_register());
743 Label discard;
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000744 if (is_logical_and) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000745 DoTest(left, &discard, &done, &discard);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000746 } else {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000747 DoTest(left, &done, &discard, &discard);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000748 }
749 __ bind(&discard);
750 __ Drop(1);
751 PrepareForBailoutForId(right_id, NO_REGISTERS);
752
753 } else {
754 ASSERT(context()->IsEffect());
755 Label eval_right;
756 if (is_logical_and) {
757 VisitForControl(left, &eval_right, &done, &eval_right);
758 } else {
759 VisitForControl(left, &done, &eval_right, &eval_right);
760 }
761 PrepareForBailoutForId(right_id, NO_REGISTERS);
762 __ bind(&eval_right);
763 }
764
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000765 VisitInDuplicateContext(right);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000766 __ bind(&done);
767}
768
769
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000770void FullCodeGenerator::VisitArithmeticExpression(BinaryOperation* expr) {
771 Token::Value op = expr->op();
772 Comment cmnt(masm_, "[ ArithmeticExpression");
773 Expression* left = expr->left();
774 Expression* right = expr->right();
775 OverwriteMode mode =
776 left->ResultOverwriteAllowed()
777 ? OVERWRITE_LEFT
778 : (right->ResultOverwriteAllowed() ? OVERWRITE_RIGHT : NO_OVERWRITE);
779
780 VisitForStackValue(left);
781 VisitForAccumulatorValue(right);
782
783 SetSourcePosition(expr->position());
784 if (ShouldInlineSmiCase(op)) {
785 EmitInlineSmiBinaryOp(expr, op, mode, left, right);
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000786 } else {
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000787 EmitBinaryOp(expr, op, mode);
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000788 }
789}
790
791
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000792void FullCodeGenerator::VisitBlock(Block* stmt) {
793 Comment cmnt(masm_, "[ Block");
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000794 NestedBlock nested_block(this, stmt);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000795 SetStatementPosition(stmt);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000796
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000797 Scope* saved_scope = scope();
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000798 // Push a block context when entering a block with block scoped variables.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000799 if (stmt->block_scope() != NULL) {
800 { Comment cmnt(masm_, "[ Extend block context");
801 scope_ = stmt->block_scope();
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000802 Handle<ScopeInfo> scope_info = scope_->GetScopeInfo();
803 int heap_slots = scope_info->ContextLength() - Context::MIN_CONTEXT_SLOTS;
svenpanne@chromium.orga8bb4d92011-10-10 13:20:40 +0000804 __ Push(scope_info);
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000805 PushFunctionArgumentForContextAllocation();
svenpanne@chromium.orga8bb4d92011-10-10 13:20:40 +0000806 if (heap_slots <= FastNewBlockContextStub::kMaximumSlots) {
807 FastNewBlockContextStub stub(heap_slots);
808 __ CallStub(&stub);
809 } else {
810 __ CallRuntime(Runtime::kPushBlockContext, 2);
811 }
812
813 // Replace the context stored in the frame.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000814 StoreToFrameField(StandardFrameConstants::kContextOffset,
815 context_register());
816 }
817 { Comment cmnt(masm_, "[ Declarations");
818 VisitDeclarations(scope_->declarations());
819 }
820 }
erik.corry@gmail.comd91075f2011-02-10 07:45:38 +0000821 PrepareForBailoutForId(stmt->EntryId(), NO_REGISTERS);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000822 VisitStatements(stmt->statements());
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000823 scope_ = saved_scope;
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000824 __ bind(nested_block.break_label());
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000825 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000826
827 // Pop block context if necessary.
828 if (stmt->block_scope() != NULL) {
829 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
830 // Update local stack frame context field.
831 StoreToFrameField(StandardFrameConstants::kContextOffset,
832 context_register());
833 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000834}
835
836
837void FullCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) {
838 Comment cmnt(masm_, "[ ExpressionStatement");
839 SetStatementPosition(stmt);
840 VisitForEffect(stmt->expression());
841}
842
843
844void FullCodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) {
845 Comment cmnt(masm_, "[ EmptyStatement");
846 SetStatementPosition(stmt);
847}
848
849
850void FullCodeGenerator::VisitIfStatement(IfStatement* stmt) {
851 Comment cmnt(masm_, "[ IfStatement");
852 SetStatementPosition(stmt);
853 Label then_part, else_part, done;
854
ricow@chromium.org65fae842010-08-25 15:26:24 +0000855 if (stmt->HasElseStatement()) {
856 VisitForControl(stmt->condition(), &then_part, &else_part, &then_part);
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000857 PrepareForBailoutForId(stmt->ThenId(), NO_REGISTERS);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000858 __ bind(&then_part);
859 Visit(stmt->then_statement());
860 __ jmp(&done);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000861
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000862 PrepareForBailoutForId(stmt->ElseId(), NO_REGISTERS);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000863 __ bind(&else_part);
864 Visit(stmt->else_statement());
865 } else {
866 VisitForControl(stmt->condition(), &then_part, &done, &then_part);
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000867 PrepareForBailoutForId(stmt->ThenId(), NO_REGISTERS);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000868 __ bind(&then_part);
869 Visit(stmt->then_statement());
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000870
871 PrepareForBailoutForId(stmt->ElseId(), NO_REGISTERS);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000872 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000873 __ bind(&done);
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000874 PrepareForBailoutForId(stmt->IfId(), NO_REGISTERS);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000875}
876
877
878void FullCodeGenerator::VisitContinueStatement(ContinueStatement* stmt) {
879 Comment cmnt(masm_, "[ ContinueStatement");
880 SetStatementPosition(stmt);
881 NestedStatement* current = nesting_stack_;
882 int stack_depth = 0;
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000883 int context_length = 0;
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000884 // When continuing, we clobber the unpredictable value in the accumulator
885 // with one that's safe for GC. If we hit an exit from the try block of
886 // try...finally on our way out, we will unconditionally preserve the
887 // accumulator on the stack.
888 ClearAccumulator();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000889 while (!current->IsContinueTarget(stmt->target())) {
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000890 current = current->Exit(&stack_depth, &context_length);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000891 }
892 __ Drop(stack_depth);
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000893 if (context_length > 0) {
894 while (context_length > 0) {
895 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
896 --context_length;
897 }
898 StoreToFrameField(StandardFrameConstants::kContextOffset,
899 context_register());
900 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000901
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000902 __ jmp(current->AsIteration()->continue_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000903}
904
905
906void FullCodeGenerator::VisitBreakStatement(BreakStatement* stmt) {
907 Comment cmnt(masm_, "[ BreakStatement");
908 SetStatementPosition(stmt);
909 NestedStatement* current = nesting_stack_;
910 int stack_depth = 0;
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000911 int context_length = 0;
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000912 // When breaking, we clobber the unpredictable value in the accumulator
913 // with one that's safe for GC. If we hit an exit from the try block of
914 // try...finally on our way out, we will unconditionally preserve the
915 // accumulator on the stack.
916 ClearAccumulator();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000917 while (!current->IsBreakTarget(stmt->target())) {
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000918 current = current->Exit(&stack_depth, &context_length);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000919 }
920 __ Drop(stack_depth);
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000921 if (context_length > 0) {
922 while (context_length > 0) {
923 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
924 --context_length;
925 }
926 StoreToFrameField(StandardFrameConstants::kContextOffset,
927 context_register());
928 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000929
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000930 __ jmp(current->AsBreakable()->break_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000931}
932
933
934void FullCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) {
935 Comment cmnt(masm_, "[ ReturnStatement");
936 SetStatementPosition(stmt);
937 Expression* expr = stmt->expression();
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000938 VisitForAccumulatorValue(expr);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000939
940 // Exit all nested statements.
941 NestedStatement* current = nesting_stack_;
942 int stack_depth = 0;
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000943 int context_length = 0;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000944 while (current != NULL) {
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000945 current = current->Exit(&stack_depth, &context_length);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000946 }
947 __ Drop(stack_depth);
948
ager@chromium.org2cc82ae2010-06-14 07:35:38 +0000949 EmitReturnSequence();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000950}
951
952
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000953void FullCodeGenerator::VisitWithStatement(WithStatement* stmt) {
954 Comment cmnt(masm_, "[ WithStatement");
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000955 SetStatementPosition(stmt);
956
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000957 VisitForStackValue(stmt->expression());
vegorov@chromium.org3cf47312011-06-29 13:20:01 +0000958 PushFunctionArgumentForContextAllocation();
959 __ CallRuntime(Runtime::kPushWithContext, 2);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000960 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register());
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000961
962 { WithOrCatch body(this);
963 Visit(stmt->statement());
964 }
965
966 // Pop context.
967 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
968 // Update local stack frame context field.
969 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000970}
971
972
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000973void FullCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) {
974 Comment cmnt(masm_, "[ DoWhileStatement");
975 SetStatementPosition(stmt);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000976 Label body, stack_check;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000977
978 Iteration loop_statement(this, stmt);
979 increment_loop_depth();
980
981 __ bind(&body);
982 Visit(stmt->body());
983
ricow@chromium.org65fae842010-08-25 15:26:24 +0000984 // Record the position of the do while condition and make sure it is
985 // possible to break on the condition.
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000986 __ bind(loop_statement.continue_label());
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000987 PrepareForBailoutForId(stmt->ContinueId(), NO_REGISTERS);
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000988 SetExpressionPosition(stmt->cond(), stmt->condition_position());
ricow@chromium.org65fae842010-08-25 15:26:24 +0000989 VisitForControl(stmt->cond(),
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000990 &stack_check,
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000991 loop_statement.break_label(),
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000992 &stack_check);
993
994 // Check stack before looping.
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000995 PrepareForBailoutForId(stmt->BackEdgeId(), NO_REGISTERS);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000996 __ bind(&stack_check);
997 EmitStackCheck(stmt);
998 __ jmp(&body);
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000999
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001000 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001001 __ bind(loop_statement.break_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001002 decrement_loop_depth();
1003}
1004
1005
1006void FullCodeGenerator::VisitWhileStatement(WhileStatement* stmt) {
1007 Comment cmnt(masm_, "[ WhileStatement");
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001008 Label test, body;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001009
1010 Iteration loop_statement(this, stmt);
1011 increment_loop_depth();
1012
1013 // Emit the test at the bottom of the loop.
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001014 __ jmp(&test);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001015
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001016 PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001017 __ bind(&body);
1018 Visit(stmt->body());
ricow@chromium.org65fae842010-08-25 15:26:24 +00001019
1020 // Emit the statement position here as this is where the while
1021 // statement code starts.
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001022 __ bind(loop_statement.continue_label());
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001023 SetStatementPosition(stmt);
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00001024
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001025 // Check stack before looping.
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001026 EmitStackCheck(stmt);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001027
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001028 __ bind(&test);
ricow@chromium.org65fae842010-08-25 15:26:24 +00001029 VisitForControl(stmt->cond(),
1030 &body,
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001031 loop_statement.break_label(),
1032 loop_statement.break_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001033
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001034 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001035 __ bind(loop_statement.break_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001036 decrement_loop_depth();
1037}
1038
1039
1040void FullCodeGenerator::VisitForStatement(ForStatement* stmt) {
1041 Comment cmnt(masm_, "[ ForStatement");
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001042 Label test, body;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001043
1044 Iteration loop_statement(this, stmt);
1045 if (stmt->init() != NULL) {
1046 Visit(stmt->init());
1047 }
1048
1049 increment_loop_depth();
1050 // Emit the test at the bottom of the loop (even if empty).
1051 __ jmp(&test);
1052
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001053 PrepareForBailoutForId(stmt->BodyId(), NO_REGISTERS);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001054 __ bind(&body);
1055 Visit(stmt->body());
1056
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001057 PrepareForBailoutForId(stmt->ContinueId(), NO_REGISTERS);
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001058 __ bind(loop_statement.continue_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001059 SetStatementPosition(stmt);
1060 if (stmt->next() != NULL) {
1061 Visit(stmt->next());
1062 }
1063
ricow@chromium.org65fae842010-08-25 15:26:24 +00001064 // Emit the statement position here as this is where the for
1065 // statement code starts.
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001066 SetStatementPosition(stmt);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001067
1068 // Check stack before looping.
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001069 EmitStackCheck(stmt);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001070
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001071 __ bind(&test);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001072 if (stmt->cond() != NULL) {
ricow@chromium.org65fae842010-08-25 15:26:24 +00001073 VisitForControl(stmt->cond(),
1074 &body,
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001075 loop_statement.break_label(),
1076 loop_statement.break_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001077 } else {
1078 __ jmp(&body);
1079 }
1080
kasperl@chromium.orga5551262010-12-07 12:49:48 +00001081 PrepareForBailoutForId(stmt->ExitId(), NO_REGISTERS);
rossberg@chromium.org28a37082011-08-22 11:03:23 +00001082 __ bind(loop_statement.break_label());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001083 decrement_loop_depth();
1084}
1085
1086
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001087void FullCodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) {
1088 Comment cmnt(masm_, "[ TryCatchStatement");
1089 SetStatementPosition(stmt);
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001090 // The try block adds a handler to the exception handler chain before
1091 // entering, and removes it again when exiting normally. If an exception
1092 // is thrown during execution of the try block, the handler is consumed
1093 // and control is passed to the catch block with the exception in the
1094 // result register.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001095
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001096 Label try_entry, handler_entry, exit;
1097 __ jmp(&try_entry);
1098 __ bind(&handler_entry);
1099 handler_table()->set(stmt->index(), Smi::FromInt(handler_entry.pos()));
1100 // Exception handler code, the exception is in the result register.
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001101 // Extend the context before executing the catch block.
1102 { Comment cmnt(masm_, "[ Extend catch context");
ricow@chromium.org4f693d62011-07-04 14:01:31 +00001103 __ Push(stmt->variable()->name());
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001104 __ push(result_register());
vegorov@chromium.org3cf47312011-06-29 13:20:01 +00001105 PushFunctionArgumentForContextAllocation();
1106 __ CallRuntime(Runtime::kPushCatchContext, 3);
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +00001107 StoreToFrameField(StandardFrameConstants::kContextOffset,
1108 context_register());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001109 }
1110
ricow@chromium.org4f693d62011-07-04 14:01:31 +00001111 Scope* saved_scope = scope();
1112 scope_ = stmt->scope();
1113 ASSERT(scope_->declarations()->is_empty());
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001114 { WithOrCatch catch_body(this);
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00001115 Visit(stmt->catch_block());
1116 }
ricow@chromium.org55ee8072011-09-08 16:33:10 +00001117 // Restore the context.
1118 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
1119 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register());
ricow@chromium.org4f693d62011-07-04 14:01:31 +00001120 scope_ = saved_scope;
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001121 __ jmp(&exit);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001122
1123 // Try block code. Sets up the exception handler chain.
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001124 __ bind(&try_entry);
1125 __ PushTryHandler(IN_JAVASCRIPT, TRY_CATCH_HANDLER, stmt->index());
1126 { TryCatch try_body(this);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001127 Visit(stmt->try_block());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001128 }
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001129 __ PopTryHandler();
1130 __ bind(&exit);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001131}
1132
1133
1134void FullCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
1135 Comment cmnt(masm_, "[ TryFinallyStatement");
1136 SetStatementPosition(stmt);
1137 // Try finally is compiled by setting up a try-handler on the stack while
1138 // executing the try body, and removing it again afterwards.
1139 //
1140 // The try-finally construct can enter the finally block in three ways:
1141 // 1. By exiting the try-block normally. This removes the try-handler and
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001142 // calls the finally block code before continuing.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001143 // 2. By exiting the try-block with a function-local control flow transfer
1144 // (break/continue/return). The site of the, e.g., break removes the
1145 // try handler and calls the finally block code before continuing
1146 // its outward control transfer.
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001147 // 3. By exiting the try-block with a thrown exception.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001148 // This can happen in nested function calls. It traverses the try-handler
1149 // chain and consumes the try-handler entry before jumping to the
1150 // handler code. The handler code then calls the finally-block before
1151 // rethrowing the exception.
1152 //
1153 // The finally block must assume a return address on top of the stack
1154 // (or in the link register on ARM chips) and a value (return value or
1155 // exception) in the result register (rax/eax/r0), both of which must
1156 // be preserved. The return address isn't GC-safe, so it should be
1157 // cooked before GC.
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001158 Label try_entry, handler_entry, finally_entry;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001159
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001160 // Jump to try-handler setup and try-block code.
1161 __ jmp(&try_entry);
1162 __ bind(&handler_entry);
1163 handler_table()->set(stmt->index(), Smi::FromInt(handler_entry.pos()));
1164 // Exception handler code. This code is only executed when an exception
1165 // is thrown. The exception is in the result register, and must be
1166 // preserved by the finally block. Call the finally block and then
1167 // rethrow the exception if it returns.
1168 __ Call(&finally_entry);
1169 __ push(result_register());
1170 __ CallRuntime(Runtime::kReThrow, 1);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001171
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001172 // Finally block implementation.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001173 __ bind(&finally_entry);
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001174 EnterFinallyBlock();
1175 { Finally finally_body(this);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001176 Visit(stmt->finally_block());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001177 }
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001178 ExitFinallyBlock(); // Return to the calling code.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001179
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001180 // Setup try handler.
1181 __ bind(&try_entry);
1182 __ PushTryHandler(IN_JAVASCRIPT, TRY_FINALLY_HANDLER, stmt->index());
1183 { TryFinally try_body(this, &finally_entry);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001184 Visit(stmt->try_block());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001185 }
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001186 __ PopTryHandler();
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001187 // Execute the finally block on the way out. Clobber the unpredictable
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +00001188 // value in the result register with one that's safe for GC because the
1189 // finally block will unconditionally preserve the result register on the
1190 // stack.
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001191 ClearAccumulator();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001192 __ Call(&finally_entry);
1193}
1194
1195
1196void FullCodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) {
1197#ifdef ENABLE_DEBUGGER_SUPPORT
1198 Comment cmnt(masm_, "[ DebuggerStatement");
1199 SetStatementPosition(stmt);
1200
ager@chromium.org5c838252010-02-19 08:53:10 +00001201 __ DebugBreak();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001202 // Ignore the return value.
1203#endif
1204}
1205
1206
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001207void FullCodeGenerator::VisitConditional(Conditional* expr) {
1208 Comment cmnt(masm_, "[ Conditional");
1209 Label true_case, false_case, done;
ricow@chromium.org65fae842010-08-25 15:26:24 +00001210 VisitForControl(expr->condition(), &true_case, &false_case, &true_case);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001211
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001212 PrepareForBailoutForId(expr->ThenId(), NO_REGISTERS);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001213 __ bind(&true_case);
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001214 SetExpressionPosition(expr->then_expression(),
1215 expr->then_expression_position());
ager@chromium.orgb61a0d12010-10-13 08:35:23 +00001216 if (context()->IsTest()) {
1217 const TestContext* for_test = TestContext::cast(context());
1218 VisitForControl(expr->then_expression(),
1219 for_test->true_label(),
1220 for_test->false_label(),
1221 NULL);
1222 } else {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001223 VisitInDuplicateContext(expr->then_expression());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001224 __ jmp(&done);
1225 }
1226
ager@chromium.org5f0c45f2010-12-17 08:51:21 +00001227 PrepareForBailoutForId(expr->ElseId(), NO_REGISTERS);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001228 __ bind(&false_case);
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +00001229 SetExpressionPosition(expr->else_expression(),
1230 expr->else_expression_position());
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001231 VisitInDuplicateContext(expr->else_expression());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001232 // If control flow falls through Visit, merge it with true case here.
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00001233 if (!context()->IsTest()) {
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001234 __ bind(&done);
1235 }
1236}
1237
1238
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001239void FullCodeGenerator::VisitLiteral(Literal* expr) {
1240 Comment cmnt(masm_, "[ Literal");
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00001241 context()->Plug(expr->handle());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001242}
1243
1244
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00001245void FullCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) {
1246 Comment cmnt(masm_, "[ FunctionLiteral");
1247
1248 // Build the function boilerplate and instantiate it.
1249 Handle<SharedFunctionInfo> function_info =
ager@chromium.orgb61a0d12010-10-13 08:35:23 +00001250 Compiler::BuildFunctionInfo(expr, script());
1251 if (function_info.is_null()) {
1252 SetStackOverflow();
1253 return;
1254 }
vegorov@chromium.org21b5e952010-11-23 10:24:40 +00001255 EmitNewClosure(function_info, expr->pretenure());
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00001256}
1257
1258
1259void FullCodeGenerator::VisitSharedFunctionInfoLiteral(
1260 SharedFunctionInfoLiteral* expr) {
1261 Comment cmnt(masm_, "[ SharedFunctionInfoLiteral");
vegorov@chromium.org21b5e952010-11-23 10:24:40 +00001262 EmitNewClosure(expr->shared_function_info(), false);
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +00001263}
1264
1265
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001266void FullCodeGenerator::VisitThrow(Throw* expr) {
1267 Comment cmnt(masm_, "[ Throw");
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +00001268 VisitForStackValue(expr->exception());
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001269 __ CallRuntime(Runtime::kThrow, 1);
1270 // Never returns here.
1271}
1272
1273
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00001274FullCodeGenerator::NestedStatement* FullCodeGenerator::TryCatch::Exit(
1275 int* stack_depth,
1276 int* context_length) {
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001277 // The macros used here must preserve the result register.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00001278 __ Drop(*stack_depth);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001279 __ PopTryHandler();
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +00001280 *stack_depth = 0;
1281 return previous_;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001282}
1283
ricow@chromium.org65fae842010-08-25 15:26:24 +00001284
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001285bool FullCodeGenerator::TryLiteralCompare(CompareOperation* expr) {
1286 Expression *sub_expr;
ager@chromium.org04921a82011-06-27 13:21:41 +00001287 Handle<String> check;
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001288 if (expr->IsLiteralCompareTypeof(&sub_expr, &check)) {
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +00001289 EmitLiteralCompareTypeof(expr, sub_expr, check);
ager@chromium.org04921a82011-06-27 13:21:41 +00001290 return true;
1291 }
1292
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +00001293 if (expr->IsLiteralCompareUndefined(&sub_expr)) {
1294 EmitLiteralCompareNil(expr, sub_expr, kUndefinedValue);
1295 return true;
1296 }
1297
1298 if (expr->IsLiteralCompareNull(&sub_expr)) {
1299 EmitLiteralCompareNil(expr, sub_expr, kNullValue);
ager@chromium.org04921a82011-06-27 13:21:41 +00001300 return true;
1301 }
1302
1303 return false;
1304}
1305
1306
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001307#undef __
1308
1309
1310} } // namespace v8::internal