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 // Represents a relocatable expression in its most general form: 23 // relocation_specifier(SymA - SymB + imm64). 24 // 25 // Not all targets support SymB. For PC-relative relocations, a specifier is 26 // typically used instead of setting SymB to DOT. 27 // 28 // This class must remain a simple POD value class, as it needs to reside in 29 // unions and similar structures. 30 class MCValue { 31 const MCSymbol *SymA = nullptr, *SymB = nullptr; 32 int64_t Cst = 0; 33 uint32_t Specifier = 0; 34 35 void print(raw_ostream &OS) const; 36 37 /// Print the value to stderr. 38 void dump() const; 39 40 public: 41 friend class MCAssembler; 42 friend class MCExpr; 43 MCValue() = default; getConstant()44 int64_t getConstant() const { return Cst; } setConstant(int64_t C)45 void setConstant(int64_t C) { Cst = C; } getSpecifier()46 uint32_t getSpecifier() const { return Specifier; } setSpecifier(uint32_t S)47 void setSpecifier(uint32_t S) { Specifier = S; } 48 getAddSym()49 const MCSymbol *getAddSym() const { return SymA; } setAddSym(const MCSymbol * A)50 void setAddSym(const MCSymbol *A) { SymA = A; } getSubSym()51 const MCSymbol *getSubSym() const { return SymB; } 52 53 /// Is this an absolute (as opposed to relocatable) value. isAbsolute()54 bool isAbsolute() const { return !SymA && !SymB; } 55 56 static MCValue get(const MCSymbol *SymA, const MCSymbol *SymB = nullptr, 57 int64_t Val = 0, uint32_t Specifier = 0) { 58 MCValue R; 59 R.Cst = Val; 60 R.SymA = SymA; 61 R.SymB = SymB; 62 R.Specifier = Specifier; 63 return R; 64 } 65 get(int64_t Val)66 static MCValue get(int64_t Val) { 67 MCValue R; 68 R.Cst = Val; 69 R.SymA = nullptr; 70 R.SymB = nullptr; 71 R.Specifier = 0; 72 return R; 73 } 74 75 }; 76 77 } // end namespace llvm 78 79 #endif 80