File tree 4 files changed +49
-23
lines changed
4 files changed +49
-23
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,7 @@ GRS_OBJS = \
88
88
rust/rust-lint-marklive.o \
89
89
rust/rust-hir-type-check-path.o \
90
90
rust/rust-compile-intrinsic.o \
91
+ rust/rust-base62.o \
91
92
$(END )
92
93
# removed object files from here
93
94
Original file line number Diff line number Diff line change 1
1
#include " rust-mangle.h"
2
2
#include " fnv-hash.h"
3
+ #include " rust-base62.h"
3
4
#include < algorithm>
4
5
5
6
// FIXME: Rename those to legacy_*
@@ -155,28 +156,6 @@ v0_simple_type_prefix (const TyTy::BaseType *ty)
155
156
gcc_unreachable ();
156
157
}
157
158
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 = x / base;
173
- }
174
- while (x != 0 );
175
-
176
- std::reverse (buffer.begin (), buffer.begin () + idx);
177
- return buffer.substr (0 , idx);
178
- }
179
-
180
159
// Add an underscore-terminated base62 integer to the mangling string.
181
160
// This corresponds to the `<base-62-number>` grammar in the v0 mangling RFC:
182
161
// - 0 is encoded as "_"
@@ -185,7 +164,7 @@ static void
185
164
v0_add_integer_62 (std::string &mangled, uint64_t x)
186
165
{
187
166
if (x > 0 )
188
- mangled.append (v0_base62_integer (x - 1 ));
167
+ mangled.append (base62_integer (x - 1 ));
189
168
190
169
mangled.append (" _" );
191
170
}
Original file line number Diff line number Diff line change
1
+ #include " rust-base62.h"
2
+
3
+ #include < algorithm>
4
+
5
+ namespace Rust {
6
+
7
+ std::string
8
+ base62_integer (uint64_t value)
9
+ {
10
+ const static std::string base_64
11
+ = " 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@$" ;
12
+ std::string buffer (128 , ' \0 ' );
13
+ size_t idx = 0 ;
14
+ size_t base = 62 ;
15
+
16
+ do
17
+ {
18
+ buffer[idx] = base_64[(value % base)];
19
+ idx++;
20
+ value = value / base;
21
+ }
22
+ while (value != 0 );
23
+
24
+ std::reverse (buffer.begin (), buffer.begin () + idx);
25
+ return buffer.substr (0 , idx);
26
+ }
27
+
28
+ } // namespace Rust
29
+
30
+ // FIXME: Add unit testing using the selftest framework
Original file line number Diff line number Diff line change
1
+ #ifndef RUST_BASE62_H
2
+ #define RUST_BASE62_H
3
+
4
+ #include < string>
5
+
6
+ namespace Rust {
7
+
8
+ /* *
9
+ * Get the Base62 representation of an integer
10
+ */
11
+ std::string
12
+ base62_integer (uint64_t value);
13
+
14
+ } // namespace Rust
15
+
16
+ #endif /* !RUST_BASE62_H */
You can’t perform that action at this time.
0 commit comments