mini-llvm
0.1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
MemoryOperand.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
3
#pragma once
4
5
#include <format>
6
#include <memory>
7
#include <string>
8
#include <utility>
9
10
#include "
mini-llvm/mir/Immediate.h
"
11
#include "
mini-llvm/mir/ImmediateOperand.h
"
12
#include "
mini-llvm/mir/IntegerImmediate.h
"
13
#include "
mini-llvm/mir/Register.h
"
14
#include "
mini-llvm/mir/RegisterClass.h
"
15
#include "
mini-llvm/mir/RegisterOperand.h
"
16
#include "
mini-llvm/utils/Memory.h
"
17
18
namespace
mini_llvm::mir
{
19
20
class
MemoryOperand
{
21
public
:
22
explicit
MemoryOperand
(std::shared_ptr<Register>
baseReg
,
23
std::unique_ptr<Immediate>
offset
= std::make_unique<IntegerImmediate>(0))
24
: baseReg_(
RegisterClass
::
kGPR
, std::move(
baseReg
)), offset_(std::move(
offset
)) {}
25
26
template
<
typename
Self>
27
auto
&
baseReg
(
this
Self &&self) {
28
return
self.baseReg_;
29
}
30
31
template
<
typename
Self>
32
auto
&
offset
(
this
Self &&self) {
33
return
self.offset_;
34
}
35
36
std::string
format
()
const
{
37
return
std::format(
"{}({})"
, *
offset
(), *
baseReg
());
38
}
39
40
MemoryOperand
clone
()
const
{
41
return
MemoryOperand
(
share
(*
baseReg
()),
offset
()->
clone
());
42
}
43
44
private
:
45
RegisterOperand
baseReg_;
46
ImmediateOperand
offset_;
47
};
48
49
}
// namespace mini_llvm::mir
50
51
template
<>
52
struct
std::formatter<
mini_llvm
::mir::MemoryOperand> {
53
constexpr
auto
parse
(std::format_parse_context &ctx) {
54
return
ctx.begin();
55
}
56
57
template
<
typename
FormatContext>
58
auto
format
(
const
mini_llvm::mir::MemoryOperand
&op, FormatContext &ctx)
const
{
59
return
std::format_to(ctx.out(),
"{}"
, op.
format
());
60
}
61
};
ImmediateOperand.h
Immediate.h
IntegerImmediate.h
Memory.h
RegisterClass.h
RegisterOperand.h
Register.h
mini_llvm::mir::ImmediateOperand
Definition
ImmediateOperand.h:12
mini_llvm::mir::MemoryOperand
Definition
MemoryOperand.h:20
mini_llvm::mir::MemoryOperand::offset
auto & offset(this Self &&self)
Definition
MemoryOperand.h:32
mini_llvm::mir::MemoryOperand::baseReg
auto & baseReg(this Self &&self)
Definition
MemoryOperand.h:27
mini_llvm::mir::MemoryOperand::format
std::string format() const
Definition
MemoryOperand.h:36
mini_llvm::mir::MemoryOperand::MemoryOperand
MemoryOperand(std::shared_ptr< Register > baseReg, std::unique_ptr< Immediate > offset=std::make_unique< IntegerImmediate >(0))
Definition
MemoryOperand.h:22
mini_llvm::mir::MemoryOperand::clone
MemoryOperand clone() const
Definition
MemoryOperand.h:40
mini_llvm::mir::RegisterOperand
Definition
RegisterOperand.h:13
mini_llvm::mir
Definition
BasicBlock.h:22
mini_llvm::mir::RegisterClass
RegisterClass
Definition
RegisterClass.h:7
mini_llvm::mir::RegisterClass::kGPR
@ kGPR
Definition
RegisterClass.h:8
mini_llvm
Definition
GraphColoringAllocator.h:13
mini_llvm::share
std::shared_ptr< T > share(T &value)
Definition
Memory.h:25
std::formatter< mini_llvm::mir::MemoryOperand >::parse
constexpr auto parse(std::format_parse_context &ctx)
Definition
MemoryOperand.h:53
std::formatter< mini_llvm::mir::MemoryOperand >::format
auto format(const mini_llvm::mir::MemoryOperand &op, FormatContext &ctx) const
Definition
MemoryOperand.h:58
include
mini-llvm
mir
MemoryOperand.h
Generated by
1.17.0