mini-llvm 0.1.0
Loading...
Searching...
No Matches
Symbol.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2
3#pragma once
4
5#include <compare>
6#include <cstddef>
7#include <format>
8#include <functional>
9#include <string>
10#include <utility>
11
13
14namespace mini_llvm::mc {
15
17public:
18 explicit Symbol(std::string name) : name_(std::move(name)) {}
19
20 const std::string &name() const & {
21 return name_;
22 }
23
24 std::string &&name() && {
25 return std::move(name_);
26 }
27
28 std::string format() const;
29
30private:
31 std::string name_;
32};
33
34inline bool operator==(const Symbol &lhs, const Symbol &rhs) {
35 return lhs.name() == rhs.name();
36}
37
38inline std::strong_ordering operator<=>(const Symbol &lhs, const Symbol &rhs) {
39 return lhs.name() <=> rhs.name();
40}
41
42} // namespace mini_llvm::mc
43
44template <>
45struct std::hash<mini_llvm::mc::Symbol> {
46 size_t operator()(const mini_llvm::mc::Symbol &symbol) const {
47 return std::hash<std::string>()(symbol.name());
48 }
49};
50
51template <>
52struct std::formatter<mini_llvm::mc::Symbol> {
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::mc::Symbol &symbol, FormatContext &ctx) const {
59 return std::format_to(ctx.out(), "{}", symbol.format());
60 }
61};
#define MINI_LLVM_EXPORT
Definition Compiler.h:17
Definition Symbol.h:16
const std::string & name() const &
Definition Symbol.h:20
Symbol(std::string name)
Definition Symbol.h:18
std::string && name() &&
Definition Symbol.h:24
std::string format() const
Definition Directive.h:8
bool operator==(const Symbol &lhs, const Symbol &rhs)
Definition Symbol.h:34
std::strong_ordering operator<=>(const Symbol &lhs, const Symbol &rhs)
Definition Symbol.h:38
Definition GraphColoringAllocator.h:13
auto format(const mini_llvm::mc::Symbol &symbol, FormatContext &ctx) const
Definition Symbol.h:58
constexpr auto parse(std::format_parse_context &ctx)
Definition Symbol.h:53
size_t operator()(const mini_llvm::mc::Symbol &symbol) const
Definition Symbol.h:46