LLVM  10.0.0svn
MCValue.cpp
Go to the documentation of this file.
1 //===- lib/MC/MCValue.cpp - MCValue implementation ------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/MC/MCValue.h"
10 #include "llvm/Config/llvm-config.h"
11 #include "llvm/MC/MCExpr.h"
12 #include "llvm/Support/Debug.h"
15 
16 using namespace llvm;
17 
18 void MCValue::print(raw_ostream &OS) const {
19  if (isAbsolute()) {
20  OS << getConstant();
21  return;
22  }
23 
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 
29  OS << *getSymA();
30 
31  if (getSymB()) {
32  OS << " - ";
33  OS << *getSymB();
34  }
35 
36  if (getConstant())
37  OS << " + " << getConstant();
38 }
39 
40 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
42  print(dbgs());
43 }
44 #endif
45 
47  const MCSymbolRefExpr *B = getSymB();
48  if (B) {
50  llvm_unreachable("unsupported");
51  }
52 
53  const MCSymbolRefExpr *A = getSymA();
54  if (!A)
56 
58  if (Kind == MCSymbolRefExpr::VK_WEAKREF)
60  return Kind;
61 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
Definition: Compiler.h:476
VariantKind getKind() const
Definition: MCExpr.h:342
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
Definition: MCValue.h:52
MCSymbolRefExpr::VariantKind getAccessVariant() const
Definition: MCValue.cpp:46
int64_t getConstant() const
Definition: MCValue.h:46
const MCSymbolRefExpr * getSymB() const
Definition: MCValue.h:48
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:169
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:47
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void print(raw_ostream &OS) const
Print the value to the stream OS.
Definition: MCValue.cpp:18
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
uint32_t getRefKind() const
Definition: MCValue.h:49
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
void dump() const
Print the value to stderr.
Definition: MCValue.cpp:41