diff options
author | Philip Herron <philip.herron@embecosm.com> | 2020-12-20 23:58:33 +0000 |
---|---|---|
committer | Philip Herron <herron.philip@googlemail.com> | 2020-12-23 14:47:34 +0000 |
commit | f701ad5352c7bc8dad53a1ee7f666c8365b35307 (patch) | |
tree | c31ad210626efa0fdfd6f0be109439a1429b003d /gcc/rust/backend | |
parent | aa2fbb5e48f6218035d7bde1336345cebf120d3e (diff) | |
download | gcc-f701ad5352c7bc8dad53a1ee7f666c8365b35307.zip gcc-f701ad5352c7bc8dad53a1ee7f666c8365b35307.tar.gz gcc-f701ad5352c7bc8dad53a1ee7f666c8365b35307.tar.bz2 |
This brings arrays back into the new framework. It resolves ArrayType
ArrayExpr, ArrayExprElems and ArrayIndexExpr. Still need to do
ArrayElemsCopied.
I expect there to be some changes to cleanup the rust-tyty-resolver
this code is to resolve all ribs within a scope but its getting a bit
hairy in there now.
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r-- | gcc/rust/backend/rust-compile-context.h | 16 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.h | 43 |
2 files changed, 56 insertions, 3 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index 1924b52..5736bf2 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -211,6 +211,19 @@ public: void visit (TyTy::FnType &type) override { gcc_unreachable (); } + void visit (TyTy::ArrayType &type) override + { + mpz_t ival; + mpz_init_set_ui (ival, type.get_capacity ()); + + Btype *capacity_type = ctx->get_backend ()->integer_type (true, 32); + Bexpression *length + = ctx->get_backend ()->integer_constant_expression (capacity_type, ival); + + Btype *element_type = TyTyResolveCompile::compile (ctx, type.get_type ()); + translated = ctx->get_backend ()->array_type (element_type, length); + } + void visit (TyTy::BoolType &type) override { ::Btype *compiled_type = nullptr; @@ -221,9 +234,6 @@ public: void visit (TyTy::IntType &type) override { - printf ("type [%s] has ref: %u\n", type.as_string ().c_str (), - type.get_ref ()); - ::Btype *compiled_type = nullptr; bool ok = ctx->lookup_compiled_types (type.get_ref (), &compiled_type); rust_assert (ok); diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index 854fe5e..6ea97ee 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -169,6 +169,48 @@ public: ctx->add_statement (assignment); } + void visit (HIR::ArrayIndexExpr &expr) + { + Bexpression *array = CompileExpr::Compile (expr.get_array_expr (), ctx); + Bexpression *index = CompileExpr::Compile (expr.get_index_expr (), ctx); + translated + = ctx->get_backend ()->array_index_expression (array, index, + expr.get_locus ()); + } + + void visit (HIR::ArrayExpr &expr) + { + TyTy::TyBase *tyty = nullptr; + if (!ctx->get_tyctx ()->lookup_type (expr.get_mappings ().get_hirid (), + &tyty)) + { + rust_fatal_error (expr.get_locus (), + "did not resolve type for this array expr"); + return; + } + + Btype *array_type = TyTyResolveCompile::compile (ctx, tyty); + + expr.get_internal_elements ()->accept_vis (*this); + std::vector<unsigned long> indexes; + for (size_t i = 0; i < constructor.size (); i++) + indexes.push_back (i); + + translated + = ctx->get_backend ()->array_constructor_expression (array_type, indexes, + constructor, + expr.get_locus ()); + } + + void visit (HIR::ArrayElemsValues &elems) + { + elems.iterate ([&] (HIR::Expr *e) mutable -> bool { + Bexpression *translated_expr = CompileExpr::Compile (e, ctx); + constructor.push_back (translated_expr); + return true; + }); + } + void visit (HIR::ArithmeticOrLogicalExpr &expr) { Operator op; @@ -303,6 +345,7 @@ private: CompileExpr (Context *ctx) : HIRCompileBase (ctx), translated (nullptr) {} Bexpression *translated; + std::vector<Bexpression *> constructor; }; } // namespace Compile |