MimIR
0.5-dev
MimIR is my Intermediate Representation
Toggle main menu visibility
Loading...
Searching...
No Matches
plugin.cpp
Go to the documentation of this file.
1
#include "
mim/plugin.h
"
2
3
namespace
mim
{
4
5
namespace
{
6
constexpr
auto
Alphabet = std::string_view(
"_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
);
7
}
8
9
std::optional<plugin_t>
Annex::mangle
(std::string_view plugin) {
10
auto
n = plugin.size();
11
if
(n >
Max_Plugin_Size
)
return
{};
12
13
u64
result = 0;
14
for
(
size_t
i = 0; i !=
Max_Plugin_Size
; ++i) {
15
u64
u =
'\0'
;
16
17
if
(i < n) {
18
auto
pos = Alphabet.find(plugin[i]);
19
if
(pos == std::string_view::npos)
return
{};
20
u = pos + 1;
21
}
22
23
result = (result << 6_u64) | u;
24
}
25
26
return
result << 16_u64;
27
}
28
29
std::string
Annex::demangle
(
plugin_t
plugin) {
30
std::string result;
31
for
(
size_t
i = 0; i !=
Max_Plugin_Size
; ++i) {
32
u64
c = (plugin & 0xfc00000000000000_u64) >> 58_u64;
33
if
(c == 0)
return
result;
34
result += Alphabet[c - 1];
35
36
plugin <<= 6_u64;
37
}
38
39
return
result;
40
}
41
42
}
// namespace mim
mim
Definition
ast.h:16
mim::plugin_t
u64 plugin_t
Definition
types.h:40
mim::u64
uint64_t u64
Definition
types.h:27
plugin.h
mim::Annex::demangle
static std::string demangle(plugin_t plugin)
Reverts an Axm::mangled plugin back to its name; never longer than Annex::Max_Plugin_Size.
Definition
plugin.cpp:29
mim::Annex::mangle
static std::optional< plugin_t > mangle(std::string_view plugin)
Mangles s into a dense 48-bit representation.
Definition
plugin.cpp:9
mim::Annex::Max_Plugin_Size
static constexpr size_t Max_Plugin_Size
Definition
plugin.h:213
src
mim
plugin.cpp
Generated by
1.18.0