diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-01-21 17:04:14 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2021-01-26 11:59:39 +0000 |
commit | 5294dfe7dce7a58fbaf2131c7589d115008ebf0e (patch) | |
tree | 04ea7976bb99c19de924eab28310a913434d5d70 /gcc/rust/backend/rust-compile-item.h | |
parent | be371b9f49e0c4fd7752cad6708fed8b1f2719a3 (diff) | |
download | gcc-5294dfe7dce7a58fbaf2131c7589d115008ebf0e.zip gcc-5294dfe7dce7a58fbaf2131c7589d115008ebf0e.tar.gz gcc-5294dfe7dce7a58fbaf2131c7589d115008ebf0e.tar.bz2 |
Remove TyTy::ParamType this was wrongly used to represent FunctionParams
TyTy::ParamType is meant to be used to represent Generic Types which is
not handled yet as part of this current milestone.
Diffstat (limited to 'gcc/rust/backend/rust-compile-item.h')
-rw-r--r-- | gcc/rust/backend/rust-compile-item.h | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h index 82dbc9b..bf899d8 100644 --- a/gcc/rust/backend/rust-compile-item.h +++ b/gcc/rust/backend/rust-compile-item.h @@ -127,14 +127,21 @@ public: return; } - TyTy::TyBase *fntype; + TyTy::TyBase *fntype_tyty; if (!ctx->get_tyctx ()->lookup_type (function.get_mappings ().get_hirid (), - &fntype)) + &fntype_tyty)) { rust_fatal_error (function.locus, "failed to lookup function type"); return; } + if (fntype_tyty->get_kind () != TyTy::TypeKind::FNDEF) + { + rust_error_at (function.get_locus (), "invalid TyTy for function item"); + return; + } + + TyTy::FnType *fntype = (TyTy::FnType *) fntype_tyty; // convert to the actual function type ::Btype *compiled_fn_type = TyTyResolveCompile::compile (ctx, fntype); @@ -159,17 +166,31 @@ public: ctx->insert_function_decl (function.get_mappings ().get_hirid (), fndecl); // setup the params - TyTy::TyBase *tyret = TyTyExtractRetFromFnType::compile (fntype); - std::vector<TyTy::ParamType *> typarams - = TyTyExtractParamsFromFnType::compile (fntype); + + TyTy::TyBase *tyret = fntype->return_type (); std::vector<Bvariable *> param_vars; - for (auto &it : typarams) + size_t i = 0; + for (auto &it : fntype->get_params ()) { - auto compiled_param = TyTyCompileParam::compile (ctx, fndecl, it); - param_vars.push_back (compiled_param); + HIR::FunctionParam &referenced_param = function.function_params.at (i); + auto param_pattern = it.first; + auto param_tyty = it.second; + + auto compiled_param_type + = TyTyResolveCompile::compile (ctx, param_tyty); + + bool tree_addressable = false; + auto compiled_param_var = ctx->get_backend ()->parameter_variable ( + fndecl, param_pattern->as_string (), compiled_param_type, + tree_addressable, + ctx->get_mappings ()->lookup_location (param_tyty->get_ref ())); + + param_vars.push_back (compiled_param_var); - ctx->insert_var_decl (it->get_ref (), compiled_param); + ctx->insert_var_decl (referenced_param.get_mappings ().get_hirid (), + compiled_param_var); + i++; } if (!ctx->get_backend ()->function_set_parameters (fndecl, param_vars)) |