aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-item.h
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-02-05 16:49:26 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-02-06 15:17:08 +0000
commit599b04aa7d928a305029d8e8cf5d6f5c5a683da8 (patch)
treed4d464c29ebab1df3ddaa8d9a39383a56e0f1dce /gcc/rust/backend/rust-compile-item.h
parentc4be77f7e0f6b35c019940200f94c7a7b30fff84 (diff)
downloadgcc-599b04aa7d928a305029d8e8cf5d6f5c5a683da8.zip
gcc-599b04aa7d928a305029d8e8cf5d6f5c5a683da8.tar.gz
gcc-599b04aa7d928a305029d8e8cf5d6f5c5a683da8.tar.bz2
This adds support for basic BlockExpressions
We keep temporary's for each block in order for the result to be referenced. For example: let x = { test() + 1 }; This can be resolved into: { let x:i32; _tmp1:i32; { _tmp2:i32 = test(); _tmp1 = _tmp2 + 1; } x = _tmp1; } Fixes #189
Diffstat (limited to 'gcc/rust/backend/rust-compile-item.h')
-rw-r--r--gcc/rust/backend/rust-compile-item.h25
1 files changed, 2 insertions, 23 deletions
diff --git a/gcc/rust/backend/rust-compile-item.h b/gcc/rust/backend/rust-compile-item.h
index 83e4451..b08c49e 100644
--- a/gcc/rust/backend/rust-compile-item.h
+++ b/gcc/rust/backend/rust-compile-item.h
@@ -265,28 +265,8 @@ public:
ctx->push_fn (fndecl, return_address);
- // compile the block
- function_body->iterate_stmts ([&] (HIR::Stmt *s) mutable -> bool {
- CompileStmt::Compile (s, ctx);
- return true;
- });
-
- if (function_body->has_expr () && function_body->tail_expr_reachable ())
- {
- // 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);
- }
+ compile_function_body (fndecl, function.function_body,
+ function.has_function_return_type ());
ctx->pop_block ();
auto body = ctx->get_backend ()->block_statement (code_block);
@@ -297,7 +277,6 @@ public:
}
ctx->pop_fn ();
-
ctx->push_function (fndecl);
}