blob: 1930f5e1a46346bc029423982dc7fddbdbeea90b [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
Steve Block6ded16b2010-05-10 14:33:55 +0100197// -------------------------------------------------------------------------
Steve Blocka7e24c12009-10-30 11:49:00 +0000198// CodeGenerator
199
200class CodeGenerator: public AstVisitor {
201 public:
Ben Murdochf87a2032010-10-22 12:50:53 +0100202 static bool MakeCode(CompilationInfo* info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000203
Steve Block3ce2e202009-11-05 08:53:23 +0000204 // Printing of AST, etc. as requested by flags.
Andrei Popescu31002712010-02-23 13:46:05 +0000205 static void MakeCodePrologue(CompilationInfo* info);
Steve Block3ce2e202009-11-05 08:53:23 +0000206
207 // Allocate and install the code.
Andrei Popescu31002712010-02-23 13:46:05 +0000208 static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm,
Steve Block3ce2e202009-11-05 08:53:23 +0000209 Code::Flags flags,
Andrei Popescu31002712010-02-23 13:46:05 +0000210 CompilationInfo* info);
Steve Block3ce2e202009-11-05 08:53:23 +0000211
Steve Blocka7e24c12009-10-30 11:49:00 +0000212#ifdef ENABLE_LOGGING_AND_PROFILING
213 static bool ShouldGenerateLog(Expression* type);
214#endif
215
216 static void SetFunctionInfo(Handle<JSFunction> fun,
217 FunctionLiteral* lit,
218 bool is_toplevel,
219 Handle<Script> script);
220
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100221 static bool RecordPositions(MacroAssembler* masm,
222 int pos,
223 bool right_here = false);
Steve Block3ce2e202009-11-05 08:53:23 +0000224
Steve Blocka7e24c12009-10-30 11:49:00 +0000225 // Accessors
226 MacroAssembler* masm() { return masm_; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000227 VirtualFrame* frame() const { return frame_; }
Andrei Popescu31002712010-02-23 13:46:05 +0000228 inline Handle<Script> script();
Steve Blocka7e24c12009-10-30 11:49:00 +0000229
230 bool has_valid_frame() const { return frame_ != NULL; }
231
232 // Set the virtual frame to be new_frame, with non-frame register
233 // reference counts given by non_frame_registers. The non-frame
234 // register reference counts of the old frame are returned in
235 // non_frame_registers.
236 void SetFrame(VirtualFrame* new_frame, RegisterFile* non_frame_registers);
237
238 void DeleteFrame();
239
240 RegisterAllocator* allocator() const { return allocator_; }
241
242 CodeGenState* state() { return state_; }
243 void set_state(CodeGenState* state) { state_ = state; }
244
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100245 TypeInfo type_info(Slot* slot) {
246 int index = NumberOfSlot(slot);
247 if (index == kInvalidSlotNumber) return TypeInfo::Unknown();
248 return (*type_info_)[index];
249 }
250
251 TypeInfo set_type_info(Slot* slot, TypeInfo info) {
252 int index = NumberOfSlot(slot);
253 ASSERT(index >= kInvalidSlotNumber);
254 if (index != kInvalidSlotNumber) {
255 TypeInfo previous_value = (*type_info_)[index];
256 (*type_info_)[index] = info;
257 return previous_value;
258 }
259 return TypeInfo::Unknown();
260 }
261
Steve Blocka7e24c12009-10-30 11:49:00 +0000262 void AddDeferred(DeferredCode* code) { deferred_.Add(code); }
263
Kristian Monsen25f61362010-05-21 11:50:48 +0100264 // Constants related to patching of inlined load/store.
Steve Block8defd9f2010-07-08 12:39:36 +0100265 static int GetInlinedKeyedLoadInstructionsAfterPatch() {
Iain Merrick75681382010-08-19 15:07:18 +0100266 return FLAG_debug_code ? 32 : 13;
Steve Block8defd9f2010-07-08 12:39:36 +0100267 }
Leon Clarkef7060e22010-06-03 12:02:55 +0100268 static const int kInlinedKeyedStoreInstructionsAfterPatch = 5;
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100269 static int GetInlinedNamedStoreInstructionsAfterPatch() {
270 ASSERT(inlined_write_barrier_size_ != -1);
271 return inlined_write_barrier_size_ + 4;
272 }
Kristian Monsen25f61362010-05-21 11:50:48 +0100273
Steve Blocka7e24c12009-10-30 11:49:00 +0000274 private:
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100275 // Type of a member function that generates inline code for a native function.
276 typedef void (CodeGenerator::*InlineFunctionGenerator)
277 (ZoneList<Expression*>*);
278
279 static const InlineFunctionGenerator kInlineFunctionGenerators[];
280
Steve Blocka7e24c12009-10-30 11:49:00 +0000281 // Construction/Destruction
Andrei Popescu31002712010-02-23 13:46:05 +0000282 explicit CodeGenerator(MacroAssembler* masm);
Steve Blocka7e24c12009-10-30 11:49:00 +0000283
284 // Accessors
Andrei Popescu31002712010-02-23 13:46:05 +0000285 inline bool is_eval();
Steve Block6ded16b2010-05-10 14:33:55 +0100286 inline Scope* scope();
Steve Blocka7e24c12009-10-30 11:49:00 +0000287
288 // Generating deferred code.
289 void ProcessDeferred();
290
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100291 static const int kInvalidSlotNumber = -1;
292
293 int NumberOfSlot(Slot* slot);
294
Steve Blocka7e24c12009-10-30 11:49:00 +0000295 // State
Kristian Monsen0d5e1162010-09-30 15:31:59 +0100296 bool has_cc() const { return cc_reg_ != al; }
297 JumpTarget* true_target() const { return state_->true_target(); }
298 JumpTarget* false_target() const { return state_->false_target(); }
Steve Blocka7e24c12009-10-30 11:49:00 +0000299
Steve Block6ded16b2010-05-10 14:33:55 +0100300 // Track loop nesting level.
301 int loop_nesting() const { return loop_nesting_; }
302 void IncrementLoopNesting() { loop_nesting_++; }
303 void DecrementLoopNesting() { loop_nesting_--; }
Steve Blocka7e24c12009-10-30 11:49:00 +0000304
305 // Node visitors.
306 void VisitStatements(ZoneList<Statement*>* statements);
307
308#define DEF_VISIT(type) \
309 void Visit##type(type* node);
310 AST_NODE_LIST(DEF_VISIT)
311#undef DEF_VISIT
312
Steve Blocka7e24c12009-10-30 11:49:00 +0000313 // Main code generation function
Andrei Popescu402d9372010-02-26 13:31:12 +0000314 void Generate(CompilationInfo* info);
Steve Blocka7e24c12009-10-30 11:49:00 +0000315
Kristian Monsen9dcf7e22010-06-28 14:14:28 +0100316 // Generate the return sequence code. Should be called no more than
317 // once per compiled function, immediately after binding the return
318 // target (which can not be done more than once). The return value should
319 // be in r0.
320 void GenerateReturnSequence();
321
Steve Block6ded16b2010-05-10 14:33:55 +0100322 // Returns the arguments allocation mode.
323 ArgumentsAllocationMode ArgumentsMode();
324
325 // Store the arguments object and allocate it if necessary.
326 void StoreArgumentsObject(bool initial);
327
Steve Blocka7e24c12009-10-30 11:49:00 +0000328 // The following are used by class Reference.
329 void LoadReference(Reference* ref);
330 void UnloadReference(Reference* ref);
331
Steve Blocka7e24c12009-10-30 11:49:00 +0000332 MemOperand SlotOperand(Slot* slot, Register tmp);
333
334 MemOperand ContextSlotOperandCheckExtensions(Slot* slot,
335 Register tmp,
336 Register tmp2,
337 JumpTarget* slow);
338
339 // Expressions
Steve Blocka7e24c12009-10-30 11:49:00 +0000340 void LoadCondition(Expression* x,
Steve Blocka7e24c12009-10-30 11:49:00 +0000341 JumpTarget* true_target,
342 JumpTarget* false_target,
343 bool force_cc);
Steve Blockd0582a62009-12-15 09:54:21 +0000344 void Load(Expression* expr);
Steve Blocka7e24c12009-10-30 11:49:00 +0000345 void LoadGlobal();
346 void LoadGlobalReceiver(Register scratch);
347
Steve Blocka7e24c12009-10-30 11:49:00 +0000348 // Read a value from a slot and leave it on top of the expression stack.
349 void LoadFromSlot(Slot* slot, TypeofState typeof_state);
Steve Block6ded16b2010-05-10 14:33:55 +0100350 void LoadFromSlotCheckForArguments(Slot* slot, TypeofState state);
Kristian Monsen25f61362010-05-21 11:50:48 +0100351
Leon Clarkee46be812010-01-19 14:06:41 +0000352 // Store the value on top of the stack to a slot.
353 void StoreToSlot(Slot* slot, InitState init_state);
Steve Block6ded16b2010-05-10 14:33:55 +0100354
355 // Support for compiling assignment expressions.
356 void EmitSlotAssignment(Assignment* node);
357 void EmitNamedPropertyAssignment(Assignment* node);
358 void EmitKeyedPropertyAssignment(Assignment* node);
359
360 // Load a named property, returning it in r0. The receiver is passed on the
361 // stack, and remains there.
362 void EmitNamedLoad(Handle<String> name, bool is_contextual);
363
364 // Store to a named property. If the store is contextual, value is passed on
365 // the frame and consumed. Otherwise, receiver and value are passed on the
366 // frame and consumed. The result is returned in r0.
367 void EmitNamedStore(Handle<String> name, bool is_contextual);
368
Leon Clarked91b9f72010-01-27 17:25:45 +0000369 // Load a keyed property, leaving it in r0. The receiver and key are
370 // passed on the stack, and remain there.
Steve Block6ded16b2010-05-10 14:33:55 +0100371 void EmitKeyedLoad();
372
373 // Store a keyed property. Key and receiver are on the stack and the value is
374 // in r0. Result is returned in r0.
Steve Block8defd9f2010-07-08 12:39:36 +0100375 void EmitKeyedStore(StaticType* key_type, WriteBarrierCharacter wb_info);
Leon Clarkee46be812010-01-19 14:06:41 +0000376
Steve Blocka7e24c12009-10-30 11:49:00 +0000377 void LoadFromGlobalSlotCheckExtensions(Slot* slot,
378 TypeofState typeof_state,
Steve Blocka7e24c12009-10-30 11:49:00 +0000379 JumpTarget* slow);
380
Kristian Monsen25f61362010-05-21 11:50:48 +0100381 // Support for loading from local/global variables and arguments
382 // whose location is known unless they are shadowed by
383 // eval-introduced bindings. Generates no code for unsupported slot
384 // types and therefore expects to fall through to the slow jump target.
385 void EmitDynamicLoadFromSlotFastCase(Slot* slot,
386 TypeofState typeof_state,
387 JumpTarget* slow,
388 JumpTarget* done);
389
Steve Blocka7e24c12009-10-30 11:49:00 +0000390 // Special code for typeof expressions: Unfortunately, we must
391 // be careful when loading the expression in 'typeof'
392 // expressions. We are not allowed to throw reference errors for
393 // non-existing properties of the global object, so we must make it
394 // look like an explicit property access, instead of an access
395 // through the context chain.
396 void LoadTypeofExpression(Expression* x);
397
398 void ToBoolean(JumpTarget* true_target, JumpTarget* false_target);
399
Steve Block6ded16b2010-05-10 14:33:55 +0100400 // Generate code that computes a shortcutting logical operation.
401 void GenerateLogicalBooleanOperation(BinaryOperation* node);
402
Steve Blocka7e24c12009-10-30 11:49:00 +0000403 void GenericBinaryOperation(Token::Value op,
404 OverwriteMode overwrite_mode,
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100405 GenerateInlineSmi inline_smi,
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100406 int known_rhs =
407 GenericBinaryOpStub::kUnknownIntValue);
Steve Blocka7e24c12009-10-30 11:49:00 +0000408 void Comparison(Condition cc,
409 Expression* left,
410 Expression* right,
411 bool strict = false);
412
413 void SmiOperation(Token::Value op,
414 Handle<Object> value,
415 bool reversed,
416 OverwriteMode mode);
417
Leon Clarkee46be812010-01-19 14:06:41 +0000418 void CallWithArguments(ZoneList<Expression*>* arguments,
419 CallFunctionFlags flags,
420 int position);
Steve Blocka7e24c12009-10-30 11:49:00 +0000421
Steve Block6ded16b2010-05-10 14:33:55 +0100422 // An optimized implementation of expressions of the form
423 // x.apply(y, arguments). We call x the applicand and y the receiver.
424 // The optimization avoids allocating an arguments object if possible.
425 void CallApplyLazy(Expression* applicand,
426 Expression* receiver,
427 VariableProxy* arguments,
428 int position);
429
Steve Blocka7e24c12009-10-30 11:49:00 +0000430 // Control flow
431 void Branch(bool if_true, JumpTarget* target);
432 void CheckStack();
433
Steve Blocka7e24c12009-10-30 11:49:00 +0000434 bool CheckForInlineRuntimeCall(CallRuntime* node);
Steve Blocka7e24c12009-10-30 11:49:00 +0000435
Steve Block3ce2e202009-11-05 08:53:23 +0000436 static Handle<Code> ComputeLazyCompile(int argc);
Steve Blocka7e24c12009-10-30 11:49:00 +0000437 void ProcessDeclarations(ZoneList<Declaration*>* declarations);
438
Steve Blocka7e24c12009-10-30 11:49:00 +0000439 // Declare global variables and functions in the given array of
440 // name/value pairs.
441 void DeclareGlobals(Handle<FixedArray> pairs);
442
Steve Block6ded16b2010-05-10 14:33:55 +0100443 // Instantiate the function based on the shared function info.
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800444 void InstantiateFunction(Handle<SharedFunctionInfo> function_info,
445 bool pretenure);
Steve Blocka7e24c12009-10-30 11:49:00 +0000446
447 // Support for type checks.
448 void GenerateIsSmi(ZoneList<Expression*>* args);
449 void GenerateIsNonNegativeSmi(ZoneList<Expression*>* args);
450 void GenerateIsArray(ZoneList<Expression*>* args);
Andrei Popescu402d9372010-02-26 13:31:12 +0000451 void GenerateIsRegExp(ZoneList<Expression*>* args);
Steve Blockd0582a62009-12-15 09:54:21 +0000452 void GenerateIsObject(ZoneList<Expression*>* args);
Ben Murdoch3bec4d22010-07-22 14:51:16 +0100453 void GenerateIsSpecObject(ZoneList<Expression*>* args);
Steve Blockd0582a62009-12-15 09:54:21 +0000454 void GenerateIsFunction(ZoneList<Expression*>* args);
Leon Clarked91b9f72010-01-27 17:25:45 +0000455 void GenerateIsUndetectableObject(ZoneList<Expression*>* args);
Iain Merrick75681382010-08-19 15:07:18 +0100456 void GenerateIsStringWrapperSafeForDefaultValueOf(
457 ZoneList<Expression*>* args);
Steve Blocka7e24c12009-10-30 11:49:00 +0000458
459 // Support for construct call checks.
460 void GenerateIsConstructCall(ZoneList<Expression*>* args);
461
462 // Support for arguments.length and arguments[?].
463 void GenerateArgumentsLength(ZoneList<Expression*>* args);
Steve Block6ded16b2010-05-10 14:33:55 +0100464 void GenerateArguments(ZoneList<Expression*>* args);
Steve Blocka7e24c12009-10-30 11:49:00 +0000465
466 // Support for accessing the class and value fields of an object.
467 void GenerateClassOf(ZoneList<Expression*>* args);
468 void GenerateValueOf(ZoneList<Expression*>* args);
469 void GenerateSetValueOf(ZoneList<Expression*>* args);
470
471 // Fast support for charCodeAt(n).
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100472 void GenerateStringCharCodeAt(ZoneList<Expression*>* args);
Steve Blocka7e24c12009-10-30 11:49:00 +0000473
Steve Block6ded16b2010-05-10 14:33:55 +0100474 // Fast support for string.charAt(n) and string[n].
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100475 void GenerateStringCharFromCode(ZoneList<Expression*>* args);
476
477 // Fast support for string.charAt(n) and string[n].
478 void GenerateStringCharAt(ZoneList<Expression*>* args);
Steve Block6ded16b2010-05-10 14:33:55 +0100479
Steve Blocka7e24c12009-10-30 11:49:00 +0000480 // Fast support for object equality testing.
481 void GenerateObjectEquals(ZoneList<Expression*>* args);
482
483 void GenerateLog(ZoneList<Expression*>* args);
484
485 // Fast support for Math.random().
Steve Block6ded16b2010-05-10 14:33:55 +0100486 void GenerateRandomHeapNumber(ZoneList<Expression*>* args);
Steve Blocka7e24c12009-10-30 11:49:00 +0000487
Steve Blockd0582a62009-12-15 09:54:21 +0000488 // Fast support for StringAdd.
489 void GenerateStringAdd(ZoneList<Expression*>* args);
490
Leon Clarkee46be812010-01-19 14:06:41 +0000491 // Fast support for SubString.
492 void GenerateSubString(ZoneList<Expression*>* args);
493
494 // Fast support for StringCompare.
495 void GenerateStringCompare(ZoneList<Expression*>* args);
496
497 // Support for direct calls from JavaScript to native RegExp code.
498 void GenerateRegExpExec(ZoneList<Expression*>* args);
499
Steve Block6ded16b2010-05-10 14:33:55 +0100500 void GenerateRegExpConstructResult(ZoneList<Expression*>* args);
501
502 // Support for fast native caches.
503 void GenerateGetFromCache(ZoneList<Expression*>* args);
504
Andrei Popescu402d9372010-02-26 13:31:12 +0000505 // Fast support for number to string.
506 void GenerateNumberToString(ZoneList<Expression*>* args);
507
Steve Block6ded16b2010-05-10 14:33:55 +0100508 // Fast swapping of elements.
509 void GenerateSwapElements(ZoneList<Expression*>* args);
510
511 // Fast call for custom callbacks.
512 void GenerateCallFunction(ZoneList<Expression*>* args);
513
514 // Fast call to math functions.
515 void GenerateMathPow(ZoneList<Expression*>* args);
Andrei Popescu402d9372010-02-26 13:31:12 +0000516 void GenerateMathSin(ZoneList<Expression*>* args);
517 void GenerateMathCos(ZoneList<Expression*>* args);
Steve Block6ded16b2010-05-10 14:33:55 +0100518 void GenerateMathSqrt(ZoneList<Expression*>* args);
Andrei Popescu402d9372010-02-26 13:31:12 +0000519
Ben Murdochbb769b22010-08-11 14:56:33 +0100520 void GenerateIsRegExpEquivalent(ZoneList<Expression*>* args);
521
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100522 void GenerateHasCachedArrayIndex(ZoneList<Expression*>* args);
523 void GenerateGetCachedArrayIndex(ZoneList<Expression*>* args);
Shimeng (Simon) Wang8a31eba2010-12-06 19:01:33 -0800524 void GenerateFastAsciiArrayJoin(ZoneList<Expression*>* args);
Kristian Monsen80d68ea2010-09-08 11:05:35 +0100525
Steve Block3ce2e202009-11-05 08:53:23 +0000526 // Simple condition analysis.
527 enum ConditionAnalysis {
528 ALWAYS_TRUE,
529 ALWAYS_FALSE,
530 DONT_KNOW
531 };
532 ConditionAnalysis AnalyzeCondition(Expression* cond);
533
Steve Blocka7e24c12009-10-30 11:49:00 +0000534 // Methods used to indicate which source code is generated for. Source
535 // positions are collected by the assembler and emitted with the relocation
536 // information.
537 void CodeForFunctionPosition(FunctionLiteral* fun);
538 void CodeForReturnPosition(FunctionLiteral* fun);
539 void CodeForStatementPosition(Statement* node);
Steve Blockd0582a62009-12-15 09:54:21 +0000540 void CodeForDoWhileConditionPosition(DoWhileStatement* stmt);
Steve Blocka7e24c12009-10-30 11:49:00 +0000541 void CodeForSourcePosition(int pos);
542
543#ifdef DEBUG
544 // True if the registers are valid for entry to a block.
545 bool HasValidEntryRegisters();
546#endif
547
Steve Blocka7e24c12009-10-30 11:49:00 +0000548 List<DeferredCode*> deferred_;
549
550 // Assembler
551 MacroAssembler* masm_; // to generate code
552
Andrei Popescu31002712010-02-23 13:46:05 +0000553 CompilationInfo* info_;
554
Steve Blocka7e24c12009-10-30 11:49:00 +0000555 // Code generation state
Steve Blocka7e24c12009-10-30 11:49:00 +0000556 VirtualFrame* frame_;
557 RegisterAllocator* allocator_;
558 Condition cc_reg_;
559 CodeGenState* state_;
Steve Block6ded16b2010-05-10 14:33:55 +0100560 int loop_nesting_;
Steve Blocka7e24c12009-10-30 11:49:00 +0000561
Ben Murdoch7f4d5bd2010-06-15 11:15:29 +0100562 Vector<TypeInfo>* type_info_;
563
Steve Blocka7e24c12009-10-30 11:49:00 +0000564 // Jump targets
565 BreakTarget function_return_;
566
567 // True if the function return is shadowed (ie, jumping to the target
568 // function_return_ does not jump to the true function return, but rather
569 // to some unlinking code).
570 bool function_return_is_shadowed_;
571
Kristian Monsen50ef84f2010-07-29 15:18:00 +0100572 // Size of inlined write barriers generated by EmitNamedStore.
573 static int inlined_write_barrier_size_;
574
Steve Blocka7e24c12009-10-30 11:49:00 +0000575 friend class VirtualFrame;
576 friend class JumpTarget;
577 friend class Reference;
Leon Clarke4515c472010-02-03 11:58:03 +0000578 friend class FastCodeGenerator;
Leon Clarked91b9f72010-01-27 17:25:45 +0000579 friend class FullCodeGenerator;
580 friend class FullCodeGenSyntaxChecker;
Steve Blocka7e24c12009-10-30 11:49:00 +0000581
582 DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
583};
584
585
Steve Blocka7e24c12009-10-30 11:49:00 +0000586} } // namespace v8::internal
587
588#endif // V8_ARM_CODEGEN_ARM_H_