| OLD | NEW |
| 1 // Copyright (c) 1994-2006 Sun Microsystems Inc. | 1 // Copyright (c) 1994-2006 Sun Microsystems Inc. |
| 2 // All Rights Reserved. | 2 // All Rights Reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // - Redistributions of source code must retain the above copyright notice, | 8 // - Redistributions of source code must retain the above copyright notice, |
| 9 // this list of conditions and the following disclaimer. | 9 // this list of conditions and the following disclaimer. |
| 10 // | 10 // |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 28 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 29 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | 30 |
| 31 // The original source code covered by the above license above has been | 31 // The original source code covered by the above license above has been |
| 32 // modified significantly by Google Inc. | 32 // modified significantly by Google Inc. |
| 33 // Copyright 2011 the V8 project authors. All rights reserved. | 33 // Copyright 2011 the V8 project authors. All rights reserved. |
| 34 | 34 |
| 35 #ifndef V8_ASSEMBLER_H_ | 35 #ifndef V8_ASSEMBLER_H_ |
| 36 #define V8_ASSEMBLER_H_ | 36 #define V8_ASSEMBLER_H_ |
| 37 | 37 |
| 38 #include "allocation.h" |
| 38 #include "gdb-jit.h" | 39 #include "gdb-jit.h" |
| 39 #include "runtime.h" | 40 #include "runtime.h" |
| 40 #include "token.h" | 41 #include "token.h" |
| 41 | 42 |
| 42 namespace v8 { | 43 namespace v8 { |
| 43 namespace internal { | 44 namespace internal { |
| 44 | 45 |
| 45 const unsigned kNoASTId = -1; | 46 const unsigned kNoASTId = -1; |
| 46 // ----------------------------------------------------------------------------- | 47 // ----------------------------------------------------------------------------- |
| 47 // Platform independent assembler base class. | 48 // Platform independent assembler base class. |
| 48 | 49 |
| 49 class AssemblerBase: public Malloced { | 50 class AssemblerBase: public Malloced { |
| 50 public: | 51 public: |
| 51 explicit AssemblerBase(Isolate* isolate) : isolate_(isolate) {} | 52 explicit AssemblerBase(Isolate* isolate); |
| 52 | 53 |
| 53 Isolate* isolate() const { return isolate_; } | 54 Isolate* isolate() const { return isolate_; } |
| 55 int jit_cookie() { return jit_cookie_; } |
| 54 | 56 |
| 55 private: | 57 private: |
| 56 Isolate* isolate_; | 58 Isolate* isolate_; |
| 59 int jit_cookie_; |
| 57 }; | 60 }; |
| 58 | 61 |
| 59 // ----------------------------------------------------------------------------- | 62 // ----------------------------------------------------------------------------- |
| 60 // Common double constants. | 63 // Common double constants. |
| 61 | 64 |
| 62 class DoubleConstant: public AllStatic { | 65 class DoubleConstant: public AllStatic { |
| 63 public: | 66 public: |
| 64 static const double min_int; | 67 static const double min_int; |
| 65 static const double one_half; | 68 static const double one_half; |
| 66 static const double minus_zero; | 69 static const double minus_zero; |
| 70 static const double zero; |
| 71 static const double uint8_max_value; |
| 67 static const double negative_infinity; | 72 static const double negative_infinity; |
| 68 static const double nan; | 73 static const double nan; |
| 69 }; | 74 }; |
| 70 | 75 |
| 71 | 76 |
| 72 // ----------------------------------------------------------------------------- | 77 // ----------------------------------------------------------------------------- |
| 73 // Labels represent pc locations; they are typically jump or call targets. | 78 // Labels represent pc locations; they are typically jump or call targets. |
| 74 // After declaration, a label can be freely used to denote known or (yet) | 79 // After declaration, a label can be freely used to denote known or (yet) |
| 75 // unknown pc location. Assembler::bind() is used to bind a label to the | 80 // unknown pc location. Assembler::bind() is used to bind a label to the |
| 76 // current pc. A label can be bound only once. | 81 // current pc. A label can be bound only once. |
| 77 | 82 |
| 78 class Label BASE_EMBEDDED { | 83 class Label BASE_EMBEDDED { |
| 79 public: | 84 public: |
| 80 INLINE(Label()) { Unuse(); } | 85 enum Distance { |
| 86 kNear, kFar |
| 87 }; |
| 88 |
| 89 INLINE(Label()) { |
| 90 Unuse(); |
| 91 UnuseNear(); |
| 92 } |
| 81 INLINE(~Label()) { ASSERT(!is_linked()); } | 93 INLINE(~Label()) { ASSERT(!is_linked()); } |
| 82 | 94 |
| 83 INLINE(void Unuse()) { pos_ = 0; } | 95 INLINE(void Unuse()) { pos_ = 0; } |
| 96 INLINE(void UnuseNear()) { near_link_pos_ = 0; } |
| 84 | 97 |
| 85 INLINE(bool is_bound() const) { return pos_ < 0; } | 98 INLINE(bool is_bound() const) { return pos_ < 0; } |
| 86 INLINE(bool is_unused() const) { return pos_ == 0; } | 99 INLINE(bool is_unused() const) { return pos_ == 0 && near_link_pos_ == 0; } |
| 87 INLINE(bool is_linked() const) { return pos_ > 0; } | 100 INLINE(bool is_linked() const) { return pos_ > 0; } |
| 101 INLINE(bool is_near_linked() const) { return near_link_pos_ > 0; } |
| 88 | 102 |
| 89 // Returns the position of bound or linked labels. Cannot be used | 103 // Returns the position of bound or linked labels. Cannot be used |
| 90 // for unused labels. | 104 // for unused labels. |
| 91 int pos() const; | 105 int pos() const; |
| 106 int near_link_pos() const { return near_link_pos_ - 1; } |
| 92 | 107 |
| 93 private: | 108 private: |
| 94 // pos_ encodes both the binding state (via its sign) | 109 // pos_ encodes both the binding state (via its sign) |
| 95 // and the binding position (via its value) of a label. | 110 // and the binding position (via its value) of a label. |
| 96 // | 111 // |
| 97 // pos_ < 0 bound label, pos() returns the jump target position | 112 // pos_ < 0 bound label, pos() returns the jump target position |
| 98 // pos_ == 0 unused label | 113 // pos_ == 0 unused label |
| 99 // pos_ > 0 linked label, pos() returns the last reference position | 114 // pos_ > 0 linked label, pos() returns the last reference position |
| 100 int pos_; | 115 int pos_; |
| 101 | 116 |
| 117 // Behaves like |pos_| in the "> 0" case, but for near jumps to this label. |
| 118 int near_link_pos_; |
| 119 |
| 102 void bind_to(int pos) { | 120 void bind_to(int pos) { |
| 103 pos_ = -pos - 1; | 121 pos_ = -pos - 1; |
| 104 ASSERT(is_bound()); | 122 ASSERT(is_bound()); |
| 105 } | 123 } |
| 106 void link_to(int pos) { | 124 void link_to(int pos, Distance distance = kFar) { |
| 107 pos_ = pos + 1; | 125 if (distance == kNear) { |
| 108 ASSERT(is_linked()); | 126 near_link_pos_ = pos + 1; |
| 127 ASSERT(is_near_linked()); |
| 128 } else { |
| 129 pos_ = pos + 1; |
| 130 ASSERT(is_linked()); |
| 131 } |
| 109 } | 132 } |
| 110 | 133 |
| 111 friend class Assembler; | 134 friend class Assembler; |
| 112 friend class RegexpAssembler; | 135 friend class RegexpAssembler; |
| 113 friend class Displacement; | 136 friend class Displacement; |
| 114 friend class RegExpMacroAssemblerIrregexp; | 137 friend class RegExpMacroAssemblerIrregexp; |
| 115 }; | 138 }; |
| 116 | 139 |
| 117 | 140 |
| 118 // ----------------------------------------------------------------------------- | |
| 119 // NearLabels are labels used for short jumps (in Intel jargon). | |
| 120 // NearLabels should be used if it can be guaranteed that the jump range is | |
| 121 // within -128 to +127. We already use short jumps when jumping backwards, | |
| 122 // so using a NearLabel will only have performance impact if used for forward | |
| 123 // jumps. | |
| 124 class NearLabel BASE_EMBEDDED { | |
| 125 public: | |
| 126 NearLabel() { Unuse(); } | |
| 127 ~NearLabel() { ASSERT(!is_linked()); } | |
| 128 | |
| 129 void Unuse() { | |
| 130 pos_ = -1; | |
| 131 unresolved_branches_ = 0; | |
| 132 #ifdef DEBUG | |
| 133 for (int i = 0; i < kMaxUnresolvedBranches; i++) { | |
| 134 unresolved_positions_[i] = -1; | |
| 135 } | |
| 136 #endif | |
| 137 } | |
| 138 | |
| 139 int pos() { | |
| 140 ASSERT(is_bound()); | |
| 141 return pos_; | |
| 142 } | |
| 143 | |
| 144 bool is_bound() { return pos_ >= 0; } | |
| 145 bool is_linked() { return !is_bound() && unresolved_branches_ > 0; } | |
| 146 bool is_unused() { return !is_bound() && unresolved_branches_ == 0; } | |
| 147 | |
| 148 void bind_to(int position) { | |
| 149 ASSERT(!is_bound()); | |
| 150 pos_ = position; | |
| 151 } | |
| 152 | |
| 153 void link_to(int position) { | |
| 154 ASSERT(!is_bound()); | |
| 155 ASSERT(unresolved_branches_ < kMaxUnresolvedBranches); | |
| 156 unresolved_positions_[unresolved_branches_++] = position; | |
| 157 } | |
| 158 | |
| 159 private: | |
| 160 static const int kMaxUnresolvedBranches = 8; | |
| 161 int pos_; | |
| 162 int unresolved_branches_; | |
| 163 int unresolved_positions_[kMaxUnresolvedBranches]; | |
| 164 | |
| 165 friend class Assembler; | |
| 166 }; | |
| 167 | |
| 168 | |
| 169 enum SaveFPRegsMode { kDontSaveFPRegs, kSaveFPRegs }; | 141 enum SaveFPRegsMode { kDontSaveFPRegs, kSaveFPRegs }; |
| 170 | 142 |
| 171 | 143 |
| 172 // ----------------------------------------------------------------------------- | 144 // ----------------------------------------------------------------------------- |
| 173 // Relocation information | 145 // Relocation information |
| 174 | 146 |
| 175 | 147 |
| 176 // Relocation information consists of the address (pc) of the datum | 148 // Relocation information consists of the address (pc) of the datum |
| 177 // to which the relocation information applies, the relocation mode | 149 // to which the relocation information applies, the relocation mode |
| 178 // (rmode), and an optional data field. The relocation mode may be | 150 // (rmode), and an optional data field. The relocation mode may be |
| (...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 static ExternalReference handle_scope_next_address(); | 613 static ExternalReference handle_scope_next_address(); |
| 642 static ExternalReference handle_scope_limit_address(); | 614 static ExternalReference handle_scope_limit_address(); |
| 643 static ExternalReference handle_scope_level_address(); | 615 static ExternalReference handle_scope_level_address(); |
| 644 | 616 |
| 645 static ExternalReference scheduled_exception_address(Isolate* isolate); | 617 static ExternalReference scheduled_exception_address(Isolate* isolate); |
| 646 | 618 |
| 647 // Static variables containing common double constants. | 619 // Static variables containing common double constants. |
| 648 static ExternalReference address_of_min_int(); | 620 static ExternalReference address_of_min_int(); |
| 649 static ExternalReference address_of_one_half(); | 621 static ExternalReference address_of_one_half(); |
| 650 static ExternalReference address_of_minus_zero(); | 622 static ExternalReference address_of_minus_zero(); |
| 623 static ExternalReference address_of_zero(); |
| 624 static ExternalReference address_of_uint8_max_value(); |
| 651 static ExternalReference address_of_negative_infinity(); | 625 static ExternalReference address_of_negative_infinity(); |
| 652 static ExternalReference address_of_nan(); | 626 static ExternalReference address_of_nan(); |
| 653 | 627 |
| 654 static ExternalReference math_sin_double_function(Isolate* isolate); | 628 static ExternalReference math_sin_double_function(Isolate* isolate); |
| 655 static ExternalReference math_cos_double_function(Isolate* isolate); | 629 static ExternalReference math_cos_double_function(Isolate* isolate); |
| 656 static ExternalReference math_log_double_function(Isolate* isolate); | 630 static ExternalReference math_log_double_function(Isolate* isolate); |
| 657 | 631 |
| 658 Address address() const {return reinterpret_cast<Address>(address_);} | 632 Address address() const {return reinterpret_cast<Address>(address_);} |
| 659 | 633 |
| 660 #ifdef ENABLE_DEBUGGER_SUPPORT | 634 #ifdef ENABLE_DEBUGGER_SUPPORT |
| (...skipping 16 matching lines...) Expand all Loading... |
| 677 // Function NativeRegExpMacroAssembler::GrowStack() | 651 // Function NativeRegExpMacroAssembler::GrowStack() |
| 678 static ExternalReference re_grow_stack(Isolate* isolate); | 652 static ExternalReference re_grow_stack(Isolate* isolate); |
| 679 | 653 |
| 680 // byte NativeRegExpMacroAssembler::word_character_bitmap | 654 // byte NativeRegExpMacroAssembler::word_character_bitmap |
| 681 static ExternalReference re_word_character_map(); | 655 static ExternalReference re_word_character_map(); |
| 682 | 656 |
| 683 #endif | 657 #endif |
| 684 | 658 |
| 685 // This lets you register a function that rewrites all external references. | 659 // This lets you register a function that rewrites all external references. |
| 686 // Used by the ARM simulator to catch calls to external references. | 660 // Used by the ARM simulator to catch calls to external references. |
| 687 static void set_redirector(ExternalReferenceRedirector* redirector) { | 661 static void set_redirector(Isolate* isolate, |
| 662 ExternalReferenceRedirector* redirector) { |
| 688 // We can't stack them. | 663 // We can't stack them. |
| 689 ASSERT(Isolate::Current()->external_reference_redirector() == NULL); | 664 ASSERT(isolate->external_reference_redirector() == NULL); |
| 690 Isolate::Current()->set_external_reference_redirector( | 665 isolate->set_external_reference_redirector( |
| 691 reinterpret_cast<ExternalReferenceRedirectorPointer*>(redirector)); | 666 reinterpret_cast<ExternalReferenceRedirectorPointer*>(redirector)); |
| 692 } | 667 } |
| 693 | 668 |
| 694 private: | 669 private: |
| 695 explicit ExternalReference(void* address) | 670 explicit ExternalReference(void* address) |
| 696 : address_(address) {} | 671 : address_(address) {} |
| 697 | 672 |
| 698 static void* Redirect(Isolate* isolate, | 673 static void* Redirect(Isolate* isolate, |
| 699 void* address, | 674 void* address, |
| 700 Type type = ExternalReference::BUILTIN_CALL) { | 675 Type type = ExternalReference::BUILTIN_CALL) { |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 public: | 847 public: |
| 873 NullCallWrapper() { } | 848 NullCallWrapper() { } |
| 874 virtual ~NullCallWrapper() { } | 849 virtual ~NullCallWrapper() { } |
| 875 virtual void BeforeCall(int call_size) const { } | 850 virtual void BeforeCall(int call_size) const { } |
| 876 virtual void AfterCall() const { } | 851 virtual void AfterCall() const { } |
| 877 }; | 852 }; |
| 878 | 853 |
| 879 } } // namespace v8::internal | 854 } } // namespace v8::internal |
| 880 | 855 |
| 881 #endif // V8_ASSEMBLER_H_ | 856 #endif // V8_ASSEMBLER_H_ |
| OLD | NEW |