mini-llvm
0.1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
Type.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
3
#pragma once
4
5
#include <concepts>
6
#include <cstdint>
7
#include <format>
8
#include <memory>
9
#include <string>
10
11
#include "
mini-llvm/ir/TypeVisitor.h
"
12
#include "
mini-llvm/utils/Compiler.h
"
13
14
namespace
mini_llvm::ir
{
15
16
class
Constant
;
17
18
class
MINI_LLVM_EXPORT
Type
{
19
public
:
20
virtual
~Type
() =
default
;
21
22
Type
() =
default
;
23
24
Type
(
const
Type
&) =
delete
;
25
Type
&
operator=
(
const
Type
&) =
delete
;
26
27
Type
(
Type
&&) =
delete
;
28
Type
&
operator=
(
Type
&&) =
delete
;
29
30
virtual
int
size
()
const
= 0;
31
virtual
int
alignment
()
const
= 0;
32
virtual
int
size
(
int
)
const
{
return
size
(); }
33
virtual
int
alignment
(
int
)
const
{
return
alignment
(); }
34
35
virtual
int
bitSize
()
const
{
36
return
size
() * 8;
37
}
38
39
virtual
int
bitAlignment
()
const
{
40
return
alignment
() * 8;
41
}
42
43
virtual
int
bitSize
(
int
pointerSize)
const
{
44
return
size
(pointerSize) * 8;
45
}
46
47
virtual
int
bitAlignment
(
int
pointerAlignment)
const
{
48
return
alignment
(pointerAlignment) * 8;
49
}
50
51
virtual
std::unique_ptr<Constant>
zeroValue
()
const
= 0;
52
virtual
std::unique_ptr<Constant>
constant
(int64_t value)
const
= 0;
53
virtual
std::unique_ptr<Type>
promoted
()
const
= 0;
54
virtual
std::unique_ptr<Type>
demoted
()
const
= 0;
55
virtual
std::string
format
()
const
= 0;
56
virtual
std::unique_ptr<Type>
clone
()
const
= 0;
57
virtual
void
accept
(
TypeVisitor
&visitor) = 0;
58
virtual
void
accept
(
TypeVisitor
&visitor)
const
= 0;
59
60
protected
:
61
virtual
bool
equals
(
const
Type
&other)
const
= 0;
62
63
friend
bool
operator==
(
const
Type
&lhs,
const
Type
&rhs);
64
};
65
66
inline
bool
operator==
(
const
Type
&lhs,
const
Type
&rhs) {
67
return
lhs.
equals
(rhs);
68
}
69
70
}
// namespace mini_llvm::ir
71
72
template
<
typename
TypeT>
73
requires
std::derived_from<TypeT, mini_llvm::ir::Type>
74
struct
std::formatter<TypeT> {
75
constexpr
auto
parse
(std::format_parse_context &ctx) {
76
return
ctx.begin();
77
}
78
79
template
<
typename
FormatContext>
80
auto
format
(
const
TypeT &type, FormatContext &ctx)
const
{
81
return
std::format_to(ctx.out(),
"{}"
, type.format());
82
}
83
};
Compiler.h
MINI_LLVM_EXPORT
#define MINI_LLVM_EXPORT
Definition
Compiler.h:17
TypeVisitor.h
mini_llvm::ir::Constant
Definition
Constant.h:13
mini_llvm::ir::TypeVisitor
Definition
TypeVisitor.h:25
mini_llvm::ir::Type::clone
virtual std::unique_ptr< Type > clone() const =0
mini_llvm::ir::Type::size
virtual int size() const =0
mini_llvm::ir::Type::alignment
virtual int alignment(int) const
Definition
Type.h:33
mini_llvm::ir::Type::bitAlignment
virtual int bitAlignment(int pointerAlignment) const
Definition
Type.h:47
mini_llvm::ir::Type::Type
Type()=default
mini_llvm::ir::Type::demoted
virtual std::unique_ptr< Type > demoted() const =0
mini_llvm::ir::Type::operator=
Type & operator=(const Type &)=delete
mini_llvm::ir::Type::~Type
virtual ~Type()=default
mini_llvm::ir::Type::Type
Type(const Type &)=delete
mini_llvm::ir::Type::operator==
friend bool operator==(const Type &lhs, const Type &rhs)
Definition
Type.h:66
mini_llvm::ir::Type::constant
virtual std::unique_ptr< Constant > constant(int64_t value) const =0
mini_llvm::ir::Type::accept
virtual void accept(TypeVisitor &visitor) const =0
mini_llvm::ir::Type::bitSize
virtual int bitSize(int pointerSize) const
Definition
Type.h:43
mini_llvm::ir::Type::Type
Type(Type &&)=delete
mini_llvm::ir::Type::zeroValue
virtual std::unique_ptr< Constant > zeroValue() const =0
mini_llvm::ir::Type::size
virtual int size(int) const
Definition
Type.h:32
mini_llvm::ir::Type::bitAlignment
virtual int bitAlignment() const
Definition
Type.h:39
mini_llvm::ir::Type::promoted
virtual std::unique_ptr< Type > promoted() const =0
mini_llvm::ir::Type::format
virtual std::string format() const =0
mini_llvm::ir::Type::operator=
Type & operator=(Type &&)=delete
mini_llvm::ir::Type::equals
virtual bool equals(const Type &other) const =0
mini_llvm::ir::Type::accept
virtual void accept(TypeVisitor &visitor)=0
mini_llvm::ir::Type::bitSize
virtual int bitSize() const
Definition
Type.h:35
mini_llvm::ir::Type::alignment
virtual int alignment() const =0
mini_llvm::ir
Definition
Argument.h:13
mini_llvm::ir::operator==
bool operator==(const Constant &lhs, const Constant &rhs)
Definition
Constant.h:28
std::formatter< TypeT >::parse
constexpr auto parse(std::format_parse_context &ctx)
Definition
Type.h:75
std::formatter< TypeT >::format
auto format(const TypeT &type, FormatContext &ctx) const
Definition
Type.h:80
include
mini-llvm
ir
Type.h
Generated by
1.17.0