| OLD | NEW |
| (Empty) |
| 1 // Copyright 2010 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_LIGHT_INL_H_ | |
| 29 #define V8_VIRTUAL_FRAME_LIGHT_INL_H_ | |
| 30 | |
| 31 #include "codegen.h" | |
| 32 #include "register-allocator.h" | |
| 33 #include "scopes.h" | |
| 34 #include "type-info.h" | |
| 35 | |
| 36 #include "codegen-inl.h" | |
| 37 #include "jump-target-light-inl.h" | |
| 38 | |
| 39 namespace v8 { | |
| 40 namespace internal { | |
| 41 | |
| 42 VirtualFrame::VirtualFrame(InvalidVirtualFrameInitializer* dummy) | |
| 43 : element_count_(0), | |
| 44 top_of_stack_state_(NO_TOS_REGISTERS), | |
| 45 register_allocation_map_(0), | |
| 46 tos_known_smi_map_(0) { } | |
| 47 | |
| 48 | |
| 49 // On entry to a function, the virtual frame already contains the receiver, | |
| 50 // the parameters, and a return address. All frame elements are in memory. | |
| 51 VirtualFrame::VirtualFrame() | |
| 52 : element_count_(parameter_count() + 2), | |
| 53 top_of_stack_state_(NO_TOS_REGISTERS), | |
| 54 register_allocation_map_(0), | |
| 55 tos_known_smi_map_(0) { } | |
| 56 | |
| 57 | |
| 58 // When cloned, a frame is a deep copy of the original. | |
| 59 VirtualFrame::VirtualFrame(VirtualFrame* original) | |
| 60 : element_count_(original->element_count()), | |
| 61 top_of_stack_state_(original->top_of_stack_state_), | |
| 62 register_allocation_map_(original->register_allocation_map_), | |
| 63 tos_known_smi_map_(0) { } | |
| 64 | |
| 65 | |
| 66 bool VirtualFrame::Equals(const VirtualFrame* other) { | |
| 67 ASSERT(element_count() == other->element_count()); | |
| 68 if (top_of_stack_state_ != other->top_of_stack_state_) return false; | |
| 69 if (register_allocation_map_ != other->register_allocation_map_) return false; | |
| 70 if (tos_known_smi_map_ != other->tos_known_smi_map_) return false; | |
| 71 | |
| 72 return true; | |
| 73 } | |
| 74 | |
| 75 | |
| 76 void VirtualFrame::PrepareForReturn() { | |
| 77 // Don't bother flushing tos registers as returning does not require more | |
| 78 // access to the expression stack. | |
| 79 top_of_stack_state_ = NO_TOS_REGISTERS; | |
| 80 } | |
| 81 | |
| 82 | |
| 83 VirtualFrame::RegisterAllocationScope::RegisterAllocationScope( | |
| 84 CodeGenerator* cgen) | |
| 85 : cgen_(cgen), | |
| 86 old_is_spilled_( | |
| 87 Isolate::Current()->is_virtual_frame_in_spilled_scope()) { | |
| 88 Isolate::Current()->set_is_virtual_frame_in_spilled_scope(false); | |
| 89 if (old_is_spilled_) { | |
| 90 VirtualFrame* frame = cgen->frame(); | |
| 91 if (frame != NULL) { | |
| 92 frame->AssertIsSpilled(); | |
| 93 } | |
| 94 } | |
| 95 } | |
| 96 | |
| 97 | |
| 98 VirtualFrame::RegisterAllocationScope::~RegisterAllocationScope() { | |
| 99 Isolate::Current()->set_is_virtual_frame_in_spilled_scope(old_is_spilled_); | |
| 100 if (old_is_spilled_) { | |
| 101 VirtualFrame* frame = cgen_->frame(); | |
| 102 if (frame != NULL) { | |
| 103 frame->SpillAll(); | |
| 104 } | |
| 105 } | |
| 106 } | |
| 107 | |
| 108 | |
| 109 CodeGenerator* VirtualFrame::cgen() const { | |
| 110 return CodeGeneratorScope::Current(Isolate::Current()); | |
| 111 } | |
| 112 | |
| 113 | |
| 114 MacroAssembler* VirtualFrame::masm() { return cgen()->masm(); } | |
| 115 | |
| 116 | |
| 117 void VirtualFrame::CallStub(CodeStub* stub, int arg_count) { | |
| 118 if (arg_count != 0) Forget(arg_count); | |
| 119 ASSERT(cgen()->HasValidEntryRegisters()); | |
| 120 masm()->CallStub(stub); | |
| 121 } | |
| 122 | |
| 123 | |
| 124 int VirtualFrame::parameter_count() const { | |
| 125 return cgen()->scope()->num_parameters(); | |
| 126 } | |
| 127 | |
| 128 | |
| 129 int VirtualFrame::local_count() const { | |
| 130 return cgen()->scope()->num_stack_slots(); | |
| 131 } | |
| 132 | |
| 133 | |
| 134 int VirtualFrame::frame_pointer() const { return parameter_count() + 3; } | |
| 135 | |
| 136 | |
| 137 int VirtualFrame::context_index() { return frame_pointer() - 1; } | |
| 138 | |
| 139 | |
| 140 int VirtualFrame::function_index() { return frame_pointer() - 2; } | |
| 141 | |
| 142 | |
| 143 int VirtualFrame::local0_index() const { return frame_pointer() + 2; } | |
| 144 | |
| 145 | |
| 146 int VirtualFrame::fp_relative(int index) { | |
| 147 ASSERT(index < element_count()); | |
| 148 ASSERT(frame_pointer() < element_count()); // FP is on the frame. | |
| 149 return (frame_pointer() - index) * kPointerSize; | |
| 150 } | |
| 151 | |
| 152 | |
| 153 int VirtualFrame::expression_base_index() const { | |
| 154 return local0_index() + local_count(); | |
| 155 } | |
| 156 | |
| 157 | |
| 158 int VirtualFrame::height() const { | |
| 159 return element_count() - expression_base_index(); | |
| 160 } | |
| 161 | |
| 162 | |
| 163 MemOperand VirtualFrame::LocalAt(int index) { | |
| 164 ASSERT(0 <= index); | |
| 165 ASSERT(index < local_count()); | |
| 166 return MemOperand(fp, kLocal0Offset - index * kPointerSize); | |
| 167 } | |
| 168 | |
| 169 } } // namespace v8::internal | |
| 170 | |
| 171 #endif // V8_VIRTUAL_FRAME_LIGHT_INL_H_ | |
| OLD | NEW |