aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile.cc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-05-11 17:46:10 +0000
committerGitHub <noreply@github.com>2021-05-11 17:46:10 +0000
commit5134aaa9f0b37ea372cb185fe7aa6c26fe0a4c2e (patch)
tree95c03868e9d05a84000e29187e2e5ccba431cd35 /gcc/rust/backend/rust-compile.cc
parent299d98d8e6fcb8d014b299adc426d93cf0c8050f (diff)
parent58e108c7c6d0fa3c9ebc7eeb681851924e22ddd5 (diff)
downloadgcc-5134aaa9f0b37ea372cb185fe7aa6c26fe0a4c2e.zip
gcc-5134aaa9f0b37ea372cb185fe7aa6c26fe0a4c2e.tar.gz
gcc-5134aaa9f0b37ea372cb185fe7aa6c26fe0a4c2e.tar.bz2
Merge #425
425: Basic implementation of legacy symbol mangling r=philberty a=philberty Implement basic rustc legacy symbol mangling Rust supports two different symbol mangling methods legacy and V0. V0 is the goal but its not yet stable. This implements the legacy method but with a dummy hash value since it requires a sip128 implementation to generate the apropriate hash which can be done in a sperate change. This change allows us to actually assemble generic functions and avoid bad symbol duplications. Addresses #305 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile.cc')
-rw-r--r--gcc/rust/backend/rust-compile.cc68
1 files changed, 68 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc
index 4893541..9dd3b57 100644
--- a/gcc/rust/backend/rust-compile.cc
+++ b/gcc/rust/backend/rust-compile.cc
@@ -413,5 +413,73 @@ HIRCompileBase::compile_function_body (
}
}
+// Mr Mangle time
+
+static const std::string kMangledSymbolPrefix = "_ZN";
+static const std::string kMangledSymbolDelim = "E";
+static const std::string kMangledGenericDelim = "$C$";
+static const std::string kMangledSubstBegin = "$LT$";
+static const std::string kMangledSubstEnd = "$GT$";
+
+static std::string
+mangle_name (const std::string &name)
+{
+ return std::to_string (name.size ()) + name;
+}
+
+static std::string
+dummy_hash ()
+{
+ return "h0123456789abcdef";
+}
+
+static std::string
+mangle_self (const TyTy::BaseType *self)
+{
+ if (self->get_kind () != TyTy::TypeKind::ADT)
+ return mangle_name (self->get_name ());
+
+ const TyTy::ADTType *s = static_cast<const TyTy::ADTType *> (self);
+ std::string buf = s->get_identifier ();
+
+ if (s->has_subsititions_defined ())
+ {
+ buf += kMangledSubstBegin;
+
+ const std::vector<TyTy::SubstitutionParamMapping> &params
+ = s->get_substs ();
+ for (size_t i = 0; i < params.size (); i++)
+ {
+ const TyTy::SubstitutionParamMapping &sub = params.at (i);
+ buf += sub.as_string ();
+
+ if ((i + 1) < params.size ())
+ buf += kMangledGenericDelim;
+ }
+
+ buf += kMangledSubstEnd;
+ }
+
+ return mangle_name (buf);
+}
+
+std::string
+Context::mangle_item (const std::string &name) const
+{
+ const std::string &crate_name = mappings->get_current_crate_name ();
+ return kMangledSymbolPrefix + mangle_name (crate_name) + mangle_name (name)
+ + mangle_name (dummy_hash ()) + kMangledSymbolDelim;
+}
+
+std::string
+Context::mangle_impl_item (const TyTy::BaseType *self,
+ const std::string &name) const
+{
+ const std::string &crate_name = mappings->get_current_crate_name ();
+ return kMangledSymbolPrefix + mangle_name (crate_name) + mangle_self (self)
+ + mangle_name (name) + mangle_name (dummy_hash ())
+ + kMangledSymbolDelim;
+}
+
} // namespace Compile
} // namespace Rust