| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 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_VIRTUAL_FRAME_IA32_H_ |
| 29 #define V8_VIRTUAL_FRAME_IA32_H_ |
| 30 |
| 31 #include "macro-assembler.h" |
| 32 |
| 33 namespace v8 { namespace internal { |
| 34 |
| 35 // ------------------------------------------------------------------------- |
| 36 // Virtual frames |
| 37 // |
| 38 // The virtual frame is an abstraction of the physical stack frame. It |
| 39 // encapsulates the parameters, frame-allocated locals, and the expression |
| 40 // stack. It supports push/pop operations on the expression stack, as well |
| 41 // as random access to the expression stack elements, locals, and |
| 42 // parameters. |
| 43 |
| 44 class VirtualFrame : public Malloced { |
| 45 public: |
| 46 // Construct a virtual frame with the given code generator used to |
| 47 // generate code. |
| 48 explicit VirtualFrame(CodeGenerator* cgen); |
| 49 |
| 50 // Construct a virtual frame that is a clone of an existing one, initially |
| 51 // with an identical state. |
| 52 explicit VirtualFrame(VirtualFrame* original); |
| 53 |
| 54 // The height of the virtual expression stack. Always non-negative. |
| 55 int height() const { return height_; } |
| 56 |
| 57 // Forget elements from the top of the expression stack. This is |
| 58 // used when the stack pointer is manually lowered to pop values |
| 59 // left by statements (eg, for...in, try...finally) that have been |
| 60 // escaped from. |
| 61 void Forget(int count); |
| 62 |
| 63 // Make this virtual frame have a state identical to an expected virtual |
| 64 // frame. As a side effect, code may be emitted to make this frame match |
| 65 // the expected one. |
| 66 void MergeTo(VirtualFrame* expected); |
| 67 |
| 68 // Emit code for the physical JS entry and exit frame sequences. After |
| 69 // calling Enter, the virtual frame is ready for use; and after calling |
| 70 // Exit it should not be used. Note that Enter does not allocate space in |
| 71 // the physical frame for storing frame-allocated locals. |
| 72 void Enter(); |
| 73 void Exit(); |
| 74 |
| 75 // Allocate and initialize the frame-allocated locals. The number of |
| 76 // locals is known from the frame's code generator's state (specifically |
| 77 // its scope). As a side effect, code may be emitted. |
| 78 void AllocateLocals(); |
| 79 |
| 80 // The current top of the expression stack as an assembly operand. |
| 81 Operand Top() const { return Operand(esp, 0); } |
| 82 |
| 83 // An element of the expression stack as an assembly operand. |
| 84 Operand Element(int index) const { |
| 85 return Operand(esp, index * kPointerSize); |
| 86 } |
| 87 |
| 88 // A frame-allocated local as an assembly operand. |
| 89 Operand Local(int index) const { |
| 90 ASSERT(0 <= index && index < frame_local_count_); |
| 91 return Operand(ebp, kLocal0Offset - index * kPointerSize); |
| 92 } |
| 93 |
| 94 // The function frame slot. |
| 95 Operand Function() const { return Operand(ebp, kFunctionOffset); } |
| 96 |
| 97 // The context frame slot. |
| 98 Operand Context() const { return Operand(ebp, kContextOffset); } |
| 99 |
| 100 // A parameter as an assembly operand. |
| 101 Operand Parameter(int index) const { |
| 102 ASSERT(-1 <= index && index < parameter_count_); |
| 103 return Operand(ebp, (1 + parameter_count_ - index) * kPointerSize); |
| 104 } |
| 105 |
| 106 // The receiver frame slot. |
| 107 Operand Receiver() const { return Parameter(-1); } |
| 108 |
| 109 // Push a try-catch or try-finally handler on top of the virtual frame. |
| 110 inline void PushTryHandler(HandlerType type); |
| 111 |
| 112 // Call a code stub, given the number of arguments it expects on (and |
| 113 // removes from) the top of the physical frame. |
| 114 inline void CallStub(CodeStub* stub, int frame_arg_count); |
| 115 |
| 116 // Call the runtime, given the number of arguments expected on (and |
| 117 // removed from) the top of the physical frame. |
| 118 inline void CallRuntime(Runtime::Function* f, int frame_arg_count); |
| 119 inline void CallRuntime(Runtime::FunctionId id, int frame_arg_count); |
| 120 |
| 121 // Invoke a builtin, given the number of arguments it expects on (and |
| 122 // removes from) the top of the physical frame. |
| 123 inline void InvokeBuiltin(Builtins::JavaScript id, |
| 124 InvokeFlag flag, |
| 125 int frame_arg_count); |
| 126 |
| 127 // Call into a JS code object, given the number of arguments it expects on |
| 128 // (and removes from) the top of the physical frame. |
| 129 inline void CallCode(Handle<Code> ic, |
| 130 RelocInfo::Mode rmode, |
| 131 int frame_arg_count); |
| 132 |
| 133 // Drop a number of elements from the top of the expression stack. May |
| 134 // emit code to effect the physical frame. |
| 135 inline void Drop(int count); |
| 136 |
| 137 // Pop and discard an element from the top of the expression stack. |
| 138 // Specifically does not clobber any registers excepting possibly the |
| 139 // stack pointer. |
| 140 inline void Pop(); |
| 141 |
| 142 // Pop and save an element from the top of the expression stack. May emit |
| 143 // code. |
| 144 inline void Pop(Register reg); |
| 145 inline void Pop(Operand operand); |
| 146 |
| 147 // Push an element on top of the expression stack. May emit code. |
| 148 inline void Push(Register reg); |
| 149 inline void Push(Operand operand); |
| 150 inline void Push(Immediate immediate); |
| 151 |
| 152 private: |
| 153 static const int kLocal0Offset = JavaScriptFrameConstants::kLocal0Offset; |
| 154 static const int kFunctionOffset = JavaScriptFrameConstants::kFunctionOffset; |
| 155 static const int kContextOffset = StandardFrameConstants::kContextOffset; |
| 156 |
| 157 static const int kHandlerSize = StackHandlerConstants::kSize / kPointerSize; |
| 158 |
| 159 MacroAssembler* masm_; |
| 160 |
| 161 // The number of frame-allocated locals and parameters respectively. |
| 162 int frame_local_count_; |
| 163 int parameter_count_; |
| 164 |
| 165 // The height of the expression stack. |
| 166 int height_; |
| 167 |
| 168 // The JumpTarget class explicitly sets the height_ field of the expected |
| 169 // frame at the actual return target. |
| 170 friend class JumpTarget; |
| 171 }; |
| 172 |
| 173 |
| 174 } } // namespace v8::internal |
| 175 |
| 176 #endif // V8_VIRTUAL_FRAME_IA32_H_ |
| OLD | NEW |