MCValue.h revision 8906ff1b9dfde28f1ff00706643ca10843b26e01
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 // 53 // FIXME: Switch to a tagged section, so this can return the tagged section 54 // value. 55 const MCSection *getAssociatedSection() const; 56 57 /// print - Print the value to the stream \arg OS. 58 void print(raw_ostream &OS) const; 59 60 /// dump - Print the value to stderr. 61 void dump() const; 62 63 static MCValue get(MCSymbol *SymA, MCSymbol *SymB = 0, int64_t Val = 0) { 64 MCValue R; 65 assert((!SymB || SymA) && "Invalid relocatable MCValue!"); 66 R.Cst = Val; 67 R.SymA = SymA; 68 R.SymB = SymB; 69 return R; 70 } 71 72 static MCValue get(int64_t Val) { 73 MCValue R; 74 R.Cst = Val; 75 R.SymA = 0; 76 R.SymB = 0; 77 return R; 78 } 79 80}; 81 82} // end namespace llvm 83 84#endif 85