diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-03-10 18:10:06 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-03-22 20:01:30 +0000 |
commit | 280ac5bd99b4d66ea10d0aa8d4edba53bf460b10 (patch) | |
tree | e67968afbe4668e6a2679ed961d137cdb409166d /gcc/rust/backend/rust-compile-item.h | |
parent | eb33139efa7bbbd09ad26403c36a5dcf31e1b14e (diff) | |
download | gcc-280ac5bd99b4d66ea10d0aa8d4edba53bf460b10.zip gcc-280ac5bd99b4d66ea10d0aa8d4edba53bf460b10.tar.gz gcc-280ac5bd99b4d66ea10d0aa8d4edba53bf460b10.tar.bz2 |
Generics continued this adds more type resolution to ADT and Functions
Adds recursive generic argument handling for structs and functions. With a
new substitution mapper class to coerce the HIR::GenericArgs appropriately.
This is the building block to work on impl blocks with generics and
better Monomorphization support to handle duplicate functions etc.
Fixes: #236 #234 #235
Addresses: #237
Diffstat (limited to 'gcc/rust/backend/rust-compile-item.h')
-rw-r--r-- | gcc/rust/backend/rust-compile-item.h | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h index 1d4fcda..2bbfe4c 100644 --- a/gcc/rust/backend/rust-compile-item.h +++ b/gcc/rust/backend/rust-compile-item.h @@ -35,9 +35,10 @@ class CompileItem : public HIRCompileBase using Rust::Compile::HIRCompileBase::visit; public: - static void compile (HIR::Item *item, Context *ctx, bool compile_fns = true) + static void compile (HIR::Item *item, Context *ctx, bool compile_fns = true, + TyTy::BaseType *concrete = nullptr) { - CompileItem compiler (ctx, compile_fns); + CompileItem compiler (ctx, compile_fns, concrete); item->accept_vis (compiler); } @@ -118,8 +119,22 @@ public: return; } - TyTy::FnType *fntype = (TyTy::FnType *) fntype_tyty; - // convert to the actual function type + TyTy::FnType *fntype = static_cast<TyTy::FnType *> (fntype_tyty); + if (fntype->has_subsititions_defined ()) + { + // we cant do anything for this only when it is used + if (concrete == nullptr) + return; + else + { + rust_assert (concrete->get_kind () == TyTy::TypeKind::FNDEF); + fntype = static_cast<TyTy::FnType *> (concrete); + + // override the Hir Lookups for the substituions in this context + fntype->override_context (); + } + } + ::Btype *compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype); unsigned int flags = 0; @@ -130,21 +145,30 @@ public: if (is_main_fn || function.has_visibility ()) flags |= Backend::function_is_visible; + std::string ir_symbol_name = function.get_function_name (); std::string asm_name = function.get_function_name (); if (!is_main_fn) { // FIXME need name mangling - asm_name = "__" + function.get_function_name (); + if (concrete == nullptr) + asm_name = "__" + function.get_function_name (); + else + { + ir_symbol_name + = function.get_function_name () + fntype->subst_as_string (); + + asm_name = "__" + function.get_function_name (); + for (auto &sub : fntype->get_substs ()) + asm_name += "G" + sub.as_string (); + } } Bfunction *fndecl - = ctx->get_backend ()->function (compiled_fn_type, - function.get_function_name (), asm_name, - flags, function.get_locus ()); - ctx->insert_function_decl (function.get_mappings ().get_hirid (), fndecl); + = 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); // setup the params - TyTy::BaseType *tyret = fntype->get_return_type (); std::vector<Bvariable *> param_vars; @@ -274,11 +298,12 @@ public: } private: - CompileItem (Context *ctx, bool compile_fns) - : HIRCompileBase (ctx), compile_fns (compile_fns) + CompileItem (Context *ctx, bool compile_fns, TyTy::BaseType *concrete) + : HIRCompileBase (ctx), compile_fns (compile_fns), concrete (concrete) {} bool compile_fns; + TyTy::BaseType *concrete; }; } // namespace Compile |