summaryrefslogtreecommitdiff
path: root/crates/parser
diff options
context:
space:
mode:
authorHenry Gressmann <mail@henrygressmann.de>2024-02-27 01:50:54 +0100
committerHenry Gressmann <mail@henrygressmann.de>2024-02-27 01:50:54 +0100
commit83a768d77ac57f5d8e8884173765e0efc80831f4 (patch)
tree70684731f7689a1e11eb9728673a09215dc7e375 /crates/parser
parente883003b7436708e91d0971b1a8e5f74c8166261 (diff)
reduce instruction enum size
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
Diffstat (limited to 'crates/parser')
-rw-r--r--crates/parser/src/conversion.rs2
-rw-r--r--crates/parser/src/visit.rs29
2 files changed, 17 insertions, 14 deletions
diff --git a/crates/parser/src/conversion.rs b/crates/parser/src/conversion.rs
index 53cceb6..c13d08f 100644
--- a/crates/parser/src/conversion.rs
+++ b/crates/parser/src/conversion.rs
@@ -226,7 +226,7 @@ pub(crate) fn convert_valtype(valtype: &wasmparser::ValType) -> ValType {
}
pub(crate) fn convert_memarg(memarg: wasmparser::MemArg) -> MemoryArg {
- MemoryArg { offset: memarg.offset, align: memarg.align, align_max: memarg.max_align, mem_addr: memarg.memory }
+ MemoryArg { offset: memarg.offset, mem_addr: memarg.memory }
}
pub(crate) fn process_const_operators(ops: OperatorsReader<'_>) -> Result<ConstInstruction> {
diff --git a/crates/parser/src/visit.rs b/crates/parser/src/visit.rs
index f994e7e..3a10a93 100644
--- a/crates/parser/src/visit.rs
+++ b/crates/parser/src/visit.rs
@@ -338,15 +338,16 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder {
}
fn visit_local_set(&mut self, idx: u32) -> Self::Output {
- if self.instructions.len() < 1 {
- return self.visit(Instruction::I64Rotl);
+ if let Some(instruction) = self.instructions.last_mut() {
+ match instruction {
+ // Needs more testing, seems to make performance worse
+ // Instruction::LocalGet(a) => *instruction = Instruction::LocalGetSet(*a, idx),
+ _ => return self.visit(Instruction::LocalSet(idx)),
+ };
+ // Ok(())
+ } else {
+ self.visit(Instruction::LocalSet(idx))
}
-
- // LocalGetSet
- match self.instructions[self.instructions.len() - 1..] {
- // Instruction::LocalGet(a) => *instruction = Instruction::LocalGetSet(*a, idx),
- _ => return self.visit(Instruction::LocalSet(idx)),
- };
}
fn visit_local_tee(&mut self, idx: u32) -> Self::Output {
@@ -413,7 +414,7 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder {
match self.instructions[label_pointer] {
Instruction::Else(ref mut else_instr_end_offset) => {
- *else_instr_end_offset = current_instr_ptr - label_pointer;
+ *else_instr_end_offset = (current_instr_ptr - label_pointer as usize) as u32;
#[cold]
fn error() -> crate::ParseError {
@@ -430,13 +431,13 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder {
return Err(error());
};
- *else_offset = Some(label_pointer - if_label_pointer);
- *end_offset = current_instr_ptr - if_label_pointer;
+ *else_offset = Some((label_pointer - if_label_pointer) as u32);
+ *end_offset = (current_instr_ptr - if_label_pointer) as u32;
}
Instruction::Block(_, ref mut end_offset)
| Instruction::Loop(_, ref mut end_offset)
| Instruction::If(_, _, ref mut end_offset) => {
- *end_offset = current_instr_ptr - label_pointer;
+ *end_offset = (current_instr_ptr - label_pointer) as u32;
}
_ => {
return Err(crate::ParseError::UnsupportedOperator(
@@ -456,7 +457,9 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder {
.collect::<Result<Vec<Instruction>, wasmparser::BinaryReaderError>>()
.expect("BrTable targets are invalid, this should have been caught by the validator");
- self.instructions.extend(IntoIterator::into_iter([Instruction::BrTable(def, instrs.len())]).chain(instrs));
+ self.instructions
+ .extend(IntoIterator::into_iter([Instruction::BrTable(def, instrs.len() as u32)]).chain(instrs));
+
Ok(())
}