LLVM API Documentation

MCValue.cpp
Go to the documentation of this file.
00001 //===- lib/MC/MCValue.cpp - MCValue implementation ------------------------===//
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 #include "llvm/MC/MCValue.h"
00011 #include "llvm/MC/MCExpr.h"
00012 #include "llvm/Support/Debug.h"
00013 #include "llvm/Support/ErrorHandling.h"
00014 #include "llvm/Support/raw_ostream.h"
00015 
00016 using namespace llvm;
00017 
00018 void MCValue::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
00019   if (isAbsolute()) {
00020     OS << getConstant();
00021     return;
00022   }
00023 
00024   // FIXME: prints as a number, which isn't ideal. But the meaning will be
00025   // target-specific anyway.
00026   if (getRefKind())
00027     OS << ':' << getRefKind() <<  ':';
00028 
00029   getSymA()->print(OS);
00030 
00031   if (getSymB()) {
00032     OS << " - ";
00033     getSymB()->print(OS);
00034   }
00035 
00036   if (getConstant())
00037     OS << " + " << getConstant();
00038 }
00039 
00040 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
00041 void MCValue::dump() const {
00042   print(dbgs(), nullptr);
00043 }
00044 #endif
00045 
00046 MCSymbolRefExpr::VariantKind MCValue::getAccessVariant() const {
00047   const MCSymbolRefExpr *B = getSymB();
00048   if (B) {
00049     if (B->getKind() != MCSymbolRefExpr::VK_None)
00050       llvm_unreachable("unsupported");
00051   }
00052 
00053   const MCSymbolRefExpr *A = getSymA();
00054   if (!A)
00055     return MCSymbolRefExpr::VK_None;
00056 
00057   MCSymbolRefExpr::VariantKind Kind = A->getKind();
00058   if (Kind == MCSymbolRefExpr::VK_WEAKREF)
00059     return MCSymbolRefExpr::VK_None;
00060   return Kind;
00061 }