sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1 | // Copyright 2010 the V8 project authors. All rights reserved. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +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 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 28 | #ifndef V8_ARM_CODEGEN_ARM_H_ |
| 29 | #define V8_ARM_CODEGEN_ARM_H_ |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 30 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 31 | namespace v8 { |
| 32 | namespace internal { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 33 | |
| 34 | // Forward declarations |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 35 | class CompilationInfo; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 36 | class DeferredCode; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 37 | class RegisterAllocator; |
| 38 | class RegisterFile; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 39 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 40 | enum InitState { CONST_INIT, NOT_CONST_INIT }; |
| 41 | enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF }; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 42 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 43 | |
| 44 | // ------------------------------------------------------------------------- |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 45 | // Reference support |
| 46 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 47 | // A reference is a C++ stack-allocated object that puts a |
| 48 | // reference on the virtual frame. The reference may be consumed |
| 49 | // by GetValue, TakeValue, SetValue, and Codegen::UnloadReference. |
| 50 | // When the lifetime (scope) of a valid reference ends, it must have |
| 51 | // been consumed, and be in state UNLOADED. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 52 | class Reference BASE_EMBEDDED { |
| 53 | public: |
| 54 | // The values of the types is important, see size(). |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 55 | enum Type { UNLOADED = -2, ILLEGAL = -1, SLOT = 0, NAMED = 1, KEYED = 2 }; |
| 56 | Reference(CodeGenerator* cgen, |
| 57 | Expression* expression, |
| 58 | bool persist_after_get = false); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 59 | ~Reference(); |
| 60 | |
| 61 | Expression* expression() const { return expression_; } |
| 62 | Type type() const { return type_; } |
| 63 | void set_type(Type value) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 64 | ASSERT_EQ(ILLEGAL, type_); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 65 | type_ = value; |
| 66 | } |
| 67 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 68 | void set_unloaded() { |
| 69 | ASSERT_NE(ILLEGAL, type_); |
| 70 | ASSERT_NE(UNLOADED, type_); |
| 71 | type_ = UNLOADED; |
| 72 | } |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 73 | // The size the reference takes up on the stack. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 74 | int size() const { |
| 75 | return (type_ < SLOT) ? 0 : type_; |
| 76 | } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 77 | |
| 78 | bool is_illegal() const { return type_ == ILLEGAL; } |
| 79 | bool is_slot() const { return type_ == SLOT; } |
| 80 | bool is_property() const { return type_ == NAMED || type_ == KEYED; } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 81 | bool is_unloaded() const { return type_ == UNLOADED; } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 82 | |
| 83 | // Return the name. Only valid for named property references. |
| 84 | Handle<String> GetName(); |
| 85 | |
| 86 | // Generate code to push the value of the reference on top of the |
| 87 | // expression stack. The reference is expected to be already on top of |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 88 | // the expression stack, and it is consumed by the call unless the |
| 89 | // reference is for a compound assignment. |
| 90 | // If the reference is not consumed, it is left in place under its value. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 91 | void GetValue(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 92 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 93 | // Generate code to pop a reference, push the value of the reference, |
| 94 | // and then spill the stack frame. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 95 | inline void GetValueAndSpill(); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 96 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 97 | // Generate code to store the value on top of the expression stack in the |
| 98 | // reference. The reference is expected to be immediately below the value |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 99 | // on the expression stack. The value is stored in the location specified |
| 100 | // by the reference, and is left on top of the stack, after the reference |
| 101 | // is popped from beneath it (unloaded). |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 102 | void SetValue(InitState init_state); |
| 103 | |
| 104 | private: |
| 105 | CodeGenerator* cgen_; |
| 106 | Expression* expression_; |
| 107 | Type type_; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 108 | // Keep the reference on the stack after get, so it can be used by set later. |
| 109 | bool persist_after_get_; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | |
| 113 | // ------------------------------------------------------------------------- |
| 114 | // Code generation state |
| 115 | |
| 116 | // The state is passed down the AST by the code generator (and back up, in |
| 117 | // the form of the state of the label pair). It is threaded through the |
| 118 | // call stack. Constructing a state implicitly pushes it on the owning code |
| 119 | // generator's stack of states, and destroying one implicitly pops it. |
| 120 | |
| 121 | class CodeGenState BASE_EMBEDDED { |
| 122 | public: |
| 123 | // Create an initial code generator state. Destroying the initial state |
| 124 | // leaves the code generator with a NULL state. |
| 125 | explicit CodeGenState(CodeGenerator* owner); |
| 126 | |
| 127 | // Create a code generator state based on a code generator's current |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 128 | // state. The new state has its own pair of branch labels. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 129 | CodeGenState(CodeGenerator* owner, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 130 | JumpTarget* true_target, |
| 131 | JumpTarget* false_target); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 132 | |
| 133 | // Destroy a code generator state and restore the owning code generator's |
| 134 | // previous state. |
| 135 | ~CodeGenState(); |
| 136 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 137 | JumpTarget* true_target() const { return true_target_; } |
| 138 | JumpTarget* false_target() const { return false_target_; } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 139 | |
| 140 | private: |
| 141 | CodeGenerator* owner_; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 142 | JumpTarget* true_target_; |
| 143 | JumpTarget* false_target_; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 144 | CodeGenState* previous_; |
| 145 | }; |
| 146 | |
| 147 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 148 | // ------------------------------------------------------------------------- |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 149 | // CodeGenerator |
| 150 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 151 | class CodeGenerator: public AstVisitor { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 152 | public: |
| 153 | // Takes a function literal, generates code for it. This function should only |
| 154 | // be called by compiler.cc. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 155 | static Handle<Code> MakeCode(CompilationInfo* info); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 156 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 157 | // Printing of AST, etc. as requested by flags. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 158 | static void MakeCodePrologue(CompilationInfo* info); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 159 | |
| 160 | // Allocate and install the code. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 161 | static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm, |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 162 | Code::Flags flags, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 163 | CompilationInfo* info); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 164 | |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 165 | #ifdef ENABLE_LOGGING_AND_PROFILING |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 166 | static bool ShouldGenerateLog(Expression* type); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 167 | #endif |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 168 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 169 | static void SetFunctionInfo(Handle<JSFunction> fun, |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 170 | FunctionLiteral* lit, |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 171 | bool is_toplevel, |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 172 | Handle<Script> script); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 173 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 174 | static void RecordPositions(MacroAssembler* masm, int pos); |
| 175 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 176 | // Accessors |
| 177 | MacroAssembler* masm() { return masm_; } |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 178 | VirtualFrame* frame() const { return frame_; } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 179 | inline Handle<Script> script(); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 180 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 181 | bool has_valid_frame() const { return frame_ != NULL; } |
| 182 | |
| 183 | // Set the virtual frame to be new_frame, with non-frame register |
| 184 | // reference counts given by non_frame_registers. The non-frame |
| 185 | // register reference counts of the old frame are returned in |
| 186 | // non_frame_registers. |
| 187 | void SetFrame(VirtualFrame* new_frame, RegisterFile* non_frame_registers); |
| 188 | |
| 189 | void DeleteFrame(); |
| 190 | |
| 191 | RegisterAllocator* allocator() const { return allocator_; } |
| 192 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 193 | CodeGenState* state() { return state_; } |
| 194 | void set_state(CodeGenState* state) { state_ = state; } |
| 195 | |
| 196 | void AddDeferred(DeferredCode* code) { deferred_.Add(code); } |
| 197 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 198 | static const int kUnknownIntValue = -1; |
| 199 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 200 | // If the name is an inline runtime function call return the number of |
| 201 | // expected arguments. Otherwise return -1. |
| 202 | static int InlineRuntimeCallArgumentsCount(Handle<String> name); |
| 203 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 204 | private: |
| 205 | // Construction/Destruction |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 206 | explicit CodeGenerator(MacroAssembler* masm); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 207 | |
| 208 | // Accessors |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 209 | inline bool is_eval(); |
sgjesse@chromium.org | 833cdd7 | 2010-02-26 10:06:16 +0000 | [diff] [blame] | 210 | inline Scope* scope(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 211 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 212 | // Generating deferred code. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 213 | void ProcessDeferred(); |
| 214 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 215 | // State |
| 216 | bool has_cc() const { return cc_reg_ != al; } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 217 | JumpTarget* true_target() const { return state_->true_target(); } |
| 218 | JumpTarget* false_target() const { return state_->false_target(); } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 219 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 220 | // We don't track loop nesting level on ARM yet. |
| 221 | int loop_nesting() const { return 0; } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 222 | |
| 223 | // Node visitors. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 224 | void VisitStatements(ZoneList<Statement*>* statements); |
| 225 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 226 | #define DEF_VISIT(type) \ |
| 227 | void Visit##type(type* node); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 228 | AST_NODE_LIST(DEF_VISIT) |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 229 | #undef DEF_VISIT |
| 230 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 231 | // Visit a statement and then spill the virtual frame if control flow can |
| 232 | // reach the end of the statement (ie, it does not exit via break, |
| 233 | // continue, return, or throw). This function is used temporarily while |
| 234 | // the code generator is being transformed. |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 235 | inline void VisitAndSpill(Statement* statement); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 236 | |
| 237 | // Visit a list of statements and then spill the virtual frame if control |
| 238 | // flow can reach the end of the list. |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 239 | inline void VisitStatementsAndSpill(ZoneList<Statement*>* statements); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 240 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 241 | // Main code generation function |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 242 | void Generate(CompilationInfo* info); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 243 | |
| 244 | // The following are used by class Reference. |
| 245 | void LoadReference(Reference* ref); |
| 246 | void UnloadReference(Reference* ref); |
| 247 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 248 | static MemOperand ContextOperand(Register context, int index) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 249 | return MemOperand(context, Context::SlotOffset(index)); |
| 250 | } |
| 251 | |
| 252 | MemOperand SlotOperand(Slot* slot, Register tmp); |
| 253 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 254 | MemOperand ContextSlotOperandCheckExtensions(Slot* slot, |
| 255 | Register tmp, |
| 256 | Register tmp2, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 257 | JumpTarget* slow); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 258 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 259 | // Expressions |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 260 | static MemOperand GlobalObject() { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 261 | return ContextOperand(cp, Context::GLOBAL_INDEX); |
| 262 | } |
| 263 | |
| 264 | void LoadCondition(Expression* x, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 265 | JumpTarget* true_target, |
| 266 | JumpTarget* false_target, |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 267 | bool force_cc); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 268 | void Load(Expression* expr); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 269 | void LoadGlobal(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 270 | void LoadGlobalReceiver(Register scratch); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 271 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 272 | // Generate code to push the value of an expression on top of the frame |
| 273 | // and then spill the frame fully to memory. This function is used |
| 274 | // temporarily while the code generator is being transformed. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 275 | inline void LoadAndSpill(Expression* expression); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 276 | |
| 277 | // Call LoadCondition and then spill the virtual frame unless control flow |
| 278 | // cannot reach the end of the expression (ie, by emitting only |
| 279 | // unconditional jumps to the control targets). |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 280 | inline void LoadConditionAndSpill(Expression* expression, |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 281 | JumpTarget* true_target, |
| 282 | JumpTarget* false_target, |
| 283 | bool force_control); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 284 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 285 | // Read a value from a slot and leave it on top of the expression stack. |
| 286 | void LoadFromSlot(Slot* slot, TypeofState typeof_state); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 287 | // Store the value on top of the stack to a slot. |
| 288 | void StoreToSlot(Slot* slot, InitState init_state); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 289 | // Load a keyed property, leaving it in r0. The receiver and key are |
| 290 | // passed on the stack, and remain there. |
| 291 | void EmitKeyedLoad(bool is_global); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 292 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 293 | void LoadFromGlobalSlotCheckExtensions(Slot* slot, |
| 294 | TypeofState typeof_state, |
| 295 | Register tmp, |
| 296 | Register tmp2, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 297 | JumpTarget* slow); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 298 | |
| 299 | // Special code for typeof expressions: Unfortunately, we must |
| 300 | // be careful when loading the expression in 'typeof' |
| 301 | // expressions. We are not allowed to throw reference errors for |
| 302 | // non-existing properties of the global object, so we must make it |
| 303 | // look like an explicit property access, instead of an access |
| 304 | // through the context chain. |
| 305 | void LoadTypeofExpression(Expression* x); |
| 306 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 307 | void ToBoolean(JumpTarget* true_target, JumpTarget* false_target); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 308 | |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame^] | 309 | // Generate code that computes a shortcutting logical operation. |
| 310 | void GenerateLogicalBooleanOperation(BinaryOperation* node); |
| 311 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 312 | void GenericBinaryOperation(Token::Value op, |
| 313 | OverwriteMode overwrite_mode, |
| 314 | int known_rhs = kUnknownIntValue); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 315 | void Comparison(Condition cc, |
| 316 | Expression* left, |
| 317 | Expression* right, |
| 318 | bool strict = false); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 319 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 320 | void SmiOperation(Token::Value op, |
| 321 | Handle<Object> value, |
| 322 | bool reversed, |
| 323 | OverwriteMode mode); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 324 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 325 | void CallWithArguments(ZoneList<Expression*>* arguments, |
| 326 | CallFunctionFlags flags, |
| 327 | int position); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 328 | |
| 329 | // Control flow |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 330 | void Branch(bool if_true, JumpTarget* target); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 331 | void CheckStack(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 332 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 333 | struct InlineRuntimeLUT { |
| 334 | void (CodeGenerator::*method)(ZoneList<Expression*>*); |
| 335 | const char* name; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 336 | int nargs; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 337 | }; |
| 338 | |
| 339 | static InlineRuntimeLUT* FindInlineRuntimeLUT(Handle<String> name); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 340 | bool CheckForInlineRuntimeCall(CallRuntime* node); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 341 | static bool PatchInlineRuntimeEntry(Handle<String> name, |
| 342 | const InlineRuntimeLUT& new_entry, |
| 343 | InlineRuntimeLUT* old_entry); |
| 344 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 345 | static Handle<Code> ComputeLazyCompile(int argc); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 346 | void ProcessDeclarations(ZoneList<Declaration*>* declarations); |
| 347 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 348 | static Handle<Code> ComputeCallInitialize(int argc, InLoopFlag in_loop); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 349 | |
| 350 | // Declare global variables and functions in the given array of |
| 351 | // name/value pairs. |
| 352 | void DeclareGlobals(Handle<FixedArray> pairs); |
| 353 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 354 | // Instantiate the function based on the shared function info. |
| 355 | void InstantiateFunction(Handle<SharedFunctionInfo> function_info); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 356 | |
| 357 | // Support for type checks. |
| 358 | void GenerateIsSmi(ZoneList<Expression*>* args); |
| 359 | void GenerateIsNonNegativeSmi(ZoneList<Expression*>* args); |
| 360 | void GenerateIsArray(ZoneList<Expression*>* args); |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 361 | void GenerateIsRegExp(ZoneList<Expression*>* args); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 362 | void GenerateIsObject(ZoneList<Expression*>* args); |
| 363 | void GenerateIsFunction(ZoneList<Expression*>* args); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 364 | void GenerateIsUndetectableObject(ZoneList<Expression*>* args); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 365 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 366 | // Support for construct call checks. |
| 367 | void GenerateIsConstructCall(ZoneList<Expression*>* args); |
| 368 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 369 | // Support for arguments.length and arguments[?]. |
| 370 | void GenerateArgumentsLength(ZoneList<Expression*>* args); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 371 | void GenerateArguments(ZoneList<Expression*>* args); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 372 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 373 | // Support for accessing the class and value fields of an object. |
| 374 | void GenerateClassOf(ZoneList<Expression*>* args); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 375 | void GenerateValueOf(ZoneList<Expression*>* args); |
| 376 | void GenerateSetValueOf(ZoneList<Expression*>* args); |
| 377 | |
| 378 | // Fast support for charCodeAt(n). |
| 379 | void GenerateFastCharCodeAt(ZoneList<Expression*>* args); |
| 380 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 381 | // Fast support for string.charAt(n) and string[n]. |
| 382 | void GenerateCharFromCode(ZoneList<Expression*>* args); |
| 383 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 384 | // Fast support for object equality testing. |
| 385 | void GenerateObjectEquals(ZoneList<Expression*>* args); |
| 386 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 387 | void GenerateLog(ZoneList<Expression*>* args); |
| 388 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 389 | // Fast support for Math.random(). |
| 390 | void GenerateRandomPositiveSmi(ZoneList<Expression*>* args); |
| 391 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 392 | // Fast support for StringAdd. |
| 393 | void GenerateStringAdd(ZoneList<Expression*>* args); |
| 394 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 395 | // Fast support for SubString. |
| 396 | void GenerateSubString(ZoneList<Expression*>* args); |
| 397 | |
| 398 | // Fast support for StringCompare. |
| 399 | void GenerateStringCompare(ZoneList<Expression*>* args); |
| 400 | |
| 401 | // Support for direct calls from JavaScript to native RegExp code. |
| 402 | void GenerateRegExpExec(ZoneList<Expression*>* args); |
| 403 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 404 | // Fast support for number to string. |
| 405 | void GenerateNumberToString(ZoneList<Expression*>* args); |
| 406 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 407 | // Fast call to math functions. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 408 | void GenerateMathPow(ZoneList<Expression*>* args); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 409 | void GenerateMathSin(ZoneList<Expression*>* args); |
| 410 | void GenerateMathCos(ZoneList<Expression*>* args); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 411 | void GenerateMathSqrt(ZoneList<Expression*>* args); |
| 412 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 413 | // Simple condition analysis. |
| 414 | enum ConditionAnalysis { |
| 415 | ALWAYS_TRUE, |
| 416 | ALWAYS_FALSE, |
| 417 | DONT_KNOW |
| 418 | }; |
| 419 | ConditionAnalysis AnalyzeCondition(Expression* cond); |
| 420 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 421 | // Methods used to indicate which source code is generated for. Source |
| 422 | // positions are collected by the assembler and emitted with the relocation |
| 423 | // information. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 424 | void CodeForFunctionPosition(FunctionLiteral* fun); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 425 | void CodeForReturnPosition(FunctionLiteral* fun); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 426 | void CodeForStatementPosition(Statement* node); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 427 | void CodeForDoWhileConditionPosition(DoWhileStatement* stmt); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 428 | void CodeForSourcePosition(int pos); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 429 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 430 | #ifdef DEBUG |
| 431 | // True if the registers are valid for entry to a block. |
| 432 | bool HasValidEntryRegisters(); |
| 433 | #endif |
| 434 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 435 | List<DeferredCode*> deferred_; |
| 436 | |
| 437 | // Assembler |
| 438 | MacroAssembler* masm_; // to generate code |
| 439 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 440 | CompilationInfo* info_; |
| 441 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 442 | // Code generation state |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 443 | VirtualFrame* frame_; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 444 | RegisterAllocator* allocator_; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 445 | Condition cc_reg_; |
| 446 | CodeGenState* state_; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 447 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 448 | // Jump targets |
| 449 | BreakTarget function_return_; |
| 450 | |
| 451 | // True if the function return is shadowed (ie, jumping to the target |
| 452 | // function_return_ does not jump to the true function return, but rather |
| 453 | // to some unlinking code). |
| 454 | bool function_return_is_shadowed_; |
| 455 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 456 | static InlineRuntimeLUT kInlineRuntimeLUT[]; |
| 457 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 458 | friend class VirtualFrame; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 459 | friend class JumpTarget; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 460 | friend class Reference; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 461 | friend class FastCodeGenerator; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 462 | friend class FullCodeGenerator; |
| 463 | friend class FullCodeGenSyntaxChecker; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 464 | |
| 465 | DISALLOW_COPY_AND_ASSIGN(CodeGenerator); |
| 466 | }; |
| 467 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 468 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 469 | class GenericBinaryOpStub : public CodeStub { |
| 470 | public: |
| 471 | GenericBinaryOpStub(Token::Value op, |
| 472 | OverwriteMode mode, |
| 473 | int constant_rhs = CodeGenerator::kUnknownIntValue) |
| 474 | : op_(op), |
| 475 | mode_(mode), |
| 476 | constant_rhs_(constant_rhs), |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 477 | specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op, constant_rhs)), |
| 478 | name_(NULL) { } |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 479 | |
| 480 | private: |
| 481 | Token::Value op_; |
| 482 | OverwriteMode mode_; |
| 483 | int constant_rhs_; |
| 484 | bool specialized_on_rhs_; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 485 | char* name_; |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 486 | |
| 487 | static const int kMaxKnownRhs = 0x40000000; |
| 488 | |
| 489 | // Minor key encoding in 16 bits. |
| 490 | class ModeBits: public BitField<OverwriteMode, 0, 2> {}; |
| 491 | class OpBits: public BitField<Token::Value, 2, 6> {}; |
| 492 | class KnownIntBits: public BitField<int, 8, 8> {}; |
| 493 | |
| 494 | Major MajorKey() { return GenericBinaryOp; } |
| 495 | int MinorKey() { |
| 496 | // Encode the parameters in a unique 16 bit value. |
| 497 | return OpBits::encode(op_) |
| 498 | | ModeBits::encode(mode_) |
| 499 | | KnownIntBits::encode(MinorKeyForKnownInt()); |
| 500 | } |
| 501 | |
| 502 | void Generate(MacroAssembler* masm); |
| 503 | void HandleNonSmiBitwiseOp(MacroAssembler* masm); |
| 504 | |
| 505 | static bool RhsIsOneWeWantToOptimizeFor(Token::Value op, int constant_rhs) { |
| 506 | if (constant_rhs == CodeGenerator::kUnknownIntValue) return false; |
| 507 | if (op == Token::DIV) return constant_rhs >= 2 && constant_rhs <= 3; |
| 508 | if (op == Token::MOD) { |
| 509 | if (constant_rhs <= 1) return false; |
| 510 | if (constant_rhs <= 10) return true; |
| 511 | if (constant_rhs <= kMaxKnownRhs && IsPowerOf2(constant_rhs)) return true; |
| 512 | return false; |
| 513 | } |
| 514 | return false; |
| 515 | } |
| 516 | |
| 517 | int MinorKeyForKnownInt() { |
| 518 | if (!specialized_on_rhs_) return 0; |
| 519 | if (constant_rhs_ <= 10) return constant_rhs_ + 1; |
| 520 | ASSERT(IsPowerOf2(constant_rhs_)); |
| 521 | int key = 12; |
| 522 | int d = constant_rhs_; |
| 523 | while ((d & 1) == 0) { |
| 524 | key++; |
| 525 | d >>= 1; |
| 526 | } |
| 527 | return key; |
| 528 | } |
| 529 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 530 | const char* GetName(); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 531 | |
| 532 | #ifdef DEBUG |
| 533 | void Print() { |
| 534 | if (!specialized_on_rhs_) { |
| 535 | PrintF("GenericBinaryOpStub (%s)\n", Token::String(op_)); |
| 536 | } else { |
| 537 | PrintF("GenericBinaryOpStub (%s by %d)\n", |
| 538 | Token::String(op_), |
| 539 | constant_rhs_); |
| 540 | } |
| 541 | } |
| 542 | #endif |
| 543 | }; |
| 544 | |
| 545 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 546 | class StringStubBase: public CodeStub { |
| 547 | public: |
| 548 | // Generate code for copying characters using a simple loop. This should only |
| 549 | // be used in places where the number of characters is small and the |
| 550 | // additional setup and checking in GenerateCopyCharactersLong adds too much |
| 551 | // overhead. Copying of overlapping regions is not supported. |
| 552 | // Dest register ends at the position after the last character written. |
| 553 | void GenerateCopyCharacters(MacroAssembler* masm, |
| 554 | Register dest, |
| 555 | Register src, |
| 556 | Register count, |
| 557 | Register scratch, |
| 558 | bool ascii); |
| 559 | |
| 560 | // Generate code for copying a large number of characters. This function |
| 561 | // is allowed to spend extra time setting up conditions to make copying |
| 562 | // faster. Copying of overlapping regions is not supported. |
| 563 | // Dest register ends at the position after the last character written. |
| 564 | void GenerateCopyCharactersLong(MacroAssembler* masm, |
| 565 | Register dest, |
| 566 | Register src, |
| 567 | Register count, |
| 568 | Register scratch1, |
| 569 | Register scratch2, |
| 570 | Register scratch3, |
| 571 | Register scratch4, |
| 572 | Register scratch5, |
| 573 | int flags); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 574 | |
| 575 | |
| 576 | // Probe the symbol table for a two character string. If the string is |
| 577 | // not found by probing a jump to the label not_found is performed. This jump |
| 578 | // does not guarantee that the string is not in the symbol table. If the |
| 579 | // string is found the code falls through with the string in register r0. |
| 580 | // Contents of both c1 and c2 registers are modified. At the exit c1 is |
| 581 | // guaranteed to contain halfword with low and high bytes equal to |
| 582 | // initial contents of c1 and c2 respectively. |
| 583 | void GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm, |
| 584 | Register c1, |
| 585 | Register c2, |
| 586 | Register scratch1, |
| 587 | Register scratch2, |
| 588 | Register scratch3, |
| 589 | Register scratch4, |
| 590 | Register scratch5, |
| 591 | Label* not_found); |
| 592 | |
| 593 | // Generate string hash. |
| 594 | void GenerateHashInit(MacroAssembler* masm, |
| 595 | Register hash, |
| 596 | Register character); |
| 597 | |
| 598 | void GenerateHashAddCharacter(MacroAssembler* masm, |
| 599 | Register hash, |
| 600 | Register character); |
| 601 | |
| 602 | void GenerateHashGetHash(MacroAssembler* masm, |
| 603 | Register hash); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 604 | }; |
| 605 | |
| 606 | |
| 607 | // Flag that indicates how to generate code for the stub StringAddStub. |
| 608 | enum StringAddFlags { |
| 609 | NO_STRING_ADD_FLAGS = 0, |
| 610 | NO_STRING_CHECK_IN_STUB = 1 << 0 // Omit string check in stub. |
| 611 | }; |
| 612 | |
| 613 | |
| 614 | class StringAddStub: public StringStubBase { |
| 615 | public: |
| 616 | explicit StringAddStub(StringAddFlags flags) { |
| 617 | string_check_ = ((flags & NO_STRING_CHECK_IN_STUB) == 0); |
| 618 | } |
| 619 | |
| 620 | private: |
| 621 | Major MajorKey() { return StringAdd; } |
| 622 | int MinorKey() { return string_check_ ? 0 : 1; } |
| 623 | |
| 624 | void Generate(MacroAssembler* masm); |
| 625 | |
| 626 | // Should the stub check whether arguments are strings? |
| 627 | bool string_check_; |
| 628 | }; |
| 629 | |
| 630 | |
| 631 | class SubStringStub: public StringStubBase { |
| 632 | public: |
| 633 | SubStringStub() {} |
| 634 | |
| 635 | private: |
| 636 | Major MajorKey() { return SubString; } |
| 637 | int MinorKey() { return 0; } |
| 638 | |
| 639 | void Generate(MacroAssembler* masm); |
| 640 | }; |
| 641 | |
| 642 | |
| 643 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 644 | class StringCompareStub: public CodeStub { |
| 645 | public: |
| 646 | StringCompareStub() { } |
| 647 | |
| 648 | // Compare two flat ASCII strings and returns result in r0. |
| 649 | // Does not use the stack. |
| 650 | static void GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 651 | Register left, |
| 652 | Register right, |
| 653 | Register scratch1, |
| 654 | Register scratch2, |
| 655 | Register scratch3, |
| 656 | Register scratch4); |
| 657 | |
| 658 | private: |
| 659 | Major MajorKey() { return StringCompare; } |
| 660 | int MinorKey() { return 0; } |
| 661 | |
| 662 | void Generate(MacroAssembler* masm); |
| 663 | }; |
| 664 | |
| 665 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 666 | // This stub can convert a signed int32 to a heap number (double). It does |
| 667 | // not work for int32s that are in Smi range! No GC occurs during this stub |
| 668 | // so you don't have to set up the frame. |
| 669 | class WriteInt32ToHeapNumberStub : public CodeStub { |
| 670 | public: |
| 671 | WriteInt32ToHeapNumberStub(Register the_int, |
| 672 | Register the_heap_number, |
| 673 | Register scratch) |
| 674 | : the_int_(the_int), |
| 675 | the_heap_number_(the_heap_number), |
| 676 | scratch_(scratch) { } |
| 677 | |
| 678 | private: |
| 679 | Register the_int_; |
| 680 | Register the_heap_number_; |
| 681 | Register scratch_; |
| 682 | |
| 683 | // Minor key encoding in 16 bits. |
| 684 | class IntRegisterBits: public BitField<int, 0, 4> {}; |
| 685 | class HeapNumberRegisterBits: public BitField<int, 4, 4> {}; |
| 686 | class ScratchRegisterBits: public BitField<int, 8, 4> {}; |
| 687 | |
| 688 | Major MajorKey() { return WriteInt32ToHeapNumber; } |
| 689 | int MinorKey() { |
| 690 | // Encode the parameters in a unique 16 bit value. |
| 691 | return IntRegisterBits::encode(the_int_.code()) |
| 692 | | HeapNumberRegisterBits::encode(the_heap_number_.code()) |
| 693 | | ScratchRegisterBits::encode(scratch_.code()); |
| 694 | } |
| 695 | |
| 696 | void Generate(MacroAssembler* masm); |
| 697 | |
| 698 | const char* GetName() { return "WriteInt32ToHeapNumberStub"; } |
| 699 | |
| 700 | #ifdef DEBUG |
| 701 | void Print() { PrintF("WriteInt32ToHeapNumberStub\n"); } |
| 702 | #endif |
| 703 | }; |
| 704 | |
| 705 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 706 | class NumberToStringStub: public CodeStub { |
| 707 | public: |
| 708 | NumberToStringStub() { } |
| 709 | |
| 710 | // Generate code to do a lookup in the number string cache. If the number in |
| 711 | // the register object is found in the cache the generated code falls through |
| 712 | // with the result in the result register. The object and the result register |
| 713 | // can be the same. If the number is not found in the cache the code jumps to |
| 714 | // the label not_found with only the content of register object unchanged. |
| 715 | static void GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 716 | Register object, |
| 717 | Register result, |
| 718 | Register scratch1, |
| 719 | Register scratch2, |
| 720 | bool object_is_smi, |
| 721 | Label* not_found); |
| 722 | |
| 723 | private: |
| 724 | Major MajorKey() { return NumberToString; } |
| 725 | int MinorKey() { return 0; } |
| 726 | |
| 727 | void Generate(MacroAssembler* masm); |
| 728 | |
| 729 | const char* GetName() { return "NumberToStringStub"; } |
| 730 | |
| 731 | #ifdef DEBUG |
| 732 | void Print() { |
| 733 | PrintF("NumberToStringStub\n"); |
| 734 | } |
| 735 | #endif |
| 736 | }; |
| 737 | |
| 738 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 739 | } } // namespace v8::internal |
| 740 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 741 | #endif // V8_ARM_CODEGEN_ARM_H_ |