blob: c770e189b357112d8a87395bc36e7f2c781dfc86 [file] [log] [blame]
Leon Clarked91b9f72010-01-27 17:25:45 +00001// Copyright 2009 the V8 project authors. All rights reserved.
2// 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
30#include "codegen-inl.h"
31#include "compiler.h"
32#include "full-codegen.h"
Kristian Monsen80d68ea2010-09-08 11:05:35 +010033#include "macro-assembler.h"
Steve Block6ded16b2010-05-10 14:33:55 +010034#include "scopes.h"
Leon Clarked91b9f72010-01-27 17:25:45 +000035#include "stub-cache.h"
36#include "debug.h"
Andrei Popescu402d9372010-02-26 13:31:12 +000037#include "liveedit.h"
Leon Clarked91b9f72010-01-27 17:25:45 +000038
39namespace v8 {
40namespace internal {
41
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +010042void BreakableStatementChecker::Check(Statement* stmt) {
43 Visit(stmt);
44}
45
46
47void BreakableStatementChecker::Check(Expression* expr) {
48 Visit(expr);
49}
50
51
52void BreakableStatementChecker::VisitDeclaration(Declaration* decl) {
53}
54
55
56void BreakableStatementChecker::VisitBlock(Block* stmt) {
57}
58
59
60void BreakableStatementChecker::VisitExpressionStatement(
61 ExpressionStatement* stmt) {
62 // Check if expression is breakable.
63 Visit(stmt->expression());
64}
65
66
67void BreakableStatementChecker::VisitEmptyStatement(EmptyStatement* stmt) {
68}
69
70
71void BreakableStatementChecker::VisitIfStatement(IfStatement* stmt) {
72 // If the condition is breakable the if statement is breakable.
73 Visit(stmt->condition());
74}
75
76
77void BreakableStatementChecker::VisitContinueStatement(
78 ContinueStatement* stmt) {
79}
80
81
82void BreakableStatementChecker::VisitBreakStatement(BreakStatement* stmt) {
83}
84
85
86void BreakableStatementChecker::VisitReturnStatement(ReturnStatement* stmt) {
87 // Return is breakable if the expression is.
88 Visit(stmt->expression());
89}
90
91
92void BreakableStatementChecker::VisitWithEnterStatement(
93 WithEnterStatement* stmt) {
94 Visit(stmt->expression());
95}
96
97
98void BreakableStatementChecker::VisitWithExitStatement(
99 WithExitStatement* stmt) {
100}
101
102
103void BreakableStatementChecker::VisitSwitchStatement(SwitchStatement* stmt) {
104 // Switch statements breakable if the tag expression is.
105 Visit(stmt->tag());
106}
107
108
109void BreakableStatementChecker::VisitDoWhileStatement(DoWhileStatement* stmt) {
110 // Mark do while as breakable to avoid adding a break slot in front of it.
111 is_breakable_ = true;
112}
113
114
115void BreakableStatementChecker::VisitWhileStatement(WhileStatement* stmt) {
116 // Mark while statements breakable if the condition expression is.
117 Visit(stmt->cond());
118}
119
120
121void BreakableStatementChecker::VisitForStatement(ForStatement* stmt) {
122 // Mark for statements breakable if the condition expression is.
123 if (stmt->cond() != NULL) {
124 Visit(stmt->cond());
125 }
126}
127
128
129void BreakableStatementChecker::VisitForInStatement(ForInStatement* stmt) {
130 // Mark for in statements breakable if the enumerable expression is.
131 Visit(stmt->enumerable());
132}
133
134
135void BreakableStatementChecker::VisitTryCatchStatement(
136 TryCatchStatement* stmt) {
137 // Mark try catch as breakable to avoid adding a break slot in front of it.
138 is_breakable_ = true;
139}
140
141
142void BreakableStatementChecker::VisitTryFinallyStatement(
143 TryFinallyStatement* stmt) {
144 // Mark try finally as breakable to avoid adding a break slot in front of it.
145 is_breakable_ = true;
146}
147
148
149void BreakableStatementChecker::VisitDebuggerStatement(
150 DebuggerStatement* stmt) {
151 // The debugger statement is breakable.
152 is_breakable_ = true;
153}
154
155
156void BreakableStatementChecker::VisitFunctionLiteral(FunctionLiteral* expr) {
157}
158
159
160void BreakableStatementChecker::VisitSharedFunctionInfoLiteral(
161 SharedFunctionInfoLiteral* expr) {
162}
163
164
165void BreakableStatementChecker::VisitConditional(Conditional* expr) {
166}
167
168
169void BreakableStatementChecker::VisitSlot(Slot* expr) {
170}
171
172
173void BreakableStatementChecker::VisitVariableProxy(VariableProxy* expr) {
174}
175
176
177void BreakableStatementChecker::VisitLiteral(Literal* expr) {
178}
179
180
181void BreakableStatementChecker::VisitRegExpLiteral(RegExpLiteral* expr) {
182}
183
184
185void BreakableStatementChecker::VisitObjectLiteral(ObjectLiteral* expr) {
186}
187
188
189void BreakableStatementChecker::VisitArrayLiteral(ArrayLiteral* expr) {
190}
191
192
193void BreakableStatementChecker::VisitCatchExtensionObject(
194 CatchExtensionObject* expr) {
195}
196
197
198void BreakableStatementChecker::VisitAssignment(Assignment* expr) {
199 // If assigning to a property (including a global property) the assignment is
200 // breakable.
201 Variable* var = expr->target()->AsVariableProxy()->AsVariable();
202 Property* prop = expr->target()->AsProperty();
203 if (prop != NULL || (var != NULL && var->is_global())) {
204 is_breakable_ = true;
205 return;
206 }
207
208 // Otherwise the assignment is breakable if the assigned value is.
209 Visit(expr->value());
210}
211
212
213void BreakableStatementChecker::VisitThrow(Throw* expr) {
214 // Throw is breakable if the expression is.
215 Visit(expr->exception());
216}
217
218
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100219void BreakableStatementChecker::VisitIncrementOperation(
220 IncrementOperation* expr) {
221 UNREACHABLE();
222}
223
224
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100225void BreakableStatementChecker::VisitProperty(Property* expr) {
226 // Property load is breakable.
227 is_breakable_ = true;
228}
229
230
231void BreakableStatementChecker::VisitCall(Call* expr) {
232 // Function calls both through IC and call stub are breakable.
233 is_breakable_ = true;
234}
235
236
237void BreakableStatementChecker::VisitCallNew(CallNew* expr) {
238 // Function calls through new are breakable.
239 is_breakable_ = true;
240}
241
242
243void BreakableStatementChecker::VisitCallRuntime(CallRuntime* expr) {
244}
245
246
247void BreakableStatementChecker::VisitUnaryOperation(UnaryOperation* expr) {
248 Visit(expr->expression());
249}
250
251
252void BreakableStatementChecker::VisitCountOperation(CountOperation* expr) {
253 Visit(expr->expression());
254}
255
256
257void BreakableStatementChecker::VisitBinaryOperation(BinaryOperation* expr) {
258 Visit(expr->left());
259 Visit(expr->right());
260}
261
262
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100263void BreakableStatementChecker::VisitCompareToNull(CompareToNull* expr) {
264 Visit(expr->expression());
265}
266
267
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100268void BreakableStatementChecker::VisitCompareOperation(CompareOperation* expr) {
269 Visit(expr->left());
270 Visit(expr->right());
271}
272
273
274void BreakableStatementChecker::VisitThisFunction(ThisFunction* expr) {
275}
276
277
Leon Clarked91b9f72010-01-27 17:25:45 +0000278#define __ ACCESS_MASM(masm())
279
Ben Murdochf87a2032010-10-22 12:50:53 +0100280bool FullCodeGenerator::MakeCode(CompilationInfo* info) {
Andrei Popescu31002712010-02-23 13:46:05 +0000281 Handle<Script> script = info->script();
Leon Clarked91b9f72010-01-27 17:25:45 +0000282 if (!script->IsUndefined() && !script->source()->IsUndefined()) {
283 int len = String::cast(script->source())->length();
284 Counters::total_full_codegen_source_size.Increment(len);
285 }
Andrei Popescu31002712010-02-23 13:46:05 +0000286 CodeGenerator::MakeCodePrologue(info);
Leon Clarked91b9f72010-01-27 17:25:45 +0000287 const int kInitialBufferSize = 4 * KB;
288 MacroAssembler masm(NULL, kInitialBufferSize);
Andrei Popescu402d9372010-02-26 13:31:12 +0000289
Andrei Popescu31002712010-02-23 13:46:05 +0000290 FullCodeGenerator cgen(&masm);
Iain Merrick75681382010-08-19 15:07:18 +0100291 cgen.Generate(info);
Leon Clarked91b9f72010-01-27 17:25:45 +0000292 if (cgen.HasStackOverflow()) {
293 ASSERT(!Top::has_pending_exception());
Ben Murdochf87a2032010-10-22 12:50:53 +0100294 return false;
Leon Clarked91b9f72010-01-27 17:25:45 +0000295 }
Ben Murdochf87a2032010-10-22 12:50:53 +0100296
Leon Clarked91b9f72010-01-27 17:25:45 +0000297 Code::Flags flags = Code::ComputeFlags(Code::FUNCTION, NOT_IN_LOOP);
Ben Murdochf87a2032010-10-22 12:50:53 +0100298 Handle<Code> code = CodeGenerator::MakeCodeEpilogue(&masm, flags, info);
299 info->SetCode(code); // may be an empty handle.
300 return !code.is_null();
Leon Clarked91b9f72010-01-27 17:25:45 +0000301}
302
303
Steve Block59151502010-09-22 15:07:15 +0100304MemOperand FullCodeGenerator::ContextOperand(Register context, int index) {
305 return CodeGenerator::ContextOperand(context, index);
306}
307
308
Leon Clarked91b9f72010-01-27 17:25:45 +0000309int FullCodeGenerator::SlotOffset(Slot* slot) {
310 ASSERT(slot != NULL);
311 // Offset is negative because higher indexes are at lower addresses.
312 int offset = -slot->index() * kPointerSize;
313 // Adjust by a (parameter or local) base offset.
314 switch (slot->type()) {
315 case Slot::PARAMETER:
Andrei Popescu31002712010-02-23 13:46:05 +0000316 offset += (scope()->num_parameters() + 1) * kPointerSize;
Leon Clarked91b9f72010-01-27 17:25:45 +0000317 break;
318 case Slot::LOCAL:
319 offset += JavaScriptFrameConstants::kLocal0Offset;
320 break;
321 case Slot::CONTEXT:
322 case Slot::LOOKUP:
323 UNREACHABLE();
324 }
325 return offset;
326}
327
328
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100329bool FullCodeGenerator::ShouldInlineSmiCase(Token::Value op) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100330 // Inline smi case inside loops, but not division and modulo which
331 // are too complicated and take up too much space.
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100332 if (op == Token::DIV ||op == Token::MOD) return false;
333 if (FLAG_always_inline_smi_code) return true;
334 return loop_depth_ > 0;
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100335}
336
337
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100338void FullCodeGenerator::EffectContext::Plug(Register reg) const {
339}
340
341
342void FullCodeGenerator::AccumulatorValueContext::Plug(Register reg) const {
343 // Move value into place.
344 __ Move(result_register(), reg);
345}
346
347
348void FullCodeGenerator::StackValueContext::Plug(Register reg) const {
349 // Move value into place.
350 __ push(reg);
351}
352
353
354void FullCodeGenerator::TestContext::Plug(Register reg) const {
355 // For simplicity we always test the accumulator register.
356 __ Move(result_register(), reg);
357 codegen()->DoTest(true_label_, false_label_, fall_through_);
358}
359
360
361void FullCodeGenerator::EffectContext::PlugTOS() const {
362 __ Drop(1);
363}
364
365
366void FullCodeGenerator::AccumulatorValueContext::PlugTOS() const {
367 __ pop(result_register());
368}
369
370
371void FullCodeGenerator::StackValueContext::PlugTOS() const {
372}
373
374
375void FullCodeGenerator::TestContext::PlugTOS() const {
376 // For simplicity we always test the accumulator register.
377 __ pop(result_register());
378 codegen()->DoTest(true_label_, false_label_, fall_through_);
379}
380
381
382void FullCodeGenerator::EffectContext::PrepareTest(
383 Label* materialize_true,
384 Label* materialize_false,
385 Label** if_true,
386 Label** if_false,
387 Label** fall_through) const {
388 // In an effect context, the true and the false case branch to the
389 // same label.
390 *if_true = *if_false = *fall_through = materialize_true;
391}
392
393
394void FullCodeGenerator::AccumulatorValueContext::PrepareTest(
395 Label* materialize_true,
396 Label* materialize_false,
397 Label** if_true,
398 Label** if_false,
399 Label** fall_through) const {
400 *if_true = *fall_through = materialize_true;
401 *if_false = materialize_false;
402}
403
404
405void FullCodeGenerator::StackValueContext::PrepareTest(
406 Label* materialize_true,
407 Label* materialize_false,
408 Label** if_true,
409 Label** if_false,
410 Label** fall_through) const {
411 *if_true = *fall_through = materialize_true;
412 *if_false = materialize_false;
413}
414
415
416void FullCodeGenerator::TestContext::PrepareTest(
417 Label* materialize_true,
418 Label* materialize_false,
419 Label** if_true,
420 Label** if_false,
421 Label** fall_through) const {
422 *if_true = true_label_;
423 *if_false = false_label_;
424 *fall_through = fall_through_;
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100425}
426
427
Leon Clarked91b9f72010-01-27 17:25:45 +0000428void FullCodeGenerator::VisitDeclarations(
429 ZoneList<Declaration*>* declarations) {
430 int length = declarations->length();
431 int globals = 0;
432 for (int i = 0; i < length; i++) {
433 Declaration* decl = declarations->at(i);
434 Variable* var = decl->proxy()->var();
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100435 Slot* slot = var->AsSlot();
Leon Clarked91b9f72010-01-27 17:25:45 +0000436
437 // If it was not possible to allocate the variable at compile
438 // time, we need to "declare" it at runtime to make sure it
439 // actually exists in the local context.
440 if ((slot != NULL && slot->type() == Slot::LOOKUP) || !var->is_global()) {
441 VisitDeclaration(decl);
442 } else {
443 // Count global variables and functions for later processing
444 globals++;
445 }
446 }
447
448 // Compute array of global variable and function declarations.
449 // Do nothing in case of no declared global functions or variables.
450 if (globals > 0) {
451 Handle<FixedArray> array = Factory::NewFixedArray(2 * globals, TENURED);
452 for (int j = 0, i = 0; i < length; i++) {
453 Declaration* decl = declarations->at(i);
454 Variable* var = decl->proxy()->var();
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100455 Slot* slot = var->AsSlot();
Leon Clarked91b9f72010-01-27 17:25:45 +0000456
457 if ((slot == NULL || slot->type() != Slot::LOOKUP) && var->is_global()) {
458 array->set(j++, *(var->name()));
459 if (decl->fun() == NULL) {
460 if (var->mode() == Variable::CONST) {
461 // In case this is const property use the hole.
462 array->set_the_hole(j++);
463 } else {
464 array->set_undefined(j++);
465 }
466 } else {
Steve Block6ded16b2010-05-10 14:33:55 +0100467 Handle<SharedFunctionInfo> function =
Ben Murdochf87a2032010-10-22 12:50:53 +0100468 Compiler::BuildFunctionInfo(decl->fun(), script());
Leon Clarked91b9f72010-01-27 17:25:45 +0000469 // Check for stack-overflow exception.
Ben Murdochf87a2032010-10-22 12:50:53 +0100470 if (function.is_null()) {
471 SetStackOverflow();
472 return;
473 }
Leon Clarked91b9f72010-01-27 17:25:45 +0000474 array->set(j++, *function);
475 }
476 }
477 }
478 // Invoke the platform-dependent code generator to do the actual
479 // declaration the global variables and functions.
480 DeclareGlobals(array);
481 }
482}
483
484
485void FullCodeGenerator::SetFunctionPosition(FunctionLiteral* fun) {
486 if (FLAG_debug_info) {
487 CodeGenerator::RecordPositions(masm_, fun->start_position());
488 }
489}
490
491
492void FullCodeGenerator::SetReturnPosition(FunctionLiteral* fun) {
493 if (FLAG_debug_info) {
Ben Murdochbb769b22010-08-11 14:56:33 +0100494 CodeGenerator::RecordPositions(masm_, fun->end_position() - 1);
Leon Clarked91b9f72010-01-27 17:25:45 +0000495 }
496}
497
498
499void FullCodeGenerator::SetStatementPosition(Statement* stmt) {
500 if (FLAG_debug_info) {
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100501#ifdef ENABLE_DEBUGGER_SUPPORT
502 if (!Debugger::IsDebuggerActive()) {
503 CodeGenerator::RecordPositions(masm_, stmt->statement_pos());
504 } else {
505 // Check if the statement will be breakable without adding a debug break
506 // slot.
507 BreakableStatementChecker checker;
508 checker.Check(stmt);
509 // Record the statement position right here if the statement is not
510 // breakable. For breakable statements the actual recording of the
511 // position will be postponed to the breakable code (typically an IC).
512 bool position_recorded = CodeGenerator::RecordPositions(
513 masm_, stmt->statement_pos(), !checker.is_breakable());
514 // If the position recording did record a new position generate a debug
515 // break slot to make the statement breakable.
516 if (position_recorded) {
517 Debug::GenerateSlot(masm_);
518 }
519 }
520#else
Leon Clarked91b9f72010-01-27 17:25:45 +0000521 CodeGenerator::RecordPositions(masm_, stmt->statement_pos());
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100522#endif
523 }
524}
525
526
527void FullCodeGenerator::SetExpressionPosition(Expression* expr, int pos) {
528 if (FLAG_debug_info) {
529#ifdef ENABLE_DEBUGGER_SUPPORT
530 if (!Debugger::IsDebuggerActive()) {
531 CodeGenerator::RecordPositions(masm_, pos);
532 } else {
533 // Check if the expression will be breakable without adding a debug break
534 // slot.
535 BreakableStatementChecker checker;
536 checker.Check(expr);
537 // Record a statement position right here if the expression is not
538 // breakable. For breakable expressions the actual recording of the
539 // position will be postponed to the breakable code (typically an IC).
540 // NOTE this will record a statement position for something which might
541 // not be a statement. As stepping in the debugger will only stop at
542 // statement positions this is used for e.g. the condition expression of
543 // a do while loop.
544 bool position_recorded = CodeGenerator::RecordPositions(
545 masm_, pos, !checker.is_breakable());
546 // If the position recording did record a new position generate a debug
547 // break slot to make the statement breakable.
548 if (position_recorded) {
549 Debug::GenerateSlot(masm_);
550 }
551 }
552#else
553 CodeGenerator::RecordPositions(masm_, pos);
554#endif
Leon Clarked91b9f72010-01-27 17:25:45 +0000555 }
556}
557
558
559void FullCodeGenerator::SetStatementPosition(int pos) {
560 if (FLAG_debug_info) {
561 CodeGenerator::RecordPositions(masm_, pos);
562 }
563}
564
565
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800566void FullCodeGenerator::SetSourcePosition(
567 int pos, PositionRecordingType recording_type) {
Leon Clarked91b9f72010-01-27 17:25:45 +0000568 if (FLAG_debug_info && pos != RelocInfo::kNoPosition) {
Teng-Hui Zhu3e5fa292010-11-09 16:16:48 -0800569 masm_->positions_recorder()->RecordPosition(pos, recording_type);
Leon Clarked91b9f72010-01-27 17:25:45 +0000570 }
571}
572
573
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100574// Lookup table for code generators for special runtime calls which are
575// generated inline.
576#define INLINE_FUNCTION_GENERATOR_ADDRESS(Name, argc, ressize) \
577 &FullCodeGenerator::Emit##Name,
Steve Block791712a2010-08-27 10:21:07 +0100578
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100579const FullCodeGenerator::InlineFunctionGenerator
580 FullCodeGenerator::kInlineFunctionGenerators[] = {
581 INLINE_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS)
582 INLINE_RUNTIME_FUNCTION_LIST(INLINE_FUNCTION_GENERATOR_ADDRESS)
583 };
584#undef INLINE_FUNCTION_GENERATOR_ADDRESS
585
586
587FullCodeGenerator::InlineFunctionGenerator
588 FullCodeGenerator::FindInlineFunctionGenerator(Runtime::FunctionId id) {
589 return kInlineFunctionGenerators[
590 static_cast<int>(id) - static_cast<int>(Runtime::kFirstInlineFunction)];
591}
592
593
594void FullCodeGenerator::EmitInlineRuntimeCall(CallRuntime* node) {
595 ZoneList<Expression*>* args = node->arguments();
596 Handle<String> name = node->name();
597 Runtime::Function* function = node->function();
598 ASSERT(function != NULL);
599 ASSERT(function->intrinsic_type == Runtime::INLINE);
600 InlineFunctionGenerator generator =
601 FindInlineFunctionGenerator(function->function_id);
602 ASSERT(generator != NULL);
603 ((*this).*(generator))(args);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100604}
605
606
607void FullCodeGenerator::VisitBinaryOperation(BinaryOperation* expr) {
608 Comment cmnt(masm_, "[ BinaryOperation");
609 Token::Value op = expr->op();
610 Expression* left = expr->left();
611 Expression* right = expr->right();
612
613 OverwriteMode mode = NO_OVERWRITE;
614 if (left->ResultOverwriteAllowed()) {
615 mode = OVERWRITE_LEFT;
616 } else if (right->ResultOverwriteAllowed()) {
617 mode = OVERWRITE_RIGHT;
618 }
619
620 switch (op) {
621 case Token::COMMA:
622 VisitForEffect(left);
623 Visit(right);
624 break;
625
626 case Token::OR:
627 case Token::AND:
628 EmitLogicalOperation(expr);
629 break;
630
631 case Token::ADD:
632 case Token::SUB:
633 case Token::DIV:
634 case Token::MOD:
635 case Token::MUL:
636 case Token::BIT_OR:
637 case Token::BIT_AND:
638 case Token::BIT_XOR:
639 case Token::SHL:
640 case Token::SHR:
641 case Token::SAR: {
642 // Figure out if either of the operands is a constant.
643 ConstantOperand constant = ShouldInlineSmiCase(op)
644 ? GetConstantOperand(op, left, right)
645 : kNoConstants;
646
647 // Load only the operands that we need to materialize.
648 if (constant == kNoConstants) {
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100649 VisitForStackValue(left);
650 VisitForAccumulatorValue(right);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100651 } else if (constant == kRightConstant) {
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100652 VisitForAccumulatorValue(left);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100653 } else {
654 ASSERT(constant == kLeftConstant);
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100655 VisitForAccumulatorValue(right);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100656 }
657
658 SetSourcePosition(expr->position());
659 if (ShouldInlineSmiCase(op)) {
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100660 EmitInlineSmiBinaryOp(expr, op, mode, left, right, constant);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100661 } else {
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100662 EmitBinaryOp(op, mode);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100663 }
664 break;
665 }
666
667 default:
668 UNREACHABLE();
669 }
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100670}
671
672
Leon Clarked91b9f72010-01-27 17:25:45 +0000673void FullCodeGenerator::EmitLogicalOperation(BinaryOperation* expr) {
674 Label eval_right, done;
675
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100676 context()->EmitLogicalLeft(expr, &eval_right, &done);
Leon Clarked91b9f72010-01-27 17:25:45 +0000677
678 __ bind(&eval_right);
679 Visit(expr->right());
680
681 __ bind(&done);
682}
683
684
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100685void FullCodeGenerator::EffectContext::EmitLogicalLeft(BinaryOperation* expr,
686 Label* eval_right,
687 Label* done) const {
688 if (expr->op() == Token::OR) {
689 codegen()->VisitForControl(expr->left(), done, eval_right, eval_right);
690 } else {
691 ASSERT(expr->op() == Token::AND);
692 codegen()->VisitForControl(expr->left(), eval_right, done, eval_right);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100693 }
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100694}
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100695
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100696
697void FullCodeGenerator::AccumulatorValueContext::EmitLogicalLeft(
698 BinaryOperation* expr,
699 Label* eval_right,
700 Label* done) const {
701 codegen()->Visit(expr->left());
702 // We want the value in the accumulator for the test, and on the stack in case
703 // we need it.
704 __ push(result_register());
705 Label discard, restore;
706 if (expr->op() == Token::OR) {
707 codegen()->DoTest(&restore, &discard, &restore);
708 } else {
709 ASSERT(expr->op() == Token::AND);
710 codegen()->DoTest(&discard, &restore, &restore);
711 }
712 __ bind(&restore);
713 __ pop(result_register());
714 __ jmp(done);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100715 __ bind(&discard);
716 __ Drop(1);
717}
718
719
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100720void FullCodeGenerator::StackValueContext::EmitLogicalLeft(
721 BinaryOperation* expr,
722 Label* eval_right,
723 Label* done) const {
724 codegen()->VisitForAccumulatorValue(expr->left());
725 // We want the value in the accumulator for the test, and on the stack in case
726 // we need it.
727 __ push(result_register());
728 Label discard;
729 if (expr->op() == Token::OR) {
730 codegen()->DoTest(done, &discard, &discard);
731 } else {
732 ASSERT(expr->op() == Token::AND);
733 codegen()->DoTest(&discard, done, &discard);
734 }
735 __ bind(&discard);
736 __ Drop(1);
737}
738
739
740void FullCodeGenerator::TestContext::EmitLogicalLeft(BinaryOperation* expr,
741 Label* eval_right,
742 Label* done) const {
743 if (expr->op() == Token::OR) {
744 codegen()->VisitForControl(expr->left(),
745 true_label_, eval_right, eval_right);
746 } else {
747 ASSERT(expr->op() == Token::AND);
748 codegen()->VisitForControl(expr->left(),
749 eval_right, false_label_, eval_right);
750 }
751}
752
753
Leon Clarked91b9f72010-01-27 17:25:45 +0000754void FullCodeGenerator::VisitBlock(Block* stmt) {
755 Comment cmnt(masm_, "[ Block");
756 Breakable nested_statement(this, stmt);
757 SetStatementPosition(stmt);
758 VisitStatements(stmt->statements());
759 __ bind(nested_statement.break_target());
760}
761
762
763void FullCodeGenerator::VisitExpressionStatement(ExpressionStatement* stmt) {
764 Comment cmnt(masm_, "[ ExpressionStatement");
765 SetStatementPosition(stmt);
766 VisitForEffect(stmt->expression());
767}
768
769
770void FullCodeGenerator::VisitEmptyStatement(EmptyStatement* stmt) {
771 Comment cmnt(masm_, "[ EmptyStatement");
772 SetStatementPosition(stmt);
773}
774
775
776void FullCodeGenerator::VisitIfStatement(IfStatement* stmt) {
777 Comment cmnt(masm_, "[ IfStatement");
778 SetStatementPosition(stmt);
779 Label then_part, else_part, done;
780
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100781 if (stmt->HasElseStatement()) {
782 VisitForControl(stmt->condition(), &then_part, &else_part, &then_part);
783 __ bind(&then_part);
784 Visit(stmt->then_statement());
785 __ jmp(&done);
Leon Clarked91b9f72010-01-27 17:25:45 +0000786
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100787 __ bind(&else_part);
788 Visit(stmt->else_statement());
789 } else {
790 VisitForControl(stmt->condition(), &then_part, &done, &then_part);
791 __ bind(&then_part);
792 Visit(stmt->then_statement());
793 }
Leon Clarked91b9f72010-01-27 17:25:45 +0000794 __ bind(&done);
795}
796
797
798void FullCodeGenerator::VisitContinueStatement(ContinueStatement* stmt) {
799 Comment cmnt(masm_, "[ ContinueStatement");
800 SetStatementPosition(stmt);
801 NestedStatement* current = nesting_stack_;
802 int stack_depth = 0;
803 while (!current->IsContinueTarget(stmt->target())) {
804 stack_depth = current->Exit(stack_depth);
805 current = current->outer();
806 }
807 __ Drop(stack_depth);
808
809 Iteration* loop = current->AsIteration();
810 __ jmp(loop->continue_target());
811}
812
813
814void FullCodeGenerator::VisitBreakStatement(BreakStatement* stmt) {
815 Comment cmnt(masm_, "[ BreakStatement");
816 SetStatementPosition(stmt);
817 NestedStatement* current = nesting_stack_;
818 int stack_depth = 0;
819 while (!current->IsBreakTarget(stmt->target())) {
820 stack_depth = current->Exit(stack_depth);
821 current = current->outer();
822 }
823 __ Drop(stack_depth);
824
825 Breakable* target = current->AsBreakable();
826 __ jmp(target->break_target());
827}
828
829
830void FullCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) {
831 Comment cmnt(masm_, "[ ReturnStatement");
832 SetStatementPosition(stmt);
833 Expression* expr = stmt->expression();
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100834 VisitForAccumulatorValue(expr);
Leon Clarked91b9f72010-01-27 17:25:45 +0000835
836 // Exit all nested statements.
837 NestedStatement* current = nesting_stack_;
838 int stack_depth = 0;
839 while (current != NULL) {
840 stack_depth = current->Exit(stack_depth);
841 current = current->outer();
842 }
843 __ Drop(stack_depth);
844
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100845 EmitReturnSequence();
Leon Clarked91b9f72010-01-27 17:25:45 +0000846}
847
848
849void FullCodeGenerator::VisitWithEnterStatement(WithEnterStatement* stmt) {
850 Comment cmnt(masm_, "[ WithEnterStatement");
851 SetStatementPosition(stmt);
852
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100853 VisitForStackValue(stmt->expression());
Leon Clarked91b9f72010-01-27 17:25:45 +0000854 if (stmt->is_catch_block()) {
855 __ CallRuntime(Runtime::kPushCatchContext, 1);
856 } else {
857 __ CallRuntime(Runtime::kPushContext, 1);
858 }
859 // Both runtime calls return the new context in both the context and the
860 // result registers.
861
862 // Update local stack frame context field.
863 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register());
864}
865
866
867void FullCodeGenerator::VisitWithExitStatement(WithExitStatement* stmt) {
868 Comment cmnt(masm_, "[ WithExitStatement");
869 SetStatementPosition(stmt);
870
871 // Pop context.
872 LoadContextField(context_register(), Context::PREVIOUS_INDEX);
873 // Update local stack frame context field.
874 StoreToFrameField(StandardFrameConstants::kContextOffset, context_register());
875}
876
877
Leon Clarked91b9f72010-01-27 17:25:45 +0000878void FullCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) {
879 Comment cmnt(masm_, "[ DoWhileStatement");
880 SetStatementPosition(stmt);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100881 Label body, stack_limit_hit, stack_check_success, done;
Leon Clarked91b9f72010-01-27 17:25:45 +0000882
883 Iteration loop_statement(this, stmt);
884 increment_loop_depth();
885
886 __ bind(&body);
887 Visit(stmt->body());
888
889 // Check stack before looping.
890 __ StackLimitCheck(&stack_limit_hit);
891 __ bind(&stack_check_success);
892
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100893 // Record the position of the do while condition and make sure it is
894 // possible to break on the condition.
Leon Clarked91b9f72010-01-27 17:25:45 +0000895 __ bind(loop_statement.continue_target());
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100896 SetExpressionPosition(stmt->cond(), stmt->condition_position());
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100897 VisitForControl(stmt->cond(),
898 &body,
899 loop_statement.break_target(),
900 loop_statement.break_target());
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100901
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100902 __ bind(loop_statement.break_target());
903 __ jmp(&done);
Leon Clarked91b9f72010-01-27 17:25:45 +0000904
905 __ bind(&stack_limit_hit);
906 StackCheckStub stack_stub;
907 __ CallStub(&stack_stub);
908 __ jmp(&stack_check_success);
909
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100910 __ bind(&done);
Leon Clarked91b9f72010-01-27 17:25:45 +0000911 decrement_loop_depth();
912}
913
914
915void FullCodeGenerator::VisitWhileStatement(WhileStatement* stmt) {
916 Comment cmnt(masm_, "[ WhileStatement");
Iain Merrick9ac36c92010-09-13 15:29:50 +0100917 Label body, stack_limit_hit, stack_check_success, done;
Leon Clarked91b9f72010-01-27 17:25:45 +0000918
919 Iteration loop_statement(this, stmt);
920 increment_loop_depth();
921
922 // Emit the test at the bottom of the loop.
923 __ jmp(loop_statement.continue_target());
924
925 __ bind(&body);
926 Visit(stmt->body());
Leon Clarked91b9f72010-01-27 17:25:45 +0000927 __ bind(loop_statement.continue_target());
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100928
929 // Emit the statement position here as this is where the while
930 // statement code starts.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100931 SetStatementPosition(stmt);
Leon Clarkef7060e22010-06-03 12:02:55 +0100932
Leon Clarked91b9f72010-01-27 17:25:45 +0000933 // Check stack before looping.
934 __ StackLimitCheck(&stack_limit_hit);
935 __ bind(&stack_check_success);
936
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100937 VisitForControl(stmt->cond(),
938 &body,
939 loop_statement.break_target(),
940 loop_statement.break_target());
Leon Clarked91b9f72010-01-27 17:25:45 +0000941
942 __ bind(loop_statement.break_target());
Iain Merrick9ac36c92010-09-13 15:29:50 +0100943 __ jmp(&done);
944
945 __ bind(&stack_limit_hit);
946 StackCheckStub stack_stub;
947 __ CallStub(&stack_stub);
948 __ jmp(&stack_check_success);
949
950 __ bind(&done);
Leon Clarked91b9f72010-01-27 17:25:45 +0000951 decrement_loop_depth();
952}
953
954
955void FullCodeGenerator::VisitForStatement(ForStatement* stmt) {
956 Comment cmnt(masm_, "[ ForStatement");
Leon Clarked91b9f72010-01-27 17:25:45 +0000957 Label test, body, stack_limit_hit, stack_check_success;
958
959 Iteration loop_statement(this, stmt);
960 if (stmt->init() != NULL) {
961 Visit(stmt->init());
962 }
963
964 increment_loop_depth();
965 // Emit the test at the bottom of the loop (even if empty).
966 __ jmp(&test);
967
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100968 __ bind(&stack_limit_hit);
969 StackCheckStub stack_stub;
970 __ CallStub(&stack_stub);
971 __ jmp(&stack_check_success);
972
Leon Clarked91b9f72010-01-27 17:25:45 +0000973 __ bind(&body);
974 Visit(stmt->body());
975
976 __ bind(loop_statement.continue_target());
977
978 SetStatementPosition(stmt);
979 if (stmt->next() != NULL) {
980 Visit(stmt->next());
981 }
982
983 __ bind(&test);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100984 // Emit the statement position here as this is where the for
985 // statement code starts.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100986 SetStatementPosition(stmt);
Leon Clarked91b9f72010-01-27 17:25:45 +0000987
988 // Check stack before looping.
989 __ StackLimitCheck(&stack_limit_hit);
990 __ bind(&stack_check_success);
991
992 if (stmt->cond() != NULL) {
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100993 VisitForControl(stmt->cond(),
994 &body,
995 loop_statement.break_target(),
996 loop_statement.break_target());
Leon Clarked91b9f72010-01-27 17:25:45 +0000997 } else {
998 __ jmp(&body);
999 }
1000
Leon Clarked91b9f72010-01-27 17:25:45 +00001001 __ bind(loop_statement.break_target());
1002 decrement_loop_depth();
1003}
1004
1005
Leon Clarked91b9f72010-01-27 17:25:45 +00001006void FullCodeGenerator::VisitTryCatchStatement(TryCatchStatement* stmt) {
1007 Comment cmnt(masm_, "[ TryCatchStatement");
1008 SetStatementPosition(stmt);
1009 // The try block adds a handler to the exception handler chain
1010 // before entering, and removes it again when exiting normally.
1011 // If an exception is thrown during execution of the try block,
1012 // control is passed to the handler, which also consumes the handler.
1013 // At this point, the exception is in a register, and store it in
1014 // the temporary local variable (prints as ".catch-var") before
1015 // executing the catch block. The catch block has been rewritten
1016 // to introduce a new scope to bind the catch variable and to remove
1017 // that scope again afterwards.
1018
1019 Label try_handler_setup, catch_entry, done;
1020 __ Call(&try_handler_setup);
1021 // Try handler code, exception in result register.
1022
1023 // Store exception in local .catch variable before executing catch block.
1024 {
1025 // The catch variable is *always* a variable proxy for a local variable.
1026 Variable* catch_var = stmt->catch_var()->AsVariableProxy()->AsVariable();
1027 ASSERT_NOT_NULL(catch_var);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001028 Slot* variable_slot = catch_var->AsSlot();
Leon Clarked91b9f72010-01-27 17:25:45 +00001029 ASSERT_NOT_NULL(variable_slot);
1030 ASSERT_EQ(Slot::LOCAL, variable_slot->type());
1031 StoreToFrameField(SlotOffset(variable_slot), result_register());
1032 }
1033
1034 Visit(stmt->catch_block());
1035 __ jmp(&done);
1036
1037 // Try block code. Sets up the exception handler chain.
1038 __ bind(&try_handler_setup);
1039 {
1040 TryCatch try_block(this, &catch_entry);
1041 __ PushTryHandler(IN_JAVASCRIPT, TRY_CATCH_HANDLER);
1042 Visit(stmt->try_block());
1043 __ PopTryHandler();
1044 }
1045 __ bind(&done);
1046}
1047
1048
1049void FullCodeGenerator::VisitTryFinallyStatement(TryFinallyStatement* stmt) {
1050 Comment cmnt(masm_, "[ TryFinallyStatement");
1051 SetStatementPosition(stmt);
1052 // Try finally is compiled by setting up a try-handler on the stack while
1053 // executing the try body, and removing it again afterwards.
1054 //
1055 // The try-finally construct can enter the finally block in three ways:
1056 // 1. By exiting the try-block normally. This removes the try-handler and
1057 // calls the finally block code before continuing.
1058 // 2. By exiting the try-block with a function-local control flow transfer
1059 // (break/continue/return). The site of the, e.g., break removes the
1060 // try handler and calls the finally block code before continuing
1061 // its outward control transfer.
1062 // 3. by exiting the try-block with a thrown exception.
1063 // This can happen in nested function calls. It traverses the try-handler
1064 // chain and consumes the try-handler entry before jumping to the
1065 // handler code. The handler code then calls the finally-block before
1066 // rethrowing the exception.
1067 //
1068 // The finally block must assume a return address on top of the stack
1069 // (or in the link register on ARM chips) and a value (return value or
1070 // exception) in the result register (rax/eax/r0), both of which must
1071 // be preserved. The return address isn't GC-safe, so it should be
1072 // cooked before GC.
1073 Label finally_entry;
1074 Label try_handler_setup;
1075
1076 // Setup the try-handler chain. Use a call to
1077 // Jump to try-handler setup and try-block code. Use call to put try-handler
1078 // address on stack.
1079 __ Call(&try_handler_setup);
1080 // Try handler code. Return address of call is pushed on handler stack.
1081 {
1082 // This code is only executed during stack-handler traversal when an
1083 // exception is thrown. The execption is in the result register, which
1084 // is retained by the finally block.
1085 // Call the finally block and then rethrow the exception.
1086 __ Call(&finally_entry);
1087 __ push(result_register());
1088 __ CallRuntime(Runtime::kReThrow, 1);
1089 }
1090
1091 __ bind(&finally_entry);
1092 {
1093 // Finally block implementation.
1094 Finally finally_block(this);
1095 EnterFinallyBlock();
1096 Visit(stmt->finally_block());
1097 ExitFinallyBlock(); // Return to the calling code.
1098 }
1099
1100 __ bind(&try_handler_setup);
1101 {
1102 // Setup try handler (stack pointer registers).
1103 TryFinally try_block(this, &finally_entry);
1104 __ PushTryHandler(IN_JAVASCRIPT, TRY_FINALLY_HANDLER);
1105 Visit(stmt->try_block());
1106 __ PopTryHandler();
1107 }
1108 // Execute the finally block on the way out.
1109 __ Call(&finally_entry);
1110}
1111
1112
1113void FullCodeGenerator::VisitDebuggerStatement(DebuggerStatement* stmt) {
1114#ifdef ENABLE_DEBUGGER_SUPPORT
1115 Comment cmnt(masm_, "[ DebuggerStatement");
1116 SetStatementPosition(stmt);
Leon Clarke4515c472010-02-03 11:58:03 +00001117
Andrei Popescu402d9372010-02-26 13:31:12 +00001118 __ DebugBreak();
Leon Clarked91b9f72010-01-27 17:25:45 +00001119 // Ignore the return value.
1120#endif
1121}
1122
1123
Leon Clarked91b9f72010-01-27 17:25:45 +00001124void FullCodeGenerator::VisitConditional(Conditional* expr) {
1125 Comment cmnt(masm_, "[ Conditional");
1126 Label true_case, false_case, done;
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001127 VisitForControl(expr->condition(), &true_case, &false_case, &true_case);
Leon Clarked91b9f72010-01-27 17:25:45 +00001128
1129 __ bind(&true_case);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001130 SetExpressionPosition(expr->then_expression(),
1131 expr->then_expression_position());
Ben Murdochf87a2032010-10-22 12:50:53 +01001132 if (context()->IsTest()) {
1133 const TestContext* for_test = TestContext::cast(context());
1134 VisitForControl(expr->then_expression(),
1135 for_test->true_label(),
1136 for_test->false_label(),
1137 NULL);
1138 } else {
1139 Visit(expr->then_expression());
Leon Clarked91b9f72010-01-27 17:25:45 +00001140 __ jmp(&done);
1141 }
1142
1143 __ bind(&false_case);
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +01001144 SetExpressionPosition(expr->else_expression(),
1145 expr->else_expression_position());
Leon Clarked91b9f72010-01-27 17:25:45 +00001146 Visit(expr->else_expression());
1147 // If control flow falls through Visit, merge it with true case here.
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001148 if (!context()->IsTest()) {
Leon Clarked91b9f72010-01-27 17:25:45 +00001149 __ bind(&done);
1150 }
1151}
1152
1153
1154void FullCodeGenerator::VisitSlot(Slot* expr) {
1155 // Slots do not appear directly in the AST.
1156 UNREACHABLE();
1157}
1158
1159
1160void FullCodeGenerator::VisitLiteral(Literal* expr) {
1161 Comment cmnt(masm_, "[ Literal");
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001162 context()->Plug(expr->handle());
Leon Clarked91b9f72010-01-27 17:25:45 +00001163}
1164
1165
Leon Clarkef7060e22010-06-03 12:02:55 +01001166void FullCodeGenerator::VisitFunctionLiteral(FunctionLiteral* expr) {
1167 Comment cmnt(masm_, "[ FunctionLiteral");
1168
1169 // Build the function boilerplate and instantiate it.
1170 Handle<SharedFunctionInfo> function_info =
Ben Murdochf87a2032010-10-22 12:50:53 +01001171 Compiler::BuildFunctionInfo(expr, script());
1172 if (function_info.is_null()) {
1173 SetStackOverflow();
1174 return;
1175 }
Leon Clarkef7060e22010-06-03 12:02:55 +01001176 EmitNewClosure(function_info);
1177}
1178
1179
1180void FullCodeGenerator::VisitSharedFunctionInfoLiteral(
1181 SharedFunctionInfoLiteral* expr) {
1182 Comment cmnt(masm_, "[ SharedFunctionInfoLiteral");
1183 EmitNewClosure(expr->shared_function_info());
1184}
1185
1186
Leon Clarked91b9f72010-01-27 17:25:45 +00001187void FullCodeGenerator::VisitCatchExtensionObject(CatchExtensionObject* expr) {
1188 // Call runtime routine to allocate the catch extension object and
1189 // assign the exception value to the catch variable.
1190 Comment cmnt(masm_, "[ CatchExtensionObject");
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001191 VisitForStackValue(expr->key());
1192 VisitForStackValue(expr->value());
Leon Clarked91b9f72010-01-27 17:25:45 +00001193 // Create catch extension object.
1194 __ CallRuntime(Runtime::kCreateCatchExtensionObject, 2);
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001195 context()->Plug(result_register());
Leon Clarked91b9f72010-01-27 17:25:45 +00001196}
1197
1198
1199void FullCodeGenerator::VisitThrow(Throw* expr) {
1200 Comment cmnt(masm_, "[ Throw");
Kristian Monsen0d5e1162010-09-30 15:31:59 +01001201 VisitForStackValue(expr->exception());
Leon Clarked91b9f72010-01-27 17:25:45 +00001202 __ CallRuntime(Runtime::kThrow, 1);
1203 // Never returns here.
1204}
1205
1206
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001207void FullCodeGenerator::VisitIncrementOperation(IncrementOperation* expr) {
1208 UNREACHABLE();
1209}
1210
1211
Leon Clarked91b9f72010-01-27 17:25:45 +00001212int FullCodeGenerator::TryFinally::Exit(int stack_depth) {
1213 // The macros used here must preserve the result register.
1214 __ Drop(stack_depth);
1215 __ PopTryHandler();
1216 __ Call(finally_entry_);
1217 return 0;
1218}
1219
1220
1221int FullCodeGenerator::TryCatch::Exit(int stack_depth) {
1222 // The macros used here must preserve the result register.
1223 __ Drop(stack_depth);
1224 __ PopTryHandler();
1225 return 0;
1226}
1227
Kristian Monsen80d68ea2010-09-08 11:05:35 +01001228
Leon Clarked91b9f72010-01-27 17:25:45 +00001229#undef __
1230
1231
1232} } // namespace v8::internal