1//===-- llvm/MC/MCValue.h - MCValue class -----------------------*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file contains the declaration of the MCValue class. 11// 12//===----------------------------------------------------------------------===// 13 14#ifndef LLVM_MC_MCVALUE_H 15#define LLVM_MC_MCVALUE_H 16 17#include "llvm/MC/MCExpr.h" 18#include "llvm/MC/MCSymbol.h" 19#include "llvm/Support/DataTypes.h" 20#include <cassert> 21 22namespace llvm { 23class MCAsmInfo; 24class raw_ostream; 25 26/// MCValue - This represents an "assembler immediate". In its most 27/// general form, this can hold ":Kind:(SymbolA - SymbolB + imm64)". 28/// Not all targets supports relocations of this general form, but we 29/// need to represent this anyway. 30/// 31/// In general both SymbolA and SymbolB will also have a modifier 32/// analogous to the top-level Kind. Current targets are not expected 33/// to make use of both though. The choice comes down to whether 34/// relocation modifiers apply to the closest symbol or the whole 35/// expression. 36/// 37/// In the general form, SymbolB can only be defined if SymbolA is, and both 38/// must be in the same (non-external) section. The latter constraint is not 39/// enforced, since a symbol's section may not be known at construction. 40/// 41/// Note that this class must remain a simple POD value class, because we need 42/// it to live in unions etc. 43class MCValue { 44 const MCSymbolRefExpr *SymA, *SymB; 45 int64_t Cst; 46 uint32_t RefKind; 47public: 48 49 int64_t getConstant() const { return Cst; } 50 const MCSymbolRefExpr *getSymA() const { return SymA; } 51 const MCSymbolRefExpr *getSymB() const { return SymB; } 52 uint32_t getRefKind() const { return RefKind; } 53 54 /// isAbsolute - Is this an absolute (as opposed to relocatable) value. 55 bool isAbsolute() const { return !SymA && !SymB; } 56 57 /// print - Print the value to the stream \p OS. 58 void print(raw_ostream &OS, const MCAsmInfo *MAI) const; 59 60 /// dump - Print the value to stderr. 61 void dump() const; 62 63 MCSymbolRefExpr::VariantKind getAccessVariant() const; 64 65 static MCValue get(const MCSymbolRefExpr *SymA, 66 const MCSymbolRefExpr *SymB = nullptr, 67 int64_t Val = 0, uint32_t RefKind = 0) { 68 MCValue R; 69 assert((!SymB || SymA) && "Invalid relocatable MCValue!"); 70 R.Cst = Val; 71 R.SymA = SymA; 72 R.SymB = SymB; 73 R.RefKind = RefKind; 74 return R; 75 } 76 77 static MCValue get(int64_t Val) { 78 MCValue R; 79 R.Cst = Val; 80 R.SymA = nullptr; 81 R.SymB = nullptr; 82 R.RefKind = 0; 83 return R; 84 } 85 86}; 87 88} // end namespace llvm 89 90#endif 91