LLVM 22.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"
18
19namespace llvm {
20class raw_ostream;
21
22// Represents a relocatable expression in its most general form:
23// relocation_specifier(SymA - SymB + imm64).
24//
25// Not all targets support SymB. For PC-relative relocations, a specifier is
26// typically used instead of setting SymB to DOT.
27//
28// This class must remain a simple POD value class, as it needs to reside in
29// unions and similar structures.
30class MCValue {
31 const MCSymbol *SymA = nullptr, *SymB = nullptr;
32 int64_t Cst = 0;
33 uint32_t Specifier = 0;
34
35 void print(raw_ostream &OS) const;
36
37 /// Print the value to stderr.
38 void dump() const;
39
40public:
41 friend class MCAssembler;
42 friend class MCExpr;
43 MCValue() = default;
44 int64_t getConstant() const { return Cst; }
45 void setConstant(int64_t C) { Cst = C; }
46 uint32_t getSpecifier() const { return Specifier; }
47 void setSpecifier(uint32_t S) { Specifier = S; }
48
49 const MCSymbol *getAddSym() const { return SymA; }
50 void setAddSym(const MCSymbol *A) { SymA = A; }
51 const MCSymbol *getSubSym() const { return SymB; }
52
53 /// Is this an absolute (as opposed to relocatable) value.
54 bool isAbsolute() const { return !SymA && !SymB; }
55
56 static MCValue get(const MCSymbol *SymA, const MCSymbol *SymB = nullptr,
57 int64_t Val = 0, uint32_t Specifier = 0) {
58 MCValue R;
59 R.Cst = Val;
60 R.SymA = SymA;
61 R.SymB = SymB;
62 R.Specifier = Specifier;
63 return R;
64 }
65
66 static MCValue get(int64_t Val) {
67 MCValue R;
68 R.Cst = Val;
69 R.SymA = nullptr;
70 R.SymB = nullptr;
71 R.Specifier = 0;
72 return R;
73 }
74
75};
76
77} // end namespace llvm
78
79#endif
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
raw_pwrite_stream & OS
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
static MCValue get(const MCSymbol *SymA, const MCSymbol *SymB=nullptr, int64_t Val=0, uint32_t Specifier=0)
Definition: MCValue.h:56
const MCSymbol * getAddSym() const
Definition: MCValue.h:49
void setSpecifier(uint32_t S)
Definition: MCValue.h:47
int64_t getConstant() const
Definition: MCValue.h:44
void setAddSym(const MCSymbol *A)
Definition: MCValue.h:50
void setConstant(int64_t C)
Definition: MCValue.h:45
static MCValue get(int64_t Val)
Definition: MCValue.h:66
uint32_t getSpecifier() const
Definition: MCValue.h:46
MCValue()=default
const MCSymbol * getSubSym() const
Definition: MCValue.h:51
bool isAbsolute() const
Is this an absolute (as opposed to relocatable) value.
Definition: MCValue.h:54
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18