/src/llvm-project/llvm/include/llvm/MC/MCValue.h
Line | Count | Source |
1 | | //===-- llvm/MC/MCValue.h - MCValue class -----------------------*- C++ -*-===// |
2 | | // |
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 |
6 | | // |
7 | | //===----------------------------------------------------------------------===// |
8 | | // |
9 | | // This file contains the declaration of the MCValue class. |
10 | | // |
11 | | //===----------------------------------------------------------------------===// |
12 | | |
13 | | #ifndef LLVM_MC_MCVALUE_H |
14 | | #define LLVM_MC_MCVALUE_H |
15 | | |
16 | | #include "llvm/MC/MCExpr.h" |
17 | | #include "llvm/Support/DataTypes.h" |
18 | | |
19 | | namespace llvm { |
20 | | class raw_ostream; |
21 | | |
22 | | /// This represents an "assembler immediate". |
23 | | /// |
24 | | /// In its most general form, this can hold ":Kind:(SymbolA - SymbolB + |
25 | | /// imm64)". Not all targets supports relocations of this general form, but we |
26 | | /// need to represent this anyway. |
27 | | /// |
28 | | /// In general both SymbolA and SymbolB will also have a modifier |
29 | | /// analogous to the top-level Kind. Current targets are not expected |
30 | | /// to make use of both though. The choice comes down to whether |
31 | | /// relocation modifiers apply to the closest symbol or the whole |
32 | | /// expression. |
33 | | /// |
34 | | /// Note that this class must remain a simple POD value class, because we need |
35 | | /// it to live in unions etc. |
36 | | class MCValue { |
37 | | const MCSymbolRefExpr *SymA = nullptr, *SymB = nullptr; |
38 | | int64_t Cst = 0; |
39 | | uint32_t RefKind = 0; |
40 | | |
41 | | public: |
42 | 1.96M | MCValue() = default; |
43 | 974k | int64_t getConstant() const { return Cst; } |
44 | 2.07k | const MCSymbolRefExpr *getSymA() const { return SymA; } |
45 | 9 | const MCSymbolRefExpr *getSymB() const { return SymB; } |
46 | 9 | uint32_t getRefKind() const { return RefKind; } |
47 | | |
48 | | /// Is this an absolute (as opposed to relocatable) value. |
49 | 976k | bool isAbsolute() const { return !SymA && !SymB; } |
50 | | |
51 | | /// Print the value to the stream \p OS. |
52 | | void print(raw_ostream &OS) const; |
53 | | |
54 | | /// Print the value to stderr. |
55 | | void dump() const; |
56 | | |
57 | | MCSymbolRefExpr::VariantKind getAccessVariant() const; |
58 | | |
59 | | static MCValue get(const MCSymbolRefExpr *SymA, |
60 | | const MCSymbolRefExpr *SymB = nullptr, |
61 | 7.10k | int64_t Val = 0, uint32_t RefKind = 0) { |
62 | 7.10k | MCValue R; |
63 | 7.10k | R.Cst = Val; |
64 | 7.10k | R.SymA = SymA; |
65 | 7.10k | R.SymB = SymB; |
66 | 7.10k | R.RefKind = RefKind; |
67 | 7.10k | return R; |
68 | 7.10k | } |
69 | | |
70 | 969k | static MCValue get(int64_t Val) { |
71 | 969k | MCValue R; |
72 | 969k | R.Cst = Val; |
73 | 969k | R.SymA = nullptr; |
74 | 969k | R.SymB = nullptr; |
75 | 969k | R.RefKind = 0; |
76 | 969k | return R; |
77 | 969k | } |
78 | | |
79 | | }; |
80 | | |
81 | | } // end namespace llvm |
82 | | |
83 | | #endif |