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/MC/MCExpr.h" 00018 #include "llvm/MC/MCSymbol.h" 00019 #include "llvm/Support/DataTypes.h" 00020 #include <cassert> 00021 00022 namespace llvm { 00023 class MCAsmInfo; 00024 class raw_ostream; 00025 00026 /// MCValue - This represents an "assembler immediate". In its most 00027 /// general form, this can hold ":Kind:(SymbolA - SymbolB + imm64)". 00028 /// Not all targets supports relocations of this general form, but we 00029 /// need to represent this anyway. 00030 /// 00031 /// In general both SymbolA and SymbolB will also have a modifier 00032 /// analogous to the top-level Kind. Current targets are not expected 00033 /// to make use of both though. The choice comes down to whether 00034 /// relocation modifiers apply to the closest symbol or the whole 00035 /// expression. 00036 /// 00037 /// In the general form, SymbolB can only be defined if SymbolA is, and both 00038 /// must be in the same (non-external) section. The latter constraint is not 00039 /// enforced, since a symbol's section may not be known at construction. 00040 /// 00041 /// Note that this class must remain a simple POD value class, because we need 00042 /// it to live in unions etc. 00043 class MCValue { 00044 const MCSymbolRefExpr *SymA, *SymB; 00045 int64_t Cst; 00046 uint32_t RefKind; 00047 public: 00048 00049 int64_t getConstant() const { return Cst; } 00050 const MCSymbolRefExpr *getSymA() const { return SymA; } 00051 const MCSymbolRefExpr *getSymB() const { return SymB; } 00052 uint32_t getRefKind() const { return RefKind; } 00053 00054 /// isAbsolute - Is this an absolute (as opposed to relocatable) value. 00055 bool isAbsolute() const { return !SymA && !SymB; } 00056 00057 /// print - Print the value to the stream \p OS. 00058 void print(raw_ostream &OS, const MCAsmInfo *MAI) const; 00059 00060 /// dump - Print the value to stderr. 00061 void dump() const; 00062 00063 MCSymbolRefExpr::VariantKind getAccessVariant() const; 00064 00065 static MCValue get(const MCSymbolRefExpr *SymA, 00066 const MCSymbolRefExpr *SymB = nullptr, 00067 int64_t Val = 0, uint32_t RefKind = 0) { 00068 MCValue R; 00069 assert((!SymB || SymA) && "Invalid relocatable MCValue!"); 00070 R.Cst = Val; 00071 R.SymA = SymA; 00072 R.SymB = SymB; 00073 R.RefKind = RefKind; 00074 return R; 00075 } 00076 00077 static MCValue get(int64_t Val) { 00078 MCValue R; 00079 R.Cst = Val; 00080 R.SymA = nullptr; 00081 R.SymB = nullptr; 00082 R.RefKind = 0; 00083 return R; 00084 } 00085 00086 }; 00087 00088 } // end namespace llvm 00089 00090 #endif