1 //===- lib/MC/MCValue.cpp - MCValue implementation ------------------------===// 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 #include "llvm/MC/MCValue.h" 11 #include "llvm/MC/MCExpr.h" 12 #include "llvm/Support/Debug.h" 13 #include "llvm/Support/ErrorHandling.h" 14 #include "llvm/Support/raw_ostream.h" 15 16 using namespace llvm; 17 print(raw_ostream & OS) const18void MCValue::print(raw_ostream &OS) const { 19 if (isAbsolute()) { 20 OS << getConstant(); 21 return; 22 } 23 24 // FIXME: prints as a number, which isn't ideal. But the meaning will be 25 // target-specific anyway. 26 if (getRefKind()) 27 OS << ':' << getRefKind() << ':'; 28 29 OS << *getSymA(); 30 31 if (getSymB()) { 32 OS << " - "; 33 OS << *getSymB(); 34 } 35 36 if (getConstant()) 37 OS << " + " << getConstant(); 38 } 39 40 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) dump() const41LLVM_DUMP_METHOD void MCValue::dump() const { 42 } 43 #endif 44 getAccessVariant() const45MCSymbolRefExpr::VariantKind MCValue::getAccessVariant() const { 46 const MCSymbolRefExpr *B = getSymB(); 47 if (B) { 48 if (B->getKind() != MCSymbolRefExpr::VK_None) 49 llvm_unreachable("unsupported"); 50 } 51 52 const MCSymbolRefExpr *A = getSymA(); 53 if (!A) 54 return MCSymbolRefExpr::VK_None; 55 56 MCSymbolRefExpr::VariantKind Kind = A->getKind(); 57 if (Kind == MCSymbolRefExpr::VK_WEAKREF) 58 return MCSymbolRefExpr::VK_None; 59 return Kind; 60 } 61