MCValue.h revision d644c32a52c36c2e52c91512d156d4332772cb1f
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 const MCSymbol *SymA, *SymB; 37 int64_t Cst; 38public: 39 40 int64_t getConstant() const { return Cst; } 41 const MCSymbol *getSymA() const { return SymA; } 42 const 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(const MCSymbol *SymA, const MCSymbol *SymB = 0, 64 int64_t Val = 0) { 65 MCValue R; 66 assert((!SymB || SymA) && "Invalid relocatable MCValue!"); 67 R.Cst = Val; 68 R.SymA = SymA; 69 R.SymB = SymB; 70 return R; 71 } 72 73 static MCValue get(int64_t Val) { 74 MCValue R; 75 R.Cst = Val; 76 R.SymA = 0; 77 R.SymB = 0; 78 return R; 79 } 80 81}; 82 83} // end namespace llvm 84 85#endif 86