aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-01-21 17:04:14 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-01-26 11:59:39 +0000
commit5294dfe7dce7a58fbaf2131c7589d115008ebf0e (patch)
tree04ea7976bb99c19de924eab28310a913434d5d70 /gcc/rust/backend
parentbe371b9f49e0c4fd7752cad6708fed8b1f2719a3 (diff)
downloadgcc-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')
-rw-r--r--gcc/rust/backend/rust-compile-context.h56
-rw-r--r--gcc/rust/backend/rust-compile-item.h39
-rw-r--r--gcc/rust/backend/rust-compile-tyty.h93
3 files changed, 42 insertions, 146 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h
index 6516c71..df29e36 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -26,6 +26,7 @@
#include "rust-backend.h"
#include "rust-compile-tyty.h"
#include "rust-ast-full.h"
+#include "rust-hir-full.h"
namespace Rust {
namespace Compile {
@@ -227,8 +228,6 @@ public:
void visit (TyTy::StructFieldType &type) override { gcc_unreachable (); }
- void visit (TyTy::ParamType &type) override { gcc_unreachable (); }
-
void visit (TyTy::FnType &type) override
{
Backend::Btyped_identifier receiver;
@@ -244,14 +243,14 @@ public:
ctx->get_mappings ()->lookup_location (hir_type->get_ref ())));
}
- for (size_t i = 0; i < type.num_params (); i++)
+ for (auto &param_pair : type.get_params ())
{
- auto param_tyty = type.param_at (i);
+ auto param_tyty = param_pair.second;
auto compiled_param_type
- = TyTyResolveCompile::compile (ctx, param_tyty->get_base_type ());
+ = TyTyResolveCompile::compile (ctx, param_tyty);
auto compiled_param = Backend::Btyped_identifier (
- param_tyty->get_identifier (), compiled_param_type,
+ param_pair.first->as_string (), compiled_param_type,
ctx->get_mappings ()->lookup_location (param_tyty->get_ref ()));
parameters.push_back (compiled_param);
@@ -351,51 +350,6 @@ private:
::Btype *translated;
};
-class TyTyCompileParam : public TyTy::TyVisitor
-{
-public:
- static ::Bvariable *compile (Context *ctx, Bfunction *fndecl,
- TyTy::TyBase *ty)
- {
- TyTyCompileParam compiler (ctx, fndecl);
- ty->accept_vis (compiler);
- rust_assert (compiler.translated != nullptr);
- return compiler.translated;
- }
-
- ~TyTyCompileParam () {}
-
- void visit (TyTy::UnitType &type) override { gcc_unreachable (); }
- void visit (TyTy::InferType &type) override { gcc_unreachable (); }
- void visit (TyTy::StructFieldType &type) override { gcc_unreachable (); }
- void visit (TyTy::ADTType &type) override { gcc_unreachable (); }
- void visit (TyTy::FnType &type) override { gcc_unreachable (); }
- void visit (TyTy::ArrayType &type) override { gcc_unreachable (); }
- void visit (TyTy::BoolType &type) override { gcc_unreachable (); }
- void visit (TyTy::IntType &type) override { gcc_unreachable (); }
- void visit (TyTy::UintType &type) override { gcc_unreachable (); }
- void visit (TyTy::FloatType &type) override { gcc_unreachable (); }
- void visit (TyTy::ErrorType &type) override { gcc_unreachable (); }
-
- void visit (TyTy::ParamType &type) override
- {
- auto btype = TyTyResolveCompile::compile (ctx, type.get_base_type ());
- bool tree_addressable = false;
- translated = ctx->get_backend ()->parameter_variable (
- fndecl, type.get_identifier (), btype, tree_addressable,
- ctx->get_mappings ()->lookup_location (type.get_ref ()));
- }
-
-private:
- TyTyCompileParam (Context *ctx, ::Bfunction *fndecl)
- : ctx (ctx), fndecl (fndecl), translated (nullptr)
- {}
-
- Context *ctx;
- ::Bfunction *fndecl;
- ::Bvariable *translated;
-};
-
} // namespace Compile
} // namespace Rust
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))
diff --git a/gcc/rust/backend/rust-compile-tyty.h b/gcc/rust/backend/rust-compile-tyty.h
index 3eb2ca5..f74b4ac 100644
--- a/gcc/rust/backend/rust-compile-tyty.h
+++ b/gcc/rust/backend/rust-compile-tyty.h
@@ -26,6 +26,7 @@
#include "rust-tyty.h"
#include "rust-tyty-visitor.h"
#include "rust-hir-map.h"
+#include "rust-hir-full.h"
namespace Rust {
namespace Compile {
@@ -49,8 +50,6 @@ public:
void visit (TyTy::StructFieldType &type) override { gcc_unreachable (); }
- void visit (TyTy::ParamType &type) override { gcc_unreachable (); }
-
void visit (TyTy::ADTType &type) override { gcc_unreachable (); }
void visit (TyTy::ArrayType &type) override { gcc_unreachable (); }
@@ -74,13 +73,14 @@ public:
"_", ret, mappings->lookup_location (hir_type->get_ref ())));
}
- for (size_t i = 0; i < type.num_params (); i++)
+ for (auto &params : type.get_params ())
{
- auto param_tyty = type.param_at (i);
- auto compiled_param_type
- = TyTyCompile::compile (backend, param_tyty->get_base_type ());
+ auto param_pattern = params.first;
+ auto param_tyty = params.second;
+ auto compiled_param_type = TyTyCompile::compile (backend, param_tyty);
+
auto compiled_param = Backend::Btyped_identifier (
- param_tyty->get_identifier (), compiled_param_type,
+ param_pattern->as_string (), compiled_param_type,
mappings->lookup_location (param_tyty->get_ref ()));
parameters.push_back (compiled_param);
@@ -199,85 +199,6 @@ private:
Analysis::Mappings *mappings;
};
-class TyTyExtractParamsFromFnType : public TyTy::TyVisitor
-{
-public:
- static std::vector<TyTy::ParamType *> compile (TyTy::TyBase *ty)
- {
- TyTyExtractParamsFromFnType compiler;
- ty->accept_vis (compiler);
- rust_assert (compiler.ok);
- return compiler.translated;
- }
-
- ~TyTyExtractParamsFromFnType () {}
-
- void visit (TyTy::UnitType &type) override { gcc_unreachable (); }
- void visit (TyTy::InferType &type) override { gcc_unreachable (); }
- void visit (TyTy::StructFieldType &type) override { gcc_unreachable (); }
- void visit (TyTy::ADTType &type) override { gcc_unreachable (); }
- void visit (TyTy::ParamType &type) override { gcc_unreachable (); }
- void visit (TyTy::ArrayType &type) override { gcc_unreachable (); }
- void visit (TyTy::BoolType &type) override { gcc_unreachable (); }
- void visit (TyTy::IntType &type) override { gcc_unreachable (); }
- void visit (TyTy::UintType &type) override { gcc_unreachable (); }
- void visit (TyTy::FloatType &type) override { gcc_unreachable (); }
- void visit (TyTy::ErrorType &type) override { gcc_unreachable (); }
-
- void visit (TyTy::FnType &type) override
- {
- ok = true;
- for (size_t i = 0; i < type.num_params (); i++)
- {
- translated.push_back (type.param_at (i));
- }
- }
-
-private:
- TyTyExtractParamsFromFnType () : ok (false) {}
-
- bool ok;
- std::vector<TyTy::ParamType *> translated;
-};
-
-class TyTyExtractRetFromFnType : public TyTy::TyVisitor
-{
-public:
- static TyTy::TyBase *compile (TyTy::TyBase *ty)
- {
- TyTyExtractRetFromFnType compiler;
- ty->accept_vis (compiler);
- rust_assert (compiler.ok);
- return compiler.translated;
- }
-
- ~TyTyExtractRetFromFnType () {}
-
- void visit (TyTy::UnitType &type) override { gcc_unreachable (); }
- void visit (TyTy::InferType &type) override { gcc_unreachable (); }
- void visit (TyTy::StructFieldType &type) override { gcc_unreachable (); }
- void visit (TyTy::ADTType &type) override { gcc_unreachable (); }
- void visit (TyTy::ParamType &type) override { gcc_unreachable (); }
- void visit (TyTy::ArrayType &type) override { gcc_unreachable (); }
- void visit (TyTy::BoolType &type) override { gcc_unreachable (); }
- void visit (TyTy::IntType &type) override { gcc_unreachable (); }
- void visit (TyTy::UintType &type) override { gcc_unreachable (); }
- void visit (TyTy::FloatType &type) override { gcc_unreachable (); }
- void visit (TyTy::ErrorType &type) override { gcc_unreachable (); }
-
- void visit (TyTy::FnType &type) override
- {
- ok = true;
- translated = type.get_return_type ();
- }
-
-private:
- TyTyExtractRetFromFnType () : ok (false), translated (nullptr) {}
-
- bool ok;
- TyTy::TyBase *translated;
-};
-
} // namespace Compile
} // namespace Rust