Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 1 | //===- MCLabel.h - Machine Code Directional Local Labels --------*- C++ -*-===// |
| 2 | // |
Andrew Walbran | 16937d0 | 2019-10-22 13:54:20 +0100 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file contains the declaration of the MCLabel class. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_MC_MCLABEL_H |
| 14 | #define LLVM_MC_MCLABEL_H |
| 15 | |
| 16 | namespace llvm { |
| 17 | |
| 18 | class raw_ostream; |
| 19 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 20 | /// Instances of this class represent a label name in the MC file, |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 21 | /// and MCLabel are created and uniqued by the MCContext class. MCLabel |
| 22 | /// should only be constructed for valid instances in the object file. |
| 23 | class MCLabel { |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 24 | // The instance number of this Directional Local Label. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 25 | unsigned Instance; |
| 26 | |
| 27 | private: // MCContext creates and uniques these. |
| 28 | friend class MCContext; |
| 29 | |
| 30 | MCLabel(unsigned instance) : Instance(instance) {} |
| 31 | |
| 32 | public: |
| 33 | MCLabel(const MCLabel &) = delete; |
| 34 | MCLabel &operator=(const MCLabel &) = delete; |
| 35 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 36 | /// Get the current instance of this Directional Local Label. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 37 | unsigned getInstance() const { return Instance; } |
| 38 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 39 | /// Increment the current instance of this Directional Local Label. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 40 | unsigned incInstance() { return ++Instance; } |
| 41 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 42 | /// Print the value to the stream \p OS. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 43 | void print(raw_ostream &OS) const; |
| 44 | |
Andrew Scull | cdfcccc | 2018-10-05 20:58:37 +0100 | [diff] [blame] | 45 | /// Print the value to stderr. |
Andrew Scull | 5e1ddfa | 2018-08-14 10:06:54 +0100 | [diff] [blame] | 46 | void dump() const; |
| 47 | }; |
| 48 | |
| 49 | inline raw_ostream &operator<<(raw_ostream &OS, const MCLabel &Label) { |
| 50 | Label.print(OS); |
| 51 | return OS; |
| 52 | } |
| 53 | |
| 54 | } // end namespace llvm |
| 55 | |
| 56 | #endif // LLVM_MC_MCLABEL_H |