blob: b6bcec9b2ca078a585c7b6cbaaf203d5e0e169ec [file] [log] [blame]
Daniel Dunbarafe66032009-08-14 03:11:09 +00001//===- lib/MC/MCValue.cpp - MCValue implementation ------------------------===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Daniel Dunbarafe66032009-08-14 03:11:09 +00006//
7//===----------------------------------------------------------------------===//
8
9#include "llvm/MC/MCValue.h"
Nico Weber432a3882018-04-30 14:59:11 +000010#include "llvm/Config/llvm-config.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
Aaron Ballman615eb472017-10-15 14:32:27 +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
Fangrui Song2b0256e2019-12-15 16:03:56 -080057 return A->getKind();
Rafael Espindola3d082fa2014-05-03 19:57:04 +000058}