Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/ssa/ir/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ fn display_instruction_inner(

writeln!(f, "] : {typ}")
}
Instruction::Noop => writeln!(f, "no-op"),
Instruction::Noop => writeln!(f, "nop"),
}
}

Expand Down
1 change: 1 addition & 0 deletions compiler/noirc_evaluator/src/ssa/parser/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ pub(crate) enum ParsedInstruction {
elements: Vec<ParsedValue>,
typ: Type,
},
Nop,
Not {
target: Identifier,
value: ParsedValue,
Expand Down
3 changes: 3 additions & 0 deletions compiler/noirc_evaluator/src/ssa/parser/into_ssa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ impl Translator {
let value_id = self.builder.insert_load(value, typ);
self.define_variable(target, value_id)?;
}
ParsedInstruction::Nop => {
self.builder.insert_instruction(Instruction::Noop, None);
}
ParsedInstruction::Not { target, value } => {
let value = self.translate_value(value)?;
let value_id = self.builder.insert_not(value);
Expand Down
12 changes: 12 additions & 0 deletions compiler/noirc_evaluator/src/ssa/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ impl<'a> Parser<'a> {
return Ok(Some(instruction));
}

if let Some(instruction) = self.parse_nop()? {
return Ok(Some(instruction));
}

if let Some(target) = self.eat_identifier()? {
return Ok(Some(self.parse_assignment(target)?));
}
Expand Down Expand Up @@ -458,6 +462,14 @@ impl<'a> Parser<'a> {
Ok(Some(ParsedInstruction::Store { address, value }))
}

fn parse_nop(&mut self) -> ParseResult<Option<ParsedInstruction>> {
if !self.eat_keyword(Keyword::Nop)? {
return Ok(None);
}

Ok(Some(ParsedInstruction::Nop))
}

fn parse_assignment(&mut self, target: Identifier) -> ParseResult<ParsedInstruction> {
let mut targets = vec![target];

Expand Down
12 changes: 12 additions & 0 deletions compiler/noirc_evaluator/src/ssa/parser/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,3 +649,15 @@ fn regression_modulo_fields_brillig() {
let ssa = Ssa::from_str(src).unwrap();
ssa.to_brillig(&BrilligOptions::default());
}

#[test]
fn test_parses_nop() {
let src = "
acir(inline) fn add f0 {
b0():
nop
return
}
";
assert_ssa_roundtrip(src);
}
3 changes: 3 additions & 0 deletions compiler/noirc_evaluator/src/ssa/parser/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ pub(crate) enum Keyword {
Mod,
Mul,
Mut,
Nop,
NoPredicates,
Not,
Of,
Expand Down Expand Up @@ -216,6 +217,7 @@ impl Keyword {
"mod" => Keyword::Mod,
"mul" => Keyword::Mul,
"mut" => Keyword::Mut,
"nop" => Keyword::Nop,
"no_predicates" => Keyword::NoPredicates,
"not" => Keyword::Not,
"of" => Keyword::Of,
Expand Down Expand Up @@ -284,6 +286,7 @@ impl Display for Keyword {
Keyword::Mod => write!(f, "mod"),
Keyword::Mul => write!(f, "mul"),
Keyword::Mut => write!(f, "mut"),
Keyword::Nop => write!(f, "nop"),
Keyword::NoPredicates => write!(f, "no_predicates"),
Keyword::Not => write!(f, "not"),
Keyword::Of => write!(f, "of"),
Expand Down
Loading