Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1 | // Copyright 2010 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_ARM_CODEGEN_ARM_H_ |
| 29 | #define V8_ARM_CODEGEN_ARM_H_ |
| 30 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 31 | #include "ast.h" |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 32 | #include "code-stubs-arm.h" |
| 33 | #include "ic-inl.h" |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 34 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 35 | namespace v8 { |
| 36 | namespace internal { |
| 37 | |
| 38 | // Forward declarations |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 39 | class CompilationInfo; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 40 | class DeferredCode; |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 41 | class JumpTarget; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 42 | class RegisterAllocator; |
| 43 | class RegisterFile; |
| 44 | |
| 45 | enum InitState { CONST_INIT, NOT_CONST_INIT }; |
| 46 | enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF }; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 47 | enum GenerateInlineSmi { DONT_GENERATE_INLINE_SMI, GENERATE_INLINE_SMI }; |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 48 | enum WriteBarrierCharacter { UNLIKELY_SMI, LIKELY_SMI, NEVER_NEWSPACE }; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 49 | |
| 50 | |
| 51 | // ------------------------------------------------------------------------- |
| 52 | // Reference support |
| 53 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 54 | // 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 Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 59 | class Reference BASE_EMBEDDED { |
| 60 | public: |
| 61 | // The values of the types is important, see size(). |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 62 | 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 Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 66 | ~Reference(); |
| 67 | |
| 68 | Expression* expression() const { return expression_; } |
| 69 | Type type() const { return type_; } |
| 70 | void set_type(Type value) { |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 71 | ASSERT_EQ(ILLEGAL, type_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 72 | type_ = value; |
| 73 | } |
| 74 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 75 | void set_unloaded() { |
| 76 | ASSERT_NE(ILLEGAL, type_); |
| 77 | ASSERT_NE(UNLOADED, type_); |
| 78 | type_ = UNLOADED; |
| 79 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 80 | // The size the reference takes up on the stack. |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 81 | int size() const { |
| 82 | return (type_ < SLOT) ? 0 : type_; |
| 83 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 84 | |
| 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 Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 88 | bool is_unloaded() const { return type_ == UNLOADED; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 89 | |
| 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 Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 95 | // 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 Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 98 | void GetValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 99 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 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 |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 102 | // 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 Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 105 | void SetValue(InitState init_state, WriteBarrierCharacter wb); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 106 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 107 | // 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 Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 112 | private: |
| 113 | CodeGenerator* cgen_; |
| 114 | Expression* expression_; |
| 115 | Type type_; |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 116 | // Keep the reference on the stack after get, so it can be used by set later. |
| 117 | bool persist_after_get_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 118 | }; |
| 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 | |
| 129 | class 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 Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 135 | // Destroy a code generator state and restore the owning code generator's |
| 136 | // previous state. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 137 | virtual ~CodeGenState(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 138 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 139 | 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 Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 145 | |
| 146 | private: |
| 147 | CodeGenerator* owner_; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 148 | CodeGenState* previous_; |
| 149 | }; |
| 150 | |
| 151 | |
| 152 | class 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 Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 164 | JumpTarget* true_target_; |
| 165 | JumpTarget* false_target_; |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | |
| 169 | class 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 Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 184 | }; |
| 185 | |
| 186 | |
| 187 | // ------------------------------------------------------------------------- |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 188 | // Arguments allocation mode |
| 189 | |
| 190 | enum 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. |
| 199 | enum NopMarkerTypes { |
| 200 | NON_MARKING_NOP = 0, |
| 201 | PROPERTY_ACCESS_INLINED |
| 202 | }; |
| 203 | |
| 204 | |
| 205 | // ------------------------------------------------------------------------- |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 206 | // CodeGenerator |
| 207 | |
| 208 | class CodeGenerator: public AstVisitor { |
| 209 | public: |
Ben Murdoch | f87a203 | 2010-10-22 12:50:53 +0100 | [diff] [blame^] | 210 | static bool MakeCode(CompilationInfo* info); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 211 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 212 | // Printing of AST, etc. as requested by flags. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 213 | static void MakeCodePrologue(CompilationInfo* info); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 214 | |
| 215 | // Allocate and install the code. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 216 | static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm, |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 217 | Code::Flags flags, |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 218 | CompilationInfo* info); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 219 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 220 | #ifdef ENABLE_LOGGING_AND_PROFILING |
| 221 | static bool ShouldGenerateLog(Expression* type); |
| 222 | #endif |
| 223 | |
| 224 | static void SetFunctionInfo(Handle<JSFunction> fun, |
| 225 | FunctionLiteral* lit, |
| 226 | bool is_toplevel, |
| 227 | Handle<Script> script); |
| 228 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 229 | static bool RecordPositions(MacroAssembler* masm, |
| 230 | int pos, |
| 231 | bool right_here = false); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 232 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 233 | // Accessors |
| 234 | MacroAssembler* masm() { return masm_; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 235 | VirtualFrame* frame() const { return frame_; } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 236 | inline Handle<Script> script(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 237 | |
| 238 | 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 | |
| 250 | CodeGenState* state() { return state_; } |
| 251 | void set_state(CodeGenState* state) { state_ = state; } |
| 252 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 253 | 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 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 270 | void AddDeferred(DeferredCode* code) { deferred_.Add(code); } |
| 271 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 272 | // Constants related to patching of inlined load/store. |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 273 | static int GetInlinedKeyedLoadInstructionsAfterPatch() { |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 274 | return FLAG_debug_code ? 32 : 13; |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 275 | } |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 276 | static const int kInlinedKeyedStoreInstructionsAfterPatch = 5; |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 277 | static int GetInlinedNamedStoreInstructionsAfterPatch() { |
| 278 | ASSERT(inlined_write_barrier_size_ != -1); |
| 279 | return inlined_write_barrier_size_ + 4; |
| 280 | } |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 281 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 282 | static MemOperand ContextOperand(Register context, int index) { |
| 283 | return MemOperand(context, Context::SlotOffset(index)); |
| 284 | } |
| 285 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 286 | private: |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 287 | // 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 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 293 | // Construction/Destruction |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 294 | explicit CodeGenerator(MacroAssembler* masm); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 295 | |
| 296 | // Accessors |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 297 | inline bool is_eval(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 298 | inline Scope* scope(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 299 | |
| 300 | // Generating deferred code. |
| 301 | void ProcessDeferred(); |
| 302 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 303 | static const int kInvalidSlotNumber = -1; |
| 304 | |
| 305 | int NumberOfSlot(Slot* slot); |
| 306 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 307 | // State |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 308 | 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(); } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 311 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 312 | // Track loop nesting level. |
| 313 | int loop_nesting() const { return loop_nesting_; } |
| 314 | void IncrementLoopNesting() { loop_nesting_++; } |
| 315 | void DecrementLoopNesting() { loop_nesting_--; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 316 | |
| 317 | // Node visitors. |
| 318 | void VisitStatements(ZoneList<Statement*>* statements); |
| 319 | |
| 320 | #define DEF_VISIT(type) \ |
| 321 | void Visit##type(type* node); |
| 322 | AST_NODE_LIST(DEF_VISIT) |
| 323 | #undef DEF_VISIT |
| 324 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 325 | // Main code generation function |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 326 | void Generate(CompilationInfo* info); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 327 | |
Kristian Monsen | 9dcf7e2 | 2010-06-28 14:14:28 +0100 | [diff] [blame] | 328 | // 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 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 334 | // 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 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 340 | // The following are used by class Reference. |
| 341 | void LoadReference(Reference* ref); |
| 342 | void UnloadReference(Reference* ref); |
| 343 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 344 | MemOperand SlotOperand(Slot* slot, Register tmp); |
| 345 | |
| 346 | MemOperand ContextSlotOperandCheckExtensions(Slot* slot, |
| 347 | Register tmp, |
| 348 | Register tmp2, |
| 349 | JumpTarget* slow); |
| 350 | |
| 351 | // Expressions |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 352 | static MemOperand GlobalObject() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 353 | return ContextOperand(cp, Context::GLOBAL_INDEX); |
| 354 | } |
| 355 | |
| 356 | void LoadCondition(Expression* x, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 357 | JumpTarget* true_target, |
| 358 | JumpTarget* false_target, |
| 359 | bool force_cc); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 360 | void Load(Expression* expr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 361 | void LoadGlobal(); |
| 362 | void LoadGlobalReceiver(Register scratch); |
| 363 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 364 | // Read a value from a slot and leave it on top of the expression stack. |
| 365 | void LoadFromSlot(Slot* slot, TypeofState typeof_state); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 366 | void LoadFromSlotCheckForArguments(Slot* slot, TypeofState state); |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 367 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 368 | // Store the value on top of the stack to a slot. |
| 369 | void StoreToSlot(Slot* slot, InitState init_state); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 370 | |
| 371 | // 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 |
| 377 | // stack, and remains there. |
| 378 | void EmitNamedLoad(Handle<String> name, bool is_contextual); |
| 379 | |
| 380 | // 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 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 385 | // Load a keyed property, leaving it in r0. The receiver and key are |
| 386 | // passed on the stack, and remain there. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 387 | 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. |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 391 | void EmitKeyedStore(StaticType* key_type, WriteBarrierCharacter wb_info); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 392 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 393 | void LoadFromGlobalSlotCheckExtensions(Slot* slot, |
| 394 | TypeofState typeof_state, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 395 | JumpTarget* slow); |
| 396 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 397 | // 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 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 406 | // 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 | |
| 414 | void ToBoolean(JumpTarget* true_target, JumpTarget* false_target); |
| 415 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 416 | // Generate code that computes a shortcutting logical operation. |
| 417 | void GenerateLogicalBooleanOperation(BinaryOperation* node); |
| 418 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 419 | void GenericBinaryOperation(Token::Value op, |
| 420 | OverwriteMode overwrite_mode, |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 421 | GenerateInlineSmi inline_smi, |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 422 | int known_rhs = |
| 423 | GenericBinaryOpStub::kUnknownIntValue); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 424 | void Comparison(Condition cc, |
| 425 | Expression* left, |
| 426 | Expression* right, |
| 427 | bool strict = false); |
| 428 | |
| 429 | void SmiOperation(Token::Value op, |
| 430 | Handle<Object> value, |
| 431 | bool reversed, |
| 432 | OverwriteMode mode); |
| 433 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 434 | void CallWithArguments(ZoneList<Expression*>* arguments, |
| 435 | CallFunctionFlags flags, |
| 436 | int position); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 437 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 438 | // 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 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 446 | // Control flow |
| 447 | void Branch(bool if_true, JumpTarget* target); |
| 448 | void CheckStack(); |
| 449 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 450 | bool CheckForInlineRuntimeCall(CallRuntime* node); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 451 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 452 | static Handle<Code> ComputeLazyCompile(int argc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 453 | void ProcessDeclarations(ZoneList<Declaration*>* declarations); |
| 454 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 455 | static Handle<Code> ComputeCallInitialize(int argc, InLoopFlag in_loop); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 456 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 457 | static Handle<Code> ComputeKeyedCallInitialize(int argc, InLoopFlag in_loop); |
| 458 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 459 | // Declare global variables and functions in the given array of |
| 460 | // name/value pairs. |
| 461 | void DeclareGlobals(Handle<FixedArray> pairs); |
| 462 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 463 | // Instantiate the function based on the shared function info. |
| 464 | void InstantiateFunction(Handle<SharedFunctionInfo> function_info); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 465 | |
| 466 | // Support for type checks. |
| 467 | void GenerateIsSmi(ZoneList<Expression*>* args); |
| 468 | void GenerateIsNonNegativeSmi(ZoneList<Expression*>* args); |
| 469 | void GenerateIsArray(ZoneList<Expression*>* args); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 470 | void GenerateIsRegExp(ZoneList<Expression*>* args); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 471 | void GenerateIsObject(ZoneList<Expression*>* args); |
Ben Murdoch | 3bec4d2 | 2010-07-22 14:51:16 +0100 | [diff] [blame] | 472 | void GenerateIsSpecObject(ZoneList<Expression*>* args); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 473 | void GenerateIsFunction(ZoneList<Expression*>* args); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 474 | void GenerateIsUndetectableObject(ZoneList<Expression*>* args); |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 475 | void GenerateIsStringWrapperSafeForDefaultValueOf( |
| 476 | ZoneList<Expression*>* args); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 477 | |
| 478 | // Support for construct call checks. |
| 479 | void GenerateIsConstructCall(ZoneList<Expression*>* args); |
| 480 | |
| 481 | // Support for arguments.length and arguments[?]. |
| 482 | void GenerateArgumentsLength(ZoneList<Expression*>* args); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 483 | void GenerateArguments(ZoneList<Expression*>* args); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 484 | |
| 485 | // Support for accessing the class and value fields of an object. |
| 486 | void GenerateClassOf(ZoneList<Expression*>* args); |
| 487 | void GenerateValueOf(ZoneList<Expression*>* args); |
| 488 | void GenerateSetValueOf(ZoneList<Expression*>* args); |
| 489 | |
| 490 | // Fast support for charCodeAt(n). |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 491 | void GenerateStringCharCodeAt(ZoneList<Expression*>* args); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 492 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 493 | // Fast support for string.charAt(n) and string[n]. |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 494 | void GenerateStringCharFromCode(ZoneList<Expression*>* args); |
| 495 | |
| 496 | // Fast support for string.charAt(n) and string[n]. |
| 497 | void GenerateStringCharAt(ZoneList<Expression*>* args); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 498 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 499 | // Fast support for object equality testing. |
| 500 | void GenerateObjectEquals(ZoneList<Expression*>* args); |
| 501 | |
| 502 | void GenerateLog(ZoneList<Expression*>* args); |
| 503 | |
| 504 | // Fast support for Math.random(). |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 505 | void GenerateRandomHeapNumber(ZoneList<Expression*>* args); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 506 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 507 | // Fast support for StringAdd. |
| 508 | void GenerateStringAdd(ZoneList<Expression*>* args); |
| 509 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 510 | // Fast support for SubString. |
| 511 | void GenerateSubString(ZoneList<Expression*>* args); |
| 512 | |
| 513 | // Fast support for StringCompare. |
| 514 | void GenerateStringCompare(ZoneList<Expression*>* args); |
| 515 | |
| 516 | // Support for direct calls from JavaScript to native RegExp code. |
| 517 | void GenerateRegExpExec(ZoneList<Expression*>* args); |
| 518 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 519 | void GenerateRegExpConstructResult(ZoneList<Expression*>* args); |
| 520 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 521 | void GenerateRegExpCloneResult(ZoneList<Expression*>* args); |
| 522 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 523 | // Support for fast native caches. |
| 524 | void GenerateGetFromCache(ZoneList<Expression*>* args); |
| 525 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 526 | // Fast support for number to string. |
| 527 | void GenerateNumberToString(ZoneList<Expression*>* args); |
| 528 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 529 | // Fast swapping of elements. |
| 530 | void GenerateSwapElements(ZoneList<Expression*>* args); |
| 531 | |
| 532 | // Fast call for custom callbacks. |
| 533 | void GenerateCallFunction(ZoneList<Expression*>* args); |
| 534 | |
| 535 | // Fast call to math functions. |
| 536 | void GenerateMathPow(ZoneList<Expression*>* args); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 537 | void GenerateMathSin(ZoneList<Expression*>* args); |
| 538 | void GenerateMathCos(ZoneList<Expression*>* args); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 539 | void GenerateMathSqrt(ZoneList<Expression*>* args); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 540 | |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 541 | void GenerateIsRegExpEquivalent(ZoneList<Expression*>* args); |
| 542 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 543 | void GenerateHasCachedArrayIndex(ZoneList<Expression*>* args); |
| 544 | void GenerateGetCachedArrayIndex(ZoneList<Expression*>* args); |
| 545 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 546 | // Simple condition analysis. |
| 547 | enum ConditionAnalysis { |
| 548 | ALWAYS_TRUE, |
| 549 | ALWAYS_FALSE, |
| 550 | DONT_KNOW |
| 551 | }; |
| 552 | ConditionAnalysis AnalyzeCondition(Expression* cond); |
| 553 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 554 | // Methods used to indicate which source code is generated for. Source |
| 555 | // positions are collected by the assembler and emitted with the relocation |
| 556 | // information. |
| 557 | void CodeForFunctionPosition(FunctionLiteral* fun); |
| 558 | void CodeForReturnPosition(FunctionLiteral* fun); |
| 559 | void CodeForStatementPosition(Statement* node); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 560 | void CodeForDoWhileConditionPosition(DoWhileStatement* stmt); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 561 | void CodeForSourcePosition(int pos); |
| 562 | |
| 563 | #ifdef DEBUG |
| 564 | // True if the registers are valid for entry to a block. |
| 565 | bool HasValidEntryRegisters(); |
| 566 | #endif |
| 567 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 568 | List<DeferredCode*> deferred_; |
| 569 | |
| 570 | // Assembler |
| 571 | MacroAssembler* masm_; // to generate code |
| 572 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 573 | CompilationInfo* info_; |
| 574 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 575 | // Code generation state |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 576 | VirtualFrame* frame_; |
| 577 | RegisterAllocator* allocator_; |
| 578 | Condition cc_reg_; |
| 579 | CodeGenState* state_; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 580 | int loop_nesting_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 581 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 582 | Vector<TypeInfo>* type_info_; |
| 583 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 584 | // Jump targets |
| 585 | BreakTarget function_return_; |
| 586 | |
| 587 | // True if the function return is shadowed (ie, jumping to the target |
| 588 | // function_return_ does not jump to the true function return, but rather |
| 589 | // to some unlinking code). |
| 590 | bool function_return_is_shadowed_; |
| 591 | |
Kristian Monsen | 50ef84f | 2010-07-29 15:18:00 +0100 | [diff] [blame] | 592 | // Size of inlined write barriers generated by EmitNamedStore. |
| 593 | static int inlined_write_barrier_size_; |
| 594 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 595 | friend class VirtualFrame; |
| 596 | friend class JumpTarget; |
| 597 | friend class Reference; |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 598 | friend class FastCodeGenerator; |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 599 | friend class FullCodeGenerator; |
| 600 | friend class FullCodeGenSyntaxChecker; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 601 | |
| 602 | DISALLOW_COPY_AND_ASSIGN(CodeGenerator); |
| 603 | }; |
| 604 | |
| 605 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 606 | } } // namespace v8::internal |
| 607 | |
| 608 | #endif // V8_ARM_CODEGEN_ARM_H_ |