blob: 7e03913aa680a3734810088355b8b81568683a48 [file] [log] [blame]
Daniel Dunbar2c116242009-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"
Nico Weber0f38c602018-04-30 14:59:11 +000011#include "llvm/Config/llvm-config.h"
Daniel Dunbar9a1d2002010-03-18 00:59:10 +000012#include "llvm/MC/MCExpr.h"
David Greene24c802b2010-01-05 01:28:17 +000013#include "llvm/Support/Debug.h"
Rafael Espindola930ca982014-05-03 19:57:04 +000014#include "llvm/Support/ErrorHandling.h"
Daniel Dunbar2c116242009-08-14 03:11:09 +000015#include "llvm/Support/raw_ostream.h"
16
17using namespace llvm;
18
Sean Silvaa875e3d2015-02-05 00:58:51 +000019void MCValue::print(raw_ostream &OS) const {
Daniel Dunbar2c116242009-08-14 03:11:09 +000020 if (isAbsolute()) {
21 OS << getConstant();
22 return;
23 }
24
Tim Northover8a272f02014-03-29 08:22:20 +000025 // FIXME: prints as a number, which isn't ideal. But the meaning will be
26 // target-specific anyway.
27 if (getRefKind())
28 OS << ':' << getRefKind() << ':';
29
Rafael Espindolaeac1f662015-05-27 13:05:42 +000030 OS << *getSymA();
Daniel Dunbar1689e0cf2009-08-14 03:41:23 +000031
Daniel Dunbar9a1d2002010-03-18 00:59:10 +000032 if (getSymB()) {
33 OS << " - ";
Rafael Espindolaeac1f662015-05-27 13:05:42 +000034 OS << *getSymB();
Daniel Dunbar9a1d2002010-03-18 00:59:10 +000035 }
Daniel Dunbar1689e0cf2009-08-14 03:41:23 +000036
Daniel Dunbar2c116242009-08-14 03:11:09 +000037 if (getConstant())
38 OS << " + " << getConstant();
39}
40
Aaron Ballman1d03d382017-10-15 14:32:27 +000041#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
Yaron Keren55307982016-01-29 20:50:44 +000042LLVM_DUMP_METHOD void MCValue::dump() const {
Reid Kleckner6d3ceb22015-02-05 01:23:14 +000043 print(dbgs());
Daniel Dunbar2c116242009-08-14 03:11:09 +000044}
Matthias Braun88d20752017-01-28 02:02:38 +000045#endif
Rafael Espindola930ca982014-05-03 19:57:04 +000046
47MCSymbolRefExpr::VariantKind MCValue::getAccessVariant() const {
48 const MCSymbolRefExpr *B = getSymB();
49 if (B) {
50 if (B->getKind() != MCSymbolRefExpr::VK_None)
51 llvm_unreachable("unsupported");
52 }
53
54 const MCSymbolRefExpr *A = getSymA();
55 if (!A)
56 return MCSymbolRefExpr::VK_None;
57
58 MCSymbolRefExpr::VariantKind Kind = A->getKind();
59 if (Kind == MCSymbolRefExpr::VK_WEAKREF)
60 return MCSymbolRefExpr::VK_None;
61 return Kind;
62}