mini-llvm 0.1.0
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
12
13namespace mini_llvm::mir {
14
16public:
17 virtual ~GlobalValue() = default;
18
19 GlobalValue() = default;
20
21 GlobalValue(const GlobalValue &) = delete;
22 GlobalValue &operator=(const GlobalValue &) = delete;
23
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
37template <typename GlobalValueT>
38 requires std::derived_from<GlobalValueT, mini_llvm::mir::GlobalValue>
39struct 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
56private:
57 bool asOperand_ = false;
58};
#define MINI_LLVM_EXPORT
Definition Compiler.h:17
std::string formatAsOperand() const
virtual Linkage linkage() const =0
GlobalValue & operator=(GlobalValue &&)=delete
GlobalValue(const GlobalValue &)=delete
GlobalValue(GlobalValue &&)=delete
virtual std::string name() const =0
virtual ~GlobalValue()=default
GlobalValue & operator=(const GlobalValue &)=delete
virtual std::string format() const =0
Definition BasicBlock.h:22
Linkage
Definition Linkage.h:7
constexpr auto parse(std::format_parse_context &ctx)
Definition GlobalValue.h:40
auto format(const GlobalValueT &value, FormatContext &ctx) const
Definition GlobalValue.h:49