aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-expr.h
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-02-10 10:33:33 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-02-10 18:10:57 +0000
commitae273ffac99cb75d832a11a83fd63291bb74cbdc (patch)
treea3d9a44ebe75c96fac728c8f4ed3d0796664ed29 /gcc/rust/backend/rust-compile-expr.h
parent016c40bedc7e3f53e2c413895f77c0d9f723eb3c (diff)
downloadgcc-ae273ffac99cb75d832a11a83fd63291bb74cbdc.zip
gcc-ae273ffac99cb75d832a11a83fd63291bb74cbdc.tar.gz
gcc-ae273ffac99cb75d832a11a83fd63291bb74cbdc.tar.bz2
Support Break without label and expression
This reuses GENERICS LOOP_EXPR and EXIT_EXPR to implement the infinite loop. Addresses: #106 #108
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.h')
-rw-r--r--gcc/rust/backend/rust-compile-expr.h30
1 files changed, 17 insertions, 13 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index 77b8888..92cb392 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -582,21 +582,25 @@ public:
void visit (HIR::LoopExpr &expr)
{
- // loop_start:
- // <loop_body>
- // goto loop_start;
fncontext fnctx = ctx->peek_fn ();
- Blabel *loop_start
- = ctx->get_backend ()->label (fnctx.fndecl, "", expr.get_locus ());
- Bstatement *label_decl_stmt
- = ctx->get_backend ()->label_definition_statement (loop_start);
- ctx->add_statement (label_decl_stmt);
-
- translated = CompileExpr::Compile (expr.get_loop_block ().get (), ctx);
+ Bblock *code_block
+ = CompileBlock::compile (expr.get_loop_block ().get (), ctx, nullptr);
+ Bexpression *loop_expr
+ = ctx->get_backend ()->loop_expression (code_block, expr.get_locus ());
+ Bstatement *loop_stmt
+ = ctx->get_backend ()->expression_statement (fnctx.fndecl, loop_expr);
+ ctx->add_statement (loop_stmt);
+ }
- Bstatement *goto_loop_start_stmt
- = ctx->get_backend ()->goto_statement (loop_start, Location ());
- ctx->add_statement (goto_loop_start_stmt);
+ void visit (HIR::BreakExpr &expr)
+ {
+ fncontext fnctx = ctx->peek_fn ();
+ Bexpression *exit_expr = ctx->get_backend ()->exit_expression (
+ ctx->get_backend ()->boolean_constant_expression (true),
+ expr.get_locus ());
+ Bstatement *break_stmt
+ = ctx->get_backend ()->expression_statement (fnctx.fndecl, exit_expr);
+ ctx->add_statement (break_stmt);
}
private: