Daniel Dunbar | afe6603 | 2009-08-14 03:11:09 +0000 | [diff] [blame] | 1 | //===- lib/MC/MCValue.cpp - MCValue implementation ------------------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // 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 Dunbar | afe6603 | 2009-08-14 03:11:09 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "llvm/MC/MCValue.h" |
Nico Weber | 432a388 | 2018-04-30 14:59:11 +0000 | [diff] [blame] | 10 | #include "llvm/Config/llvm-config.h" |
Daniel Dunbar | 9c64ec0 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 11 | #include "llvm/MC/MCExpr.h" |
David Greene | ac7f537 | 2010-01-05 01:28:17 +0000 | [diff] [blame] | 12 | #include "llvm/Support/Debug.h" |
Rafael Espindola | 3d082fa | 2014-05-03 19:57:04 +0000 | [diff] [blame] | 13 | #include "llvm/Support/ErrorHandling.h" |
Daniel Dunbar | afe6603 | 2009-08-14 03:11:09 +0000 | [diff] [blame] | 14 | #include "llvm/Support/raw_ostream.h" |
| 15 | |
| 16 | using namespace llvm; |
| 17 | |
Sean Silva | 0e1fe18 | 2015-02-05 00:58:51 +0000 | [diff] [blame] | 18 | void MCValue::print(raw_ostream &OS) const { |
Daniel Dunbar | afe6603 | 2009-08-14 03:11:09 +0000 | [diff] [blame] | 19 | if (isAbsolute()) { |
| 20 | OS << getConstant(); |
| 21 | return; |
| 22 | } |
| 23 | |
Tim Northover | 0999cbd | 2014-03-29 08:22:20 +0000 | [diff] [blame] | 24 | // 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 Espindola | f4a1365 | 2015-05-27 13:05:42 +0000 | [diff] [blame] | 29 | OS << *getSymA(); |
Daniel Dunbar | 1a019d8 | 2009-08-14 03:41:23 +0000 | [diff] [blame] | 30 | |
Daniel Dunbar | 9c64ec0 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 31 | if (getSymB()) { |
| 32 | OS << " - "; |
Rafael Espindola | f4a1365 | 2015-05-27 13:05:42 +0000 | [diff] [blame] | 33 | OS << *getSymB(); |
Daniel Dunbar | 9c64ec0 | 2010-03-18 00:59:10 +0000 | [diff] [blame] | 34 | } |
Daniel Dunbar | 1a019d8 | 2009-08-14 03:41:23 +0000 | [diff] [blame] | 35 | |
Daniel Dunbar | afe6603 | 2009-08-14 03:11:09 +0000 | [diff] [blame] | 36 | if (getConstant()) |
| 37 | OS << " + " << getConstant(); |
| 38 | } |
| 39 | |
Aaron Ballman | 615eb47 | 2017-10-15 14:32:27 +0000 | [diff] [blame] | 40 | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
Yaron Keren | eb2a254 | 2016-01-29 20:50:44 +0000 | [diff] [blame] | 41 | LLVM_DUMP_METHOD void MCValue::dump() const { |
Reid Kleckner | 9ccec06 | 2015-02-05 01:23:14 +0000 | [diff] [blame] | 42 | print(dbgs()); |
Daniel Dunbar | afe6603 | 2009-08-14 03:11:09 +0000 | [diff] [blame] | 43 | } |
Matthias Braun | 8c209aa | 2017-01-28 02:02:38 +0000 | [diff] [blame] | 44 | #endif |
Rafael Espindola | 3d082fa | 2014-05-03 19:57:04 +0000 | [diff] [blame] | 45 | |
| 46 | MCSymbolRefExpr::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 Song | 2b0256e | 2019-12-15 16:03:56 -0800 | [diff] [blame] | 57 | return A->getKind(); |
Rafael Espindola | 3d082fa | 2014-05-03 19:57:04 +0000 | [diff] [blame] | 58 | } |