]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/MC/MCValue.cpp
MFV r348551: 9862 fix typo in comment in vdev_impl.h
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / MC / MCValue.cpp
1 //===- 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"
11 #include "llvm/Config/llvm-config.h"
12 #include "llvm/MC/MCExpr.h"
13 #include "llvm/Support/Debug.h"
14 #include "llvm/Support/ErrorHandling.h"
15 #include "llvm/Support/raw_ostream.h"
16
17 using namespace llvm;
18
19 void MCValue::print(raw_ostream &OS) const {
20   if (isAbsolute()) {
21     OS << getConstant();
22     return;
23   }
24
25   // 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
30   OS << *getSymA();
31
32   if (getSymB()) {
33     OS << " - ";
34     OS << *getSymB();
35   }
36
37   if (getConstant())
38     OS << " + " << getConstant();
39 }
40
41 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
42 LLVM_DUMP_METHOD void MCValue::dump() const {
43   print(dbgs());
44 }
45 #endif
46
47 MCSymbolRefExpr::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 }