MimIR
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
plugin.cpp
Go to the documentation of this file.
1#include "mim/plugin.h"
2
3namespace mim {
4
5std::optional<plugin_t> Annex::mangle(std::string_view plugin) {
6 auto n = plugin.size();
7 if (n > Max_Plugin_Size) return {};
8
9 u64 result = 0;
10 for (size_t i = 0; i != Max_Plugin_Size; ++i) {
11 u64 u = '\0';
12
13 if (i < n) {
14 auto c = plugin[i];
15 if (c == '_')
16 u = 1;
17 else if ('a' <= c && c <= 'z')
18 u = c - 'a' + 2_u64;
19 else if ('A' <= c && c <= 'Z')
20 u = c - 'A' + 28_u64;
21 else if ('0' <= c && c <= '9')
22 u = c - '0' + 54_u64;
23 else
24 return {};
25 }
26
27 result = (result << 6_u64) | u;
28 }
29
30 return result << 16_u64;
31}
32
33std::string Annex::demangle(plugin_t plugin) {
34 std::string result;
35 for (size_t i = 0; i != Max_Plugin_Size; ++i) {
36 u64 c = (plugin & 0xfc00000000000000_u64) >> 58_u64;
37 if (c == 0)
38 return result;
39 else if (c == 1)
40 result += '_';
41 else if (2 <= c && c < 28)
42 result += 'a' + ((char)c - 2);
43 else if (28 <= c && c < 54)
44 result += 'A' + ((char)c - 28);
45 else
46 result += '0' + ((char)c - 54);
47
48 plugin <<= 6_u64;
49 }
50
51 return result;
52}
53
54} // namespace mim
Definition ast.h:16
u64 plugin_t
Definition types.h:40
uint64_t u64
Definition types.h:27
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:33
static std::optional< plugin_t > mangle(std::string_view plugin)
Mangles s into a dense 48-bit representation.
Definition plugin.cpp:5
static constexpr size_t Max_Plugin_Size
Definition plugin.h:187