mini-llvm 0.1.0
Loading...
Searching...
No Matches
Immediate.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
12
13namespace mini_llvm::mir {
14
16public:
17 virtual ~Immediate() = default;
18
19 Immediate(const Immediate &) = delete;
20 Immediate &operator=(const Immediate &) = delete;
21
22 Immediate(Immediate &&) = delete;
24
25 virtual int64_t value() const = 0;
26 virtual std::unique_ptr<Immediate> clone() const = 0;
27
28 std::string format() const {
29 return std::to_string(value());
30 }
31
32protected:
33 Immediate() = default;
34};
35
36} // namespace mini_llvm::mir
37
38template <typename ImmediateT>
39 requires std::derived_from<ImmediateT, mini_llvm::mir::Immediate>
40struct std::formatter<ImmediateT> {
41 constexpr auto parse(std::format_parse_context &ctx) {
42 return ctx.begin();
43 }
44
45 template <typename FormatContext>
46 auto format(const ImmediateT &imm, FormatContext &ctx) const {
47 return std::format_to(ctx.out(), "{}", imm.format());
48 }
49};
#define MINI_LLVM_EXPORT
Definition Compiler.h:17
Immediate & operator=(const Immediate &)=delete
Immediate(const Immediate &)=delete
virtual int64_t value() const =0
Immediate(Immediate &&)=delete
std::string format() const
Definition Immediate.h:28
virtual ~Immediate()=default
Immediate & operator=(Immediate &&)=delete
virtual std::unique_ptr< Immediate > clone() const =0
Definition BasicBlock.h:22
auto format(const ImmediateT &imm, FormatContext &ctx) const
Definition Immediate.h:46
constexpr auto parse(std::format_parse_context &ctx)
Definition Immediate.h:41