From 1a2c0911f0e818328a8909b1f5ba0685b6eca351 Mon Sep 17 00:00:00 2001 From: Philip Herron Date: Tue, 9 Feb 2021 17:50:39 +0000 Subject: 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 --- gcc/rust/backend/rust-compile-expr.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'gcc/rust/backend') 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: + // + // 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) {} -- cgit v1.1