FE
0.16.1
Fast, Effecient FrontEnds
Toggle main menu visibility
Loading...
Searching...
No Matches
dbg.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <bit>
4
#include <ostream>
5
#include <tuple>
6
7
#include <ankerl/unordered_dense.h>
8
9
#include "
fe/format.h
"
10
#include "
fe/loc.h
"
11
#include "
fe/sym.h
"
12
13
namespace
fe
{
14
15
/// The debug info of an entity: where it came from and what it was called.
16
struct
Dbg
{
17
/// @name Constructors
18
///@{
19
constexpr
Dbg
() noexcept = default;
20
constexpr
Dbg
(
Loc
loc
,
Sym
sym
) noexcept
21
: loc_(
loc
)
22
, sym_(
sym
) {}
23
constexpr
Dbg
(
Loc
loc
) noexcept
24
:
Dbg
(
loc
, {}) {}
25
constexpr
Dbg
(
Sym
sym
) noexcept
26
:
Dbg
({},
sym
) {}
27
///@}
28
29
/// @name Getters
30
///@{
31
constexpr
Sym
sym
() const noexcept {
return
sym_; }
32
constexpr
Loc
loc
() const noexcept {
return
loc_; }
33
/// Assumes `_` as the anonymous name.
34
constexpr
bool
is_anon
() const noexcept {
return
!
sym
() ||
sym
() ==
'_'
; }
35
constexpr
explicit
operator
bool() const noexcept {
return
sym
().operator bool(); }
36
///@}
37
38
/// @name Setters
39
///@{
40
constexpr
Dbg
&
set
(
Sym
sym
)
noexcept
{
return
sym_ =
sym
, *
this
; }
41
constexpr
Dbg
&
set
(
Loc
loc
)
noexcept
{
return
loc_ =
loc
, *
this
; }
42
///@}
43
44
/// @name Comparison and Hashing
45
///@{
46
/// @note Like Loc::operator==, this only compares Loc::src by pointer identity.
47
constexpr
bool
operator==
(
const
Dbg
& other)
const
noexcept
{
return
loc_ == other.loc_ && sym_ == other.sym_; }
48
49
struct
Hash
{
50
using
is_avalanching
= void;
51
52
size_t
operator()
(
Dbg
dbg)
const
noexcept
{
53
using
Tuple = std::tuple<uintptr_t, uint32_t, uint32_t, uintptr_t>;
54
return
ankerl::unordered_dense::hash<Tuple>()(
55
{std::bit_cast<uintptr_t>(dbg.loc_.src), dbg.loc_.begin.off, dbg.loc_.end.off, dbg.sym_.raw()});
56
}
57
};
58
59
struct
Eq
{
60
constexpr
bool
operator()
(
Dbg
d1,
Dbg
d2)
const
noexcept
{
return
d1 == d2; }
61
};
62
///@}
63
64
private
:
65
Loc
loc_;
66
Sym
sym_;
67
68
friend
std::ostream&
operator<<
(std::ostream& os,
const
Dbg
& dbg) {
return
os << dbg.
sym
(); }
69
};
70
71
/// @name DbgMap/DbgSet
72
///@{
73
template
<
class
V>
74
using
DbgMap
= ankerl::unordered_dense::map<Dbg, V, Dbg::Hash, Dbg::Eq>;
75
using
DbgSet
= ankerl::unordered_dense::set<Dbg, Dbg::Hash, Dbg::Eq>;
76
///@}
77
78
/// Opaque handle to a Dbg interned in a Driver; see Driver::dbg.
79
/// Handing one node another's key copies the handle verbatim: no Dbg is materialised and nothing is
80
/// looked up in the Driver's table.
81
/// @warning A key is only meaningful within the Driver that interned it.
82
class
DbgKey
{
83
public
:
84
constexpr
DbgKey
() noexcept = default;
///< The empty Dbg.
85
86
constexpr explicit operator
bool
() const noexcept {
return
key_ != 0; }
///< Not the empty Dbg?
87
constexpr
bool
operator==
(
const
DbgKey
&)
const
noexcept
=
default
;
88
89
private
:
90
constexpr
explicit
DbgKey
(uint32_t key) noexcept
91
: key_(key) {}
92
93
uint32_t key_ = 0;
94
95
friend
struct
Driver
;
96
};
97
98
}
// namespace fe
99
100
#ifndef DOXYGEN
101
template
<>
102
struct
std::formatter<
fe
::Dbg> :
fe::ostream_formatter
{};
103
#endif
fe::DbgKey::operator==
constexpr bool operator==(const DbgKey &) const noexcept=default
fe::DbgKey::DbgKey
constexpr DbgKey() noexcept=default
The empty Dbg.
fe::DbgKey::Driver
friend struct Driver
Definition
dbg.h:95
fe::Sym
A Symbol just wraps a pointer to Sym::String, so pass Sym itself around as value.
Definition
sym.h:30
format.h
loc.h
fe
Definition
algo.h:17
fe::DbgMap
ankerl::unordered_dense::map< Dbg, V, Dbg::Hash, Dbg::Eq > DbgMap
Definition
dbg.h:74
fe::DbgSet
ankerl::unordered_dense::set< Dbg, Dbg::Hash, Dbg::Eq > DbgSet
Definition
dbg.h:75
fe::ostream_formatter
basic_ostream_formatter< char > ostream_formatter
Definition
format.h:61
fe::Dbg::Eq
Definition
dbg.h:59
fe::Dbg::Eq::operator()
constexpr bool operator()(Dbg d1, Dbg d2) const noexcept
Definition
dbg.h:60
fe::Dbg::Hash
Definition
dbg.h:49
fe::Dbg::Hash::operator()
size_t operator()(Dbg dbg) const noexcept
Definition
dbg.h:52
fe::Dbg::Hash::is_avalanching
void is_avalanching
Definition
dbg.h:50
fe::Dbg::loc
constexpr Loc loc() const noexcept
Definition
dbg.h:32
fe::Dbg::set
constexpr Dbg & set(Sym sym) noexcept
Definition
dbg.h:40
fe::Dbg::operator==
constexpr bool operator==(const Dbg &other) const noexcept
Definition
dbg.h:47
fe::Dbg::Dbg
constexpr Dbg(Loc loc) noexcept
Definition
dbg.h:23
fe::Dbg::operator<<
friend std::ostream & operator<<(std::ostream &os, const Dbg &dbg)
Definition
dbg.h:68
fe::Dbg::Dbg
constexpr Dbg() noexcept=default
fe::Dbg::is_anon
constexpr bool is_anon() const noexcept
Assumes _ as the anonymous name.
Definition
dbg.h:34
fe::Dbg::sym
constexpr Sym sym() const noexcept
Definition
dbg.h:31
fe::Dbg::Dbg
constexpr Dbg(Sym sym) noexcept
Definition
dbg.h:25
fe::Dbg::set
constexpr Dbg & set(Loc loc) noexcept
Definition
dbg.h:41
fe::Loc
Location within a Src: the half-open byte range [Loc::begin, Loc::end).
Definition
loc.h:42
sym.h
fe
dbg.h
Generated by
1.18.0