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