2009-08-14 05:11:09 +02:00
|
|
|
//===- lib/MC/MCValue.cpp - MCValue implementation ------------------------===//
|
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2009-08-14 05:11:09 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/MC/MCValue.h"
|
2018-04-30 16:59:11 +02:00
|
|
|
#include "llvm/Config/llvm-config.h"
|
2010-03-18 01:59:10 +01:00
|
|
|
#include "llvm/MC/MCExpr.h"
|
2010-01-05 02:28:17 +01:00
|
|
|
#include "llvm/Support/Debug.h"
|
2014-05-03 21:57:04 +02:00
|
|
|
#include "llvm/Support/ErrorHandling.h"
|
2009-08-14 05:11:09 +02:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
2015-02-05 01:58:51 +01:00
|
|
|
void MCValue::print(raw_ostream &OS) const {
|
2009-08-14 05:11:09 +02:00
|
|
|
if (isAbsolute()) {
|
|
|
|
OS << getConstant();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-29 09:22:20 +01: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 15:05:42 +02:00
|
|
|
OS << *getSymA();
|
2009-08-14 05:41:23 +02:00
|
|
|
|
2010-03-18 01:59:10 +01:00
|
|
|
if (getSymB()) {
|
|
|
|
OS << " - ";
|
2015-05-27 15:05:42 +02:00
|
|
|
OS << *getSymB();
|
2010-03-18 01:59:10 +01:00
|
|
|
}
|
2009-08-14 05:41:23 +02:00
|
|
|
|
2009-08-14 05:11:09 +02:00
|
|
|
if (getConstant())
|
|
|
|
OS << " + " << getConstant();
|
|
|
|
}
|
|
|
|
|
2017-10-15 16:32:27 +02:00
|
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
2016-01-29 21:50:44 +01:00
|
|
|
LLVM_DUMP_METHOD void MCValue::dump() const {
|
2015-02-05 02:23:14 +01:00
|
|
|
print(dbgs());
|
2009-08-14 05:11:09 +02:00
|
|
|
}
|
2017-01-28 03:02:38 +01:00
|
|
|
#endif
|
2014-05-03 21:57:04 +02: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;
|
|
|
|
|
2019-12-16 01:03:56 +01:00
|
|
|
return A->getKind();
|
2014-05-03 21:57:04 +02:00
|
|
|
}
|