mini-llvm
0.1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
GlobalValue.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
3
#pragma once
4
5
#include <concepts>
6
#include <format>
7
#include <iterator>
8
#include <string>
9
10
#include "
mini-llvm/common/Linkage.h
"
11
#include "
mini-llvm/utils/Compiler.h
"
12
13
namespace
mini_llvm::mir
{
14
15
class
MINI_LLVM_EXPORT
GlobalValue
{
16
public
:
17
virtual
~GlobalValue
() =
default
;
18
19
GlobalValue
() =
default
;
20
21
GlobalValue
(
const
GlobalValue
&) =
delete
;
22
GlobalValue
&
operator=
(
const
GlobalValue
&) =
delete
;
23
24
GlobalValue
(
GlobalValue
&&) =
delete
;
25
GlobalValue
&
operator=
(
GlobalValue
&&) =
delete
;
26
27
virtual
std::string
name
()
const
= 0;
28
virtual
Linkage
linkage
()
const
= 0;
29
30
virtual
std::string
format
()
const
= 0;
31
32
std::string
formatAsOperand
()
const
;
33
};
34
35
}
// namespace mini_llvm::mir
36
37
template
<
typename
GlobalValueT>
38
requires
std::derived_from<GlobalValueT, mini_llvm::mir::GlobalValue>
39
struct
std::formatter<GlobalValueT> {
40
constexpr
auto
parse
(std::format_parse_context &ctx) {
41
if
(*ctx.begin() ==
'o'
) {
42
asOperand_ =
true
;
43
return
std::next(ctx.begin());
44
}
45
return
ctx.begin();
46
}
47
48
template
<
typename
FormatContext>
49
auto
format
(
const
GlobalValueT &value, FormatContext &ctx)
const
{
50
if
(asOperand_) {
51
return
std::format_to(ctx.out(),
"{}"
, value.formatAsOperand());
52
}
53
return
std::format_to(ctx.out(),
"{}"
, value.format());
54
}
55
56
private
:
57
bool
asOperand_ =
false
;
58
};
Compiler.h
MINI_LLVM_EXPORT
#define MINI_LLVM_EXPORT
Definition
Compiler.h:17
Linkage.h
mini_llvm::mir::GlobalValue::formatAsOperand
std::string formatAsOperand() const
mini_llvm::mir::GlobalValue::linkage
virtual Linkage linkage() const =0
mini_llvm::mir::GlobalValue::operator=
GlobalValue & operator=(GlobalValue &&)=delete
mini_llvm::mir::GlobalValue::GlobalValue
GlobalValue(const GlobalValue &)=delete
mini_llvm::mir::GlobalValue::GlobalValue
GlobalValue(GlobalValue &&)=delete
mini_llvm::mir::GlobalValue::name
virtual std::string name() const =0
mini_llvm::mir::GlobalValue::GlobalValue
GlobalValue()=default
mini_llvm::mir::GlobalValue::~GlobalValue
virtual ~GlobalValue()=default
mini_llvm::mir::GlobalValue::operator=
GlobalValue & operator=(const GlobalValue &)=delete
mini_llvm::mir::GlobalValue::format
virtual std::string format() const =0
mini_llvm::mir
Definition
BasicBlock.h:22
mini_llvm::Linkage
Linkage
Definition
Linkage.h:7
std::formatter< GlobalValueT >::parse
constexpr auto parse(std::format_parse_context &ctx)
Definition
GlobalValue.h:40
std::formatter< GlobalValueT >::format
auto format(const GlobalValueT &value, FormatContext &ctx) const
Definition
GlobalValue.h:49
include
mini-llvm
mir
GlobalValue.h
Generated by
1.17.0