yangguo@chromium.org | 78d1ad4 | 2012-02-09 13:53:47 +0000 | [diff] [blame] | 1 | // Copyright 2012 the V8 project authors. All rights reserved. |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +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_MACRO_ASSEMBLER_H_ |
| 29 | #define V8_MACRO_ASSEMBLER_H_ |
| 30 | |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 31 | |
| 32 | // Helper types to make boolean flag easier to read at call-site. |
| 33 | enum InvokeFlag { |
| 34 | CALL_FUNCTION, |
| 35 | JUMP_FUNCTION |
| 36 | }; |
| 37 | |
| 38 | |
yangguo@chromium.org | 4cd70b4 | 2013-01-04 08:57:54 +0000 | [diff] [blame] | 39 | // Flags used for the AllocateInNewSpace functions. |
| 40 | enum AllocationFlags { |
| 41 | // No special flags. |
| 42 | NO_ALLOCATION_FLAGS = 0, |
| 43 | // Return the pointer to the allocated already tagged as a heap object. |
| 44 | TAG_OBJECT = 1 << 0, |
| 45 | // The content of the result register already contains the allocation top in |
| 46 | // new space. |
| 47 | RESULT_CONTAINS_TOP = 1 << 1, |
| 48 | // Specify that the requested size of the space to allocate is specified in |
| 49 | // words instead of bytes. |
| 50 | SIZE_IN_WORDS = 1 << 2, |
| 51 | // Align the allocation to a multiple of kDoubleSize |
| 52 | DOUBLE_ALIGNMENT = 1 << 3 |
| 53 | }; |
| 54 | |
| 55 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 56 | // Invalid depth in prototype chain. |
| 57 | const int kInvalidProtoDepth = -1; |
ager@chromium.org | a1645e2 | 2009-09-09 19:27:10 +0000 | [diff] [blame] | 58 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 59 | #if V8_TARGET_ARCH_IA32 |
| 60 | #include "assembler.h" |
| 61 | #include "ia32/assembler-ia32.h" |
| 62 | #include "ia32/assembler-ia32-inl.h" |
| 63 | #include "code.h" // must be after assembler_*.h |
| 64 | #include "ia32/macro-assembler-ia32.h" |
| 65 | #elif V8_TARGET_ARCH_X64 |
| 66 | #include "assembler.h" |
| 67 | #include "x64/assembler-x64.h" |
| 68 | #include "x64/assembler-x64-inl.h" |
| 69 | #include "code.h" // must be after assembler_*.h |
| 70 | #include "x64/macro-assembler-x64.h" |
| 71 | #elif V8_TARGET_ARCH_ARM |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 72 | #include "arm/constants-arm.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 73 | #include "assembler.h" |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 74 | #include "arm/assembler-arm.h" |
| 75 | #include "arm/assembler-arm-inl.h" |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 76 | #include "code.h" // must be after assembler_*.h |
ager@chromium.org | 3a37e9b | 2009-04-27 09:26:21 +0000 | [diff] [blame] | 77 | #include "arm/macro-assembler-arm.h" |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 78 | #elif V8_TARGET_ARCH_MIPS |
| 79 | #include "mips/constants-mips.h" |
| 80 | #include "assembler.h" |
| 81 | #include "mips/assembler-mips.h" |
| 82 | #include "mips/assembler-mips-inl.h" |
| 83 | #include "code.h" // must be after assembler_*.h |
| 84 | #include "mips/macro-assembler-mips.h" |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 85 | #else |
| 86 | #error Unsupported target architecture. |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 87 | #endif |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 88 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 89 | namespace v8 { |
| 90 | namespace internal { |
| 91 | |
erik.corry@gmail.com | c3b670f | 2011-10-05 21:44:48 +0000 | [diff] [blame] | 92 | class FrameScope { |
| 93 | public: |
| 94 | explicit FrameScope(MacroAssembler* masm, StackFrame::Type type) |
| 95 | : masm_(masm), type_(type), old_has_frame_(masm->has_frame()) { |
| 96 | masm->set_has_frame(true); |
| 97 | if (type != StackFrame::MANUAL && type_ != StackFrame::NONE) { |
| 98 | masm->EnterFrame(type); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | ~FrameScope() { |
| 103 | if (type_ != StackFrame::MANUAL && type_ != StackFrame::NONE) { |
| 104 | masm_->LeaveFrame(type_); |
| 105 | } |
| 106 | masm_->set_has_frame(old_has_frame_); |
| 107 | } |
| 108 | |
| 109 | // Normally we generate the leave-frame code when this object goes |
| 110 | // out of scope. Sometimes we may need to generate the code somewhere else |
| 111 | // in addition. Calling this will achieve that, but the object stays in |
| 112 | // scope, the MacroAssembler is still marked as being in a frame scope, and |
| 113 | // the code will be generated again when it goes out of scope. |
| 114 | void GenerateLeaveFrame() { |
| 115 | masm_->LeaveFrame(type_); |
| 116 | } |
| 117 | |
| 118 | private: |
| 119 | MacroAssembler* masm_; |
| 120 | StackFrame::Type type_; |
| 121 | bool old_has_frame_; |
| 122 | }; |
| 123 | |
| 124 | |
| 125 | class AllowExternalCallThatCantCauseGC: public FrameScope { |
| 126 | public: |
| 127 | explicit AllowExternalCallThatCantCauseGC(MacroAssembler* masm) |
| 128 | : FrameScope(masm, StackFrame::NONE) { } |
| 129 | }; |
| 130 | |
| 131 | |
| 132 | class NoCurrentFrameScope { |
| 133 | public: |
| 134 | explicit NoCurrentFrameScope(MacroAssembler* masm) |
| 135 | : masm_(masm), saved_(masm->has_frame()) { |
| 136 | masm->set_has_frame(false); |
| 137 | } |
| 138 | |
| 139 | ~NoCurrentFrameScope() { |
| 140 | masm_->set_has_frame(saved_); |
| 141 | } |
| 142 | |
| 143 | private: |
| 144 | MacroAssembler* masm_; |
| 145 | bool saved_; |
| 146 | }; |
| 147 | |
| 148 | |
ricow@chromium.org | d236f4d | 2010-09-01 06:52:08 +0000 | [diff] [blame] | 149 | // Support for "structured" code comments. |
| 150 | #ifdef DEBUG |
| 151 | |
| 152 | class Comment { |
| 153 | public: |
| 154 | Comment(MacroAssembler* masm, const char* msg); |
| 155 | ~Comment(); |
| 156 | |
| 157 | private: |
| 158 | MacroAssembler* masm_; |
| 159 | const char* msg_; |
| 160 | }; |
| 161 | |
| 162 | #else |
| 163 | |
| 164 | class Comment { |
| 165 | public: |
| 166 | Comment(MacroAssembler*, const char*) {} |
| 167 | }; |
| 168 | |
| 169 | #endif // DEBUG |
| 170 | |
| 171 | } } // namespace v8::internal |
| 172 | |
christian.plesner.hansen | 43d26ec | 2008-07-03 15:10:15 +0000 | [diff] [blame] | 173 | #endif // V8_MACRO_ASSEMBLER_H_ |