blob: 32a6adbf224e6999c12cfe0409906d44b5ba69d7 [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
Rafael Espindolaf4a13652015-05-27 13:05:42 +000029 OS << *getSymA();
Daniel Dunbar1a019d82009-08-14 03:41:23 +000030
Daniel Dunbar9c64ec02010-03-18 00:59:10 +000031 if (getSymB()) {
32 OS << " - ";
Rafael Espindolaf4a13652015-05-27 13:05:42 +000033 OS << *getSymB();
Daniel Dunbar9c64ec02010-03-18 00:59:10 +000034 }
Daniel Dunbar1a019d82009-08-14 03:41:23 +000035
Daniel Dunbarafe66032009-08-14 03:11:09 +000036 if (getConstant())
37 OS << " + " << getConstant();
38}
39
Matthias Braun8c209aa2017-01-28 02:02:38 +000040#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Yaron Kereneb2a2542016-01-29 20:50:44 +000041LLVM_DUMP_METHOD void MCValue::dump() const {
Reid Kleckner9ccec062015-02-05 01:23:14 +000042 print(dbgs());
Daniel Dunbarafe66032009-08-14 03:11:09 +000043}
Matthias Braun8c209aa2017-01-28 02:02:38 +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}