MCValue.h revision 2c11624b65a65fe487f335603dc0bf6372a50a89
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/Support/DataTypes.h" 18#include "llvm/MC/MCSymbol.h" 19#include <cassert> 20 21namespace llvm { 22class MCSymbol; 23class raw_ostream; 24 25/// MCValue - This represents an "assembler immediate". In its most general 26/// form, this can hold "SymbolA - SymbolB + imm64". Not all targets supports 27/// relocations of this general form, but we need to represent this anyway. 28/// 29/// In the general form, SymbolB can only be defined if SymbolA is, and both 30/// must be in the same (non-external) section. The latter constraint is not 31/// enforced, since a symbol's section may not be known at construction. 32/// 33/// Note that this class must remain a simple POD value class, because we need 34/// it to live in unions etc. 35class MCValue { 36 MCSymbol *SymA, *SymB; 37 int64_t Cst; 38public: 39 40 int64_t getConstant() const { return Cst; } 41 MCSymbol *getSymA() const { return SymA; } 42 MCSymbol *getSymB() const { return SymB; } 43 44 /// isAbsolute - Is this an absolute (as opposed to relocatable) value. 45 bool isAbsolute() const { return !SymA && !SymB; } 46 47 /// getAssociatedSection - For relocatable values, return the section the 48 /// value is associated with. 49 /// 50 /// @result - The value's associated section, or null for external or constant 51 /// values. 52 MCSection *getAssociatedSection() const { 53 return SymA ? SymA->getSection() : 0; 54 } 55 56 /// print - Print the value to the stream \arg OS. 57 void print(raw_ostream &OS) const; 58 59 /// dump - Print the value to stderr. 60 void dump() const; 61 62 static MCValue get(MCSymbol *SymA, MCSymbol *SymB = 0, int64_t Val = 0) { 63 MCValue R; 64 assert((!SymB || SymA) && "Invalid relocatable MCValue!"); 65 R.Cst = Val; 66 R.SymA = SymA; 67 R.SymB = SymB; 68 return R; 69 } 70 71 static MCValue get(int64_t Val) { 72 MCValue R; 73 R.Cst = Val; 74 R.SymA = 0; 75 R.SymB = 0; 76 return R; 77 } 78 79}; 80 81} // end namespace llvm 82 83#endif 84