Skip to content

Commit

Permalink
msl-out: Fix break_ifs with side effects
Browse files Browse the repository at this point in the history
  • Loading branch information
Patryk27 committed Jun 6, 2023
1 parent 1360551 commit fdcdb4f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/back/msl/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2585,14 +2585,21 @@ impl<W: Write> Writer<W> {
let lif = level.next();
let lcontinuing = lif.next();
writeln!(self.out, "{}if (!{}) {{", lif, gate_name)?;
self.put_block(lcontinuing, continuing, context)?;

if let Some(condition) = break_if {
write!(self.out, "{}if (", lcontinuing)?;
write!(self.out, "{}bool loop_break = ", lcontinuing)?;
self.put_expression(condition, &context.expression, true)?;
writeln!(self.out, ") {{")?;
writeln!(self.out, ";")?;
}

self.put_block(lcontinuing, continuing, context)?;

if break_if.is_some() {
writeln!(self.out, "{}if (loop_break) {{", lcontinuing)?;
writeln!(self.out, "{}break;", lcontinuing.next())?;
writeln!(self.out, "{}}}", lcontinuing)?;
}

writeln!(self.out, "{}}}", lif)?;
writeln!(self.out, "{}{} = false;", lif, gate_name)?;
} else {
Expand Down

0 comments on commit fdcdb4f

Please sign in to comment.