]> gcc.gnu.org Git - gcc.git/commitdiff
Lookup the canonical path for code-generation
authorPhilip Herron <philip.herron@embecosm.com>
Wed, 11 Aug 2021 12:04:55 +0000 (13:04 +0100)
committerPhilip Herron <philip.herron@embecosm.com>
Wed, 11 Aug 2021 12:38:04 +0000 (13:38 +0100)
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.

gcc/rust/backend/rust-compile-implitem.h
gcc/rust/backend/rust-compile-item.h

index 83af5deab178a646fc0ccde6fa6ef0ff7b121f54..7608599391c4062dc8c8e03365f051d81e607668 100644 (file)
@@ -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);
 
index a6bc7f3f73bf077da5ea917d69b07c1f29d89128..719d51c57266e3a4fa2c82bea5653118908e5713 100644 (file)
@@ -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
This page took 0.06511 seconds and 5 git commands to generate.