Chromium Code Reviews| Index: src/assembler.h |
| =================================================================== |
| --- src/assembler.h (revision 5449) |
| +++ src/assembler.h (working copy) |
| @@ -92,6 +92,57 @@ |
| // ----------------------------------------------------------------------------- |
| +// NearLabels are labels used for short jumps (in Intel jargon). |
| +// NearLabels should be used if it can be guaranteed that the jump range is |
| +// within -128 to +127. We already use short jumps when jumping backwards, |
| +// so using a NearLabel will only have performance impact if used for forward |
| +// jumps. |
| +class NearLabel BASE_EMBEDDED { |
|
Søren Thygesen Gjesse
2010/09/15 10:38:20
How about adding a type to the Label class
class
|
| + public: |
| + NearLabel() { Unuse(); } |
| + ~NearLabel() { ASSERT(!is_linked()); } |
| + |
| + void Unuse() { |
| + pos_ = -1; |
| + unresolved_branches_ = 0; |
| +#ifdef DEBUG |
| + for (int i = 0; i < kMaxUnresolvedBranches; i++) { |
| + unresolved_positions_[i] = -1; |
| + } |
| +#endif |
| + } |
| + |
| + int pos() { |
| + ASSERT(is_bound()); |
| + return pos_; |
| + } |
| + |
| + bool is_bound() { return pos_ >= 0; } |
| + bool is_linked() { return !is_bound() && unresolved_branches_ > 0; } |
| + bool is_unused() { return !is_bound() && unresolved_branches_ == 0; } |
| + |
| + void bind_to(int position) { |
| + ASSERT(!is_bound()); |
| + pos_ = position; |
| + } |
| + |
| + void link_to(int position) { |
| + ASSERT(!is_bound()); |
| + ASSERT(unresolved_branches_ < kMaxUnresolvedBranches); |
| + unresolved_positions_[unresolved_branches_++] = position; |
| + } |
| + |
| + private: |
| + static const int kMaxUnresolvedBranches = 8; |
| + int pos_; |
| + int unresolved_branches_; |
| + int unresolved_positions_[kMaxUnresolvedBranches]; |
| + |
| + friend class Assembler; |
| +}; |
| + |
| + |
| +// ----------------------------------------------------------------------------- |
| // Relocation information |