aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-expr.h
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-02-09 17:50:39 +0000
committerPhilip Herron <herron.philip@googlemail.com>2021-02-10 18:10:57 +0000
commit1a2c0911f0e818328a8909b1f5ba0685b6eca351 (patch)
treedb3d500a783d5794a1a190f7172d6b8205b0db4e /gcc/rust/backend/rust-compile-expr.h
parentcb9998216d76ccc62b45fcf01b3a0928a026f7ed (diff)
downloadgcc-1a2c0911f0e818328a8909b1f5ba0685b6eca351.zip
gcc-1a2c0911f0e818328a8909b1f5ba0685b6eca351.tar.gz
gcc-1a2c0911f0e818328a8909b1f5ba0685b6eca351.tar.bz2
Support Simple LoopExpr
This is the building block for the rest of loops where we have a basic infinite loop. Break/Continue reliest on the resolution of labels and breaks can also make a loop into a BlockExpr Fixes #106
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.h')
-rw-r--r--gcc/rust/backend/rust-compile-expr.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index 2dabe01..77b8888 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -580,6 +580,25 @@ public:
translated = ResolvePathRef::Compile (&expr, ctx);
}
+ 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);
+
+ Bstatement *goto_loop_start_stmt
+ = ctx->get_backend ()->goto_statement (loop_start, Location ());
+ ctx->add_statement (goto_loop_start_stmt);
+ }
+
private:
CompileExpr (Context *ctx) : HIRCompileBase (ctx), translated (nullptr) {}