File tree 4 files changed +85
-23
lines changed
4 files changed +85
-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
+ // Copyright (C) 2020 Free Software Foundation, Inc.
2
+
3
+ // This file is part of GCC.
4
+
5
+ // GCC is free software; you can redistribute it and/or modify it under
6
+ // the terms of the GNU General Public License as published by the Free
7
+ // Software Foundation; either version 3, or (at your option) any later
8
+ // version.
9
+
10
+ // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11
+ // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
+ // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
+ // for more details.
14
+
15
+ // You should have received a copy of the GNU General Public License
16
+ // along with GCC; see the file COPYING3. If not see
17
+ // <http://www.gnu.org/licenses/>.
18
+
19
+ #include " rust-base62.h"
20
+
21
+ #include < algorithm>
22
+
23
+ namespace Rust {
24
+
25
+ std::string
26
+ base62_integer (uint64_t value)
27
+ {
28
+ const static std::string base_64
29
+ = " 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@$" ;
30
+ std::string buffer (128 , ' \0 ' );
31
+ size_t idx = 0 ;
32
+ size_t base = 62 ;
33
+
34
+ do
35
+ {
36
+ buffer[idx] = base_64[(value % base)];
37
+ idx++;
38
+ value = value / base;
39
+ }
40
+ while (value != 0 );
41
+
42
+ std::reverse (buffer.begin (), buffer.begin () + idx);
43
+ return buffer.substr (0 , idx);
44
+ }
45
+
46
+ } // namespace Rust
47
+
48
+ // FIXME: Add unit testing using the selftest framework
Original file line number Diff line number Diff line change
1
+ // Copyright (C) 2020 Free Software Foundation, Inc.
2
+
3
+ // This file is part of GCC.
4
+
5
+ // GCC is free software; you can redistribute it and/or modify it under
6
+ // the terms of the GNU General Public License as published by the Free
7
+ // Software Foundation; either version 3, or (at your option) any later
8
+ // version.
9
+
10
+ // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11
+ // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
+ // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
+ // for more details.
14
+
15
+ // You should have received a copy of the GNU General Public License
16
+ // along with GCC; see the file COPYING3. If not see
17
+ // <http://www.gnu.org/licenses/>.
18
+
19
+ #ifndef RUST_BASE62_H
20
+ #define RUST_BASE62_H
21
+
22
+ #include < string>
23
+
24
+ namespace Rust {
25
+
26
+ /* *
27
+ * Get the Base62 representation of an integer
28
+ */
29
+ std::string
30
+ base62_integer (uint64_t value);
31
+
32
+ } // namespace Rust
33
+
34
+ #endif /* !RUST_BASE62_H */
You can’t perform that action at this time.
0 commit comments