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