blob: 5512e031b61f065cc9505fd51e88699448b214c8 [file] [log] [blame]
Daniel Dunbarafe66032009-08-14 03:11:09 +00001//===- 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"
Daniel Dunbar9c64ec02010-03-18 00:59:10 +000011#include "llvm/MC/MCExpr.h"
David Greeneac7f5372010-01-05 01:28:17 +000012#include "llvm/Support/Debug.h"
Rafael Espindola3d082fa2014-05-03 19:57:04 +000013#include "llvm/Support/ErrorHandling.h"
Daniel Dunbarafe66032009-08-14 03:11:09 +000014#include "llvm/Support/raw_ostream.h"
15
16using namespace llvm;
17
Sean Silva0e1fe182015-02-05 00:58:51 +000018void MCValue::print(raw_ostream &OS) const {
Daniel Dunbarafe66032009-08-14 03:11:09 +000019 if (isAbsolute()) {
20 OS << getConstant();
21 return;
22 }
23
Tim Northover0999cbd2014-03-29 08:22:20 +000024 // 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
Daniel Dunbar9c64ec02010-03-18 00:59:10 +000029 getSymA()->print(OS);
Daniel Dunbar1a019d82009-08-14 03:41:23 +000030
Daniel Dunbar9c64ec02010-03-18 00:59:10 +000031 if (getSymB()) {
32 OS << " - ";
33 getSymB()->print(OS);
34 }
Daniel Dunbar1a019d82009-08-14 03:41:23 +000035
Daniel Dunbarafe66032009-08-14 03:11:09 +000036 if (getConstant())
37 OS << " + " << getConstant();
38}
39
Manman Ren49d684e2012-09-12 05:06:18 +000040#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Daniel Dunbarafe66032009-08-14 03:11:09 +000041void MCValue::dump() const {
Reid Kleckner9ccec062015-02-05 01:23:14 +000042 print(dbgs());
Daniel Dunbarafe66032009-08-14 03:11:09 +000043}
Manman Renc3366cc2012-09-06 19:55:56 +000044#endif
Rafael Espindola3d082fa2014-05-03 19:57:04 +000045
46MCSymbolRefExpr::VariantKind MCValue::getAccessVariant() const {
47 const MCSymbolRefExpr *B = getSymB();
48 if (B) {
49 if (B->getKind() != MCSymbolRefExpr::VK_None)
50 llvm_unreachable("unsupported");
51 }
52
53 const MCSymbolRefExpr *A = getSymA();
54 if (!A)
55 return MCSymbolRefExpr::VK_None;
56
57 MCSymbolRefExpr::VariantKind Kind = A->getKind();
58 if (Kind == MCSymbolRefExpr::VK_WEAKREF)
59 return MCSymbolRefExpr::VK_None;
60 return Kind;
61}