| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_VIRTUAL_FRAME_ARM_H_ | 28 #ifndef V8_VIRTUAL_FRAME_ARM_H_ |
| 29 #define V8_VIRTUAL_FRAME_ARM_H_ | 29 #define V8_VIRTUAL_FRAME_ARM_H_ |
| 30 | 30 |
| 31 #include "macro-assembler.h" | 31 #include "macro-assembler.h" |
| 32 | 32 |
| 33 namespace v8 { namespace internal { | 33 namespace v8 { namespace internal { |
| 34 | 34 |
| 35 // ------------------------------------------------------------------------- | 35 // ------------------------------------------------------------------------- |
| 36 // Virtual frame elements |
| 37 // |
| 38 // The internal elements of the virtual frames. Elements are (currently) of |
| 39 // only one kind, in-memory. Their actual location is given by their |
| 40 // position in the virtual frame. |
| 41 |
| 42 class Element BASE_EMBEDDED { |
| 43 public: |
| 44 Element() {} |
| 45 |
| 46 bool matches(const Element& other) { return true; } |
| 47 }; |
| 48 |
| 49 |
| 50 // ------------------------------------------------------------------------- |
| 36 // Virtual frames | 51 // Virtual frames |
| 37 // | 52 // |
| 38 // The virtual frame is an abstraction of the physical stack frame. It | 53 // The virtual frame is an abstraction of the physical stack frame. It |
| 39 // encapsulates the parameters, frame-allocated locals, and the expression | 54 // encapsulates the parameters, frame-allocated locals, and the expression |
| 40 // stack. It supports push/pop operations on the expression stack, as well | 55 // stack. It supports push/pop operations on the expression stack, as well |
| 41 // as random access to the expression stack elements, locals, and | 56 // as random access to the expression stack elements, locals, and |
| 42 // parameters. | 57 // parameters. |
| 43 | 58 |
| 44 class VirtualFrame { | 59 class VirtualFrame : public Malloced{ |
| 45 public: | 60 public: |
| 46 // Construct a virtual frame with the given code generator used to | 61 // Construct a virtual frame with the given code generator used to |
| 47 // generate code. | 62 // generate code. |
| 48 explicit VirtualFrame(CodeGenerator* cgen); | 63 explicit VirtualFrame(CodeGenerator* cgen); |
| 49 | 64 |
| 50 // Construct a virtual frame that is a clone of an existing one, initially | 65 // Construct a virtual frame that is a clone of an existing one, initially |
| 51 // with an identical state. | 66 // with an identical state. |
| 52 explicit VirtualFrame(VirtualFrame* original); | 67 explicit VirtualFrame(VirtualFrame* original); |
| 53 | 68 |
| 69 int height() const { |
| 70 return virtual_stack_pointer_ - expression_base_index() + 1; |
| 71 } |
| 72 |
| 73 // Add extra in-memory elements to the top of the frame without generating |
| 74 // code. |
| 75 void Adjust(int count); |
| 76 |
| 77 // Forget frame elements without generating code. |
| 78 void Forget(int count); |
| 79 |
| 54 // Make this virtual frame have a state identical to an expected virtual | 80 // Make this virtual frame have a state identical to an expected virtual |
| 55 // frame. As a side effect, code may be emitted to make this frame match | 81 // frame. As a side effect, code may be emitted to make this frame match |
| 56 // the expected one. | 82 // the expected one. |
| 57 void MergeTo(VirtualFrame* expected); | 83 void MergeTo(VirtualFrame* expected); |
| 58 | 84 |
| 59 // Emit code for the physical JS entry and exit frame sequences. After | 85 // Emit code for the physical JS entry and exit frame sequences. After |
| 60 // calling Enter, the virtual frame is ready for use; and after calling | 86 // calling Enter, the virtual frame is ready for use; and after calling |
| 61 // Exit it should not be used. Note that Enter does not allocate space in | 87 // Exit it should not be used. Note that Enter does not allocate space in |
| 62 // the physical frame for storing frame-allocated locals. | 88 // the physical frame for storing frame-allocated locals. |
| 63 void Enter(); | 89 void Enter(); |
| 64 void Exit(); | 90 void Exit(); |
| 65 | 91 |
| 66 // Allocate and initialize the frame-allocated locals. The number of | 92 // Allocate and initialize the frame-allocated locals. The number of |
| 67 // locals is known from the frame's code generator's state (specifically | 93 // locals is known from the frame's code generator's state (specifically |
| 68 // its scope). As a side effect, code may be emitted. | 94 // its scope). As a side effect, code may be emitted. |
| 69 void AllocateLocals(); | 95 void AllocateStackSlots(int count); |
| 70 | 96 |
| 71 // The current top of the expression stack as an assembly operand. | 97 // The current top of the expression stack as an assembly operand. |
| 72 MemOperand Top() const { return MemOperand(sp, 0); } | 98 MemOperand Top() const { return MemOperand(sp, 0); } |
| 73 | 99 |
| 74 // An element of the expression stack as an assembly operand. | 100 // An element of the expression stack as an assembly operand. |
| 75 MemOperand Element(int index) const { | 101 MemOperand ElementAt(int index) const { |
| 76 return MemOperand(sp, index * kPointerSize); | 102 return MemOperand(sp, index * kPointerSize); |
| 77 } | 103 } |
| 78 | 104 |
| 79 // A frame-allocated local as an assembly operand. | 105 // A frame-allocated local as an assembly operand. |
| 80 MemOperand Local(int index) const { | 106 MemOperand LocalAt(int index) const { |
| 81 ASSERT(0 <= index && index < frame_local_count_); | 107 ASSERT(0 <= index); |
| 108 ASSERT(index < local_count_); |
| 82 return MemOperand(fp, kLocal0Offset - index * kPointerSize); | 109 return MemOperand(fp, kLocal0Offset - index * kPointerSize); |
| 83 } | 110 } |
| 84 | 111 |
| 85 // The function frame slot. | 112 // The function frame slot. |
| 86 MemOperand Function() const { return MemOperand(fp, kFunctionOffset); } | 113 MemOperand Function() const { return MemOperand(fp, kFunctionOffset); } |
| 87 | 114 |
| 88 // The context frame slot. | 115 // The context frame slot. |
| 89 MemOperand Context() const { return MemOperand(fp, kContextOffset); } | 116 MemOperand Context() const { return MemOperand(fp, kContextOffset); } |
| 90 | 117 |
| 91 // A parameter as an assembly operand. | 118 // A parameter as an assembly operand. |
| 92 MemOperand Parameter(int index) const { | 119 MemOperand ParameterAt(int index) const { |
| 93 // Index -1 corresponds to the receiver. | 120 // Index -1 corresponds to the receiver. |
| 94 ASSERT(-1 <= index && index <= parameter_count_); | 121 ASSERT(-1 <= index && index <= parameter_count_); |
| 95 return MemOperand(fp, (1 + parameter_count_ - index) * kPointerSize); | 122 return MemOperand(fp, (1 + parameter_count_ - index) * kPointerSize); |
| 96 } | 123 } |
| 97 | 124 |
| 125 // Push a try-catch or try-finally handler on top of the virtual frame. |
| 126 void PushTryHandler(HandlerType type); |
| 127 |
| 128 // Call a code stub, given the number of arguments it expects on (and |
| 129 // removes from) the top of the physical frame. |
| 130 void CallStub(CodeStub* stub, int frame_arg_count); |
| 131 |
| 132 // Call the runtime, given the number of arguments expected on (and |
| 133 // removed from) the top of the physical frame. |
| 134 void CallRuntime(Runtime::Function* f, int frame_arg_count); |
| 135 void CallRuntime(Runtime::FunctionId id, int frame_arg_count); |
| 136 |
| 137 // Invoke a builtin, given the number of arguments it expects on (and |
| 138 // removes from) the top of the physical frame. |
| 139 void InvokeBuiltin(Builtins::JavaScript id, |
| 140 InvokeJSFlags flags, |
| 141 int frame_arg_count); |
| 142 |
| 143 // Call into a JS code object, given the number of arguments it expects on |
| 144 // (and removes from) the top of the physical frame. |
| 145 void CallCodeObject(Handle<Code> ic, |
| 146 RelocInfo::Mode rmode, |
| 147 int frame_arg_count); |
| 148 |
| 98 // Drop a number of elements from the top of the expression stack. May | 149 // Drop a number of elements from the top of the expression stack. May |
| 99 // emit code to effect the physical frame. | 150 // emit code to affect the physical frame. Does not clobber any registers |
| 100 inline void Drop(int count); | 151 // excepting possibly the stack pointer. |
| 152 void Drop(int count); |
| 101 | 153 |
| 102 // Pop and discard an element from the top of the expression stack. | 154 // Drop one element. |
| 103 // Specifically does not clobber any registers excepting possibly the | 155 void Drop(); |
| 104 // stack pointer. | |
| 105 inline void Pop(); | |
| 106 | 156 |
| 107 // Pop and save an element from the top of the expression stack. May emit | 157 // Pop and save an element from the top of the expression stack. May emit |
| 108 // code. | 158 // code. |
| 109 inline void Pop(Register reg); | 159 void Pop(Register reg); |
| 110 | 160 |
| 111 // Push an element on top of the expression stack. May emit code. | 161 // Push an element on top of the expression stack. May emit code. |
| 112 inline void Push(Register reg); | 162 void Push(Register reg); |
| 113 | 163 |
| 114 private: | 164 private: |
| 115 static const int kLocal0Offset = JavaScriptFrameConstants::kLocal0Offset; | 165 static const int kLocal0Offset = JavaScriptFrameConstants::kLocal0Offset; |
| 116 static const int kFunctionOffset = JavaScriptFrameConstants::kFunctionOffset; | 166 static const int kFunctionOffset = JavaScriptFrameConstants::kFunctionOffset; |
| 117 static const int kContextOffset = StandardFrameConstants::kContextOffset; | 167 static const int kContextOffset = StandardFrameConstants::kContextOffset; |
| 118 | 168 |
| 169 static const int kHandlerSize = StackHandlerConstants::kSize / kPointerSize; |
| 170 |
| 119 MacroAssembler* masm_; | 171 MacroAssembler* masm_; |
| 120 | 172 |
| 173 List<Element> elements_; |
| 174 |
| 175 // The virtual stack pointer is the index of the top element of the stack. |
| 176 int virtual_stack_pointer_; |
| 177 |
| 178 int virtual_frame_pointer_; |
| 179 |
| 121 // The number of frame-allocated locals and parameters respectively. | 180 // The number of frame-allocated locals and parameters respectively. |
| 122 int frame_local_count_; | |
| 123 int parameter_count_; | 181 int parameter_count_; |
| 182 int local_count_; |
| 183 |
| 184 // The index of the first parameter. The receiver lies below the first |
| 185 // parameter. |
| 186 int param0_index() const { return 1; } |
| 187 |
| 188 // The index of the first local. Between the parameters and the locals |
| 189 // lie the return address, the saved frame pointer, the context, and the |
| 190 // function. |
| 191 int local0_index() const { return param0_index() + parameter_count_ + 4; } |
| 192 |
| 193 // The index of the base of the expression stack. |
| 194 int expression_base_index() const { return local0_index() + local_count_; } |
| 195 |
| 196 void AddElement(const Element& element) { |
| 197 virtual_stack_pointer_++; |
| 198 elements_.Add(element); |
| 199 } |
| 200 |
| 201 Element RemoveElement() { |
| 202 virtual_stack_pointer_--; |
| 203 return elements_.RemoveLast(); |
| 204 } |
| 124 }; | 205 }; |
| 125 | 206 |
| 126 | 207 |
| 127 } } // namespace v8::internal | 208 } } // namespace v8::internal |
| 128 | 209 |
| 129 #endif // V8_VIRTUAL_FRAME_ARM_H_ | 210 #endif // V8_VIRTUAL_FRAME_ARM_H_ |
| OLD | NEW |