Skip to content

Commit a2484d5

Browse files
committed
v0-mangling: Add base for base62 encoding
1 parent b5e3892 commit a2484d5

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

gcc/rust/backend/rust-mangle.cc

+43
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "rust-mangle.h"
22
#include "fnv-hash.h"
3+
#include <algorithm>
34

45
// FIXME: Rename those to legacy_*
56
static const std::string kMangledSymbolPrefix = "_ZN";
@@ -154,6 +155,44 @@ v0_simple_type_prefix (const TyTy::BaseType *ty)
154155
gcc_unreachable ();
155156
}
156157

158+
// FIXME: Is this present somewhere in libbiberty already?
159+
static std::string
160+
v0_base62_integer(uint64_t x)
161+
{
162+
const static std::string base_64
163+
= "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@$";
164+
std::string buffer(128, '\0');
165+
size_t idx = 0;
166+
size_t base = 62;
167+
168+
do
169+
{
170+
buffer[idx] = base_64[(x % base)];
171+
idx++;
172+
x /= base;
173+
} while (x != 0);
174+
175+
std::reverse(buffer.begin(), buffer.begin() + idx);
176+
return buffer.substr(0, idx);
177+
}
178+
179+
static std::string
180+
v0_add_integer_62 (std::string mangled, std::string tag, uint64_t x)
181+
{
182+
// /// Push a `_`-terminated base 62 integer, using the format
183+
// /// specified in the RFC as `<base-62-number>`, that is:
184+
// /// * `x = 0` is encoded as just the `"_"` terminator
185+
// /// * `x > 0` is encoded as `x - 1` in base 62, followed by `"_"`,
186+
// /// e.g. `1` becomes `"0_"`, `62` becomes `"Z_"`, etc.
187+
// fn push_integer_62(&mut self, x: u64) {
188+
// if let Some(x) = x.checked_sub(1) {
189+
// base_n::push_str(x as u128, 62, &mut self.out);
190+
// }
191+
// self.push("_");
192+
// }
193+
}
194+
195+
157196
static std::string
158197
v0_type_prefix (const TyTy::BaseType *ty)
159198
{
@@ -194,7 +233,11 @@ static std::string
194233
v0_mangle_item (const TyTy::BaseType *ty, const Resolver::CanonicalPath &path,
195234
const std::string &crate_name)
196235
{
236+
auto def_id = ty->get_ref();
197237
auto ty_prefix = v0_type_prefix (ty);
238+
auto prefix = "_R";
239+
240+
198241
gcc_unreachable ();
199242
}
200243

0 commit comments

Comments
 (0)