Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [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_IA32_MACRO_ASSEMBLER_IA32_H_ |
| 29 | #define V8_IA32_MACRO_ASSEMBLER_IA32_H_ |
| 30 | |
| 31 | #include "assembler.h" |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 32 | #include "type-info.h" |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 33 | |
| 34 | namespace v8 { |
| 35 | namespace internal { |
| 36 | |
Kristian Monsen | 25f6136 | 2010-05-21 11:50:48 +0100 | [diff] [blame] | 37 | // Flags used for the AllocateInNewSpace functions. |
| 38 | enum AllocationFlags { |
| 39 | // No special flags. |
| 40 | NO_ALLOCATION_FLAGS = 0, |
| 41 | // Return the pointer to the allocated already tagged as a heap object. |
| 42 | TAG_OBJECT = 1 << 0, |
| 43 | // The content of the result register already contains the allocation top in |
| 44 | // new space. |
| 45 | RESULT_CONTAINS_TOP = 1 << 1 |
| 46 | }; |
| 47 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 48 | // Convenience for platform-independent signatures. We do not normally |
| 49 | // distinguish memory operands from other operands on ia32. |
| 50 | typedef Operand MemOperand; |
| 51 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 52 | // Forward declaration. |
| 53 | class JumpTarget; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 54 | class PostCallGenerator; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 55 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 56 | // MacroAssembler implements a collection of frequently used macros. |
| 57 | class MacroAssembler: public Assembler { |
| 58 | public: |
| 59 | MacroAssembler(void* buffer, int size); |
| 60 | |
| 61 | // --------------------------------------------------------------------------- |
| 62 | // GC Support |
| 63 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 64 | // For page containing |object| mark region covering |addr| dirty. |
| 65 | // RecordWriteHelper only works if the object is not in new |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 66 | // space. |
| 67 | void RecordWriteHelper(Register object, |
| 68 | Register addr, |
| 69 | Register scratch); |
| 70 | |
| 71 | // Check if object is in new space. |
| 72 | // scratch can be object itself, but it will be clobbered. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 73 | template <typename LabelType> |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 74 | void InNewSpace(Register object, |
| 75 | Register scratch, |
| 76 | Condition cc, // equal for new space, not_equal otherwise. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 77 | LabelType* branch); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 78 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 79 | // For page containing |object| mark region covering [object+offset] |
| 80 | // dirty. |object| is the object being stored into, |value| is the |
| 81 | // object being stored. If offset is zero, then the scratch register |
| 82 | // contains the array index into the elements array represented as a |
| 83 | // Smi. All registers are clobbered by the operation. RecordWrite |
| 84 | // filters out smis so it does not update the write barrier if the |
| 85 | // value is a smi. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 86 | void RecordWrite(Register object, |
| 87 | int offset, |
| 88 | Register value, |
| 89 | Register scratch); |
| 90 | |
Steve Block | 8defd9f | 2010-07-08 12:39:36 +0100 | [diff] [blame] | 91 | // For page containing |object| mark region covering |address| |
| 92 | // dirty. |object| is the object being stored into, |value| is the |
| 93 | // object being stored. All registers are clobbered by the |
| 94 | // operation. RecordWrite filters out smis so it does not update the |
| 95 | // write barrier if the value is a smi. |
| 96 | void RecordWrite(Register object, |
| 97 | Register address, |
| 98 | Register value); |
| 99 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 100 | #ifdef ENABLE_DEBUGGER_SUPPORT |
| 101 | // --------------------------------------------------------------------------- |
| 102 | // Debugger Support |
| 103 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 104 | void DebugBreak(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 105 | #endif |
| 106 | |
| 107 | // --------------------------------------------------------------------------- |
| 108 | // Activation frames |
| 109 | |
| 110 | void EnterInternalFrame() { EnterFrame(StackFrame::INTERNAL); } |
| 111 | void LeaveInternalFrame() { LeaveFrame(StackFrame::INTERNAL); } |
| 112 | |
| 113 | void EnterConstructFrame() { EnterFrame(StackFrame::CONSTRUCT); } |
| 114 | void LeaveConstructFrame() { LeaveFrame(StackFrame::CONSTRUCT); } |
| 115 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 116 | // Enter specific kind of exit frame. Expects the number of |
| 117 | // arguments in register eax and sets up the number of arguments in |
| 118 | // register edi and the pointer to the first argument in register |
| 119 | // esi. |
| 120 | void EnterExitFrame(bool save_doubles); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 121 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 122 | void EnterApiExitFrame(int argc); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 123 | |
| 124 | // Leave the current exit frame. Expects the return value in |
| 125 | // register eax:edx (untouched) and the pointer to the first |
| 126 | // argument in register esi. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 127 | void LeaveExitFrame(bool save_doubles); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 128 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 129 | // Leave the current exit frame. Expects the return value in |
| 130 | // register eax (untouched). |
| 131 | void LeaveApiExitFrame(); |
| 132 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 133 | // Find the function context up the context chain. |
| 134 | void LoadContext(Register dst, int context_chain_length); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 135 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 136 | // Load the global function with the given index. |
| 137 | void LoadGlobalFunction(int index, Register function); |
| 138 | |
| 139 | // Load the initial map from the global function. The registers |
| 140 | // function and map can be the same. |
| 141 | void LoadGlobalFunctionInitialMap(Register function, Register map); |
| 142 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 143 | // Push and pop the registers that can hold pointers. |
| 144 | void PushSafepointRegisters() { pushad(); } |
| 145 | void PopSafepointRegisters() { popad(); } |
| 146 | static int SafepointRegisterStackIndex(int reg_code); |
| 147 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 148 | // --------------------------------------------------------------------------- |
| 149 | // JavaScript invokes |
| 150 | |
| 151 | // Invoke the JavaScript function code by either calling or jumping. |
| 152 | void InvokeCode(const Operand& code, |
| 153 | const ParameterCount& expected, |
| 154 | const ParameterCount& actual, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 155 | InvokeFlag flag, |
| 156 | PostCallGenerator* post_call_generator = NULL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 157 | |
| 158 | void InvokeCode(Handle<Code> code, |
| 159 | const ParameterCount& expected, |
| 160 | const ParameterCount& actual, |
| 161 | RelocInfo::Mode rmode, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 162 | InvokeFlag flag, |
| 163 | PostCallGenerator* post_call_generator = NULL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 164 | |
| 165 | // Invoke the JavaScript function in the given register. Changes the |
| 166 | // current context to the context in the function before invoking. |
| 167 | void InvokeFunction(Register function, |
| 168 | const ParameterCount& actual, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 169 | InvokeFlag flag, |
| 170 | PostCallGenerator* post_call_generator = NULL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 171 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 172 | void InvokeFunction(JSFunction* function, |
| 173 | const ParameterCount& actual, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 174 | InvokeFlag flag, |
| 175 | PostCallGenerator* post_call_generator = NULL); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 176 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 177 | // Invoke specified builtin JavaScript function. Adds an entry to |
| 178 | // the unresolved list if the name does not resolve. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 179 | void InvokeBuiltin(Builtins::JavaScript id, |
| 180 | InvokeFlag flag, |
| 181 | PostCallGenerator* post_call_generator = NULL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 182 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 183 | // Store the function for the given builtin in the target register. |
| 184 | void GetBuiltinFunction(Register target, Builtins::JavaScript id); |
| 185 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 186 | // Store the code object for the given builtin in the target register. |
| 187 | void GetBuiltinEntry(Register target, Builtins::JavaScript id); |
| 188 | |
| 189 | // Expression support |
| 190 | void Set(Register dst, const Immediate& x); |
| 191 | void Set(const Operand& dst, const Immediate& x); |
| 192 | |
| 193 | // Compare object type for heap object. |
| 194 | // Incoming register is heap_object and outgoing register is map. |
| 195 | void CmpObjectType(Register heap_object, InstanceType type, Register map); |
| 196 | |
| 197 | // Compare instance type for map. |
| 198 | void CmpInstanceType(Register map, InstanceType type); |
| 199 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 200 | // Check if the map of an object is equal to a specified map and |
| 201 | // branch to label if not. Skip the smi check if not required |
| 202 | // (object is known to be a heap object) |
| 203 | void CheckMap(Register obj, |
| 204 | Handle<Map> map, |
| 205 | Label* fail, |
| 206 | bool is_heap_object); |
| 207 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 208 | // Check if the object in register heap_object is a string. Afterwards the |
| 209 | // register map contains the object map and the register instance_type |
| 210 | // contains the instance_type. The registers map and instance_type can be the |
| 211 | // same in which case it contains the instance type afterwards. Either of the |
| 212 | // registers map and instance_type can be the same as heap_object. |
| 213 | Condition IsObjectStringType(Register heap_object, |
| 214 | Register map, |
| 215 | Register instance_type); |
| 216 | |
Ben Murdoch | 7f4d5bd | 2010-06-15 11:15:29 +0100 | [diff] [blame] | 217 | // Check if a heap object's type is in the JSObject range, not including |
| 218 | // JSFunction. The object's map will be loaded in the map register. |
| 219 | // Any or all of the three registers may be the same. |
| 220 | // The contents of the scratch register will always be overwritten. |
| 221 | void IsObjectJSObjectType(Register heap_object, |
| 222 | Register map, |
| 223 | Register scratch, |
| 224 | Label* fail); |
| 225 | |
| 226 | // The contents of the scratch register will be overwritten. |
| 227 | void IsInstanceJSObjectType(Register map, Register scratch, Label* fail); |
| 228 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 229 | // FCmp is similar to integer cmp, but requires unsigned |
| 230 | // jcc instructions (je, ja, jae, jb, jbe, je, and jz). |
| 231 | void FCmp(); |
| 232 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 233 | // Smi tagging support. |
| 234 | void SmiTag(Register reg) { |
| 235 | ASSERT(kSmiTag == 0); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 236 | ASSERT(kSmiTagSize == 1); |
| 237 | add(reg, Operand(reg)); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 238 | } |
| 239 | void SmiUntag(Register reg) { |
| 240 | sar(reg, kSmiTagSize); |
| 241 | } |
| 242 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 243 | // Modifies the register even if it does not contain a Smi! |
| 244 | void SmiUntag(Register reg, TypeInfo info, Label* non_smi) { |
| 245 | ASSERT(kSmiTagSize == 1); |
| 246 | sar(reg, kSmiTagSize); |
| 247 | if (info.IsSmi()) { |
| 248 | ASSERT(kSmiTag == 0); |
| 249 | j(carry, non_smi); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | // Modifies the register even if it does not contain a Smi! |
| 254 | void SmiUntag(Register reg, Label* is_smi) { |
| 255 | ASSERT(kSmiTagSize == 1); |
| 256 | sar(reg, kSmiTagSize); |
| 257 | ASSERT(kSmiTag == 0); |
| 258 | j(not_carry, is_smi); |
| 259 | } |
| 260 | |
| 261 | // Assumes input is a heap object. |
| 262 | void JumpIfNotNumber(Register reg, TypeInfo info, Label* on_not_number); |
| 263 | |
| 264 | // Assumes input is a heap number. Jumps on things out of range. Also jumps |
| 265 | // on the min negative int32. Ignores frational parts. |
| 266 | void ConvertToInt32(Register dst, |
| 267 | Register src, // Can be the same as dst. |
| 268 | Register scratch, // Can be no_reg or dst, but not src. |
| 269 | TypeInfo info, |
| 270 | Label* on_not_int32); |
| 271 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 272 | void LoadPowerOf2(XMMRegister dst, Register scratch, int power); |
| 273 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 274 | // Abort execution if argument is not a number. Used in debug code. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 275 | void AbortIfNotNumber(Register object); |
| 276 | |
| 277 | // Abort execution if argument is not a smi. Used in debug code. |
| 278 | void AbortIfNotSmi(Register object); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 279 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 280 | // Abort execution if argument is a smi. Used in debug code. |
| 281 | void AbortIfSmi(Register object); |
| 282 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 283 | // Abort execution if argument is a string. Used in debug code. |
| 284 | void AbortIfNotString(Register object); |
| 285 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 286 | // --------------------------------------------------------------------------- |
| 287 | // Exception handling |
| 288 | |
| 289 | // Push a new try handler and link into try handler chain. The return |
| 290 | // address must be pushed before calling this helper. |
| 291 | void PushTryHandler(CodeLocation try_location, HandlerType type); |
| 292 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 293 | // Unlink the stack handler on top of the stack from the try handler chain. |
| 294 | void PopTryHandler(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 295 | |
| 296 | // --------------------------------------------------------------------------- |
| 297 | // Inline caching support |
| 298 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 299 | // Generate code for checking access rights - used for security checks |
| 300 | // on access to global objects across environments. The holder register |
| 301 | // is left untouched, but the scratch register is clobbered. |
| 302 | void CheckAccessGlobalProxy(Register holder_reg, |
| 303 | Register scratch, |
| 304 | Label* miss); |
| 305 | |
| 306 | |
| 307 | // --------------------------------------------------------------------------- |
| 308 | // Allocation support |
| 309 | |
| 310 | // Allocate an object in new space. If the new space is exhausted control |
| 311 | // continues at the gc_required label. The allocated object is returned in |
| 312 | // result and end of the new object is returned in result_end. The register |
| 313 | // scratch can be passed as no_reg in which case an additional object |
| 314 | // reference will be added to the reloc info. The returned pointers in result |
| 315 | // and result_end have not yet been tagged as heap objects. If |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 316 | // result_contains_top_on_entry is true the content of result is known to be |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 317 | // the allocation top on entry (could be result_end from a previous call to |
| 318 | // AllocateInNewSpace). If result_contains_top_on_entry is true scratch |
| 319 | // should be no_reg as it is never used. |
| 320 | void AllocateInNewSpace(int object_size, |
| 321 | Register result, |
| 322 | Register result_end, |
| 323 | Register scratch, |
| 324 | Label* gc_required, |
| 325 | AllocationFlags flags); |
| 326 | |
| 327 | void AllocateInNewSpace(int header_size, |
| 328 | ScaleFactor element_size, |
| 329 | Register element_count, |
| 330 | Register result, |
| 331 | Register result_end, |
| 332 | Register scratch, |
| 333 | Label* gc_required, |
| 334 | AllocationFlags flags); |
| 335 | |
| 336 | void AllocateInNewSpace(Register object_size, |
| 337 | Register result, |
| 338 | Register result_end, |
| 339 | Register scratch, |
| 340 | Label* gc_required, |
| 341 | AllocationFlags flags); |
| 342 | |
| 343 | // Undo allocation in new space. The object passed and objects allocated after |
| 344 | // it will no longer be allocated. Make sure that no pointers are left to the |
| 345 | // object(s) no longer allocated as they would be invalid when allocation is |
| 346 | // un-done. |
| 347 | void UndoAllocationInNewSpace(Register object); |
| 348 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 349 | // Allocate a heap number in new space with undefined value. The |
| 350 | // register scratch2 can be passed as no_reg; the others must be |
| 351 | // valid registers. Returns tagged pointer in result register, or |
| 352 | // jumps to gc_required if new space is full. |
| 353 | void AllocateHeapNumber(Register result, |
| 354 | Register scratch1, |
| 355 | Register scratch2, |
| 356 | Label* gc_required); |
| 357 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 358 | // Allocate a sequential string. All the header fields of the string object |
| 359 | // are initialized. |
| 360 | void AllocateTwoByteString(Register result, |
| 361 | Register length, |
| 362 | Register scratch1, |
| 363 | Register scratch2, |
| 364 | Register scratch3, |
| 365 | Label* gc_required); |
| 366 | void AllocateAsciiString(Register result, |
| 367 | Register length, |
| 368 | Register scratch1, |
| 369 | Register scratch2, |
| 370 | Register scratch3, |
| 371 | Label* gc_required); |
Iain Merrick | 9ac36c9 | 2010-09-13 15:29:50 +0100 | [diff] [blame] | 372 | void AllocateAsciiString(Register result, |
| 373 | int length, |
| 374 | Register scratch1, |
| 375 | Register scratch2, |
| 376 | Label* gc_required); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 377 | |
| 378 | // Allocate a raw cons string object. Only the map field of the result is |
| 379 | // initialized. |
| 380 | void AllocateConsString(Register result, |
| 381 | Register scratch1, |
| 382 | Register scratch2, |
| 383 | Label* gc_required); |
| 384 | void AllocateAsciiConsString(Register result, |
| 385 | Register scratch1, |
| 386 | Register scratch2, |
| 387 | Label* gc_required); |
| 388 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 389 | // All registers must be distinct. Only current_string needs valid contents |
| 390 | // on entry. All registers may be invalid on exit. result_operand is |
| 391 | // unchanged, padding_chars is updated correctly. |
| 392 | // The top of new space must contain a sequential ascii string with |
| 393 | // padding_chars bytes free in its top word. The sequential ascii string |
| 394 | // current_string is concatenated to it, allocating the necessary amount |
| 395 | // of new memory. |
| 396 | void AppendStringToTopOfNewSpace( |
| 397 | Register current_string, // Tagged pointer to string to copy. |
| 398 | Register current_string_length, |
| 399 | Register result_pos, |
| 400 | Register scratch, |
| 401 | Register new_padding_chars, |
| 402 | Operand operand_result, |
| 403 | Operand operand_padding_chars, |
| 404 | Label* bailout); |
| 405 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 406 | // --------------------------------------------------------------------------- |
| 407 | // Support functions. |
| 408 | |
| 409 | // Check if result is zero and op is negative. |
| 410 | void NegativeZeroTest(Register result, Register op, Label* then_label); |
| 411 | |
| 412 | // Check if result is zero and op is negative in code using jump targets. |
| 413 | void NegativeZeroTest(CodeGenerator* cgen, |
| 414 | Register result, |
| 415 | Register op, |
| 416 | JumpTarget* then_target); |
| 417 | |
| 418 | // Check if result is zero and any of op1 and op2 are negative. |
| 419 | // Register scratch is destroyed, and it must be different from op2. |
| 420 | void NegativeZeroTest(Register result, Register op1, Register op2, |
| 421 | Register scratch, Label* then_label); |
| 422 | |
| 423 | // Try to get function prototype of a function and puts the value in |
| 424 | // the result register. Checks that the function really is a |
| 425 | // function and jumps to the miss label if the fast checks fail. The |
| 426 | // function register will be untouched; the other registers may be |
| 427 | // clobbered. |
| 428 | void TryGetFunctionPrototype(Register function, |
| 429 | Register result, |
| 430 | Register scratch, |
| 431 | Label* miss); |
| 432 | |
| 433 | // Generates code for reporting that an illegal operation has |
| 434 | // occurred. |
| 435 | void IllegalOperation(int num_arguments); |
| 436 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 437 | // Picks out an array index from the hash field. |
| 438 | // Register use: |
| 439 | // hash - holds the index's hash. Clobbered. |
| 440 | // index - holds the overwritten index on exit. |
| 441 | void IndexFromHash(Register hash, Register index); |
| 442 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 443 | // --------------------------------------------------------------------------- |
| 444 | // Runtime calls |
| 445 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 446 | // Call a code stub. Generate the code if necessary. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 447 | void CallStub(CodeStub* stub); |
| 448 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 449 | // Call a code stub and return the code object called. Try to generate |
| 450 | // the code if necessary. Do not perform a GC but instead return a retry |
| 451 | // after GC failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 452 | MUST_USE_RESULT MaybeObject* TryCallStub(CodeStub* stub); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 453 | |
| 454 | // Tail call a code stub (jump). Generate the code if necessary. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 455 | void TailCallStub(CodeStub* stub); |
| 456 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 457 | // Tail call a code stub (jump) and return the code object called. Try to |
| 458 | // generate the code if necessary. Do not perform a GC but instead return |
| 459 | // a retry after GC failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 460 | MUST_USE_RESULT MaybeObject* TryTailCallStub(CodeStub* stub); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 461 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 462 | // Return from a code stub after popping its arguments. |
| 463 | void StubReturn(int argc); |
| 464 | |
| 465 | // Call a runtime routine. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 466 | void CallRuntime(Runtime::Function* f, int num_arguments); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 467 | void CallRuntimeSaveDoubles(Runtime::FunctionId id); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 468 | |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 469 | // Call a runtime function, returning the CodeStub object called. |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 470 | // Try to generate the stub code if necessary. Do not perform a GC |
| 471 | // but instead return a retry after GC failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 472 | MUST_USE_RESULT MaybeObject* TryCallRuntime(Runtime::Function* f, |
| 473 | int num_arguments); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 474 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 475 | // Convenience function: Same as above, but takes the fid instead. |
| 476 | void CallRuntime(Runtime::FunctionId id, int num_arguments); |
| 477 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 478 | // Convenience function: Same as above, but takes the fid instead. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 479 | MUST_USE_RESULT MaybeObject* TryCallRuntime(Runtime::FunctionId id, |
| 480 | int num_arguments); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 481 | |
Ben Murdoch | bb769b2 | 2010-08-11 14:56:33 +0100 | [diff] [blame] | 482 | // Convenience function: call an external reference. |
| 483 | void CallExternalReference(ExternalReference ref, int num_arguments); |
| 484 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 485 | // Tail call of a runtime routine (jump). |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 486 | // Like JumpToExternalReference, but also takes care of passing the number |
| 487 | // of parameters. |
| 488 | void TailCallExternalReference(const ExternalReference& ext, |
| 489 | int num_arguments, |
| 490 | int result_size); |
| 491 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 492 | // Tail call of a runtime routine (jump). Try to generate the code if |
| 493 | // necessary. Do not perform a GC but instead return a retry after GC failure. |
| 494 | MUST_USE_RESULT MaybeObject* TryTailCallExternalReference( |
| 495 | const ExternalReference& ext, int num_arguments, int result_size); |
| 496 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 497 | // Convenience function: tail call a runtime routine (jump). |
| 498 | void TailCallRuntime(Runtime::FunctionId fid, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 499 | int num_arguments, |
| 500 | int result_size); |
| 501 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 502 | // Convenience function: tail call a runtime routine (jump). Try to generate |
| 503 | // the code if necessary. Do not perform a GC but instead return a retry after |
| 504 | // GC failure. |
| 505 | MUST_USE_RESULT MaybeObject* TryTailCallRuntime(Runtime::FunctionId fid, |
| 506 | int num_arguments, |
| 507 | int result_size); |
| 508 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 509 | // Before calling a C-function from generated code, align arguments on stack. |
| 510 | // After aligning the frame, arguments must be stored in esp[0], esp[4], |
| 511 | // etc., not pushed. The argument count assumes all arguments are word sized. |
| 512 | // Some compilers/platforms require the stack to be aligned when calling |
| 513 | // C++ code. |
| 514 | // Needs a scratch register to do some arithmetic. This register will be |
| 515 | // trashed. |
| 516 | void PrepareCallCFunction(int num_arguments, Register scratch); |
| 517 | |
| 518 | // Calls a C function and cleans up the space for arguments allocated |
| 519 | // by PrepareCallCFunction. The called function is not allowed to trigger a |
| 520 | // garbage collection, since that might move the code and invalidate the |
| 521 | // return address (unless this is somehow accounted for by the called |
| 522 | // function). |
| 523 | void CallCFunction(ExternalReference function, int num_arguments); |
| 524 | void CallCFunction(Register function, int num_arguments); |
| 525 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 526 | // Prepares stack to put arguments (aligns and so on). Reserves |
| 527 | // space for return value if needed (assumes the return value is a handle). |
| 528 | // Uses callee-saved esi to restore stack state after call. Arguments must be |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 529 | // stored in ApiParameterOperand(0), ApiParameterOperand(1) etc. Saves |
| 530 | // context (esi). |
| 531 | void PrepareCallApiFunction(int argc, Register scratch); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 532 | |
Russell Brenner | 90bac25 | 2010-11-18 13:33:46 -0800 | [diff] [blame] | 533 | // Calls an API function. Allocates HandleScope, extracts |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 534 | // returned value from handle and propagates exceptions. |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 535 | // Clobbers ebx, edi and caller-save registers. Restores context. |
| 536 | // On return removes stack_space * kPointerSize (GCed). |
| 537 | MaybeObject* TryCallApiFunctionAndReturn(ApiFunction* function, |
| 538 | int stack_space); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 539 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 540 | // Jump to a runtime routine. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 541 | void JumpToExternalReference(const ExternalReference& ext); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 542 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 543 | MaybeObject* TryJumpToExternalReference(const ExternalReference& ext); |
| 544 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 545 | |
| 546 | // --------------------------------------------------------------------------- |
| 547 | // Utilities |
| 548 | |
| 549 | void Ret(); |
| 550 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 551 | // Emit code to discard a non-negative number of pointer-sized elements |
| 552 | // from the stack, clobbering only the esp register. |
| 553 | void Drop(int element_count); |
| 554 | |
| 555 | void Call(Label* target) { call(target); } |
| 556 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 557 | // Emit call to the code we are currently generating. |
| 558 | void CallSelf() { |
| 559 | Handle<Code> self(reinterpret_cast<Code**>(CodeObject().location())); |
| 560 | call(self, RelocInfo::CODE_TARGET); |
| 561 | } |
| 562 | |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 563 | // Move if the registers are not identical. |
| 564 | void Move(Register target, Register source); |
| 565 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 566 | void Move(Register target, Handle<Object> value); |
| 567 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 568 | Handle<Object> CodeObject() { return code_object_; } |
| 569 | |
| 570 | |
| 571 | // --------------------------------------------------------------------------- |
| 572 | // StatsCounter support |
| 573 | |
| 574 | void SetCounter(StatsCounter* counter, int value); |
| 575 | void IncrementCounter(StatsCounter* counter, int value); |
| 576 | void DecrementCounter(StatsCounter* counter, int value); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 577 | void IncrementCounter(Condition cc, StatsCounter* counter, int value); |
| 578 | void DecrementCounter(Condition cc, StatsCounter* counter, int value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 579 | |
| 580 | |
| 581 | // --------------------------------------------------------------------------- |
| 582 | // Debugging |
| 583 | |
| 584 | // Calls Abort(msg) if the condition cc is not satisfied. |
| 585 | // Use --debug_code to enable. |
| 586 | void Assert(Condition cc, const char* msg); |
| 587 | |
Iain Merrick | 7568138 | 2010-08-19 15:07:18 +0100 | [diff] [blame] | 588 | void AssertFastElements(Register elements); |
| 589 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 590 | // Like Assert(), but always enabled. |
| 591 | void Check(Condition cc, const char* msg); |
| 592 | |
| 593 | // Print a message to stdout and abort execution. |
| 594 | void Abort(const char* msg); |
| 595 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 596 | // Check that the stack is aligned. |
| 597 | void CheckStackAlignment(); |
| 598 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 599 | // Verify restrictions about code generated in stubs. |
| 600 | void set_generating_stub(bool value) { generating_stub_ = value; } |
| 601 | bool generating_stub() { return generating_stub_; } |
| 602 | void set_allow_stub_calls(bool value) { allow_stub_calls_ = value; } |
| 603 | bool allow_stub_calls() { return allow_stub_calls_; } |
| 604 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 605 | // --------------------------------------------------------------------------- |
| 606 | // String utilities. |
| 607 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 608 | // Check whether the instance type represents a flat ascii string. Jump to the |
| 609 | // label if not. If the instance type can be scratched specify same register |
| 610 | // for both instance type and scratch. |
| 611 | void JumpIfInstanceTypeIsNotSequentialAscii(Register instance_type, |
| 612 | Register scratch, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 613 | Label* on_not_flat_ascii_string); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 614 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 615 | // Checks if both objects are sequential ASCII strings, and jumps to label |
| 616 | // if either is not. |
| 617 | void JumpIfNotBothSequentialAsciiStrings(Register object1, |
| 618 | Register object2, |
| 619 | Register scratch1, |
| 620 | Register scratch2, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 621 | Label* on_not_flat_ascii_strings); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 622 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 623 | private: |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 624 | bool generating_stub_; |
| 625 | bool allow_stub_calls_; |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 626 | // This handle will be patched with the code object on installation. |
| 627 | Handle<Object> code_object_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 628 | |
| 629 | // Helper functions for generating invokes. |
| 630 | void InvokePrologue(const ParameterCount& expected, |
| 631 | const ParameterCount& actual, |
| 632 | Handle<Code> code_constant, |
| 633 | const Operand& code_operand, |
| 634 | Label* done, |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 635 | InvokeFlag flag, |
| 636 | PostCallGenerator* post_call_generator = NULL); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 637 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 638 | // Activation support. |
| 639 | void EnterFrame(StackFrame::Type type); |
| 640 | void LeaveFrame(StackFrame::Type type); |
| 641 | |
Kristian Monsen | 80d68ea | 2010-09-08 11:05:35 +0100 | [diff] [blame] | 642 | void EnterExitFramePrologue(); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 643 | void EnterExitFrameEpilogue(int argc, bool save_doubles); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 644 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 645 | void LeaveExitFrameEpilogue(); |
| 646 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 647 | // Allocation support helpers. |
| 648 | void LoadAllocationTopHelper(Register result, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 649 | Register scratch, |
| 650 | AllocationFlags flags); |
| 651 | void UpdateAllocationTopHelper(Register result_end, Register scratch); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 652 | |
| 653 | // Helper for PopHandleScope. Allowed to perform a GC and returns |
| 654 | // NULL if gc_allowed. Does not perform a GC if !gc_allowed, and |
| 655 | // possibly returns a failure object indicating an allocation failure. |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 656 | MUST_USE_RESULT MaybeObject* PopHandleScopeHelper(Register saved, |
| 657 | Register scratch, |
| 658 | bool gc_allowed); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 659 | }; |
| 660 | |
| 661 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 662 | template <typename LabelType> |
| 663 | void MacroAssembler::InNewSpace(Register object, |
| 664 | Register scratch, |
| 665 | Condition cc, |
| 666 | LabelType* branch) { |
| 667 | ASSERT(cc == equal || cc == not_equal); |
| 668 | if (Serializer::enabled()) { |
| 669 | // Can't do arithmetic on external references if it might get serialized. |
| 670 | mov(scratch, Operand(object)); |
| 671 | // The mask isn't really an address. We load it as an external reference in |
| 672 | // case the size of the new space is different between the snapshot maker |
| 673 | // and the running system. |
| 674 | and_(Operand(scratch), Immediate(ExternalReference::new_space_mask())); |
| 675 | cmp(Operand(scratch), Immediate(ExternalReference::new_space_start())); |
| 676 | j(cc, branch); |
| 677 | } else { |
| 678 | int32_t new_space_start = reinterpret_cast<int32_t>( |
| 679 | ExternalReference::new_space_start().address()); |
| 680 | lea(scratch, Operand(object, -new_space_start)); |
| 681 | and_(scratch, Heap::NewSpaceMask()); |
| 682 | j(cc, branch); |
| 683 | } |
| 684 | } |
| 685 | |
| 686 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 687 | // The code patcher is used to patch (typically) small parts of code e.g. for |
| 688 | // debugging and other types of instrumentation. When using the code patcher |
| 689 | // the exact number of bytes specified must be emitted. Is not legal to emit |
| 690 | // relocation information. If any of these constraints are violated it causes |
| 691 | // an assertion. |
| 692 | class CodePatcher { |
| 693 | public: |
| 694 | CodePatcher(byte* address, int size); |
| 695 | virtual ~CodePatcher(); |
| 696 | |
| 697 | // Macro assembler to emit code. |
| 698 | MacroAssembler* masm() { return &masm_; } |
| 699 | |
| 700 | private: |
| 701 | byte* address_; // The address of the code being patched. |
| 702 | int size_; // Number of bytes of the expected patch size. |
| 703 | MacroAssembler masm_; // Macro assembler used to generate the code. |
| 704 | }; |
| 705 | |
| 706 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame^] | 707 | // Helper class for generating code or data associated with the code |
| 708 | // right after a call instruction. As an example this can be used to |
| 709 | // generate safepoint data after calls for crankshaft. |
| 710 | class PostCallGenerator { |
| 711 | public: |
| 712 | PostCallGenerator() { } |
| 713 | virtual ~PostCallGenerator() { } |
| 714 | virtual void Generate() = 0; |
| 715 | }; |
| 716 | |
| 717 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 718 | // ----------------------------------------------------------------------------- |
| 719 | // Static helper functions. |
| 720 | |
| 721 | // Generate an Operand for loading a field from an object. |
| 722 | static inline Operand FieldOperand(Register object, int offset) { |
| 723 | return Operand(object, offset - kHeapObjectTag); |
| 724 | } |
| 725 | |
| 726 | |
| 727 | // Generate an Operand for loading an indexed field from an object. |
| 728 | static inline Operand FieldOperand(Register object, |
| 729 | Register index, |
| 730 | ScaleFactor scale, |
| 731 | int offset) { |
| 732 | return Operand(object, index, scale, offset - kHeapObjectTag); |
| 733 | } |
| 734 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 735 | |
| 736 | static inline Operand ContextOperand(Register context, int index) { |
| 737 | return Operand(context, Context::SlotOffset(index)); |
| 738 | } |
| 739 | |
| 740 | |
| 741 | static inline Operand GlobalObjectOperand() { |
| 742 | return ContextOperand(esi, Context::GLOBAL_INDEX); |
| 743 | } |
| 744 | |
| 745 | |
John Reck | 5913587 | 2010-11-02 12:39:01 -0700 | [diff] [blame] | 746 | // Generates an Operand for saving parameters after PrepareCallApiFunction. |
| 747 | Operand ApiParameterOperand(int index); |
| 748 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 749 | |
| 750 | #ifdef GENERATED_CODE_COVERAGE |
| 751 | extern void LogGeneratedCodeCoverage(const char* file_line); |
| 752 | #define CODE_COVERAGE_STRINGIFY(x) #x |
| 753 | #define CODE_COVERAGE_TOSTRING(x) CODE_COVERAGE_STRINGIFY(x) |
| 754 | #define __FILE_LINE__ __FILE__ ":" CODE_COVERAGE_TOSTRING(__LINE__) |
| 755 | #define ACCESS_MASM(masm) { \ |
| 756 | byte* ia32_coverage_function = \ |
| 757 | reinterpret_cast<byte*>(FUNCTION_ADDR(LogGeneratedCodeCoverage)); \ |
| 758 | masm->pushfd(); \ |
| 759 | masm->pushad(); \ |
| 760 | masm->push(Immediate(reinterpret_cast<int>(&__FILE_LINE__))); \ |
| 761 | masm->call(ia32_coverage_function, RelocInfo::RUNTIME_ENTRY); \ |
| 762 | masm->pop(eax); \ |
| 763 | masm->popad(); \ |
| 764 | masm->popfd(); \ |
| 765 | } \ |
| 766 | masm-> |
| 767 | #else |
| 768 | #define ACCESS_MASM(masm) masm-> |
| 769 | #endif |
| 770 | |
| 771 | |
| 772 | } } // namespace v8::internal |
| 773 | |
| 774 | #endif // V8_IA32_MACRO_ASSEMBLER_IA32_H_ |