Skip to content

Commit

Permalink
Simplify VisitOperator for VisitConstOperator (bytecodealliance#1912)
Browse files Browse the repository at this point in the history
Don't generate a `format!`-per-opcode but instead delegate to a single
helper method.
  • Loading branch information
alexcrichton authored Nov 25, 2024
1 parent 8f17e78 commit d9ca220
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions crates/wasmparser/src/validator/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,13 @@ impl ModuleState {
.insert(index);
}
}

fn not_const(&self, instr: &str) -> BinaryReaderError {
BinaryReaderError::new(
format!("constant expression required: non-constant operator: {instr}"),
self.offset,
)
}
}

macro_rules! define_visit_operator {
Expand Down Expand Up @@ -512,10 +519,7 @@ impl ModuleState {
}};

(@visit $self:ident $op:ident $($args:tt)*) => {{
Err(BinaryReaderError::new(
format!("constant expression required: non-constant operator: {}", stringify!($op)),
$self.offset,
))
Err($self.not_const(stringify!($op)))
}}
}

Expand Down

0 comments on commit d9ca220

Please sign in to comment.