aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-08-11 13:04:55 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-08-11 13:38:04 +0100
commit06ce0a66557f7989a945733e9e51250a7d05f266 (patch)
tree911e6ddd87f3e824d4e3cbe0bdc4cace4656db45 /gcc
parent5c828514d779745a329ee95d7c533db1d773972b (diff)
downloadgcc-06ce0a66557f7989a945733e9e51250a7d05f266.zip
gcc-06ce0a66557f7989a945733e9e51250a7d05f266.tar.gz
gcc-06ce0a66557f7989a945733e9e51250a7d05f266.tar.bz2
Lookup the canonical path for code-generation
This uses the mappings for canonical paths to give more meaning ful names to the flat GENERIC IR. This will also be used to cleanup the duplications in code-generation for two distinct methods to compile functions. This code will also be needed to enhance name mangling.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-implitem.h18
-rw-r--r--gcc/rust/backend/rust-compile-item.h26
2 files changed, 36 insertions, 8 deletions
diff --git a/gcc/rust/backend/rust-compile-implitem.h b/gcc/rust/backend/rust-compile-implitem.h
index 83af5de..7608599 100644
--- a/gcc/rust/backend/rust-compile-implitem.h
+++ b/gcc/rust/backend/rust-compile-implitem.h
@@ -52,7 +52,12 @@ public:
::Btype *type = TyTyResolveCompile::compile (ctx, resolved_type);
Bexpression *value = CompileExpr::Compile (constant.get_expr (), ctx);
- std::string ident = self->get_name () + "_" + constant.get_identifier ();
+ const Resolver::CanonicalPath *canonical_path = nullptr;
+ rust_assert (ctx->get_mappings ()->lookup_canonical_path (
+ constant.get_mappings ().get_crate_num (),
+ constant.get_mappings ().get_nodeid (), &canonical_path));
+
+ std::string ident = canonical_path->get ();
Bexpression *const_expr = ctx->get_backend ()->named_constant_expression (
type, constant.get_identifier (), value, constant.get_locus ());
@@ -121,13 +126,18 @@ public:
if (function.has_visibility ())
flags |= Backend::function_is_visible;
- std::string fn_identifier
- = self->get_name () + "_" + function.get_function_name ();
+ const Resolver::CanonicalPath *canonical_path = nullptr;
+ rust_assert (ctx->get_mappings ()->lookup_canonical_path (
+ function.get_mappings ().get_crate_num (),
+ function.get_mappings ().get_nodeid (), &canonical_path));
+
+ std::string ir_symbol_name
+ = canonical_path->get () + fntype->subst_as_string ();
std::string asm_name
= ctx->mangle_impl_item (self, fntype, function.get_function_name ());
Bfunction *fndecl
- = ctx->get_backend ()->function (compiled_fn_type, fn_identifier,
+ = ctx->get_backend ()->function (compiled_fn_type, ir_symbol_name,
asm_name, flags, function.get_locus ());
ctx->insert_function_decl (fntype->get_ty_ref (), fndecl, fntype);
diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h
index a6bc7f3..719d51c 100644
--- a/gcc/rust/backend/rust-compile-item.h
+++ b/gcc/rust/backend/rust-compile-item.h
@@ -53,7 +53,12 @@ public:
Btype *type = TyTyResolveCompile::compile (ctx, resolved_type);
Bexpression *value = CompileExpr::Compile (var.get_expr (), ctx);
- std::string name = var.get_identifier ();
+ const Resolver::CanonicalPath *canonical_path = nullptr;
+ rust_assert (ctx->get_mappings ()->lookup_canonical_path (
+ var.get_mappings ().get_crate_num (), var.get_mappings ().get_nodeid (),
+ &canonical_path));
+
+ std::string name = canonical_path->get ();
std::string asm_name = ctx->mangle_item (resolved_type, name);
bool is_external = false;
@@ -81,8 +86,15 @@ public:
::Btype *type = TyTyResolveCompile::compile (ctx, resolved_type);
Bexpression *value = CompileExpr::Compile (constant.get_expr (), ctx);
- Bexpression *const_expr = ctx->get_backend ()->named_constant_expression (
- type, constant.get_identifier (), value, constant.get_locus ());
+ const Resolver::CanonicalPath *canonical_path = nullptr;
+ rust_assert (ctx->get_mappings ()->lookup_canonical_path (
+ constant.get_mappings ().get_crate_num (),
+ constant.get_mappings ().get_nodeid (), &canonical_path));
+
+ std::string ident = canonical_path->get ();
+ Bexpression *const_expr
+ = ctx->get_backend ()->named_constant_expression (type, ident, value,
+ constant.get_locus ());
ctx->push_const (const_expr);
ctx->insert_const_decl (constant.get_mappings ().get_hirid (), const_expr);
@@ -149,7 +161,13 @@ public:
if (is_main_fn || function.has_visibility ())
flags |= Backend::function_is_visible;
- std::string ir_symbol_name = function.get_function_name ();
+ const Resolver::CanonicalPath *canonical_path = nullptr;
+ rust_assert (ctx->get_mappings ()->lookup_canonical_path (
+ function.get_mappings ().get_crate_num (),
+ function.get_mappings ().get_nodeid (), &canonical_path));
+
+ std::string ir_symbol_name
+ = canonical_path->get () + fntype->subst_as_string ();
std::string asm_name = function.get_function_name ();
// we don't mangle the main fn since we haven't implemented the main shim