blob: 43f4d8771fcc55628bf0573eddf4752e2f7f5968 [file] [log] [blame]
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +00001// Copyright 2010 the V8 project authors. All rights reserved.
ager@chromium.org7c537e22008-10-16 08:43:32 +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
ager@chromium.org5ec48922009-05-05 07:25:34 +000028#ifndef V8_ARM_CODEGEN_ARM_H_
29#define V8_ARM_CODEGEN_ARM_H_
ager@chromium.org7c537e22008-10-16 08:43:32 +000030
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +000031#include "ast.h"
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +000032#include "code-stubs-arm.h"
33#include "ic-inl.h"
ager@chromium.org357bf652010-04-12 11:30:10 +000034
kasperl@chromium.org71affb52009-05-26 05:44:31 +000035namespace v8 {
36namespace internal {
ager@chromium.org7c537e22008-10-16 08:43:32 +000037
38// Forward declarations
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +000039class CompilationInfo;
ager@chromium.org7c537e22008-10-16 08:43:32 +000040class DeferredCode;
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +000041class JumpTarget;
ager@chromium.orgbb29dc92009-03-24 13:25:23 +000042class RegisterAllocator;
43class RegisterFile;
ager@chromium.org7c537e22008-10-16 08:43:32 +000044
ager@chromium.org3bf7b912008-11-17 09:09:45 +000045enum InitState { CONST_INIT, NOT_CONST_INIT };
46enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF };
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +000047enum GenerateInlineSmi { DONT_GENERATE_INLINE_SMI, GENERATE_INLINE_SMI };
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +000048enum WriteBarrierCharacter { UNLIKELY_SMI, LIKELY_SMI, NEVER_NEWSPACE };
ager@chromium.org7c537e22008-10-16 08:43:32 +000049
ager@chromium.org3bf7b912008-11-17 09:09:45 +000050
51// -------------------------------------------------------------------------
ager@chromium.org7c537e22008-10-16 08:43:32 +000052// Reference support
53
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +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.
ager@chromium.org7c537e22008-10-16 08:43:32 +000059class Reference BASE_EMBEDDED {
60 public:
61 // The values of the types is important, see size().
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +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);
ager@chromium.org7c537e22008-10-16 08:43:32 +000066 ~Reference();
67
68 Expression* expression() const { return expression_; }
69 Type type() const { return type_; }
70 void set_type(Type value) {
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +000071 ASSERT_EQ(ILLEGAL, type_);
ager@chromium.org7c537e22008-10-16 08:43:32 +000072 type_ = value;
73 }
74
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +000075 void set_unloaded() {
76 ASSERT_NE(ILLEGAL, type_);
77 ASSERT_NE(UNLOADED, type_);
78 type_ = UNLOADED;
79 }
ager@chromium.org3bf7b912008-11-17 09:09:45 +000080 // The size the reference takes up on the stack.
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +000081 int size() const {
82 return (type_ < SLOT) ? 0 : type_;
83 }
ager@chromium.org7c537e22008-10-16 08:43:32 +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; }
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +000088 bool is_unloaded() const { return type_ == UNLOADED; }
ager@chromium.org7c537e22008-10-16 08:43:32 +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
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +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.
ager@chromium.orgc4c92722009-11-18 14:12:51 +000098 void GetValue();
ager@chromium.org7c537e22008-10-16 08:43:32 +000099
100 // 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
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +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).
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000105 void SetValue(InitState init_state, WriteBarrierCharacter wb);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000106
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000107 // 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
ager@chromium.org7c537e22008-10-16 08:43:32 +0000112 private:
113 CodeGenerator* cgen_;
114 Expression* expression_;
115 Type type_;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000116 // Keep the reference on the stack after get, so it can be used by set later.
117 bool persist_after_get_;
ager@chromium.org7c537e22008-10-16 08:43:32 +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
ager@chromium.org7c537e22008-10-16 08:43:32 +0000135 // Destroy a code generator state and restore the owning code generator's
136 // previous state.
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +0000137 virtual ~CodeGenState();
ager@chromium.org7c537e22008-10-16 08:43:32 +0000138
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +0000139 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_; }
ager@chromium.org7c537e22008-10-16 08:43:32 +0000145
146 private:
147 CodeGenerator* owner_;
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +0000148 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:
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000164 JumpTarget* true_target_;
165 JumpTarget* false_target_;
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +0000166};
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_;
ager@chromium.org7c537e22008-10-16 08:43:32 +0000184};
185
186
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000187// -------------------------------------------------------------------------
fschneider@chromium.org013f3e12010-04-26 13:27:52 +0000188// 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,
lrn@chromium.orgc34f5802010-04-28 12:53:43 +0000201 PROPERTY_ACCESS_INLINED
fschneider@chromium.org013f3e12010-04-26 13:27:52 +0000202};
203
204
205// -------------------------------------------------------------------------
ager@chromium.org7c537e22008-10-16 08:43:32 +0000206// CodeGenerator
207
ager@chromium.orga74f0da2008-12-03 16:05:52 +0000208class CodeGenerator: public AstVisitor {
ager@chromium.org7c537e22008-10-16 08:43:32 +0000209 public:
ager@chromium.orgb61a0d12010-10-13 08:35:23 +0000210 static bool MakeCode(CompilationInfo* info);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000211
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000212 // Printing of AST, etc. as requested by flags.
ager@chromium.org5c838252010-02-19 08:53:10 +0000213 static void MakeCodePrologue(CompilationInfo* info);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000214
215 // Allocate and install the code.
ager@chromium.org5c838252010-02-19 08:53:10 +0000216 static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm,
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000217 Code::Flags flags,
ager@chromium.org5c838252010-02-19 08:53:10 +0000218 CompilationInfo* info);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000219
christian.plesner.hansen@gmail.comaca49682009-01-07 14:29:04 +0000220#ifdef ENABLE_LOGGING_AND_PROFILING
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000221 static bool ShouldGenerateLog(Expression* type);
christian.plesner.hansen@gmail.comaca49682009-01-07 14:29:04 +0000222#endif
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000223
ager@chromium.org7c537e22008-10-16 08:43:32 +0000224 static void SetFunctionInfo(Handle<JSFunction> fun,
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000225 FunctionLiteral* lit,
ager@chromium.org7c537e22008-10-16 08:43:32 +0000226 bool is_toplevel,
sgjesse@chromium.org911335c2009-08-19 12:59:44 +0000227 Handle<Script> script);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000228
vegorov@chromium.org2356e6f2010-06-09 09:38:56 +0000229 static bool RecordPositions(MacroAssembler* masm,
230 int pos,
231 bool right_here = false);
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000232
ager@chromium.org7c537e22008-10-16 08:43:32 +0000233 // Accessors
234 MacroAssembler* masm() { return masm_; }
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000235 VirtualFrame* frame() const { return frame_; }
ager@chromium.org5c838252010-02-19 08:53:10 +0000236 inline Handle<Script> script();
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000237
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000238 bool has_valid_frame() const { return frame_ != NULL; }
239
240 // Set the virtual frame to be new_frame, with non-frame register
241 // reference counts given by non_frame_registers. The non-frame
242 // register reference counts of the old frame are returned in
243 // non_frame_registers.
244 void SetFrame(VirtualFrame* new_frame, RegisterFile* non_frame_registers);
245
246 void DeleteFrame();
247
248 RegisterAllocator* allocator() const { return allocator_; }
249
ager@chromium.org7c537e22008-10-16 08:43:32 +0000250 CodeGenState* state() { return state_; }
251 void set_state(CodeGenState* state) { state_ = state; }
252
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +0000253 TypeInfo type_info(Slot* slot) {
254 int index = NumberOfSlot(slot);
255 if (index == kInvalidSlotNumber) return TypeInfo::Unknown();
256 return (*type_info_)[index];
257 }
258
259 TypeInfo set_type_info(Slot* slot, TypeInfo info) {
260 int index = NumberOfSlot(slot);
261 ASSERT(index >= kInvalidSlotNumber);
262 if (index != kInvalidSlotNumber) {
263 TypeInfo previous_value = (*type_info_)[index];
264 (*type_info_)[index] = info;
265 return previous_value;
266 }
267 return TypeInfo::Unknown();
268 }
269
ager@chromium.org7c537e22008-10-16 08:43:32 +0000270 void AddDeferred(DeferredCode* code) { deferred_.Add(code); }
271
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +0000272 // Constants related to patching of inlined load/store.
fschneider@chromium.org40b9da32010-06-28 11:29:21 +0000273 static int GetInlinedKeyedLoadInstructionsAfterPatch() {
ricow@chromium.org0b9f8502010-08-18 07:45:01 +0000274 return FLAG_debug_code ? 32 : 13;
fschneider@chromium.org40b9da32010-06-28 11:29:21 +0000275 }
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +0000276 static const int kInlinedKeyedStoreInstructionsAfterPatch = 5;
whesse@chromium.orgba5a61b2010-07-26 11:44:40 +0000277 static int GetInlinedNamedStoreInstructionsAfterPatch() {
278 ASSERT(inlined_write_barrier_size_ != -1);
279 return inlined_write_barrier_size_ + 4;
280 }
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +0000281
ager@chromium.orgea4f62e2010-08-16 16:28:43 +0000282 static MemOperand ContextOperand(Register context, int index) {
283 return MemOperand(context, Context::SlotOffset(index));
284 }
285
ager@chromium.org7c537e22008-10-16 08:43:32 +0000286 private:
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000287 // Type of a member function that generates inline code for a native function.
288 typedef void (CodeGenerator::*InlineFunctionGenerator)
289 (ZoneList<Expression*>*);
290
291 static const InlineFunctionGenerator kInlineFunctionGenerators[];
292
ager@chromium.org7c537e22008-10-16 08:43:32 +0000293 // Construction/Destruction
ager@chromium.org5c838252010-02-19 08:53:10 +0000294 explicit CodeGenerator(MacroAssembler* masm);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000295
296 // Accessors
ager@chromium.org5c838252010-02-19 08:53:10 +0000297 inline bool is_eval();
sgjesse@chromium.org833cdd72010-02-26 10:06:16 +0000298 inline Scope* scope();
ager@chromium.org7c537e22008-10-16 08:43:32 +0000299
sgjesse@chromium.org755c5b12009-05-29 11:04:38 +0000300 // Generating deferred code.
ager@chromium.org7c537e22008-10-16 08:43:32 +0000301 void ProcessDeferred();
302
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +0000303 static const int kInvalidSlotNumber = -1;
304
305 int NumberOfSlot(Slot* slot);
306
ager@chromium.org7c537e22008-10-16 08:43:32 +0000307 // State
whesse@chromium.org4a1fe7d2010-09-27 12:32:04 +0000308 bool has_cc() const { return cc_reg_ != al; }
309 JumpTarget* true_target() const { return state_->true_target(); }
310 JumpTarget* false_target() const { return state_->false_target(); }
ager@chromium.org7c537e22008-10-16 08:43:32 +0000311
ricow@chromium.orgc9c80822010-04-21 08:22:37 +0000312 // Track loop nesting level.
313 int loop_nesting() const { return loop_nesting_; }
314 void IncrementLoopNesting() { loop_nesting_++; }
315 void DecrementLoopNesting() { loop_nesting_--; }
ager@chromium.org7c537e22008-10-16 08:43:32 +0000316
317 // Node visitors.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000318 void VisitStatements(ZoneList<Statement*>* statements);
319
ager@chromium.org7c537e22008-10-16 08:43:32 +0000320#define DEF_VISIT(type) \
321 void Visit##type(type* node);
sgjesse@chromium.org0b6db592009-07-30 14:48:31 +0000322 AST_NODE_LIST(DEF_VISIT)
ager@chromium.org7c537e22008-10-16 08:43:32 +0000323#undef DEF_VISIT
324
325 // Main code generation function
fschneider@chromium.orgb95b98b2010-02-23 10:34:29 +0000326 void Generate(CompilationInfo* info);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000327
whesse@chromium.org2c186ca2010-06-16 11:32:39 +0000328 // Generate the return sequence code. Should be called no more than
329 // once per compiled function, immediately after binding the return
330 // target (which can not be done more than once). The return value should
331 // be in r0.
332 void GenerateReturnSequence();
333
fschneider@chromium.org013f3e12010-04-26 13:27:52 +0000334 // Returns the arguments allocation mode.
335 ArgumentsAllocationMode ArgumentsMode();
336
337 // Store the arguments object and allocate it if necessary.
338 void StoreArgumentsObject(bool initial);
339
ager@chromium.org7c537e22008-10-16 08:43:32 +0000340 // The following are used by class Reference.
341 void LoadReference(Reference* ref);
342 void UnloadReference(Reference* ref);
343
ager@chromium.org7c537e22008-10-16 08:43:32 +0000344 MemOperand SlotOperand(Slot* slot, Register tmp);
345
ager@chromium.org381abbb2009-02-25 13:23:22 +0000346 MemOperand ContextSlotOperandCheckExtensions(Slot* slot,
347 Register tmp,
348 Register tmp2,
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000349 JumpTarget* slow);
ager@chromium.org381abbb2009-02-25 13:23:22 +0000350
ager@chromium.org7c537e22008-10-16 08:43:32 +0000351 // Expressions
ager@chromium.org3811b432009-10-28 14:53:37 +0000352 static MemOperand GlobalObject() {
ager@chromium.org7c537e22008-10-16 08:43:32 +0000353 return ContextOperand(cp, Context::GLOBAL_INDEX);
354 }
355
356 void LoadCondition(Expression* x,
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000357 JumpTarget* true_target,
358 JumpTarget* false_target,
ager@chromium.org7c537e22008-10-16 08:43:32 +0000359 bool force_cc);
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000360 void Load(Expression* expr);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000361 void LoadGlobal();
kasperl@chromium.org5a8ca6c2008-10-23 13:57:19 +0000362 void LoadGlobalReceiver(Register scratch);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000363
364 // Read a value from a slot and leave it on top of the expression stack.
365 void LoadFromSlot(Slot* slot, TypeofState typeof_state);
fschneider@chromium.org013f3e12010-04-26 13:27:52 +0000366 void LoadFromSlotCheckForArguments(Slot* slot, TypeofState state);
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +0000367
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000368 // Store the value on top of the stack to a slot.
369 void StoreToSlot(Slot* slot, InitState init_state);
ricow@chromium.orgc9c80822010-04-21 08:22:37 +0000370
ager@chromium.orgac091b72010-05-05 07:34:42 +0000371 // Support for compiling assignment expressions.
372 void EmitSlotAssignment(Assignment* node);
373 void EmitNamedPropertyAssignment(Assignment* node);
374 void EmitKeyedPropertyAssignment(Assignment* node);
375
376 // Load a named property, returning it in r0. The receiver is passed on the
fschneider@chromium.org013f3e12010-04-26 13:27:52 +0000377 // stack, and remains there.
378 void EmitNamedLoad(Handle<String> name, bool is_contextual);
379
ager@chromium.orgac091b72010-05-05 07:34:42 +0000380 // Store to a named property. If the store is contextual, value is passed on
381 // the frame and consumed. Otherwise, receiver and value are passed on the
382 // frame and consumed. The result is returned in r0.
383 void EmitNamedStore(Handle<String> name, bool is_contextual);
384
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000385 // Load a keyed property, leaving it in r0. The receiver and key are
386 // passed on the stack, and remain there.
lrn@chromium.orgc34f5802010-04-28 12:53:43 +0000387 void EmitKeyedLoad();
388
389 // Store a keyed property. Key and receiver are on the stack and the value is
390 // in r0. Result is returned in r0.
kmillikin@chromium.org69ea3962010-07-05 11:01:40 +0000391 void EmitKeyedStore(StaticType* key_type, WriteBarrierCharacter wb_info);
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000392
ager@chromium.org381abbb2009-02-25 13:23:22 +0000393 void LoadFromGlobalSlotCheckExtensions(Slot* slot,
394 TypeofState typeof_state,
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000395 JumpTarget* slow);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000396
vegorov@chromium.orgdff694e2010-05-17 09:10:26 +0000397 // Support for loading from local/global variables and arguments
398 // whose location is known unless they are shadowed by
399 // eval-introduced bindings. Generates no code for unsupported slot
400 // types and therefore expects to fall through to the slow jump target.
401 void EmitDynamicLoadFromSlotFastCase(Slot* slot,
402 TypeofState typeof_state,
403 JumpTarget* slow,
404 JumpTarget* done);
405
ager@chromium.org7c537e22008-10-16 08:43:32 +0000406 // Special code for typeof expressions: Unfortunately, we must
407 // be careful when loading the expression in 'typeof'
408 // expressions. We are not allowed to throw reference errors for
409 // non-existing properties of the global object, so we must make it
410 // look like an explicit property access, instead of an access
411 // through the context chain.
412 void LoadTypeofExpression(Expression* x);
413
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000414 void ToBoolean(JumpTarget* true_target, JumpTarget* false_target);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000415
ager@chromium.orgb26c50a2010-03-26 09:27:16 +0000416 // Generate code that computes a shortcutting logical operation.
417 void GenerateLogicalBooleanOperation(BinaryOperation* node);
418
kasperl@chromium.org86f77b72009-07-06 08:21:57 +0000419 void GenericBinaryOperation(Token::Value op,
420 OverwriteMode overwrite_mode,
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +0000421 GenerateInlineSmi inline_smi,
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000422 int known_rhs =
423 GenericBinaryOpStub::kUnknownIntValue);
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000424 void Comparison(Condition cc,
425 Expression* left,
426 Expression* right,
427 bool strict = false);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000428
ager@chromium.org65dad4b2009-04-23 08:48:43 +0000429 void SmiOperation(Token::Value op,
430 Handle<Object> value,
431 bool reversed,
432 OverwriteMode mode);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000433
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000434 void CallWithArguments(ZoneList<Expression*>* arguments,
435 CallFunctionFlags flags,
436 int position);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000437
fschneider@chromium.org013f3e12010-04-26 13:27:52 +0000438 // An optimized implementation of expressions of the form
439 // x.apply(y, arguments). We call x the applicand and y the receiver.
440 // The optimization avoids allocating an arguments object if possible.
441 void CallApplyLazy(Expression* applicand,
442 Expression* receiver,
443 VariableProxy* arguments,
444 int position);
445
ager@chromium.org7c537e22008-10-16 08:43:32 +0000446 // Control flow
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000447 void Branch(bool if_true, JumpTarget* target);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000448 void CheckStack();
ager@chromium.org7c537e22008-10-16 08:43:32 +0000449
erik.corry@gmail.comd88afa22010-09-15 12:33:05 +0000450 static InlineFunctionGenerator FindInlineFunctionGenerator(
451 Runtime::FunctionId function_id);
ager@chromium.org9085a012009-05-11 19:22:57 +0000452
ager@chromium.org7c537e22008-10-16 08:43:32 +0000453 bool CheckForInlineRuntimeCall(CallRuntime* node);
ager@chromium.org9085a012009-05-11 19:22:57 +0000454
ager@chromium.org3811b432009-10-28 14:53:37 +0000455 static Handle<Code> ComputeLazyCompile(int argc);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000456 void ProcessDeclarations(ZoneList<Declaration*>* declarations);
457
ager@chromium.org3811b432009-10-28 14:53:37 +0000458 static Handle<Code> ComputeCallInitialize(int argc, InLoopFlag in_loop);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000459
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +0000460 static Handle<Code> ComputeKeyedCallInitialize(int argc, InLoopFlag in_loop);
461
ager@chromium.org7c537e22008-10-16 08:43:32 +0000462 // Declare global variables and functions in the given array of
463 // name/value pairs.
464 void DeclareGlobals(Handle<FixedArray> pairs);
465
kmillikin@chromium.org5d8f0e62010-03-24 08:21:20 +0000466 // Instantiate the function based on the shared function info.
467 void InstantiateFunction(Handle<SharedFunctionInfo> function_info);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000468
469 // Support for type checks.
470 void GenerateIsSmi(ZoneList<Expression*>* args);
471 void GenerateIsNonNegativeSmi(ZoneList<Expression*>* args);
472 void GenerateIsArray(ZoneList<Expression*>* args);
fschneider@chromium.orgb95b98b2010-02-23 10:34:29 +0000473 void GenerateIsRegExp(ZoneList<Expression*>* args);
ager@chromium.org6141cbe2009-11-20 12:14:52 +0000474 void GenerateIsObject(ZoneList<Expression*>* args);
ricow@chromium.org4980dff2010-07-19 08:33:45 +0000475 void GenerateIsSpecObject(ZoneList<Expression*>* args);
ager@chromium.org6141cbe2009-11-20 12:14:52 +0000476 void GenerateIsFunction(ZoneList<Expression*>* args);
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000477 void GenerateIsUndetectableObject(ZoneList<Expression*>* args);
ager@chromium.orgea4f62e2010-08-16 16:28:43 +0000478 void GenerateIsStringWrapperSafeForDefaultValueOf(
479 ZoneList<Expression*>* args);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000480
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000481 // Support for construct call checks.
482 void GenerateIsConstructCall(ZoneList<Expression*>* args);
483
ager@chromium.org7c537e22008-10-16 08:43:32 +0000484 // Support for arguments.length and arguments[?].
485 void GenerateArgumentsLength(ZoneList<Expression*>* args);
vegorov@chromium.orgf8372902010-03-15 10:26:20 +0000486 void GenerateArguments(ZoneList<Expression*>* args);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000487
kasperl@chromium.org2abc4502009-07-02 07:00:29 +0000488 // Support for accessing the class and value fields of an object.
489 void GenerateClassOf(ZoneList<Expression*>* args);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000490 void GenerateValueOf(ZoneList<Expression*>* args);
491 void GenerateSetValueOf(ZoneList<Expression*>* args);
492
493 // Fast support for charCodeAt(n).
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000494 void GenerateStringCharCodeAt(ZoneList<Expression*>* args);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000495
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000496 // Fast support for string.charAt(n) and string[n].
ricow@chromium.org30ce4112010-05-31 10:38:25 +0000497 void GenerateStringCharFromCode(ZoneList<Expression*>* args);
498
499 // Fast support for string.charAt(n) and string[n].
500 void GenerateStringCharAt(ZoneList<Expression*>* args);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000501
ager@chromium.org7c537e22008-10-16 08:43:32 +0000502 // Fast support for object equality testing.
503 void GenerateObjectEquals(ZoneList<Expression*>* args);
504
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000505 void GenerateLog(ZoneList<Expression*>* args);
506
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000507 // Fast support for Math.random().
ager@chromium.org357bf652010-04-12 11:30:10 +0000508 void GenerateRandomHeapNumber(ZoneList<Expression*>* args);
ager@chromium.orgeadaf222009-06-16 09:43:10 +0000509
sgjesse@chromium.orgac6aa172009-12-04 12:29:05 +0000510 // Fast support for StringAdd.
511 void GenerateStringAdd(ZoneList<Expression*>* args);
512
fschneider@chromium.org0c20e672010-01-14 15:28:53 +0000513 // Fast support for SubString.
514 void GenerateSubString(ZoneList<Expression*>* args);
515
516 // Fast support for StringCompare.
517 void GenerateStringCompare(ZoneList<Expression*>* args);
518
519 // Support for direct calls from JavaScript to native RegExp code.
520 void GenerateRegExpExec(ZoneList<Expression*>* args);
521
whesse@chromium.orgb6e43bb2010-04-14 09:36:28 +0000522 void GenerateRegExpConstructResult(ZoneList<Expression*>* args);
523
erik.corry@gmail.com145eff52010-08-23 11:36:18 +0000524 void GenerateRegExpCloneResult(ZoneList<Expression*>* args);
525
ricow@chromium.orgc9c80822010-04-21 08:22:37 +0000526 // Support for fast native caches.
527 void GenerateGetFromCache(ZoneList<Expression*>* args);
528
ager@chromium.org5c838252010-02-19 08:53:10 +0000529 // Fast support for number to string.
530 void GenerateNumberToString(ZoneList<Expression*>* args);
531
kmillikin@chromium.org4111b802010-05-03 10:34:42 +0000532 // Fast swapping of elements.
533 void GenerateSwapElements(ZoneList<Expression*>* args);
534
ager@chromium.org357bf652010-04-12 11:30:10 +0000535 // Fast call for custom callbacks.
536 void GenerateCallFunction(ZoneList<Expression*>* args);
537
vegorov@chromium.orgf8372902010-03-15 10:26:20 +0000538 // Fast call to math functions.
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000539 void GenerateMathPow(ZoneList<Expression*>* args);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000540 void GenerateMathSin(ZoneList<Expression*>* args);
541 void GenerateMathCos(ZoneList<Expression*>* args);
ager@chromium.orgce5e87b2010-03-10 10:24:18 +0000542 void GenerateMathSqrt(ZoneList<Expression*>* args);
543
lrn@chromium.orgc4e51ac2010-08-09 09:47:21 +0000544 void GenerateIsRegExpEquivalent(ZoneList<Expression*>* args);
545
ricow@chromium.orgd236f4d2010-09-01 06:52:08 +0000546 void GenerateHasCachedArrayIndex(ZoneList<Expression*>* args);
547 void GenerateGetCachedArrayIndex(ZoneList<Expression*>* args);
548
christian.plesner.hansen@gmail.com9d58c2b2009-10-16 11:48:38 +0000549 // Simple condition analysis.
550 enum ConditionAnalysis {
551 ALWAYS_TRUE,
552 ALWAYS_FALSE,
553 DONT_KNOW
554 };
555 ConditionAnalysis AnalyzeCondition(Expression* cond);
556
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000557 // Methods used to indicate which source code is generated for. Source
558 // positions are collected by the assembler and emitted with the relocation
559 // information.
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000560 void CodeForFunctionPosition(FunctionLiteral* fun);
kasperl@chromium.org8ccb0be2009-04-07 07:21:39 +0000561 void CodeForReturnPosition(FunctionLiteral* fun);
sgjesse@chromium.orgc5145742009-10-07 09:00:33 +0000562 void CodeForStatementPosition(Statement* node);
ager@chromium.orgc4c92722009-11-18 14:12:51 +0000563 void CodeForDoWhileConditionPosition(DoWhileStatement* stmt);
christian.plesner.hansen@gmail.com37abdec2009-01-06 14:43:28 +0000564 void CodeForSourcePosition(int pos);
ager@chromium.org7c537e22008-10-16 08:43:32 +0000565
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000566#ifdef DEBUG
567 // True if the registers are valid for entry to a block.
568 bool HasValidEntryRegisters();
569#endif
570
ager@chromium.org7c537e22008-10-16 08:43:32 +0000571 List<DeferredCode*> deferred_;
572
573 // Assembler
574 MacroAssembler* masm_; // to generate code
575
ager@chromium.org5c838252010-02-19 08:53:10 +0000576 CompilationInfo* info_;
577
ager@chromium.org7c537e22008-10-16 08:43:32 +0000578 // Code generation state
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000579 VirtualFrame* frame_;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000580 RegisterAllocator* allocator_;
ager@chromium.org7c537e22008-10-16 08:43:32 +0000581 Condition cc_reg_;
582 CodeGenState* state_;
ricow@chromium.orgc9c80822010-04-21 08:22:37 +0000583 int loop_nesting_;
ager@chromium.org7c537e22008-10-16 08:43:32 +0000584
lrn@chromium.org1af7e1b2010-06-07 11:12:01 +0000585 Vector<TypeInfo>* type_info_;
586
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000587 // Jump targets
588 BreakTarget function_return_;
589
590 // True if the function return is shadowed (ie, jumping to the target
591 // function_return_ does not jump to the true function return, but rather
592 // to some unlinking code).
593 bool function_return_is_shadowed_;
594
whesse@chromium.orgba5a61b2010-07-26 11:44:40 +0000595 // Size of inlined write barriers generated by EmitNamedStore.
596 static int inlined_write_barrier_size_;
597
ager@chromium.org3bf7b912008-11-17 09:09:45 +0000598 friend class VirtualFrame;
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000599 friend class JumpTarget;
ager@chromium.org7c537e22008-10-16 08:43:32 +0000600 friend class Reference;
ager@chromium.org3811b432009-10-28 14:53:37 +0000601 friend class FastCodeGenerator;
sgjesse@chromium.orgb302e562010-02-03 11:26:59 +0000602 friend class FullCodeGenerator;
603 friend class FullCodeGenSyntaxChecker;
ager@chromium.org7c537e22008-10-16 08:43:32 +0000604
605 DISALLOW_COPY_AND_ASSIGN(CodeGenerator);
606};
607
kasperl@chromium.org7be3c992009-03-12 07:19:55 +0000608
ager@chromium.org7c537e22008-10-16 08:43:32 +0000609} } // namespace v8::internal
610
ager@chromium.org5ec48922009-05-05 07:25:34 +0000611#endif // V8_ARM_CODEGEN_ARM_H_