2009-08-14 11:11:09 +08:00
|
|
|
//===- lib/MC/MCValue.cpp - MCValue implementation ------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/MC/MCValue.h"
|
2010-03-18 08:59:10 +08:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2010-01-05 09:28:17 +08:00
|
|
|
#include "llvm/Support/Debug.h"
|
2014-05-04 03:57:04 +08:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-08-14 11:11:09 +08:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2015-02-05 08:58:51 +08:00
|
|
|
void MCValue::print(raw_ostream &OS) const {
|
2009-08-14 11:11:09 +08:00
|
|
|
if (isAbsolute()) {
|
|
|
|
OS << getConstant();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-29 16:22:20 +08:00
|
|
|
// FIXME: prints as a number, which isn't ideal. But the meaning will be
|
|
|
|
// target-specific anyway.
|
|
|
|
if (getRefKind())
|
|
|
|
OS << ':' << getRefKind() << ':';
|
|
|
|
|
2015-05-27 21:05:42 +08:00
|
|
|
OS << *getSymA();
|
2009-08-14 11:41:23 +08:00
|
|
|
|
2010-03-18 08:59:10 +08:00
|
|
|
if (getSymB()) {
|
|
|
|
OS << " - ";
|
2015-05-27 21:05:42 +08:00
|
|
|
OS << *getSymB();
|
2010-03-18 08:59:10 +08:00
|
|
|
}
|
2009-08-14 11:41:23 +08:00
|
|
|
|
2009-08-14 11:11:09 +08:00
|
|
|
if (getConstant())
|
|
|
|
OS << " + " << getConstant();
|
|
|
|
}
|
|
|
|
|
2016-01-30 04:50:44 +08:00
|
|
|
LLVM_DUMP_METHOD void MCValue::dump() const {
|
2015-02-05 09:23:14 +08:00
|
|
|
print(dbgs());
|
2009-08-14 11:11:09 +08:00
|
|
|
}
|
2014-05-04 03:57:04 +08:00
|
|
|
|
|
|
|
MCSymbolRefExpr::VariantKind MCValue::getAccessVariant() const {
|
|
|
|
const MCSymbolRefExpr *B = getSymB();
|
|
|
|
if (B) {
|
|
|
|
if (B->getKind() != MCSymbolRefExpr::VK_None)
|
|
|
|
llvm_unreachable("unsupported");
|
|
|
|
}
|
|
|
|
|
|
|
|
const MCSymbolRefExpr *A = getSymA();
|
|
|
|
if (!A)
|
|
|
|
return MCSymbolRefExpr::VK_None;
|
|
|
|
|
|
|
|
MCSymbolRefExpr::VariantKind Kind = A->getKind();
|
|
|
|
if (Kind == MCSymbolRefExpr::VK_WEAKREF)
|
|
|
|
return MCSymbolRefExpr::VK_None;
|
|
|
|
return Kind;
|
|
|
|
}
|