1195098Sed//===-- llvm/MC/MCValue.h - MCValue class -----------------------*- C++ -*-===// 2195098Sed// 3195098Sed// The LLVM Compiler Infrastructure 4195098Sed// 5195098Sed// This file is distributed under the University of Illinois Open Source 6195098Sed// License. See LICENSE.TXT for details. 7195098Sed// 8195098Sed//===----------------------------------------------------------------------===// 9195098Sed// 10195098Sed// This file contains the declaration of the MCValue class. 11195098Sed// 12195098Sed//===----------------------------------------------------------------------===// 13195098Sed 14195098Sed#ifndef LLVM_MC_MCVALUE_H 15195098Sed#define LLVM_MC_MCVALUE_H 16195098Sed 17252723Sdim#include "llvm/MC/MCSymbol.h" 18218893Sdim#include "llvm/Support/DataTypes.h" 19195340Sed#include <cassert> 20195098Sed 21195098Sednamespace llvm { 22205407Srdivackyclass MCAsmInfo; 23195098Sedclass MCSymbol; 24205407Srdivackyclass MCSymbolRefExpr; 25198090Srdivackyclass raw_ostream; 26195098Sed 27195098Sed/// MCValue - This represents an "assembler immediate". In its most general 28195098Sed/// form, this can hold "SymbolA - SymbolB + imm64". Not all targets supports 29195098Sed/// relocations of this general form, but we need to represent this anyway. 30195098Sed/// 31195340Sed/// In the general form, SymbolB can only be defined if SymbolA is, and both 32195340Sed/// must be in the same (non-external) section. The latter constraint is not 33195340Sed/// enforced, since a symbol's section may not be known at construction. 34195340Sed/// 35195098Sed/// Note that this class must remain a simple POD value class, because we need 36195098Sed/// it to live in unions etc. 37195098Sedclass MCValue { 38205407Srdivacky const MCSymbolRefExpr *SymA, *SymB; 39195098Sed int64_t Cst; 40195098Sedpublic: 41195098Sed 42195340Sed int64_t getConstant() const { return Cst; } 43205407Srdivacky const MCSymbolRefExpr *getSymA() const { return SymA; } 44205407Srdivacky const MCSymbolRefExpr *getSymB() const { return SymB; } 45195340Sed 46195340Sed /// isAbsolute - Is this an absolute (as opposed to relocatable) value. 47195340Sed bool isAbsolute() const { return !SymA && !SymB; } 48195340Sed 49245431Sdim /// print - Print the value to the stream \p OS. 50198090Srdivacky void print(raw_ostream &OS, const MCAsmInfo *MAI) const; 51205407Srdivacky 52198090Srdivacky /// dump - Print the value to stderr. 53198090Srdivacky void dump() const; 54198090Srdivacky 55205407Srdivacky static MCValue get(const MCSymbolRefExpr *SymA, const MCSymbolRefExpr *SymB=0, 56198090Srdivacky int64_t Val = 0) { 57195098Sed MCValue R; 58195340Sed assert((!SymB || SymA) && "Invalid relocatable MCValue!"); 59195098Sed R.Cst = Val; 60195098Sed R.SymA = SymA; 61195098Sed R.SymB = SymB; 62195098Sed return R; 63195098Sed } 64205407Srdivacky 65195098Sed static MCValue get(int64_t Val) { 66195098Sed MCValue R; 67195098Sed R.Cst = Val; 68195098Sed R.SymA = 0; 69195098Sed R.SymB = 0; 70195098Sed return R; 71195098Sed } 72205407Srdivacky 73195098Sed}; 74195098Sed 75195098Sed} // end namespace llvm 76195098Sed 77195098Sed#endif 78