OLD | NEW |
---|---|
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 13 matching lines...) Expand all Loading... | |
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | 27 |
28 #ifndef V8_VIRTUAL_FRAME_LIGHT_INL_H_ | 28 #ifndef V8_VIRTUAL_FRAME_LIGHT_INL_H_ |
29 #define V8_VIRTUAL_FRAME_LIGHT_INL_H_ | 29 #define V8_VIRTUAL_FRAME_LIGHT_INL_H_ |
30 | 30 |
31 #include "type-info.h" | 31 #include "type-info.h" |
32 #include "register-allocator.h" | 32 #include "register-allocator.h" |
33 #include "scopes.h" | 33 #include "scopes.h" |
34 #include "jump-target-light-inl.h" | |
35 #include "codegen.h" | |
36 #include "codegen-inl.h" | |
34 | 37 |
35 namespace v8 { | 38 namespace v8 { |
36 namespace internal { | 39 namespace internal { |
37 | 40 |
41 VirtualFrame::VirtualFrame(InvalidVirtualFrameInitializer* dummy) | |
42 : element_count_(0), | |
43 top_of_stack_state_(NO_TOS_REGISTERS), | |
44 register_allocation_map_(0) { } | |
45 | |
46 | |
38 // On entry to a function, the virtual frame already contains the receiver, | 47 // On entry to a function, the virtual frame already contains the receiver, |
39 // the parameters, and a return address. All frame elements are in memory. | 48 // the parameters, and a return address. All frame elements are in memory. |
40 VirtualFrame::VirtualFrame() | 49 VirtualFrame::VirtualFrame() |
41 : element_count_(parameter_count() + 2), | 50 : element_count_(parameter_count() + 2), |
42 top_of_stack_state_(NO_TOS_REGISTERS), | 51 top_of_stack_state_(NO_TOS_REGISTERS), |
43 register_allocation_map_(0) { } | 52 register_allocation_map_(0) { } |
44 | 53 |
45 | 54 |
46 // When cloned, a frame is a deep copy of the original. | 55 // When cloned, a frame is a deep copy of the original. |
47 VirtualFrame::VirtualFrame(VirtualFrame* original) | 56 VirtualFrame::VirtualFrame(VirtualFrame* original) |
48 : element_count_(original->element_count()), | 57 : element_count_(original->element_count()), |
49 top_of_stack_state_(original->top_of_stack_state_), | 58 top_of_stack_state_(original->top_of_stack_state_), |
50 register_allocation_map_(original->register_allocation_map_) { } | 59 register_allocation_map_(original->register_allocation_map_) { } |
51 | 60 |
52 | 61 |
53 bool VirtualFrame::Equals(VirtualFrame* other) { | 62 bool VirtualFrame::Equals(VirtualFrame* other) { |
54 ASSERT(element_count() == other->element_count()); | 63 ASSERT(element_count() == other->element_count()); |
55 if (top_of_stack_state_ != other->top_of_stack_state_) return false; | 64 if (top_of_stack_state_ != other->top_of_stack_state_) return false; |
56 if (register_allocation_map_ != other->register_allocation_map_) return false; | 65 if (register_allocation_map_ != other->register_allocation_map_) return false; |
57 | 66 |
58 return true; | 67 return true; |
59 } | 68 } |
60 | 69 |
61 | 70 |
62 void VirtualFrame::PrepareForReturn() { | 71 void VirtualFrame::PrepareForReturn() { |
63 SpillAll(); | 72 SpillAll(); |
64 } | 73 } |
65 | 74 |
66 | 75 |
76 VirtualFrame::RegisterAllocationScope::RegisterAllocationScope( | |
77 CodeGenerator* cgen) | |
78 : cgen_(cgen), | |
79 old_is_spilled_(SpilledScope::is_spilled_) { | |
80 SpilledScope::is_spilled_ = false; | |
81 if (old_is_spilled_) { | |
82 VirtualFrame* frame = cgen->frame(); | |
83 if (frame != NULL) { | |
84 frame->AssertIsSpilled(); | |
85 } | |
86 } | |
87 } | |
88 | |
89 | |
90 VirtualFrame::RegisterAllocationScope::~RegisterAllocationScope() { | |
91 SpilledScope::is_spilled_ = old_is_spilled_; | |
92 if (old_is_spilled_) { | |
93 VirtualFrame* frame = cgen_->frame(); | |
94 if (frame != NULL) { | |
95 frame->SpillAll(); | |
96 } | |
97 } | |
98 } | |
99 | |
100 | |
101 CodeGenerator* VirtualFrame::cgen() { return CodeGeneratorScope::Current(); } | |
102 | |
103 | |
104 MacroAssembler* VirtualFrame::masm() { return cgen()->masm(); } | |
105 | |
106 | |
107 void VirtualFrame::CallStub(CodeStub* stub, int arg_count) { | |
108 if (arg_count != 0) Forget(arg_count); | |
109 ASSERT(cgen()->HasValidEntryRegisters()); | |
110 masm()->CallStub(stub); | |
111 } | |
112 | |
113 | |
114 int VirtualFrame::parameter_count() { | |
115 return cgen()->scope()->num_parameters(); | |
116 } | |
117 | |
118 | |
119 int VirtualFrame::local_count() { return cgen()->scope()->num_stack_slots(); } | |
120 | |
121 | |
Søren Thygesen Gjesse
2010/05/06 07:48:11
Can these numbers in some way use the constants fr
Erik Corry
2010/05/10 10:34:10
I tried this but it got much uglier (this code is
| |
122 int VirtualFrame::frame_pointer() { return parameter_count() + 3; } | |
123 | |
124 | |
125 int VirtualFrame::context_index() { return frame_pointer() - 1; } | |
126 | |
127 | |
128 int VirtualFrame::function_index() { return frame_pointer() - 2; } | |
129 | |
130 | |
131 int VirtualFrame::local0_index() { return frame_pointer() + 2; } | |
132 | |
133 | |
134 int VirtualFrame::fp_relative(int index) { | |
135 ASSERT(index < element_count()); | |
136 ASSERT(frame_pointer() < element_count()); // FP is on the frame. | |
137 return (frame_pointer() - index) * kPointerSize; | |
138 } | |
139 | |
140 | |
141 int VirtualFrame::expression_base_index() { | |
142 return local0_index() + local_count(); | |
143 } | |
144 | |
145 | |
146 int VirtualFrame::height() { | |
147 return element_count() - expression_base_index(); | |
148 } | |
149 | |
150 | |
151 MemOperand VirtualFrame::LocalAt(int index) { | |
152 ASSERT(0 <= index); | |
153 ASSERT(index < local_count()); | |
154 return MemOperand(fp, kLocal0Offset - index * kPointerSize); | |
155 } | |
156 | |
67 } } // namespace v8::internal | 157 } } // namespace v8::internal |
68 | 158 |
69 #endif // V8_VIRTUAL_FRAME_LIGHT_INL_H_ | 159 #endif // V8_VIRTUAL_FRAME_LIGHT_INL_H_ |
OLD | NEW |