diff options
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r-- | gcc/rust/backend/rust-compile-context.h | 6 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.h | 4 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-item.h | 17 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile-tyty.h | 62 | ||||
-rw-r--r-- | gcc/rust/backend/rust-compile.cc | 17 |
5 files changed, 91 insertions, 15 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index d241921..298ff50 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -221,12 +221,18 @@ public: virtual ~TyTyResolveCompile () {} + void visit (TyTy::ErrorType &type) override { gcc_unreachable (); } + void visit (TyTy::UnitType &type) override { gcc_unreachable (); } void visit (TyTy::InferType &type) override { gcc_unreachable (); } void visit (TyTy::FnType &type) override { gcc_unreachable (); } + void visit (TyTy::StructFieldType &type) override { gcc_unreachable (); } + + void visit (TyTy::ParamType &type) override { gcc_unreachable (); } + void visit (TyTy::ADTType &type) override { ::Btype *compiled_type = nullptr; diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h index 9081000..0370129 100644 --- a/gcc/rust/backend/rust-compile-expr.h +++ b/gcc/rust/backend/rust-compile-expr.h @@ -156,8 +156,6 @@ public: return; case HIR::Literal::FLOAT: { - printf ("FLOATY BOYO: [%s]\n", expr.as_string ().c_str ()); - mpfr_t fval; if (mpfr_init_set_str (fval, expr.as_string ().c_str (), 10, MPFR_RNDN) @@ -177,8 +175,6 @@ public: return; } - printf ("tyty float is [%s]\n", tyty->as_string ().c_str ()); - Btype *type = TyTyResolveCompile::compile (ctx, tyty); translated = ctx->get_backend ()->float_constant_expression (type, fval); diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h index 90630bb..f1b39da 100644 --- a/gcc/rust/backend/rust-compile-item.h +++ b/gcc/rust/backend/rust-compile-item.h @@ -232,6 +232,23 @@ public: return true; }); + if (function_body->has_expr ()) + { + // the previous passes will ensure this is a valid return + // dead code elimination should remove any bad trailing expressions + Bexpression *compiled_expr + = CompileExpr::Compile (function_body->expr.get (), ctx); + rust_assert (compiled_expr != nullptr); + + auto fncontext = ctx->peek_fn (); + + std::vector<Bexpression *> retstmts; + retstmts.push_back (compiled_expr); + auto s = ctx->get_backend ()->return_statement ( + fncontext.fndecl, retstmts, function_body->expr->get_locus_slow ()); + ctx->add_statement (s); + } + ctx->pop_block (); auto body = ctx->get_backend ()->block_statement (code_block); if (!ctx->get_backend ()->function_set_body (fndecl, body)) diff --git a/gcc/rust/backend/rust-compile-tyty.h b/gcc/rust/backend/rust-compile-tyty.h index 528f90e..137b74b 100644 --- a/gcc/rust/backend/rust-compile-tyty.h +++ b/gcc/rust/backend/rust-compile-tyty.h @@ -43,13 +43,19 @@ public: ~TyTyCompile () {} - void visit (TyTy::InferType &type) override - { - // there shouldn't be any of these left - gcc_unreachable (); - } + void visit (TyTy::ErrorType &type) override { gcc_unreachable (); } + + 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::UnitType &type) override {} + void visit (TyTy::ParamType &type) override { gcc_unreachable (); } + + void visit (TyTy::ADTType &type) override { gcc_unreachable (); } + + void visit (TyTy::ArrayType &type) override { gcc_unreachable (); } void visit (TyTy::FnType &type) override { @@ -82,8 +88,6 @@ public: mappings->lookup_location (type.get_ref ())); } - void visit (TyTy::ParamType &type) override {} - void visit (TyTy::BoolType &type) override { translated = backend->named_type ("bool", backend->bool_type (), @@ -132,19 +136,19 @@ public: switch (type.get_kind ()) { case TyTy::UintType::U8: - translated = backend->named_type ("i8", backend->integer_type (true, 8), + translated = backend->named_type ("u8", backend->integer_type (true, 8), Linemap::predeclared_location ()); return; case TyTy::UintType::U16: translated - = backend->named_type ("i16", backend->integer_type (true, 16), + = backend->named_type ("u16", backend->integer_type (true, 16), Linemap::predeclared_location ()); return; case TyTy::UintType::U32: translated - = backend->named_type ("i32", backend->integer_type (true, 32), + = backend->named_type ("u32", backend->integer_type (true, 32), Linemap::predeclared_location ()); return; @@ -205,6 +209,18 @@ public: ~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; @@ -234,6 +250,18 @@ public: ~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; @@ -261,6 +289,18 @@ public: ~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 = TyTyCompile::compile (backend, type.get_base_type ()); diff --git a/gcc/rust/backend/rust-compile.cc b/gcc/rust/backend/rust-compile.cc index 24b45ee..a52f183 100644 --- a/gcc/rust/backend/rust-compile.cc +++ b/gcc/rust/backend/rust-compile.cc @@ -90,6 +90,23 @@ CompileBlock::visit (HIR::BlockExpr &expr) return true; }); + if (expr.has_expr ()) + { + // the previous passes will ensure this is a valid return + // dead code elimination should remove any bad trailing expressions + Bexpression *compiled_expr = CompileExpr::Compile (expr.expr.get (), ctx); + rust_assert (compiled_expr != nullptr); + + auto fncontext = ctx->peek_fn (); + + std::vector<Bexpression *> retstmts; + retstmts.push_back (compiled_expr); + auto s + = ctx->get_backend ()->return_statement (fncontext.fndecl, retstmts, + expr.expr->get_locus_slow ()); + ctx->add_statement (s); + } + ctx->pop_block (); translated = new_block; } |