diff options
Diffstat (limited to 'gcc')
| -rw-r--r-- | gcc/rust/backend/rust-compile-extern.h | 11 | ||||
| -rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-item.cc | 6 | ||||
| -rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-path.cc | 3 | ||||
| -rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-type.cc | 3 | ||||
| -rw-r--r-- | gcc/rust/rust-object-export.h | 2 | ||||
| -rw-r--r-- | gcc/rust/util/rust-hir-map.cc | 68 | ||||
| -rw-r--r-- | gcc/rust/util/rust-hir-map.h | 31 | 
7 files changed, 96 insertions, 28 deletions
| diff --git a/gcc/rust/backend/rust-compile-extern.h b/gcc/rust/backend/rust-compile-extern.h index c24437d..ddad350 100644 --- a/gcc/rust/backend/rust-compile-extern.h +++ b/gcc/rust/backend/rust-compile-extern.h @@ -130,6 +130,17 @@ public:      tree compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype);      std::string ir_symbol_name = function.get_item_name ();      std::string asm_name = function.get_item_name (); +    if (fntype->get_abi () == ABI::RUST) +      { +	// then we need to get the canonical path of it and mangle it +	const Resolver::CanonicalPath *canonical_path = nullptr; +	bool ok = ctx->get_mappings ()->lookup_canonical_path ( +	  function.get_mappings ().get_nodeid (), &canonical_path); +	rust_assert (ok); + +	ir_symbol_name = canonical_path->get () + fntype->subst_as_string (); +	asm_name = ctx->mangle_item (fntype, *canonical_path); +      }      const unsigned int flags = Backend::function_is_declaration;      tree fndecl diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index 244bf64..75bd2e1 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -1027,6 +1027,12 @@ void  ResolveExternItem::visit (AST::ExternalFunctionItem &function)  {    NodeId scope_node_id = function.get_node_id (); +  auto decl = CanonicalPath::new_seg (function.get_node_id (), +				      function.get_identifier ()); +  auto path = prefix.append (decl); +  auto cpath = canonical_prefix.append (decl); + +  mappings->insert_canonical_path (function.get_node_id (), cpath);    resolve_visibility (function.get_visibility ()); diff --git a/gcc/rust/resolve/rust-ast-resolve-path.cc b/gcc/rust/resolve/rust-ast-resolve-path.cc index a03bfb4..27f32aa 100644 --- a/gcc/rust/resolve/rust-ast-resolve-path.cc +++ b/gcc/rust/resolve/rust-ast-resolve-path.cc @@ -199,7 +199,8 @@ ResolvePath::resolve_path (AST::PathInExpression *expr)        bool did_resolve_segment = resolved_node_id != UNKNOWN_NODEID;        if (did_resolve_segment)  	{ -	  if (mappings->node_is_module (resolved_node_id)) +	  if (mappings->node_is_module (resolved_node_id) +	      || mappings->node_is_crate (resolved_node_id))  	    {  	      module_scope_id = resolved_node_id;  	    } diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc index 8e85889..04183a4 100644 --- a/gcc/rust/resolve/rust-ast-resolve-type.cc +++ b/gcc/rust/resolve/rust-ast-resolve-type.cc @@ -220,7 +220,8 @@ ResolveRelativeTypePath::go (AST::TypePath &path, NodeId &resolved_node_id)        bool did_resolve_segment = resolved_node_id != UNKNOWN_NODEID;        if (did_resolve_segment)  	{ -	  if (mappings->node_is_module (resolved_node_id)) +	  if (mappings->node_is_module (resolved_node_id) +	      || mappings->node_is_crate (resolved_node_id))  	    {  	      module_scope_id = resolved_node_id;  	    } diff --git a/gcc/rust/rust-object-export.h b/gcc/rust/rust-object-export.h index 1704f59..fcede54 100644 --- a/gcc/rust/rust-object-export.h +++ b/gcc/rust/rust-object-export.h @@ -19,6 +19,8 @@  #ifndef RUST_OBJECT_EXPORT_H  #define RUST_OBJECT_EXPORT_H +#include "rust-system.h" +  extern unsigned int  rust_field_alignment (tree t); diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index 353b7cb..c7bf182 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -130,6 +130,70 @@ Mappings::get_current_crate () const    return currentCrateNum;  } +bool +Mappings::get_crate_name (CrateNum crate_num, std::string &name) const +{ +  auto it = crate_names.find (crate_num); +  if (it == crate_names.end ()) +    return false; + +  name.assign (it->second); +  return true; +} + +void +Mappings::set_crate_name (CrateNum crate_num, const std::string &name) +{ +  crate_names[crate_num] = name; +} + +std::string +Mappings::get_current_crate_name () const +{ +  std::string name; +  bool ok = get_crate_name (get_current_crate (), name); +  rust_assert (ok); +  return name; +} + +bool +Mappings::lookup_crate_name (const std::string &crate_name, +			     CrateNum &resolved_crate_num) const +{ +  for (const auto &it : crate_names) +    { +      if (it.second.compare (crate_name) == 0) +	{ +	  resolved_crate_num = it.first; +	  return true; +	} +    } +  return false; +} + +bool +Mappings::crate_num_to_nodeid (const CrateNum &crate_num, NodeId &node_id) const +{ +  auto it = ast_crate_mappings.find (crate_num); +  if (it == ast_crate_mappings.end ()) +    return false; + +  node_id = it->second->get_node_id (); +  return true; +} + +bool +Mappings::node_is_crate (NodeId node_id) const +{ +  for (const auto &it : ast_crate_mappings) +    { +      NodeId crate_node_id = it.second->get_node_id (); +      if (crate_node_id == node_id) +	return true; +    } +  return false; +} +  NodeId  Mappings::get_next_node_id ()  { @@ -199,7 +263,7 @@ Mappings::insert_ast_crate (std::unique_ptr<AST::Crate> &&crate,    rust_assert (it == ast_crate_mappings.end ());    // store it -  ast_crate_mappings.insert ({crate_num, crate.get ()}); +  ast_crate_mappings.insert ({crate_num, crate.release ()});    // return the reference to it    it = ast_crate_mappings.find (crate_num); @@ -236,7 +300,7 @@ Mappings::insert_hir_crate (std::unique_ptr<HIR::Crate> &&crate)    insert_node_to_hir (crate->get_mappings ().get_nodeid (),  		      crate->get_mappings ().get_hirid ()); -  hir_crate_mappings.insert ({crateNum, crate.get ()}); +  hir_crate_mappings.insert ({crateNum, crate.release ()});    it = hir_crate_mappings.find (crateNum);    rust_assert (it != hir_crate_mappings.end ()); diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h index 804242e..c8cebef 100644 --- a/gcc/rust/util/rust-hir-map.h +++ b/gcc/rust/util/rust-hir-map.h @@ -77,30 +77,13 @@ public:    CrateNum get_next_crate_num (const std::string &name);    void set_current_crate (CrateNum crateNum);    CrateNum get_current_crate () const; - -  bool get_crate_name (CrateNum crate_num, std::string &name) const -  { -    auto it = crate_names.find (crate_num); -    if (it == crate_names.end ()) -      return false; - -    name.assign (it->second); -    return true; -  } - -  // set crate name mid-compilation -  void set_crate_name (CrateNum crate_num, const std::string &name) -  { -    crate_names[crate_num] = name; -  } - -  std::string get_current_crate_name () const -  { -    std::string name; -    bool ok = get_crate_name (get_current_crate (), name); -    rust_assert (ok); -    return name; -  } +  bool get_crate_name (CrateNum crate_num, std::string &name) const; +  void set_crate_name (CrateNum crate_num, const std::string &name); +  std::string get_current_crate_name () const; +  bool lookup_crate_name (const std::string &crate_name, +			  CrateNum &resolved_crate_num) const; +  bool crate_num_to_nodeid (const CrateNum &crate_num, NodeId &node_id) const; +  bool node_is_crate (NodeId node_id) const;    NodeId get_next_node_id ();    HirId get_next_hir_id () { return get_next_hir_id (get_current_crate ()); } | 
