LLVM API Documentation
00001 //===-- llvm/MC/MCValue.h - MCValue class -----------------------*- C++ -*-===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This file contains the declaration of the MCValue class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #ifndef LLVM_MC_MCVALUE_H 00015 #define LLVM_MC_MCVALUE_H 00016 00017 #include "llvm/Support/DataTypes.h" 00018 #include "llvm/MC/MCSymbol.h" 00019 #include <cassert> 00020 00021 namespace llvm { 00022 class MCSymbol; 00023 class raw_ostream; 00024 00025 /// MCValue - This represents an "assembler immediate". In its most general 00026 /// form, this can hold "SymbolA - SymbolB + imm64". Not all targets supports 00027 /// relocations of this general form, but we need to represent this anyway. 00028 /// 00029 /// In the general form, SymbolB can only be defined if SymbolA is, and both 00030 /// must be in the same (non-external) section. The latter constraint is not 00031 /// enforced, since a symbol's section may not be known at construction. 00032 /// 00033 /// Note that this class must remain a simple POD value class, because we need 00034 /// it to live in unions etc. 00035 class MCValue { 00036 MCSymbol *SymA, *SymB; 00037 int64_t Cst; 00038 public: 00039 00040 int64_t getConstant() const { return Cst; } 00041 MCSymbol *getSymA() const { return SymA; } 00042 MCSymbol *getSymB() const { return SymB; } 00043 00044 /// isAbsolute - Is this an absolute (as opposed to relocatable) value. 00045 bool isAbsolute() const { return !SymA && !SymB; } 00046 00047 /// getAssociatedSection - For relocatable values, return the section the 00048 /// value is associated with. 00049 /// 00050 /// @result - The value's associated section, or null for external or constant 00051 /// values. 00052 const MCSection *getAssociatedSection() const { 00053 return SymA ? SymA->getSection() : 0; 00054 } 00055 00056 /// print - Print the value to the stream \arg OS. 00057 void print(raw_ostream &OS) const; 00058 00059 /// dump - Print the value to stderr. 00060 void dump() const; 00061 00062 static MCValue get(MCSymbol *SymA, MCSymbol *SymB = 0, int64_t Val = 0) { 00063 MCValue R; 00064 assert((!SymB || SymA) && "Invalid relocatable MCValue!"); 00065 R.Cst = Val; 00066 R.SymA = SymA; 00067 R.SymB = SymB; 00068 return R; 00069 } 00070 00071 static MCValue get(int64_t Val) { 00072 MCValue R; 00073 R.Cst = Val; 00074 R.SymA = 0; 00075 R.SymB = 0; 00076 return R; 00077 } 00078 00079 }; 00080 00081 } // end namespace llvm 00082 00083 #endif