LCOV - code coverage report
Current view: top level - src - label.h (source / functions) Hit Total Coverage
Test: app.info Lines: 10 11 90.9 %
Date: 2017-10-20 Functions: 3 4 75.0 %

          Line data    Source code
       1             : // Copyright 2017 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #ifndef V8_LABEL_H_
       6             : #define V8_LABEL_H_
       7             : 
       8             : #include "src/base/macros.h"
       9             : 
      10             : namespace v8 {
      11             : namespace internal {
      12             : 
      13             : // -----------------------------------------------------------------------------
      14             : // Labels represent pc locations; they are typically jump or call targets.
      15             : // After declaration, a label can be freely used to denote known or (yet)
      16             : // unknown pc location. Assembler::bind() is used to bind a label to the
      17             : // current pc. A label can be bound only once.
      18             : 
      19             : class Label {
      20             :  public:
      21             :   enum Distance { kNear, kFar };
      22             : 
      23             :   INLINE(Label()) {
      24             :     Unuse();
      25             :     UnuseNear();
      26             :   }
      27             : 
      28             :   INLINE(~Label()) {
      29             :     DCHECK(!is_linked());
      30             :     DCHECK(!is_near_linked());
      31             :   }
      32             : 
      33    34845632 :   INLINE(void Unuse()) { pos_ = 0; }
      34    35065324 :   INLINE(void UnuseNear()) { near_link_pos_ = 0; }
      35             : 
      36             :   INLINE(bool is_bound() const) { return pos_ < 0; }
      37      487870 :   INLINE(bool is_unused() const) { return pos_ == 0 && near_link_pos_ == 0; }
      38             :   INLINE(bool is_linked() const) { return pos_ > 0; }
      39             :   INLINE(bool is_near_linked() const) { return near_link_pos_ > 0; }
      40             : 
      41             :   // Returns the position of bound or linked labels. Cannot be used
      42             :   // for unused labels.
      43   615827000 :   int pos() const {
      44   615827000 :     if (pos_ < 0) return -pos_ - 1;
      45   611415888 :     if (pos_ > 0) return pos_ - 1;
      46           0 :     UNREACHABLE();
      47             :   }
      48             : 
      49      321353 :   int near_link_pos() const { return near_link_pos_ - 1; }
      50             : 
      51             :  private:
      52             :   // pos_ encodes both the binding state (via its sign)
      53             :   // and the binding position (via its value) of a label.
      54             :   //
      55             :   // pos_ <  0  bound label, pos() returns the jump target position
      56             :   // pos_ == 0  unused label
      57             :   // pos_ >  0  linked label, pos() returns the last reference position
      58             :   int pos_;
      59             : 
      60             :   // Behaves like |pos_| in the "> 0" case, but for near jumps to this label.
      61             :   int near_link_pos_;
      62             : 
      63             :   void bind_to(int pos) {
      64    24967700 :     pos_ = -pos - 1;
      65             :     DCHECK(is_bound());
      66             :   }
      67             :   void link_to(int pos, Distance distance = kFar) {
      68             :     if (distance == kNear) {
      69      321346 :       near_link_pos_ = pos + 1;
      70             :       DCHECK(is_near_linked());
      71             :     } else {
      72   611415765 :       pos_ = pos + 1;
      73             :       DCHECK(is_linked());
      74             :     }
      75             :   }
      76             : 
      77             :   friend class Assembler;
      78             :   friend class Displacement;
      79             :   friend class RegExpMacroAssemblerIrregexp;
      80             : 
      81             : #if V8_TARGET_ARCH_ARM64
      82             :   // On ARM64, the Assembler keeps track of pointers to Labels to resolve
      83             :   // branches to distant targets. Copying labels would confuse the Assembler.
      84             :   DISALLOW_COPY_AND_ASSIGN(Label);  // NOLINT
      85             : #endif
      86             : };
      87             : 
      88             : }  // namespace internal
      89             : }  // namespace v8
      90             : 
      91             : #endif  // V8_LABEL_H_

Generated by: LCOV version 1.10