blob: 32242b297b430a48f904073f71edf61a5577c780 [file] [log] [blame]
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +00001// Copyright 2012 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#ifndef V8_FULL_CODEGEN_H_
29#define V8_FULL_CODEGEN_H_
30
31#include "v8.h"
32
lrn@chromium.org1c092762011-05-09 09:42:16 +000033#include "allocation.h"
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +000034#include "ast.h"
kasperl@chromium.orga5551262010-12-07 12:49:48 +000035#include "code-stubs.h"
36#include "codegen.h"
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +000037#include "compiler.h"
jkummerow@chromium.org59297c72013-01-09 16:32:23 +000038#include "data-flow.h"
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +000039
40namespace v8 {
41namespace internal {
42
ager@chromium.org5f0c45f2010-12-17 08:51:21 +000043// Forward declarations.
44class JumpPatchSite;
45
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +000046// AST node visitor which can tell whether a given statement will be breakable
47// when the code is compiled by the full compiler in the debugger. This means
48// that there will be an IC (load/store/call) in the code generated for the
49// debugger to piggybag on.
50class BreakableStatementChecker: public AstVisitor {
51 public:
yangguo@chromium.orga6bbcc82012-12-21 12:35:02 +000052 BreakableStatementChecker() : is_breakable_(false) {
53 InitializeAstVisitor();
54 }
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +000055
56 void Check(Statement* stmt);
57 void Check(Expression* stmt);
58
59 bool is_breakable() { return is_breakable_; }
60
61 private:
62 // AST node visit functions.
63#define DECLARE_VISIT(type) virtual void Visit##type(type* node);
64 AST_NODE_LIST(DECLARE_VISIT)
65#undef DECLARE_VISIT
66
67 bool is_breakable_;
68
yangguo@chromium.orga6bbcc82012-12-21 12:35:02 +000069 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +000070 DISALLOW_COPY_AND_ASSIGN(BreakableStatementChecker);
71};
72
73
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +000074// -----------------------------------------------------------------------------
75// Full code generator.
76
77class FullCodeGenerator: public AstVisitor {
78 public:
kasperl@chromium.orga5551262010-12-07 12:49:48 +000079 enum State {
80 NO_REGISTERS,
81 TOS_REG
82 };
83
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +000084 FullCodeGenerator(MacroAssembler* masm, CompilationInfo* info)
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +000085 : masm_(masm),
yangguo@chromium.org56454712012-02-16 15:33:53 +000086 info_(info),
87 scope_(info->scope()),
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +000088 nesting_stack_(NULL),
89 loop_depth_(0),
erik.corry@gmail.comed49e962012-04-17 11:57:53 +000090 globals_(NULL),
kasperl@chromium.orga5551262010-12-07 12:49:48 +000091 context_(NULL),
yangguo@chromium.org56454712012-02-16 15:33:53 +000092 bailout_entries_(info->HasDeoptimizationSupport()
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +000093 ? info->function()->ast_node_count() : 0,
94 info->zone()),
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +000095 back_edges_(2, info->zone()),
yangguo@chromium.org56454712012-02-16 15:33:53 +000096 type_feedback_cells_(info->HasDeoptimizationSupport()
yangguo@chromium.org5a11aaf2012-06-20 11:29:00 +000097 ? info->function()->ast_node_count() : 0,
98 info->zone()),
mmassi@chromium.org7028c052012-06-13 11:51:58 +000099 ic_total_count_(0),
jkummerow@chromium.org000f7fb2012-08-01 11:14:42 +0000100 zone_(info->zone()) {
101 Initialize();
102 }
103
104 void Initialize();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000105
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000106 static bool MakeCode(CompilationInfo* info);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000107
yangguo@chromium.org56454712012-02-16 15:33:53 +0000108 // Encode state and pc-offset as a BitField<type, start, size>.
109 // Only use 30 bits because we encode the result as a smi.
110 class StateField : public BitField<State, 0, 1> { };
111 class PcField : public BitField<unsigned, 1, 30-1> { };
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000112
113 static const char* State2String(State state) {
114 switch (state) {
115 case NO_REGISTERS: return "NO_REGISTERS";
116 case TOS_REG: return "TOS_REG";
117 }
118 UNREACHABLE();
119 return NULL;
120 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000121
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000122 Zone* zone() const { return zone_; }
123
danno@chromium.org129d3982012-07-25 15:01:47 +0000124 static const int kMaxBackEdgeWeight = 127;
125
126#if V8_TARGET_ARCH_IA32
127 static const int kBackEdgeDistanceUnit = 100;
128#elif V8_TARGET_ARCH_X64
129 static const int kBackEdgeDistanceUnit = 162;
130#elif V8_TARGET_ARCH_ARM
131 static const int kBackEdgeDistanceUnit = 142;
132#elif V8_TARGET_ARCH_MIPS
133 static const int kBackEdgeDistanceUnit = 142;
134#else
135#error Unsupported target architecture.
136#endif
137
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000138 static const int kBackEdgeEntrySize = 2 * kIntSize + kOneByteSize;
danno@chromium.org129d3982012-07-25 15:01:47 +0000139
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000140 private:
141 class Breakable;
142 class Iteration;
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000143
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000144 class TestContext;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000145
146 class NestedStatement BASE_EMBEDDED {
147 public:
148 explicit NestedStatement(FullCodeGenerator* codegen) : codegen_(codegen) {
149 // Link into codegen's nesting stack.
150 previous_ = codegen->nesting_stack_;
151 codegen->nesting_stack_ = this;
152 }
153 virtual ~NestedStatement() {
154 // Unlink from codegen's nesting stack.
155 ASSERT_EQ(this, codegen_->nesting_stack_);
156 codegen_->nesting_stack_ = previous_;
157 }
158
159 virtual Breakable* AsBreakable() { return NULL; }
160 virtual Iteration* AsIteration() { return NULL; }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000161
162 virtual bool IsContinueTarget(Statement* target) { return false; }
163 virtual bool IsBreakTarget(Statement* target) { return false; }
164
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000165 // Notify the statement that we are exiting it via break, continue, or
166 // return and give it a chance to generate cleanup code. Return the
167 // next outer statement in the nesting stack. We accumulate in
168 // *stack_depth the amount to drop the stack and in *context_length the
169 // number of context chain links to unwind as we traverse the nesting
170 // stack from an exit to its target.
171 virtual NestedStatement* Exit(int* stack_depth, int* context_length) {
172 return previous_;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000173 }
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000174
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +0000175 protected:
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000176 MacroAssembler* masm() { return codegen_->masm(); }
jkummerow@chromium.orge297f592011-06-08 10:05:15 +0000177
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000178 FullCodeGenerator* codegen_;
179 NestedStatement* previous_;
jkummerow@chromium.org05ed9dd2012-01-23 14:42:48 +0000180
181 private:
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000182 DISALLOW_COPY_AND_ASSIGN(NestedStatement);
183 };
184
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000185 // A breakable statement such as a block.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000186 class Breakable : public NestedStatement {
187 public:
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000188 Breakable(FullCodeGenerator* codegen, BreakableStatement* statement)
189 : NestedStatement(codegen), statement_(statement) {
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000190 }
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000191 virtual ~Breakable() {}
192
193 virtual Breakable* AsBreakable() { return this; }
194 virtual bool IsBreakTarget(Statement* target) {
195 return statement() == target;
196 }
197
198 BreakableStatement* statement() { return statement_; }
199 Label* break_label() { return &break_label_; }
200
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000201 private:
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000202 BreakableStatement* statement_;
203 Label break_label_;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000204 };
205
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000206 // An iteration statement such as a while, for, or do loop.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000207 class Iteration : public Breakable {
208 public:
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000209 Iteration(FullCodeGenerator* codegen, IterationStatement* statement)
210 : Breakable(codegen, statement) {
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000211 }
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000212 virtual ~Iteration() {}
213
214 virtual Iteration* AsIteration() { return this; }
215 virtual bool IsContinueTarget(Statement* target) {
216 return statement() == target;
217 }
218
219 Label* continue_label() { return &continue_label_; }
220
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000221 private:
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000222 Label continue_label_;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000223 };
224
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000225 // A nested block statement.
226 class NestedBlock : public Breakable {
227 public:
228 NestedBlock(FullCodeGenerator* codegen, Block* block)
229 : Breakable(codegen, block) {
230 }
231 virtual ~NestedBlock() {}
232
233 virtual NestedStatement* Exit(int* stack_depth, int* context_length) {
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000234 if (statement()->AsBlock()->scope() != NULL) {
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000235 ++(*context_length);
236 }
237 return previous_;
238 };
239 };
240
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000241 // The try block of a try/catch statement.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000242 class TryCatch : public NestedStatement {
243 public:
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000244 explicit TryCatch(FullCodeGenerator* codegen) : NestedStatement(codegen) {
245 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000246 virtual ~TryCatch() {}
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000247
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000248 virtual NestedStatement* Exit(int* stack_depth, int* context_length);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000249 };
250
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000251 // The try block of a try/finally statement.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000252 class TryFinally : public NestedStatement {
253 public:
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000254 TryFinally(FullCodeGenerator* codegen, Label* finally_entry)
255 : NestedStatement(codegen), finally_entry_(finally_entry) {
256 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000257 virtual ~TryFinally() {}
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000258
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000259 virtual NestedStatement* Exit(int* stack_depth, int* context_length);
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000260
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000261 private:
262 Label* finally_entry_;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000263 };
264
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000265 // The finally block of a try/finally statement.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000266 class Finally : public NestedStatement {
267 public:
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000268 static const int kElementCount = 5;
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000269
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000270 explicit Finally(FullCodeGenerator* codegen) : NestedStatement(codegen) { }
271 virtual ~Finally() {}
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000272
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000273 virtual NestedStatement* Exit(int* stack_depth, int* context_length) {
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000274 *stack_depth += kElementCount;
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000275 return previous_;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000276 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000277 };
278
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000279 // The body of a for/in loop.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000280 class ForIn : public Iteration {
281 public:
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000282 static const int kElementCount = 5;
283
284 ForIn(FullCodeGenerator* codegen, ForInStatement* statement)
285 : Iteration(codegen, statement) {
286 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000287 virtual ~ForIn() {}
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000288
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000289 virtual NestedStatement* Exit(int* stack_depth, int* context_length) {
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000290 *stack_depth += kElementCount;
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000291 return previous_;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000292 }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000293 };
294
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000295
rossberg@chromium.org28a37082011-08-22 11:03:23 +0000296 // The body of a with or catch.
whesse@chromium.org4acdc2c2011-08-15 13:01:23 +0000297 class WithOrCatch : public NestedStatement {
298 public:
299 explicit WithOrCatch(FullCodeGenerator* codegen)
300 : NestedStatement(codegen) {
301 }
302 virtual ~WithOrCatch() {}
303
304 virtual NestedStatement* Exit(int* stack_depth, int* context_length) {
305 ++(*context_length);
306 return previous_;
307 }
308 };
309
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000310 // Type of a member function that generates inline code for a native function.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000311 typedef void (FullCodeGenerator::*InlineFunctionGenerator)(CallRuntime* expr);
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000312
313 static const InlineFunctionGenerator kInlineFunctionGenerators[];
314
ager@chromium.org5f0c45f2010-12-17 08:51:21 +0000315 // A platform-specific utility to overwrite the accumulator register
316 // with a GC-safe value.
317 void ClearAccumulator();
318
ricow@chromium.org65fae842010-08-25 15:26:24 +0000319 // Determine whether or not to inline the smi case for the given
320 // operation.
321 bool ShouldInlineSmiCase(Token::Value op);
322
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000323 // Helper function to convert a pure value into a test context. The value
324 // is expected on the stack or the accumulator, depending on the platform.
325 // See the platform-specific implementation for details.
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000326 void DoTest(Expression* condition,
327 Label* if_true,
328 Label* if_false,
329 Label* fall_through);
330 void DoTest(const TestContext* context);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000331
332 // Helper function to split control flow and avoid a branch to the
333 // fall-through label if it is set up.
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000334#ifdef V8_TARGET_ARCH_MIPS
335 void Split(Condition cc,
336 Register lhs,
337 const Operand& rhs,
338 Label* if_true,
339 Label* if_false,
340 Label* fall_through);
341#else // All non-mips arch.
ricow@chromium.org65fae842010-08-25 15:26:24 +0000342 void Split(Condition cc,
343 Label* if_true,
344 Label* if_false,
345 Label* fall_through);
kmillikin@chromium.orgc53e10d2011-05-18 09:12:58 +0000346#endif // V8_TARGET_ARCH_MIPS
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000347
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000348 // Load the value of a known (PARAMETER, LOCAL, or CONTEXT) variable into
349 // a register. Emits a context chain walk if if necessary (so does
350 // SetVar) so avoid calling both on the same variable.
351 void GetVar(Register destination, Variable* var);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000352
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000353 // Assign to a known (PARAMETER, LOCAL, or CONTEXT) variable. If it's in
354 // the context, the write barrier will be emitted and source, scratch0,
355 // scratch1 will be clobbered. Emits a context chain walk if if necessary
356 // (so does GetVar) so avoid calling both on the same variable.
357 void SetVar(Variable* var,
358 Register source,
359 Register scratch0,
360 Register scratch1);
361
362 // An operand used to read/write a stack-allocated (PARAMETER or LOCAL)
363 // variable. Writing does not need the write barrier.
364 MemOperand StackOperand(Variable* var);
365
366 // An operand used to read/write a known (PARAMETER, LOCAL, or CONTEXT)
367 // variable. May emit code to traverse the context chain, loading the
368 // found context into the scratch register. Writing to this operand will
369 // need the write barrier if location is CONTEXT.
370 MemOperand VarOperand(Variable* var, Register scratch);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000371
372 void VisitForEffect(Expression* expr) {
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000373 EffectContext context(this);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000374 Visit(expr);
375 PrepareForBailout(expr, NO_REGISTERS);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000376 }
377
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000378 void VisitForAccumulatorValue(Expression* expr) {
379 AccumulatorValueContext context(this);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000380 Visit(expr);
381 PrepareForBailout(expr, TOS_REG);
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000382 }
383
384 void VisitForStackValue(Expression* expr) {
385 StackValueContext context(this);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000386 Visit(expr);
387 PrepareForBailout(expr, NO_REGISTERS);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000388 }
389
ricow@chromium.org65fae842010-08-25 15:26:24 +0000390 void VisitForControl(Expression* expr,
391 Label* if_true,
392 Label* if_false,
393 Label* fall_through) {
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000394 TestContext context(this, expr, if_true, if_false, fall_through);
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000395 Visit(expr);
396 // For test contexts, we prepare for bailout before branching, not at
397 // the end of the entire expression. This happens as part of visiting
398 // the expression.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000399 }
400
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000401 void VisitInDuplicateContext(Expression* expr);
402
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000403 void VisitDeclarations(ZoneList<Declaration*>* declarations);
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000404 void DeclareModules(Handle<FixedArray> descriptions);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000405 void DeclareGlobals(Handle<FixedArray> pairs);
fschneider@chromium.org1805e212011-09-05 10:49:12 +0000406 int DeclareGlobalsFlags();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000407
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000408 // Generate code to allocate all (including nested) modules and contexts.
409 // Because of recursive linking and the presence of module alias declarations,
410 // this has to be a separate pass _before_ populating or executing any module.
411 void AllocateModules(ZoneList<Declaration*>* declarations);
412
ulan@chromium.org57ff8812013-05-10 08:16:55 +0000413 // Generator code to return a fresh iterator result object. The "value"
414 // property is set to a value popped from the stack, and "done" is set
415 // according to the argument.
416 void EmitReturnIteratorResult(bool done);
417
ricow@chromium.org65fae842010-08-25 15:26:24 +0000418 // Try to perform a comparison as a fast inlined literal compare if
419 // the operands allow it. Returns true if the compare operations
420 // has been matched and all code generated; false otherwise.
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000421 bool TryLiteralCompare(CompareOperation* compare);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000422
ager@chromium.org04921a82011-06-27 13:21:41 +0000423 // Platform-specific code for comparing the type of a value with
424 // a given literal string.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000425 void EmitLiteralCompareTypeof(Expression* expr,
426 Expression* sub_expr,
427 Handle<String> check);
ager@chromium.org04921a82011-06-27 13:21:41 +0000428
erik.corry@gmail.comc3b670f2011-10-05 21:44:48 +0000429 // Platform-specific code for equality comparison with a nil-like value.
430 void EmitLiteralCompareNil(CompareOperation* expr,
431 Expression* sub_expr,
432 NilValue nil);
ager@chromium.org04921a82011-06-27 13:21:41 +0000433
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000434 // Bailout support.
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000435 void PrepareForBailout(Expression* node, State state);
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000436 void PrepareForBailoutForId(BailoutId id, State state);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000437
danno@chromium.orgfa458e42012-02-01 10:48:36 +0000438 // Cache cell support. This associates AST ids with global property cells
439 // that will be cleared during GC and collected by the type-feedback oracle.
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000440 void RecordTypeFeedbackCell(TypeFeedbackId id,
441 Handle<JSGlobalPropertyCell> cell);
danno@chromium.orgfa458e42012-02-01 10:48:36 +0000442
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000443 // Record a call's return site offset, used to rebuild the frame if the
444 // called function was inlined at the site.
445 void RecordJSReturnSite(Call* call);
446
447 // Prepare for bailout before a test (or compare) and branch. If
448 // should_normalize, then the following comparison will not handle the
449 // canonical JS true value so we will insert a (dead) test against true at
450 // the actual bailout target from the optimized code. If not
451 // should_normalize, the true and false labels are ignored.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000452 void PrepareForBailoutBeforeSplit(Expression* expr,
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000453 bool should_normalize,
454 Label* if_true,
455 Label* if_false);
456
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000457 // If enabled, emit debug code for checking that the current context is
458 // neither a with nor a catch context.
459 void EmitDebugCheckDeclarationContext(Variable* variable);
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000460
yangguo@chromium.org56454712012-02-16 15:33:53 +0000461 // This is meant to be called at loop back edges, |back_edge_target| is
462 // the jump target of the back edge and is used to approximate the amount
463 // of code inside the loop.
rossberg@chromium.orgcddc71f2012-12-07 12:40:13 +0000464 void EmitBackEdgeBookkeeping(IterationStatement* stmt,
465 Label* back_edge_target);
466 // Record the OSR AST id corresponding to a back edge in the code.
467 void RecordBackEdge(BailoutId osr_ast_id);
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000468 // Emit a table of back edge ids, pcs and loop depths into the code stream.
469 // Return the offset of the start of the table.
470 unsigned EmitBackEdgeTable();
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000471
svenpanne@chromium.org4efbdb12012-03-12 08:18:42 +0000472 void EmitProfilingCounterDecrement(int delta);
473 void EmitProfilingCounterReset();
474
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000475 // Platform-specific return sequence
ager@chromium.org2cc82ae2010-06-14 07:35:38 +0000476 void EmitReturnSequence();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000477
478 // Platform-specific code sequences for calls
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +0000479 void EmitCallWithStub(Call* expr, CallFunctionFlags flags);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000480 void EmitCallWithIC(Call* expr, Handle<Object> name, RelocInfo::Mode mode);
danno@chromium.org40cb8782011-05-25 07:58:50 +0000481 void EmitKeyedCallWithIC(Call* expr, Expression* key);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000482
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000483 // Platform-specific code for inline runtime calls.
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000484 InlineFunctionGenerator FindInlineFunctionGenerator(Runtime::FunctionId id);
485
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000486 void EmitInlineRuntimeCall(CallRuntime* expr);
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000487
488#define EMIT_INLINE_RUNTIME_CALL(name, x, y) \
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000489 void Emit##name(CallRuntime* expr);
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000490 INLINE_FUNCTION_LIST(EMIT_INLINE_RUNTIME_CALL)
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000491 INLINE_RUNTIME_FUNCTION_LIST(EMIT_INLINE_RUNTIME_CALL)
492#undef EMIT_INLINE_RUNTIME_CALL
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000493
danno@chromium.orgca29dd82013-04-26 11:59:48 +0000494 // Platform-specific code for resuming generators.
495 void EmitGeneratorResume(Expression *generator,
496 Expression *value,
497 JSGeneratorObject::ResumeMode resume_mode);
498
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000499 // Platform-specific code for loading variables.
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000500 void EmitLoadGlobalCheckExtensions(Variable* var,
501 TypeofState typeof_state,
502 Label* slow);
503 MemOperand ContextSlotOperandCheckExtensions(Variable* var, Label* slow);
504 void EmitDynamicLookupFastCase(Variable* var,
505 TypeofState typeof_state,
506 Label* slow,
507 Label* done);
whesse@chromium.org030d38e2011-07-13 13:23:34 +0000508 void EmitVariableLoad(VariableProxy* proxy);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000509
rossberg@chromium.org2c067b12012-03-19 11:01:52 +0000510 void EmitAccessor(Expression* expression);
511
ager@chromium.org9ee27ae2011-03-02 13:43:26 +0000512 // Expects the arguments and the function already pushed.
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000513 void EmitResolvePossiblyDirectEval(int arg_count);
ager@chromium.org9ee27ae2011-03-02 13:43:26 +0000514
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000515 // Platform-specific support for allocating a new closure based on
516 // the given function info.
vegorov@chromium.org21b5e952010-11-23 10:24:40 +0000517 void EmitNewClosure(Handle<SharedFunctionInfo> info, bool pretenure);
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000518
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000519 // Platform-specific support for compiling assignments.
520
521 // Load a value from a named property.
522 // The receiver is left on the stack by the IC.
523 void EmitNamedPropertyLoad(Property* expr);
524
525 // Load a value from a keyed property.
526 // The receiver and the key is left on the stack by the IC.
527 void EmitKeyedPropertyLoad(Property* expr);
528
529 // Apply the compound assignment operator. Expects the left operand on top
530 // of the stack and the right one in the accumulator.
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +0000531 void EmitBinaryOp(BinaryOperation* expr,
532 Token::Value op,
ricow@chromium.org65fae842010-08-25 15:26:24 +0000533 OverwriteMode mode);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000534
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000535 // Helper functions for generating inlined smi code for certain
536 // binary operations.
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +0000537 void EmitInlineSmiBinaryOp(BinaryOperation* expr,
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000538 Token::Value op,
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000539 OverwriteMode mode,
540 Expression* left,
ager@chromium.org9ee27ae2011-03-02 13:43:26 +0000541 Expression* right);
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000542
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000543 // Assign to the given expression as if via '='. The right-hand-side value
544 // is expected in the accumulator.
kmillikin@chromium.orgbe6bd102012-02-23 08:45:21 +0000545 void EmitAssignment(Expression* expr);
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000546
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000547 // Complete a variable assignment. The right-hand-side value is expected
548 // in the accumulator.
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000549 void EmitVariableAssignment(Variable* var,
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000550 Token::Value op);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000551
552 // Complete a named property assignment. The receiver is expected on top
553 // of the stack and the right-hand-side value in the accumulator.
554 void EmitNamedPropertyAssignment(Assignment* expr);
555
556 // Complete a keyed property assignment. The receiver and key are
557 // expected on top of the stack and the right-hand-side value in the
558 // accumulator.
559 void EmitKeyedPropertyAssignment(Assignment* expr);
560
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +0000561 void CallIC(Handle<Code> code,
562 RelocInfo::Mode rmode = RelocInfo::CODE_TARGET,
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000563 TypeFeedbackId id = TypeFeedbackId::None());
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +0000564
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000565 void SetFunctionPosition(FunctionLiteral* fun);
566 void SetReturnPosition(FunctionLiteral* fun);
567 void SetStatementPosition(Statement* stmt);
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000568 void SetExpressionPosition(Expression* expr, int pos);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000569 void SetStatementPosition(int pos);
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000570 void SetSourcePosition(int pos);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000571
572 // Non-local control flow support.
573 void EnterFinallyBlock();
574 void ExitFinallyBlock();
575
576 // Loop nesting counter.
577 int loop_depth() { return loop_depth_; }
578 void increment_loop_depth() { loop_depth_++; }
579 void decrement_loop_depth() {
580 ASSERT(loop_depth_ > 0);
581 loop_depth_--;
582 }
583
584 MacroAssembler* masm() { return masm_; }
ager@chromium.org5c838252010-02-19 08:53:10 +0000585
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000586 class ExpressionContext;
587 const ExpressionContext* context() { return context_; }
588 void set_new_context(const ExpressionContext* context) { context_ = context; }
589
ager@chromium.org5c838252010-02-19 08:53:10 +0000590 Handle<Script> script() { return info_->script(); }
591 bool is_eval() { return info_->is_eval(); }
fschneider@chromium.org1805e212011-09-05 10:49:12 +0000592 bool is_native() { return info_->is_native(); }
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000593 bool is_classic_mode() { return language_mode() == CLASSIC_MODE; }
594 LanguageMode language_mode() { return function()->language_mode(); }
ager@chromium.org5c838252010-02-19 08:53:10 +0000595 FunctionLiteral* function() { return info_->function(); }
ricow@chromium.org4f693d62011-07-04 14:01:31 +0000596 Scope* scope() { return scope_; }
ager@chromium.org5c838252010-02-19 08:53:10 +0000597
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000598 static Register result_register();
599 static Register context_register();
600
601 // Set fields in the stack frame. Offsets are the frame pointer relative
602 // offsets defined in, e.g., StandardFrameConstants.
603 void StoreToFrameField(int frame_offset, Register value);
604
605 // Load a value from the current context. Indices are defined as an enum
606 // in v8::internal::Context.
607 void LoadContextField(Register dst, int context_index);
608
vegorov@chromium.org3cf47312011-06-29 13:20:01 +0000609 // Push the function argument for the runtime functions PushWithContext
610 // and PushCatchContext.
611 void PushFunctionArgumentForContextAllocation();
612
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000613 // AST node visit functions.
614#define DECLARE_VISIT(type) virtual void Visit##type(type* node);
615 AST_NODE_LIST(DECLARE_VISIT)
616#undef DECLARE_VISIT
sgjesse@chromium.org8e8294a2011-05-02 14:30:53 +0000617
618 void EmitUnaryOperation(UnaryOperation* expr, const char* comment);
619
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000620 void VisitComma(BinaryOperation* expr);
621 void VisitLogicalExpression(BinaryOperation* expr);
622 void VisitArithmeticExpression(BinaryOperation* expr);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000623
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000624 void VisitForTypeofValue(Expression* expr);
ricow@chromium.org65fae842010-08-25 15:26:24 +0000625
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +0000626 void Generate();
627 void PopulateDeoptimizationData(Handle<Code> code);
628 void PopulateTypeFeedbackInfo(Handle<Code> code);
629 void PopulateTypeFeedbackCells(Handle<Code> code);
630
631 Handle<FixedArray> handler_table() { return handler_table_; }
632
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000633 struct BailoutEntry {
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000634 BailoutId id;
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000635 unsigned pc_and_state;
636 };
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000637
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000638 struct BackEdgeEntry {
639 BailoutId id;
640 unsigned pc;
641 uint8_t loop_depth;
642 };
643
danno@chromium.orgfa458e42012-02-01 10:48:36 +0000644 struct TypeFeedbackCellEntry {
mstarzinger@chromium.org471f2f12012-08-10 14:46:33 +0000645 TypeFeedbackId ast_id;
danno@chromium.orgfa458e42012-02-01 10:48:36 +0000646 Handle<JSGlobalPropertyCell> cell;
647 };
648
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000649
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000650 class ExpressionContext BASE_EMBEDDED {
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000651 public:
652 explicit ExpressionContext(FullCodeGenerator* codegen)
653 : masm_(codegen->masm()), old_(codegen->context()), codegen_(codegen) {
654 codegen->set_new_context(this);
655 }
656
657 virtual ~ExpressionContext() {
658 codegen_->set_new_context(old_);
659 }
660
sgjesse@chromium.orgea88ce92011-03-23 11:19:56 +0000661 Isolate* isolate() const { return codegen_->isolate(); }
662
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000663 // Convert constant control flow (true or false) to the result expected for
664 // this expression context.
665 virtual void Plug(bool flag) const = 0;
666
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000667 // Emit code to convert a pure value (in a register, known variable
668 // location, as a literal, or on top of the stack) into the result
669 // expected according to this expression context.
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000670 virtual void Plug(Register reg) const = 0;
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000671 virtual void Plug(Variable* var) const = 0;
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000672 virtual void Plug(Handle<Object> lit) const = 0;
673 virtual void Plug(Heap::RootListIndex index) const = 0;
674 virtual void PlugTOS() const = 0;
675
676 // Emit code to convert pure control flow to a pair of unbound labels into
677 // the result expected according to this expression context. The
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000678 // implementation will bind both labels unless it's a TestContext, which
679 // won't bind them at this point.
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000680 virtual void Plug(Label* materialize_true,
681 Label* materialize_false) const = 0;
682
683 // Emit code to discard count elements from the top of stack, then convert
684 // a pure value into the result expected according to this expression
685 // context.
686 virtual void DropAndPlug(int count, Register reg) const = 0;
687
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000688 // Set up branch labels for a test expression. The three Label** parameters
689 // are output parameters.
690 virtual void PrepareTest(Label* materialize_true,
691 Label* materialize_false,
692 Label** if_true,
693 Label** if_false,
694 Label** fall_through) const = 0;
695
ulan@chromium.org2efb9002012-01-19 15:36:35 +0000696 // Returns true if we are evaluating only for side effects (i.e. if the
697 // result will be discarded).
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000698 virtual bool IsEffect() const { return false; }
699
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000700 // Returns true if we are evaluating for the value (in accu/on stack).
701 virtual bool IsAccumulatorValue() const { return false; }
702 virtual bool IsStackValue() const { return false; }
703
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000704 // Returns true if we are branching on the value rather than materializing
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000705 // it. Only used for asserts.
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000706 virtual bool IsTest() const { return false; }
707
708 protected:
709 FullCodeGenerator* codegen() const { return codegen_; }
710 MacroAssembler* masm() const { return masm_; }
711 MacroAssembler* masm_;
712
713 private:
714 const ExpressionContext* old_;
715 FullCodeGenerator* codegen_;
716 };
717
718 class AccumulatorValueContext : public ExpressionContext {
719 public:
720 explicit AccumulatorValueContext(FullCodeGenerator* codegen)
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000721 : ExpressionContext(codegen) { }
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000722
723 virtual void Plug(bool flag) const;
724 virtual void Plug(Register reg) const;
725 virtual void Plug(Label* materialize_true, Label* materialize_false) const;
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000726 virtual void Plug(Variable* var) const;
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000727 virtual void Plug(Handle<Object> lit) const;
728 virtual void Plug(Heap::RootListIndex) const;
729 virtual void PlugTOS() const;
730 virtual void DropAndPlug(int count, Register reg) const;
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000731 virtual void PrepareTest(Label* materialize_true,
732 Label* materialize_false,
733 Label** if_true,
734 Label** if_false,
735 Label** fall_through) const;
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000736 virtual bool IsAccumulatorValue() const { return true; }
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000737 };
738
739 class StackValueContext : public ExpressionContext {
740 public:
741 explicit StackValueContext(FullCodeGenerator* codegen)
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000742 : ExpressionContext(codegen) { }
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000743
744 virtual void Plug(bool flag) const;
745 virtual void Plug(Register reg) const;
746 virtual void Plug(Label* materialize_true, Label* materialize_false) const;
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000747 virtual void Plug(Variable* var) const;
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000748 virtual void Plug(Handle<Object> lit) const;
749 virtual void Plug(Heap::RootListIndex) const;
750 virtual void PlugTOS() const;
751 virtual void DropAndPlug(int count, Register reg) const;
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000752 virtual void PrepareTest(Label* materialize_true,
753 Label* materialize_false,
754 Label** if_true,
755 Label** if_false,
756 Label** fall_through) const;
ricow@chromium.orgd2be9012011-06-01 06:00:58 +0000757 virtual bool IsStackValue() const { return true; }
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000758 };
759
760 class TestContext : public ExpressionContext {
761 public:
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000762 TestContext(FullCodeGenerator* codegen,
763 Expression* condition,
764 Label* true_label,
765 Label* false_label,
766 Label* fall_through)
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000767 : ExpressionContext(codegen),
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000768 condition_(condition),
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000769 true_label_(true_label),
770 false_label_(false_label),
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000771 fall_through_(fall_through) { }
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000772
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000773 static const TestContext* cast(const ExpressionContext* context) {
774 ASSERT(context->IsTest());
775 return reinterpret_cast<const TestContext*>(context);
776 }
777
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000778 Expression* condition() const { return condition_; }
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000779 Label* true_label() const { return true_label_; }
780 Label* false_label() const { return false_label_; }
781 Label* fall_through() const { return fall_through_; }
782
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000783 virtual void Plug(bool flag) const;
784 virtual void Plug(Register reg) const;
785 virtual void Plug(Label* materialize_true, Label* materialize_false) const;
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000786 virtual void Plug(Variable* var) const;
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000787 virtual void Plug(Handle<Object> lit) const;
788 virtual void Plug(Heap::RootListIndex) const;
789 virtual void PlugTOS() const;
790 virtual void DropAndPlug(int count, Register reg) const;
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000791 virtual void PrepareTest(Label* materialize_true,
792 Label* materialize_false,
793 Label** if_true,
794 Label** if_false,
795 Label** fall_through) const;
796 virtual bool IsTest() const { return true; }
797
798 private:
svenpanne@chromium.org6d786c92011-06-15 10:58:27 +0000799 Expression* condition_;
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000800 Label* true_label_;
801 Label* false_label_;
802 Label* fall_through_;
803 };
804
805 class EffectContext : public ExpressionContext {
806 public:
807 explicit EffectContext(FullCodeGenerator* codegen)
jkummerow@chromium.orgc3b37122011-11-07 10:14:12 +0000808 : ExpressionContext(codegen) { }
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000809
810 virtual void Plug(bool flag) const;
811 virtual void Plug(Register reg) const;
812 virtual void Plug(Label* materialize_true, Label* materialize_false) const;
jkummerow@chromium.org486075a2011-09-07 12:44:28 +0000813 virtual void Plug(Variable* var) const;
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000814 virtual void Plug(Handle<Object> lit) const;
815 virtual void Plug(Heap::RootListIndex) const;
816 virtual void PlugTOS() const;
817 virtual void DropAndPlug(int count, Register reg) const;
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000818 virtual void PrepareTest(Label* materialize_true,
819 Label* materialize_false,
820 Label** if_true,
821 Label** if_false,
822 Label** fall_through) const;
823 virtual bool IsEffect() const { return true; }
824 };
825
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000826 MacroAssembler* masm_;
827 CompilationInfo* info_;
ricow@chromium.org4f693d62011-07-04 14:01:31 +0000828 Scope* scope_;
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000829 Label return_label_;
830 NestedStatement* nesting_stack_;
831 int loop_depth_;
erik.corry@gmail.comed49e962012-04-17 11:57:53 +0000832 ZoneList<Handle<Object> >* globals_;
ulan@chromium.org8e8d8822012-11-23 14:36:46 +0000833 Handle<FixedArray> modules_;
834 int module_index_;
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000835 const ExpressionContext* context_;
kasperl@chromium.orga5551262010-12-07 12:49:48 +0000836 ZoneList<BailoutEntry> bailout_entries_;
jkummerow@chromium.org59297c72013-01-09 16:32:23 +0000837 GrowableBitVector prepared_bailout_ids_;
mstarzinger@chromium.orge27d6172013-04-17 11:51:44 +0000838 ZoneList<BackEdgeEntry> back_edges_;
danno@chromium.orgfa458e42012-02-01 10:48:36 +0000839 ZoneList<TypeFeedbackCellEntry> type_feedback_cells_;
jkummerow@chromium.orgf7a58842012-02-21 10:08:21 +0000840 int ic_total_count_;
jkummerow@chromium.org04e4f1e2011-11-14 13:36:17 +0000841 Handle<FixedArray> handler_table_;
yangguo@chromium.org56454712012-02-16 15:33:53 +0000842 Handle<JSGlobalPropertyCell> profiling_counter_;
jkummerow@chromium.org000f7fb2012-08-01 11:14:42 +0000843 bool generate_debug_code_;
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000844 Zone* zone_;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000845
846 friend class NestedStatement;
847
yangguo@chromium.orga6bbcc82012-12-21 12:35:02 +0000848 DEFINE_AST_VISITOR_SUBCLASS_MEMBERS();
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000849 DISALLOW_COPY_AND_ASSIGN(FullCodeGenerator);
850};
851
852
rossberg@chromium.org2c067b12012-03-19 11:01:52 +0000853// A map from property names to getter/setter pairs allocated in the zone.
854class AccessorTable: public TemplateHashMap<Literal,
855 ObjectLiteral::Accessors,
rossberg@chromium.org400388e2012-06-06 09:29:22 +0000856 ZoneAllocationPolicy> {
rossberg@chromium.org2c067b12012-03-19 11:01:52 +0000857 public:
858 explicit AccessorTable(Zone* zone) :
rossberg@chromium.org400388e2012-06-06 09:29:22 +0000859 TemplateHashMap<Literal, ObjectLiteral::Accessors,
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000860 ZoneAllocationPolicy>(Literal::Match,
861 ZoneAllocationPolicy(zone)),
rossberg@chromium.org2c067b12012-03-19 11:01:52 +0000862 zone_(zone) { }
863
864 Iterator lookup(Literal* literal) {
mmassi@chromium.org7028c052012-06-13 11:51:58 +0000865 Iterator it = find(literal, true, ZoneAllocationPolicy(zone_));
rossberg@chromium.org2c067b12012-03-19 11:01:52 +0000866 if (it->second == NULL) it->second = new(zone_) ObjectLiteral::Accessors();
867 return it;
868 }
869
870 private:
871 Zone* zone_;
872};
873
874
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000875} } // namespace v8::internal
876
877#endif // V8_FULL_CODEGEN_H_