blob: 1483c0b54562e25c258d5dba663110b254f0ab23 [file] [log] [blame]
Leon Clarked91b9f72010-01-27 17:25:45 +00001// Copyright 2010 the V8 project authors. All rights reserved.
Steve Blocka7e24c12009-10-30 11:49:00 +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_ARM_CODEGEN_ARM_H_
29#define V8_ARM_CODEGEN_ARM_H_
30
Kristian Monsen25f61362010-05-21 11:50:48 +010031#include "ast.h"
Kristian Monsen80d68ea2010-09-08 11:05:35 +010032#include "code-stubs-arm.h"
33#include "ic-inl.h"
Steve Block6ded16b2010-05-10 14:33:55 +010034
Steve Blocka7e24c12009-10-30 11:49:00 +000035namespace v8 {
36namespace internal {
37
38// Forward declarations
Leon Clarke4515c472010-02-03 11:58:03 +000039class CompilationInfo;
Steve Blocka7e24c12009-10-30 11:49:00 +000040class DeferredCode;
Kristian Monsen25f61362010-05-21 11:50:48 +010041class JumpTarget;
Steve Blocka7e24c12009-10-30 11:49:00 +000042class RegisterAllocator;
43class RegisterFile;
44
45enum InitState { CONST_INIT, NOT_CONST_INIT };
46enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF };
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +010047enum GenerateInlineSmi { DONT_GENERATE_INLINE_SMI, GENERATE_INLINE_SMI };
Steve Block8defd9f2010-07-08 12:39:36 +010048enum WriteBarrierCharacter { UNLIKELY_SMI, LIKELY_SMI, NEVER_NEWSPACE };
Steve Blocka7e24c12009-10-30 11:49:00 +000049
50
51// -------------------------------------------------------------------------
52// Reference support
53
Leon Clarked91b9f72010-01-27 17:25:45 +000054// A reference is a C++ stack-allocated object that puts a
55// reference on the virtual frame. The reference may be consumed
56// by GetValue, TakeValue, SetValue, and Codegen::UnloadReference.
57// When the lifetime (scope) of a valid reference ends, it must have
58// been consumed, and be in state UNLOADED.
Steve Blocka7e24c12009-10-30 11:49:00 +000059class Reference BASE_EMBEDDED {
60 public:
61 // The values of the types is important, see size().
Leon Clarked91b9f72010-01-27 17:25:45 +000062 enum Type { UNLOADED = -2, ILLEGAL = -1, SLOT = 0, NAMED = 1, KEYED = 2 };
63 Reference(CodeGenerator* cgen,
64 Expression* expression,
65 bool persist_after_get = false);
Steve Blocka7e24c12009-10-30 11:49:00 +000066 ~Reference();
67
68 Expression* expression() const { return expression_; }
69 Type type() const { return type_; }
70 void set_type(Type value) {
Leon Clarked91b9f72010-01-27 17:25:45 +000071 ASSERT_EQ(ILLEGAL, type_);
Steve Blocka7e24c12009-10-30 11:49:00 +000072 type_ = value;
73 }
74
Leon Clarked91b9f72010-01-27 17:25:45 +000075 void set_unloaded() {
76 ASSERT_NE(ILLEGAL, type_);
77 ASSERT_NE(UNLOADED, type_);
78 type_ = UNLOADED;
79 }
Steve Blocka7e24c12009-10-30 11:49:00 +000080 // The size the reference takes up on the stack.
Leon Clarked91b9f72010-01-27 17:25:45 +000081 int size() const {
82 return (type_ < SLOT) ? 0 : type_;
83 }
Steve Blocka7e24c12009-10-30 11:49:00 +000084
85 bool is_illegal() const { return type_ == ILLEGAL; }
86 bool is_slot() const { return type_ == SLOT; }
87 bool is_property() const { return type_ == NAMED || type_ == KEYED; }
Leon Clarked91b9f72010-01-27 17:25:45 +000088 bool is_unloaded() const { return type_ == UNLOADED; }
Steve Blocka7e24c12009-10-30 11:49:00 +000089
90 // Return the name. Only valid for named property references.
91 Handle<String> GetName();
92
93 // Generate code to push the value of the reference on top of the
94 // expression stack. The reference is expected to be already on top of
Leon Clarked91b9f72010-01-27 17:25:45 +000095 // the expression stack, and it is consumed by the call unless the
96 // reference is for a compound assignment.
97 // If the reference is not consumed, it is left in place under its value.
Steve Blockd0582a62009-12-15 09:54:21 +000098 void GetValue();
Steve Blocka7e24c12009-10-30 11:49:00 +000099
Steve Blocka7e24c12009-10-30 11:49:00 +0000100 // Generate code to store the value on top of the expression stack in the
101 // reference. The reference is expected to be immediately below the value
Leon Clarked91b9f72010-01-27 17:25:45 +0000102 // on the expression stack. The value is stored in the location specified
103 // by the reference, and is left on top of the stack, after the reference
104 // is popped from beneath it (unloaded).
Steve Block8defd9f2010-07-08 12:39:36 +0100105 void SetValue(InitState init_state, WriteBarrierCharacter wb);
Steve Blocka7e24c12009-10-30 11:49:00 +0000106
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100107 // This is in preparation for something that uses the reference on the stack.
108 // If we need this reference afterwards get then dup it now. Otherwise mark
109 // it as used.
110 inline void DupIfPersist();
111
Steve Blocka7e24c12009-10-30 11:49:00 +0000112 private:
113 CodeGenerator* cgen_;
114 Expression* expression_;
115 Type type_;
Leon Clarked91b9f72010-01-27 17:25:45 +0000116 // Keep the reference on the stack after get, so it can be used by set later.
117 bool persist_after_get_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000118};
119
120
121// -------------------------------------------------------------------------
122// Code generation state
123
124// The state is passed down the AST by the code generator (and back up, in
125// the form of the state of the label pair). It is threaded through the
126// call stack. Constructing a state implicitly pushes it on the owning code
127// generator's stack of states, and destroying one implicitly pops it.
128
129class CodeGenState BASE_EMBEDDED {
130 public:
131 // Create an initial code generator state. Destroying the initial state
132 // leaves the code generator with a NULL state.
133 explicit CodeGenState(CodeGenerator* owner);
134
Steve Blocka7e24c12009-10-30 11:49:00 +0000135 // Destroy a code generator state and restore the owning code generator's
136 // previous state.
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100137 virtual ~CodeGenState();
Steve Blocka7e24c12009-10-30 11:49:00 +0000138
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100139 virtual JumpTarget* true_target() const { return NULL; }
140 virtual JumpTarget* false_target() const { return NULL; }
141
142 protected:
143 inline CodeGenerator* owner() { return owner_; }
144 inline CodeGenState* previous() const { return previous_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000145
146 private:
147 CodeGenerator* owner_;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100148 CodeGenState* previous_;
149};
150
151
152class ConditionCodeGenState : public CodeGenState {
153 public:
154 // Create a code generator state based on a code generator's current
155 // state. The new state has its own pair of branch labels.
156 ConditionCodeGenState(CodeGenerator* owner,
157 JumpTarget* true_target,
158 JumpTarget* false_target);
159
160 virtual JumpTarget* true_target() const { return true_target_; }
161 virtual JumpTarget* false_target() const { return false_target_; }
162
163 private:
Steve Blocka7e24c12009-10-30 11:49:00 +0000164 JumpTarget* true_target_;
165 JumpTarget* false_target_;
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100166};
167
168
169class TypeInfoCodeGenState : public CodeGenState {
170 public:
171 TypeInfoCodeGenState(CodeGenerator* owner,
172 Slot* slot_number,
173 TypeInfo info);
174 ~TypeInfoCodeGenState();
175
176 virtual JumpTarget* true_target() const { return previous()->true_target(); }
177 virtual JumpTarget* false_target() const {
178 return previous()->false_target();
179 }
180
181 private:
182 Slot* slot_;
183 TypeInfo old_type_info_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000184};
185
186
187// -------------------------------------------------------------------------
Steve Block6ded16b2010-05-10 14:33:55 +0100188// Arguments allocation mode
189
190enum ArgumentsAllocationMode {
191 NO_ARGUMENTS_ALLOCATION,
192 EAGER_ARGUMENTS_ALLOCATION,
193 LAZY_ARGUMENTS_ALLOCATION
194};
195
196
197// Different nop operations are used by the code generator to detect certain
198// states of the generated code.
199enum NopMarkerTypes {
200 NON_MARKING_NOP = 0,
201 PROPERTY_ACCESS_INLINED
202};
203
204
205// -------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000206// CodeGenerator
207
208class CodeGenerator: public AstVisitor {
209 public:
210 // Takes a function literal, generates code for it. This function should only
211 // be called by compiler.cc.
Andrei Popescu31002712010-02-23 13:46:05 +0000212 static Handle<Code> MakeCode(CompilationInfo* info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000213
Steve Block3ce2e202009-11-05 08:53:23 +0000214 // Printing of AST, etc. as requested by flags.
Andrei Popescu31002712010-02-23 13:46:05 +0000215 static void MakeCodePrologue(CompilationInfo* info);
Steve Block3ce2e202009-11-05 08:53:23 +0000216
217 // Allocate and install the code.
Andrei Popescu31002712010-02-23 13:46:05 +0000218 static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm,
Steve Block3ce2e202009-11-05 08:53:23 +0000219 Code::Flags flags,
Andrei Popescu31002712010-02-23 13:46:05 +0000220 CompilationInfo* info);
Steve Block3ce2e202009-11-05 08:53:23 +0000221
Steve Blocka7e24c12009-10-30 11:49:00 +0000222#ifdef ENABLE_LOGGING_AND_PROFILING
223 static bool ShouldGenerateLog(Expression* type);
224#endif
225
226 static void SetFunctionInfo(Handle<JSFunction> fun,
227 FunctionLiteral* lit,
228 bool is_toplevel,
229 Handle<Script> script);
230
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100231 static bool RecordPositions(MacroAssembler* masm,
232 int pos,
233 bool right_here = false);
Steve Block3ce2e202009-11-05 08:53:23 +0000234
Steve Blocka7e24c12009-10-30 11:49:00 +0000235 // Accessors
236 MacroAssembler* masm() { return masm_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000237 VirtualFrame* frame() const { return frame_; }
Andrei Popescu31002712010-02-23 13:46:05 +0000238 inline Handle<Script> script();
Steve Blocka7e24c12009-10-30 11:49:00 +0000239
240 bool has_valid_frame() const { return frame_ != NULL; }
241
242 // Set the virtual frame to be new_frame, with non-frame register
243 // reference counts given by non_frame_registers. The non-frame
244 // register reference counts of the old frame are returned in
245 // non_frame_registers.
246 void SetFrame(VirtualFrame* new_frame, RegisterFile* non_frame_registers);
247
248 void DeleteFrame();
249
250 RegisterAllocator* allocator() const { return allocator_; }
251
252 CodeGenState* state() { return state_; }
253 void set_state(CodeGenState* state) { state_ = state; }
254
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100255 TypeInfo type_info(Slot* slot) {
256 int index = NumberOfSlot(slot);
257 if (index == kInvalidSlotNumber) return TypeInfo::Unknown();
258 return (*type_info_)[index];
259 }
260
261 TypeInfo set_type_info(Slot* slot, TypeInfo info) {
262 int index = NumberOfSlot(slot);
263 ASSERT(index >= kInvalidSlotNumber);
264 if (index != kInvalidSlotNumber) {
265 TypeInfo previous_value = (*type_info_)[index];
266 (*type_info_)[index] = info;
267 return previous_value;
268 }
269 return TypeInfo::Unknown();
270 }
271
Steve Blocka7e24c12009-10-30 11:49:00 +0000272 void AddDeferred(DeferredCode* code) { deferred_.Add(code); }
273
Kristian Monsen25f61362010-05-21 11:50:48 +0100274 // Constants related to patching of inlined load/store.
Steve Block8defd9f2010-07-08 12:39:36 +0100275 static int GetInlinedKeyedLoadInstructionsAfterPatch() {
Iain Merrick75681382010-08-19 15:07:18 +0100276 return FLAG_debug_code ? 32 : 13;
Steve Block8defd9f2010-07-08 12:39:36 +0100277 }
Leon Clarkef7060e22010-06-03 12:02:55 +0100278 static const int kInlinedKeyedStoreInstructionsAfterPatch = 5;
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100279 static int GetInlinedNamedStoreInstructionsAfterPatch() {
280 ASSERT(inlined_write_barrier_size_ != -1);
281 return inlined_write_barrier_size_ + 4;
282 }
Kristian Monsen25f61362010-05-21 11:50:48 +0100283
Iain Merrick75681382010-08-19 15:07:18 +0100284 static MemOperand ContextOperand(Register context, int index) {
285 return MemOperand(context, Context::SlotOffset(index));
286 }
287
Steve Blocka7e24c12009-10-30 11:49:00 +0000288 private:
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100289 // Type of a member function that generates inline code for a native function.
290 typedef void (CodeGenerator::*InlineFunctionGenerator)
291 (ZoneList<Expression*>*);
292
293 static const InlineFunctionGenerator kInlineFunctionGenerators[];
294
Steve Blocka7e24c12009-10-30 11:49:00 +0000295 // Construction/Destruction
Andrei Popescu31002712010-02-23 13:46:05 +0000296 explicit CodeGenerator(MacroAssembler* masm);
Steve Blocka7e24c12009-10-30 11:49:00 +0000297
298 // Accessors
Andrei Popescu31002712010-02-23 13:46:05 +0000299 inline bool is_eval();
Steve Block6ded16b2010-05-10 14:33:55 +0100300 inline Scope* scope();
Steve Blocka7e24c12009-10-30 11:49:00 +0000301
302 // Generating deferred code.
303 void ProcessDeferred();
304
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100305 static const int kInvalidSlotNumber = -1;
306
307 int NumberOfSlot(Slot* slot);
308
Steve Blocka7e24c12009-10-30 11:49:00 +0000309 // State
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100310 bool has_cc() const { return cc_reg_ != al; }
311 JumpTarget* true_target() const { return state_->true_target(); }
312 JumpTarget* false_target() const { return state_->false_target(); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000313
Steve Block6ded16b2010-05-10 14:33:55 +0100314 // Track loop nesting level.
315 int loop_nesting() const { return loop_nesting_; }
316 void IncrementLoopNesting() { loop_nesting_++; }
317 void DecrementLoopNesting() { loop_nesting_--; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000318
319 // Node visitors.
320 void VisitStatements(ZoneList<Statement*>* statements);
321
322#define DEF_VISIT(type) \
323 void Visit##type(type* node);
324 AST_NODE_LIST(DEF_VISIT)
325#undef DEF_VISIT
326
Steve Blocka7e24c12009-10-30 11:49:00 +0000327 // Main code generation function
Andrei Popescu402d9372010-02-26 13:31:12 +0000328 void Generate(CompilationInfo* info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000329
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100330 // Generate the return sequence code. Should be called no more than
331 // once per compiled function, immediately after binding the return
332 // target (which can not be done more than once). The return value should
333 // be in r0.
334 void GenerateReturnSequence();
335
Steve Block6ded16b2010-05-10 14:33:55 +0100336 // Returns the arguments allocation mode.
337 ArgumentsAllocationMode ArgumentsMode();
338
339 // Store the arguments object and allocate it if necessary.
340 void StoreArgumentsObject(bool initial);
341
Steve Blocka7e24c12009-10-30 11:49:00 +0000342 // The following are used by class Reference.
343 void LoadReference(Reference* ref);
344 void UnloadReference(Reference* ref);
345
Steve Blocka7e24c12009-10-30 11:49:00 +0000346 MemOperand SlotOperand(Slot* slot, Register tmp);
347
348 MemOperand ContextSlotOperandCheckExtensions(Slot* slot,
349 Register tmp,
350 Register tmp2,
351 JumpTarget* slow);
352
353 // Expressions
Steve Block3ce2e202009-11-05 08:53:23 +0000354 static MemOperand GlobalObject() {
Steve Blocka7e24c12009-10-30 11:49:00 +0000355 return ContextOperand(cp, Context::GLOBAL_INDEX);
356 }
357
358 void LoadCondition(Expression* x,
Steve Blocka7e24c12009-10-30 11:49:00 +0000359 JumpTarget* true_target,
360 JumpTarget* false_target,
361 bool force_cc);
Steve Blockd0582a62009-12-15 09:54:21 +0000362 void Load(Expression* expr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000363 void LoadGlobal();
364 void LoadGlobalReceiver(Register scratch);
365
Steve Blocka7e24c12009-10-30 11:49:00 +0000366 // Read a value from a slot and leave it on top of the expression stack.
367 void LoadFromSlot(Slot* slot, TypeofState typeof_state);
Steve Block6ded16b2010-05-10 14:33:55 +0100368 void LoadFromSlotCheckForArguments(Slot* slot, TypeofState state);
Kristian Monsen25f61362010-05-21 11:50:48 +0100369
Leon Clarkee46be812010-01-19 14:06:41 +0000370 // Store the value on top of the stack to a slot.
371 void StoreToSlot(Slot* slot, InitState init_state);
Steve Block6ded16b2010-05-10 14:33:55 +0100372
373 // Support for compiling assignment expressions.
374 void EmitSlotAssignment(Assignment* node);
375 void EmitNamedPropertyAssignment(Assignment* node);
376 void EmitKeyedPropertyAssignment(Assignment* node);
377
378 // Load a named property, returning it in r0. The receiver is passed on the
379 // stack, and remains there.
380 void EmitNamedLoad(Handle<String> name, bool is_contextual);
381
382 // Store to a named property. If the store is contextual, value is passed on
383 // the frame and consumed. Otherwise, receiver and value are passed on the
384 // frame and consumed. The result is returned in r0.
385 void EmitNamedStore(Handle<String> name, bool is_contextual);
386
Leon Clarked91b9f72010-01-27 17:25:45 +0000387 // Load a keyed property, leaving it in r0. The receiver and key are
388 // passed on the stack, and remain there.
Steve Block6ded16b2010-05-10 14:33:55 +0100389 void EmitKeyedLoad();
390
391 // Store a keyed property. Key and receiver are on the stack and the value is
392 // in r0. Result is returned in r0.
Steve Block8defd9f2010-07-08 12:39:36 +0100393 void EmitKeyedStore(StaticType* key_type, WriteBarrierCharacter wb_info);
Leon Clarkee46be812010-01-19 14:06:41 +0000394
Steve Blocka7e24c12009-10-30 11:49:00 +0000395 void LoadFromGlobalSlotCheckExtensions(Slot* slot,
396 TypeofState typeof_state,
Steve Blocka7e24c12009-10-30 11:49:00 +0000397 JumpTarget* slow);
398
Kristian Monsen25f61362010-05-21 11:50:48 +0100399 // Support for loading from local/global variables and arguments
400 // whose location is known unless they are shadowed by
401 // eval-introduced bindings. Generates no code for unsupported slot
402 // types and therefore expects to fall through to the slow jump target.
403 void EmitDynamicLoadFromSlotFastCase(Slot* slot,
404 TypeofState typeof_state,
405 JumpTarget* slow,
406 JumpTarget* done);
407
Steve Blocka7e24c12009-10-30 11:49:00 +0000408 // Special code for typeof expressions: Unfortunately, we must
409 // be careful when loading the expression in 'typeof'
410 // expressions. We are not allowed to throw reference errors for
411 // non-existing properties of the global object, so we must make it
412 // look like an explicit property access, instead of an access
413 // through the context chain.
414 void LoadTypeofExpression(Expression* x);
415
416 void ToBoolean(JumpTarget* true_target, JumpTarget* false_target);
417
Steve Block6ded16b2010-05-10 14:33:55 +0100418 // Generate code that computes a shortcutting logical operation.
419 void GenerateLogicalBooleanOperation(BinaryOperation* node);
420
Steve Blocka7e24c12009-10-30 11:49:00 +0000421 void GenericBinaryOperation(Token::Value op,
422 OverwriteMode overwrite_mode,
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100423 GenerateInlineSmi inline_smi,
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100424 int known_rhs =
425 GenericBinaryOpStub::kUnknownIntValue);
Steve Blocka7e24c12009-10-30 11:49:00 +0000426 void Comparison(Condition cc,
427 Expression* left,
428 Expression* right,
429 bool strict = false);
430
431 void SmiOperation(Token::Value op,
432 Handle<Object> value,
433 bool reversed,
434 OverwriteMode mode);
435
Leon Clarkee46be812010-01-19 14:06:41 +0000436 void CallWithArguments(ZoneList<Expression*>* arguments,
437 CallFunctionFlags flags,
438 int position);
Steve Blocka7e24c12009-10-30 11:49:00 +0000439
Steve Block6ded16b2010-05-10 14:33:55 +0100440 // An optimized implementation of expressions of the form
441 // x.apply(y, arguments). We call x the applicand and y the receiver.
442 // The optimization avoids allocating an arguments object if possible.
443 void CallApplyLazy(Expression* applicand,
444 Expression* receiver,
445 VariableProxy* arguments,
446 int position);
447
Steve Blocka7e24c12009-10-30 11:49:00 +0000448 // Control flow
449 void Branch(bool if_true, JumpTarget* target);
450 void CheckStack();
451
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100452 static InlineFunctionGenerator FindInlineFunctionGenerator(
453 Runtime::FunctionId function_id);
Steve Blocka7e24c12009-10-30 11:49:00 +0000454
Steve Blocka7e24c12009-10-30 11:49:00 +0000455 bool CheckForInlineRuntimeCall(CallRuntime* node);
Steve Blocka7e24c12009-10-30 11:49:00 +0000456
Steve Block3ce2e202009-11-05 08:53:23 +0000457 static Handle<Code> ComputeLazyCompile(int argc);
Steve Blocka7e24c12009-10-30 11:49:00 +0000458 void ProcessDeclarations(ZoneList<Declaration*>* declarations);
459
Steve Block3ce2e202009-11-05 08:53:23 +0000460 static Handle<Code> ComputeCallInitialize(int argc, InLoopFlag in_loop);
Steve Blocka7e24c12009-10-30 11:49:00 +0000461
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100462 static Handle<Code> ComputeKeyedCallInitialize(int argc, InLoopFlag in_loop);
463
Steve Blocka7e24c12009-10-30 11:49:00 +0000464 // Declare global variables and functions in the given array of
465 // name/value pairs.
466 void DeclareGlobals(Handle<FixedArray> pairs);
467
Steve Block6ded16b2010-05-10 14:33:55 +0100468 // Instantiate the function based on the shared function info.
469 void InstantiateFunction(Handle<SharedFunctionInfo> function_info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000470
471 // Support for type checks.
472 void GenerateIsSmi(ZoneList<Expression*>* args);
473 void GenerateIsNonNegativeSmi(ZoneList<Expression*>* args);
474 void GenerateIsArray(ZoneList<Expression*>* args);
Andrei Popescu402d9372010-02-26 13:31:12 +0000475 void GenerateIsRegExp(ZoneList<Expression*>* args);
Steve Blockd0582a62009-12-15 09:54:21 +0000476 void GenerateIsObject(ZoneList<Expression*>* args);
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100477 void GenerateIsSpecObject(ZoneList<Expression*>* args);
Steve Blockd0582a62009-12-15 09:54:21 +0000478 void GenerateIsFunction(ZoneList<Expression*>* args);
Leon Clarked91b9f72010-01-27 17:25:45 +0000479 void GenerateIsUndetectableObject(ZoneList<Expression*>* args);
Iain Merrick75681382010-08-19 15:07:18 +0100480 void GenerateIsStringWrapperSafeForDefaultValueOf(
481 ZoneList<Expression*>* args);
Steve Blocka7e24c12009-10-30 11:49:00 +0000482
483 // Support for construct call checks.
484 void GenerateIsConstructCall(ZoneList<Expression*>* args);
485
486 // Support for arguments.length and arguments[?].
487 void GenerateArgumentsLength(ZoneList<Expression*>* args);
Steve Block6ded16b2010-05-10 14:33:55 +0100488 void GenerateArguments(ZoneList<Expression*>* args);
Steve Blocka7e24c12009-10-30 11:49:00 +0000489
490 // Support for accessing the class and value fields of an object.
491 void GenerateClassOf(ZoneList<Expression*>* args);
492 void GenerateValueOf(ZoneList<Expression*>* args);
493 void GenerateSetValueOf(ZoneList<Expression*>* args);
494
495 // Fast support for charCodeAt(n).
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100496 void GenerateStringCharCodeAt(ZoneList<Expression*>* args);
Steve Blocka7e24c12009-10-30 11:49:00 +0000497
Steve Block6ded16b2010-05-10 14:33:55 +0100498 // Fast support for string.charAt(n) and string[n].
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100499 void GenerateStringCharFromCode(ZoneList<Expression*>* args);
500
501 // Fast support for string.charAt(n) and string[n].
502 void GenerateStringCharAt(ZoneList<Expression*>* args);
Steve Block6ded16b2010-05-10 14:33:55 +0100503
Steve Blocka7e24c12009-10-30 11:49:00 +0000504 // Fast support for object equality testing.
505 void GenerateObjectEquals(ZoneList<Expression*>* args);
506
507 void GenerateLog(ZoneList<Expression*>* args);
508
509 // Fast support for Math.random().
Steve Block6ded16b2010-05-10 14:33:55 +0100510 void GenerateRandomHeapNumber(ZoneList<Expression*>* args);
Steve Blocka7e24c12009-10-30 11:49:00 +0000511
Steve Blockd0582a62009-12-15 09:54:21 +0000512 // Fast support for StringAdd.
513 void GenerateStringAdd(ZoneList<Expression*>* args);
514
Leon Clarkee46be812010-01-19 14:06:41 +0000515 // Fast support for SubString.
516 void GenerateSubString(ZoneList<Expression*>* args);
517
518 // Fast support for StringCompare.
519 void GenerateStringCompare(ZoneList<Expression*>* args);
520
521 // Support for direct calls from JavaScript to native RegExp code.
522 void GenerateRegExpExec(ZoneList<Expression*>* args);
523
Steve Block6ded16b2010-05-10 14:33:55 +0100524 void GenerateRegExpConstructResult(ZoneList<Expression*>* args);
525
Steve Block791712a2010-08-27 10:21:07 +0100526 void GenerateRegExpCloneResult(ZoneList<Expression*>* args);
527
Steve Block6ded16b2010-05-10 14:33:55 +0100528 // Support for fast native caches.
529 void GenerateGetFromCache(ZoneList<Expression*>* args);
530
Andrei Popescu402d9372010-02-26 13:31:12 +0000531 // Fast support for number to string.
532 void GenerateNumberToString(ZoneList<Expression*>* args);
533
Steve Block6ded16b2010-05-10 14:33:55 +0100534 // Fast swapping of elements.
535 void GenerateSwapElements(ZoneList<Expression*>* args);
536
537 // Fast call for custom callbacks.
538 void GenerateCallFunction(ZoneList<Expression*>* args);
539
540 // Fast call to math functions.
541 void GenerateMathPow(ZoneList<Expression*>* args);
Andrei Popescu402d9372010-02-26 13:31:12 +0000542 void GenerateMathSin(ZoneList<Expression*>* args);
543 void GenerateMathCos(ZoneList<Expression*>* args);
Steve Block6ded16b2010-05-10 14:33:55 +0100544 void GenerateMathSqrt(ZoneList<Expression*>* args);
Andrei Popescu402d9372010-02-26 13:31:12 +0000545
Ben Murdochbb769b22010-08-11 14:56:33 +0100546 void GenerateIsRegExpEquivalent(ZoneList<Expression*>* args);
547
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100548 void GenerateHasCachedArrayIndex(ZoneList<Expression*>* args);
549 void GenerateGetCachedArrayIndex(ZoneList<Expression*>* args);
550
Steve Block3ce2e202009-11-05 08:53:23 +0000551 // Simple condition analysis.
552 enum ConditionAnalysis {
553 ALWAYS_TRUE,
554 ALWAYS_FALSE,
555 DONT_KNOW
556 };
557 ConditionAnalysis AnalyzeCondition(Expression* cond);
558
Steve Blocka7e24c12009-10-30 11:49:00 +0000559 // Methods used to indicate which source code is generated for. Source
560 // positions are collected by the assembler and emitted with the relocation
561 // information.
562 void CodeForFunctionPosition(FunctionLiteral* fun);
563 void CodeForReturnPosition(FunctionLiteral* fun);
564 void CodeForStatementPosition(Statement* node);
Steve Blockd0582a62009-12-15 09:54:21 +0000565 void CodeForDoWhileConditionPosition(DoWhileStatement* stmt);
Steve Blocka7e24c12009-10-30 11:49:00 +0000566 void CodeForSourcePosition(int pos);
567
568#ifdef DEBUG
569 // True if the registers are valid for entry to a block.
570 bool HasValidEntryRegisters();
571#endif
572
Steve Blocka7e24c12009-10-30 11:49:00 +0000573 List<DeferredCode*> deferred_;
574
575 // Assembler
576 MacroAssembler* masm_; // to generate code
577
Andrei Popescu31002712010-02-23 13:46:05 +0000578 CompilationInfo* info_;
579
Steve Blocka7e24c12009-10-30 11:49:00 +0000580 // Code generation state
Steve Blocka7e24c12009-10-30 11:49:00 +0000581 VirtualFrame* frame_;
582 RegisterAllocator* allocator_;
583 Condition cc_reg_;
584 CodeGenState* state_;
Steve Block6ded16b2010-05-10 14:33:55 +0100585 int loop_nesting_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000586
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100587 Vector<TypeInfo>* type_info_;
588
Steve Blocka7e24c12009-10-30 11:49:00 +0000589 // Jump targets
590 BreakTarget function_return_;
591
592 // True if the function return is shadowed (ie, jumping to the target
593 // function_return_ does not jump to the true function return, but rather
594 // to some unlinking code).
595 bool function_return_is_shadowed_;
596
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100597 // Size of inlined write barriers generated by EmitNamedStore.
598 static int inlined_write_barrier_size_;
599
Steve Blocka7e24c12009-10-30 11:49:00 +0000600 friend class VirtualFrame;
601 friend class JumpTarget;
602 friend class Reference;
Leon Clarke4515c472010-02-03 11:58:03 +0000603 friend class FastCodeGenerator;
Leon Clarked91b9f72010-01-27 17:25:45 +0000604 friend class FullCodeGenerator;
605 friend class FullCodeGenSyntaxChecker;
Steve Blocka7e24c12009-10-30 11:49:00 +0000606
607 DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
608};
609
610
Steve Blocka7e24c12009-10-30 11:49:00 +0000611} } // namespace v8::internal
612
613#endif // V8_ARM_CODEGEN_ARM_H_