Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 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 | |
| 29 | |
| 30 | #include "v8.h" |
| 31 | |
| 32 | #include "codegen-inl.h" |
| 33 | #include "register-allocator-inl.h" |
| 34 | #include "scopes.h" |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 35 | #include "virtual-frame-inl.h" |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 36 | |
| 37 | namespace v8 { |
| 38 | namespace internal { |
| 39 | |
| 40 | // ------------------------------------------------------------------------- |
| 41 | // VirtualFrame implementation. |
| 42 | |
| 43 | #define __ ACCESS_MASM(masm()) |
| 44 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 45 | void VirtualFrame::SyncElementBelowStackPointer(int index) { |
| 46 | UNREACHABLE(); |
| 47 | } |
| 48 | |
| 49 | |
| 50 | void VirtualFrame::SyncElementByPushing(int index) { |
| 51 | UNREACHABLE(); |
| 52 | } |
| 53 | |
| 54 | |
| 55 | void VirtualFrame::SyncRange(int begin, int end) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 56 | // All elements are in memory on MIPS (ie, synced). |
| 57 | #ifdef DEBUG |
| 58 | for (int i = begin; i <= end; i++) { |
| 59 | ASSERT(elements_[i].is_synced()); |
| 60 | } |
| 61 | #endif |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | |
| 65 | void VirtualFrame::MergeTo(VirtualFrame* expected) { |
| 66 | UNIMPLEMENTED_MIPS(); |
| 67 | } |
| 68 | |
| 69 | |
| 70 | void VirtualFrame::Enter() { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 71 | // TODO(MIPS): Implement DEBUG |
| 72 | |
| 73 | // We are about to push four values to the frame. |
| 74 | Adjust(4); |
| 75 | __ MultiPush(ra.bit() | fp.bit() | cp.bit() | a1.bit()); |
| 76 | // Adjust FP to point to saved FP. |
| 77 | __ addiu(fp, sp, 2 * kPointerSize); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | |
| 81 | void VirtualFrame::Exit() { |
| 82 | UNIMPLEMENTED_MIPS(); |
| 83 | } |
| 84 | |
| 85 | |
| 86 | void VirtualFrame::AllocateStackSlots() { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 87 | int count = local_count(); |
| 88 | if (count > 0) { |
| 89 | Comment cmnt(masm(), "[ Allocate space for locals"); |
| 90 | Adjust(count); |
| 91 | // Initialize stack slots with 'undefined' value. |
| 92 | __ LoadRoot(t0, Heap::kUndefinedValueRootIndex); |
| 93 | __ addiu(sp, sp, -count * kPointerSize); |
| 94 | for (int i = 0; i < count; i++) { |
| 95 | __ sw(t0, MemOperand(sp, (count-i-1)*kPointerSize)); |
| 96 | } |
| 97 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | |
| 101 | void VirtualFrame::SaveContextRegister() { |
| 102 | UNIMPLEMENTED_MIPS(); |
| 103 | } |
| 104 | |
| 105 | |
| 106 | void VirtualFrame::RestoreContextRegister() { |
| 107 | UNIMPLEMENTED_MIPS(); |
| 108 | } |
| 109 | |
| 110 | |
| 111 | void VirtualFrame::PushReceiverSlotAddress() { |
| 112 | UNIMPLEMENTED_MIPS(); |
| 113 | } |
| 114 | |
| 115 | |
| 116 | int VirtualFrame::InvalidateFrameSlotAt(int index) { |
| 117 | return kIllegalIndex; |
| 118 | } |
| 119 | |
| 120 | |
| 121 | void VirtualFrame::TakeFrameSlotAt(int index) { |
| 122 | UNIMPLEMENTED_MIPS(); |
| 123 | } |
| 124 | |
| 125 | |
| 126 | void VirtualFrame::StoreToFrameSlotAt(int index) { |
| 127 | UNIMPLEMENTED_MIPS(); |
| 128 | } |
| 129 | |
| 130 | |
| 131 | void VirtualFrame::PushTryHandler(HandlerType type) { |
| 132 | UNIMPLEMENTED_MIPS(); |
| 133 | } |
| 134 | |
| 135 | |
| 136 | void VirtualFrame::RawCallStub(CodeStub* stub) { |
| 137 | UNIMPLEMENTED_MIPS(); |
| 138 | } |
| 139 | |
| 140 | |
| 141 | void VirtualFrame::CallStub(CodeStub* stub, Result* arg) { |
| 142 | UNIMPLEMENTED_MIPS(); |
| 143 | } |
| 144 | |
| 145 | |
| 146 | void VirtualFrame::CallStub(CodeStub* stub, Result* arg0, Result* arg1) { |
| 147 | UNIMPLEMENTED_MIPS(); |
| 148 | } |
| 149 | |
| 150 | |
| 151 | void VirtualFrame::CallRuntime(Runtime::Function* f, int arg_count) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 152 | PrepareForCall(arg_count, arg_count); |
| 153 | ASSERT(cgen()->HasValidEntryRegisters()); |
| 154 | __ CallRuntime(f, arg_count); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | |
| 158 | void VirtualFrame::CallRuntime(Runtime::FunctionId id, int arg_count) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 159 | PrepareForCall(arg_count, arg_count); |
| 160 | ASSERT(cgen()->HasValidEntryRegisters()); |
| 161 | __ CallRuntime(id, arg_count); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | |
| 165 | void VirtualFrame::CallAlignedRuntime(Runtime::Function* f, int arg_count) { |
| 166 | UNIMPLEMENTED_MIPS(); |
| 167 | } |
| 168 | |
| 169 | |
| 170 | void VirtualFrame::CallAlignedRuntime(Runtime::FunctionId id, int arg_count) { |
| 171 | UNIMPLEMENTED_MIPS(); |
| 172 | } |
| 173 | |
| 174 | |
| 175 | void VirtualFrame::InvokeBuiltin(Builtins::JavaScript id, |
| 176 | InvokeJSFlags flags, |
| 177 | Result* arg_count_register, |
| 178 | int arg_count) { |
| 179 | UNIMPLEMENTED_MIPS(); |
| 180 | } |
| 181 | |
| 182 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 183 | void VirtualFrame::CallCodeObject(Handle<Code> code, |
| 184 | RelocInfo::Mode rmode, |
| 185 | int dropped_args) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 186 | switch (code->kind()) { |
| 187 | case Code::CALL_IC: |
| 188 | break; |
| 189 | case Code::FUNCTION: |
| 190 | UNIMPLEMENTED_MIPS(); |
| 191 | break; |
| 192 | case Code::KEYED_LOAD_IC: |
| 193 | UNIMPLEMENTED_MIPS(); |
| 194 | break; |
| 195 | case Code::LOAD_IC: |
| 196 | UNIMPLEMENTED_MIPS(); |
| 197 | break; |
| 198 | case Code::KEYED_STORE_IC: |
| 199 | UNIMPLEMENTED_MIPS(); |
| 200 | break; |
| 201 | case Code::STORE_IC: |
| 202 | UNIMPLEMENTED_MIPS(); |
| 203 | break; |
| 204 | case Code::BUILTIN: |
| 205 | UNIMPLEMENTED_MIPS(); |
| 206 | break; |
| 207 | default: |
| 208 | UNREACHABLE(); |
| 209 | break; |
| 210 | } |
| 211 | Forget(dropped_args); |
| 212 | ASSERT(cgen()->HasValidEntryRegisters()); |
| 213 | __ Call(code, rmode); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | |
| 217 | void VirtualFrame::CallCodeObject(Handle<Code> code, |
| 218 | RelocInfo::Mode rmode, |
| 219 | Result* arg, |
| 220 | int dropped_args) { |
| 221 | UNIMPLEMENTED_MIPS(); |
| 222 | } |
| 223 | |
| 224 | |
| 225 | void VirtualFrame::CallCodeObject(Handle<Code> code, |
| 226 | RelocInfo::Mode rmode, |
| 227 | Result* arg0, |
| 228 | Result* arg1, |
| 229 | int dropped_args, |
| 230 | bool set_auto_args_slots) { |
| 231 | UNIMPLEMENTED_MIPS(); |
| 232 | } |
| 233 | |
| 234 | |
| 235 | void VirtualFrame::Drop(int count) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 236 | ASSERT(count >= 0); |
| 237 | ASSERT(height() >= count); |
| 238 | int num_virtual_elements = (element_count() - 1) - stack_pointer_; |
| 239 | |
| 240 | // Emit code to lower the stack pointer if necessary. |
| 241 | if (num_virtual_elements < count) { |
| 242 | int num_dropped = count - num_virtual_elements; |
| 243 | stack_pointer_ -= num_dropped; |
| 244 | __ addiu(sp, sp, num_dropped * kPointerSize); |
| 245 | } |
| 246 | |
| 247 | // Discard elements from the virtual frame and free any registers. |
| 248 | for (int i = 0; i < count; i++) { |
| 249 | FrameElement dropped = elements_.RemoveLast(); |
| 250 | if (dropped.is_register()) { |
| 251 | Unuse(dropped.reg()); |
| 252 | } |
| 253 | } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | |
| 257 | void VirtualFrame::DropFromVFrameOnly(int count) { |
| 258 | UNIMPLEMENTED_MIPS(); |
| 259 | } |
| 260 | |
| 261 | |
| 262 | Result VirtualFrame::Pop() { |
| 263 | UNIMPLEMENTED_MIPS(); |
| 264 | Result res = Result(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 265 | return res; // UNIMPLEMENTED RETURN |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | |
| 269 | void VirtualFrame::EmitPop(Register reg) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 270 | ASSERT(stack_pointer_ == element_count() - 1); |
| 271 | stack_pointer_--; |
| 272 | elements_.RemoveLast(); |
| 273 | __ Pop(reg); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 276 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 277 | void VirtualFrame::EmitMultiPop(RegList regs) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 278 | ASSERT(stack_pointer_ == element_count() - 1); |
| 279 | for (int16_t i = 0; i < kNumRegisters; i++) { |
| 280 | if ((regs & (1 << i)) != 0) { |
| 281 | stack_pointer_--; |
| 282 | elements_.RemoveLast(); |
| 283 | } |
| 284 | } |
| 285 | __ MultiPop(regs); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | |
| 289 | void VirtualFrame::EmitPush(Register reg) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 290 | ASSERT(stack_pointer_ == element_count() - 1); |
| 291 | elements_.Add(FrameElement::MemoryElement(NumberInfo::Unknown())); |
| 292 | stack_pointer_++; |
| 293 | __ Push(reg); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 294 | } |
| 295 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 296 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 297 | void VirtualFrame::EmitMultiPush(RegList regs) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 298 | ASSERT(stack_pointer_ == element_count() - 1); |
| 299 | for (int16_t i = kNumRegisters; i > 0; i--) { |
| 300 | if ((regs & (1 << i)) != 0) { |
| 301 | elements_.Add(FrameElement::MemoryElement(NumberInfo::Unknown())); |
| 302 | stack_pointer_++; |
| 303 | } |
| 304 | } |
| 305 | __ MultiPush(regs); |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 308 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 309 | void VirtualFrame::EmitArgumentSlots(RegList reglist) { |
| 310 | UNIMPLEMENTED_MIPS(); |
| 311 | } |
| 312 | |
| 313 | #undef __ |
| 314 | |
| 315 | } } // namespace v8::internal |
| 316 | |