aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-09-19 21:13:36 +0000
committerGitHub <noreply@github.com>2021-09-19 21:13:36 +0000
commit98359f20cd2d9268df582ea1ee289e0ea69efcb5 (patch)
tree51e58a17019b1a30f135549ca1f09f6d73eee8cf
parentde43a0ac6d4d5816a5b59cde78aabce651d43cc8 (diff)
parent6c1a482c9b6162f31270f35a95a6e4cf19195232 (diff)
downloadgcc-98359f20cd2d9268df582ea1ee289e0ea69efcb5.zip
gcc-98359f20cd2d9268df582ea1ee289e0ea69efcb5.tar.gz
gcc-98359f20cd2d9268df582ea1ee289e0ea69efcb5.tar.bz2
Merge #685
685: Add v0 type mangling prefixing for simple types r=philberty a=CohenArthur This PR adds the generation of type prefixes for simple types, which are numeric types, booleans, chars, strings, empty tuples/unit types and placeholder types. I'm unsure as to how to test this, even in the long run. There might be some shenanigans we can pull using an elf reader and regexes in order to compare ABI names with rustc. The entire implementation of v0 name mangling is very large, so I thought I'd split it up in multiple PRs. Co-authored-by: CohenArthur <arthur.cohen@epita.fr>
-rw-r--r--gcc/rust/backend/rust-mangle.cc109
1 files changed, 97 insertions, 12 deletions
diff --git a/gcc/rust/backend/rust-mangle.cc b/gcc/rust/backend/rust-mangle.cc
index 40822b4..840acb9 100644
--- a/gcc/rust/backend/rust-mangle.cc
+++ b/gcc/rust/backend/rust-mangle.cc
@@ -80,6 +80,92 @@ legacy_mangle_self (const TyTy::BaseType *self)
}
static std::string
+v0_tuple_prefix (const TyTy::BaseType *ty)
+{
+ if (ty->is_unit ())
+ return "u";
+
+ // FIXME: ARTHUR: Add rest of algorithm
+ return "";
+}
+
+static std::string
+v0_numeric_prefix (const TyTy::BaseType *ty)
+{
+ static const std::map<std::string, std::string> num_prefixes = {
+ {"[i8]", "a"}, {"[u8]", "h"}, {"[i16]", "s"}, {"[u16]", "t"},
+ {"[i32]", "l"}, {"[u32]", "m"}, {"[i64]", "x"}, {"[u64]", "y"},
+ {"[isize]", "i"}, {"[usize]", "j"}, {"[f32]", "f"}, {"[f64]", "d"},
+ };
+
+ auto ty_kind = ty->get_kind ();
+ auto ty_str = ty->as_string ();
+ auto numeric_iter = num_prefixes.end ();
+
+ // Special numeric types
+ if (ty_kind == TyTy::TypeKind::ISIZE)
+ return "i";
+ else if (ty_kind == TyTy::TypeKind::USIZE)
+ return "j";
+
+ numeric_iter = num_prefixes.find (ty_str);
+ if (numeric_iter != num_prefixes.end ())
+ return numeric_iter->second;
+
+ return "";
+}
+
+static std::string
+v0_simple_type_prefix (const TyTy::BaseType *ty)
+{
+ switch (ty->get_kind ())
+ {
+ case TyTy::TypeKind::BOOL:
+ return "b";
+ case TyTy::TypeKind::CHAR:
+ return "c";
+ case TyTy::TypeKind::STR:
+ return "e";
+ case TyTy::TypeKind::NEVER:
+ return "z";
+
+ // Placeholder types
+ case TyTy::TypeKind::ERROR: // Fallthrough
+ case TyTy::TypeKind::INFER: // Fallthrough
+ case TyTy::TypeKind::PLACEHOLDER: // Fallthrough
+ case TyTy::TypeKind::PARAM:
+ // FIXME: TyTy::TypeKind::BOUND is also a valid variant in rustc
+ return "p";
+
+ case TyTy::TypeKind::TUPLE:
+ return v0_tuple_prefix (ty);
+
+ case TyTy::TypeKind::UINT: // Fallthrough
+ case TyTy::TypeKind::INT: // Fallthrough
+ case TyTy::TypeKind::FLOAT: // Fallthrough
+ case TyTy::TypeKind::ISIZE: // Fallthrough
+ case TyTy::TypeKind::USIZE: // Fallthrough
+ return v0_numeric_prefix (ty);
+
+ default:
+ return "";
+ }
+
+ gcc_unreachable ();
+}
+
+static std::string
+v0_type_prefix (const TyTy::BaseType *ty)
+{
+ auto ty_prefix = v0_simple_type_prefix (ty);
+ if (!ty_prefix.empty ())
+ return ty_prefix;
+
+ // FIXME: We need to fetch more type prefixes
+ gcc_unreachable ();
+}
+
+static std::string
legacy_mangle_item (const TyTy::BaseType *ty,
const Resolver::CanonicalPath &path,
const std::string &crate_name)
@@ -104,17 +190,16 @@ legacy_mangle_impl_item (const TyTy::BaseType *self, const TyTy::BaseType *ty,
+ kMangledSymbolDelim;
}
-// FIXME: Uncomment once v0 mangling is implemented
-// static std::string
-// Mangler::v0_mangle_item (const TyTy::BaseType *ty,
-// const std::string &name)
-// {}
-//
-// static std::string
-// Mangler::v0_mangle_impl_item (const TyTy::BaseType *self,
-// const TyTy::BaseType *ty,
-// const std::string &name)
-// {}
+static std::string
+v0_mangle_item (const TyTy::BaseType *ty, const Resolver::CanonicalPath &path,
+ const std::string &crate_name)
+{
+ auto ty_prefix = v0_type_prefix (ty);
+}
+
+static std::string
+v0_mangle_impl_item (const TyTy::BaseType *self, const TyTy::BaseType *ty,
+ const std::string &name, const std::string &crate_name);
std::string
Mangler::mangle_item (const TyTy::BaseType *ty,
@@ -126,7 +211,7 @@ Mangler::mangle_item (const TyTy::BaseType *ty,
case Mangler::MangleVersion::LEGACY:
return legacy_mangle_item (ty, path, crate_name);
case Mangler::MangleVersion::V0:
- gcc_unreachable ();
+ return v0_mangle_item (ty, path, crate_name);
default:
gcc_unreachable ();
}