| 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 17 matching lines...) Expand all Loading... |
| 28 #include "v8.h" | 28 #include "v8.h" |
| 29 | 29 |
| 30 #include "codegen.h" | 30 #include "codegen.h" |
| 31 #include "codegen-inl.h" | 31 #include "codegen-inl.h" |
| 32 #include "virtual-frame.h" | 32 #include "virtual-frame.h" |
| 33 | 33 |
| 34 namespace v8 { namespace internal { | 34 namespace v8 { namespace internal { |
| 35 | 35 |
| 36 #define __ masm_-> | 36 #define __ masm_-> |
| 37 | 37 |
| 38 |
| 39 // ------------------------------------------------------------------------- |
| 40 // Result implementation. |
| 41 |
| 42 |
| 43 Result::Result(Register reg, CodeGenerator* cgen) |
| 44 : type_(REGISTER), |
| 45 cgen_(cgen) { |
| 46 data_.reg_ = reg; |
| 47 ASSERT(!reg().is(no_reg)); |
| 48 cgen_->allocator()->Use(reg); |
| 49 } |
| 50 |
| 51 |
| 52 void Result::Unuse() { |
| 53 ASSERT(!reg().is(no_reg)); |
| 54 cgen_->allocator()->Unuse(reg()); |
| 55 data_.reg_ = no_reg; |
| 56 } |
| 57 |
| 58 |
| 38 // ------------------------------------------------------------------------- | 59 // ------------------------------------------------------------------------- |
| 39 // VirtualFrame implementation. | 60 // VirtualFrame implementation. |
| 40 | 61 |
| 41 // On entry to a function, the virtual frame already contains the receiver, | 62 // On entry to a function, the virtual frame already contains the receiver, |
| 42 // the parameters, and a return address. All frame elements are in memory. | 63 // the parameters, and a return address. All frame elements are in memory. |
| 43 VirtualFrame::VirtualFrame(CodeGenerator* cgen) | 64 VirtualFrame::VirtualFrame(CodeGenerator* cgen) |
| 44 : cgen_(cgen), | 65 : cgen_(cgen), |
| 45 masm_(cgen->masm()), | 66 masm_(cgen->masm()), |
| 46 elements_(0), | 67 elements_(0), |
| 47 parameter_count_(cgen->scope()->num_parameters()), | 68 parameter_count_(cgen->scope()->num_parameters()), |
| (...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 if (dropped.is_register()) { | 608 if (dropped.is_register()) { |
| 588 Unuse(dropped.reg()); | 609 Unuse(dropped.reg()); |
| 589 } | 610 } |
| 590 } | 611 } |
| 591 } | 612 } |
| 592 | 613 |
| 593 | 614 |
| 594 void VirtualFrame::Drop() { Drop(1); } | 615 void VirtualFrame::Drop() { Drop(1); } |
| 595 | 616 |
| 596 | 617 |
| 618 /* |
| 619 We need comparison with literal to work. |
| 620 It will get Result, is register or constant. |
| 621 Pop gives it this, from register, constant, memory, or |
| 622 reference to slot. |
| 623 |
| 624 In comparison to literal, we need register case to work. |
| 625 We need non-smi stub to exit and return with a non-spilled frame. |
| 626 */ |
| 627 |
| 628 |
| 629 Result VirtualFrame::Pop() { |
| 630 FrameElement popped = elements_.RemoveLast(); |
| 631 bool pop_needed = (stack_pointer_ == elements_.length()); |
| 632 |
| 633 if (popped.is_constant()) { |
| 634 if (pop_needed) { |
| 635 stack_pointer_--; |
| 636 __ add(Operand(esp), Immediate(kPointerSize)); |
| 637 } |
| 638 return Result(popped.handle(), cgen_); |
| 639 } else if (popped.is_register()) { |
| 640 Unuse(popped.reg()); |
| 641 if (pop_needed) { |
| 642 stack_pointer_--; |
| 643 __ add(Operand(esp), Immediate(kPointerSize)); |
| 644 } |
| 645 return Result(popped.reg(), cgen_); |
| 646 } else { |
| 647 ASSERT(popped.is_memory()); |
| 648 Register temp = cgen_->allocator()->Allocate(); |
| 649 ASSERT(!temp.is(no_reg)); |
| 650 ASSERT(pop_needed); |
| 651 stack_pointer_--; |
| 652 __ pop(temp); |
| 653 // The register temp is double counted, by Allocate and Result(temp). |
| 654 cgen_->allocator()->Unuse(temp); |
| 655 return Result(temp, cgen_); |
| 656 } |
| 657 } |
| 658 |
| 597 void VirtualFrame::EmitPop(Register reg) { | 659 void VirtualFrame::EmitPop(Register reg) { |
| 598 ASSERT(stack_pointer_ == elements_.length() - 1); | 660 ASSERT(stack_pointer_ == elements_.length() - 1); |
| 599 stack_pointer_--; | 661 stack_pointer_--; |
| 600 elements_.RemoveLast(); | 662 elements_.RemoveLast(); |
| 601 __ pop(reg); | 663 __ pop(reg); |
| 602 } | 664 } |
| 603 | 665 |
| 604 | 666 |
| 605 void VirtualFrame::EmitPop(Operand operand) { | 667 void VirtualFrame::EmitPop(Operand operand) { |
| 606 ASSERT(stack_pointer_ == elements_.length() - 1); | 668 ASSERT(stack_pointer_ == elements_.length() - 1); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 return false; | 717 return false; |
| 656 } | 718 } |
| 657 } | 719 } |
| 658 return true; | 720 return true; |
| 659 } | 721 } |
| 660 #endif | 722 #endif |
| 661 | 723 |
| 662 #undef __ | 724 #undef __ |
| 663 | 725 |
| 664 } } // namespace v8::internal | 726 } } // namespace v8::internal |
| OLD | NEW |