LLVM  8.0.1
MCValue.h
Go to the documentation of this file.
1 //===-- llvm/MC/MCValue.h - MCValue class -----------------------*- C++ -*-===//
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 // This file contains the declaration of the MCValue class.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_MC_MCVALUE_H
15 #define LLVM_MC_MCVALUE_H
16 
17 #include "llvm/MC/MCExpr.h"
18 #include "llvm/MC/MCSymbol.h"
19 #include "llvm/Support/DataTypes.h"
20 #include <cassert>
21 
22 namespace llvm {
23 class MCAsmInfo;
24 class raw_ostream;
25 
26 /// This represents an "assembler immediate".
27 ///
28 /// In its most general form, this can hold ":Kind:(SymbolA - SymbolB +
29 /// imm64)". Not all targets supports relocations of this general form, but we
30 /// need to represent this anyway.
31 ///
32 /// In general both SymbolA and SymbolB will also have a modifier
33 /// analogous to the top-level Kind. Current targets are not expected
34 /// to make use of both though. The choice comes down to whether
35 /// relocation modifiers apply to the closest symbol or the whole
36 /// expression.
37 ///
38 /// Note that this class must remain a simple POD value class, because we need
39 /// it to live in unions etc.
40 class MCValue {
41  const MCSymbolRefExpr *SymA = nullptr, *SymB = nullptr;
42  int64_t Cst = 0;
43  uint32_t RefKind = 0;
44 
45 public:
46  MCValue() = default;
47  int64_t getConstant() const { return Cst; }
48  const MCSymbolRefExpr *getSymA() const { return SymA; }
49  const MCSymbolRefExpr *getSymB() const { return SymB; }
50  uint32_t getRefKind() const { return RefKind; }
51 
52  /// Is this an absolute (as opposed to relocatable) value.
53  bool isAbsolute() const { return !SymA && !SymB; }
54 
55  /// Print the value to the stream \p OS.
56  void print(raw_ostream &OS) const;
57 
58  /// Print the value to stderr.
59  void dump() const;
60 
62 
63  static MCValue get(const MCSymbolRefExpr *SymA,
64  const MCSymbolRefExpr *SymB = nullptr,
65  int64_t Val = 0, uint32_t RefKind = 0) {
66  MCValue R;
67  R.Cst = Val;
68  R.SymA = SymA;
69  R.SymB = SymB;
70  R.RefKind = RefKind;
71  return R;
72  }
73 
74  static MCValue get(int64_t Val) {
75  MCValue R;
76  R.Cst = Val;
77  R.SymA = nullptr;
78  R.SymB = nullptr;
79  R.RefKind = 0;
80  return R;
81  }
82 
83 };
84 
85 } // end namespace llvm
86 
87 #endif
This class represents lattice values for constants.
Definition: AllocatorList.h:24
This represents an "assembler immediate".
Definition: MCValue.h:40
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
Definition: MCValue.h:53
MCSymbolRefExpr::VariantKind getAccessVariant() const
Definition: MCValue.cpp:47
int64_t getConstant() const
Definition: MCValue.h:47
const MCSymbolRefExpr * getSymB() const
Definition: MCValue.h:49
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:166
const MCSymbolRefExpr * getSymA() const
Definition: MCValue.h:48
MCValue()=default
void print(raw_ostream &OS) const
Print the value to the stream OS.
Definition: MCValue.cpp:19
uint32_t getRefKind() const
Definition: MCValue.h:50
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
void dump() const
Print the value to stderr.
Definition: MCValue.cpp:42