From 66c9f7ab06dd67ac6e62321dd33943de7f9f9e57 Mon Sep 17 00:00:00 2001 From: Henry Date: Sun, 5 Apr 2026 19:02:08 +0200 Subject: chore: fix stable build, move BranchTableTarget to FunctionData Signed-off-by: Henry --- crates/parser/src/visit.rs | 54 +++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'crates/parser/src/visit.rs') diff --git a/crates/parser/src/visit.rs b/crates/parser/src/visit.rs index 09e3fae..076f7c1 100644 --- a/crates/parser/src/visit.rs +++ b/crates/parser/src/visit.rs @@ -32,6 +32,21 @@ struct LoweringCtx { branch_jumps: Vec, } +#[derive(Default)] +struct FunctionDataBuilder { + v128_constants: Vec, + branch_table_targets: Vec, +} + +impl FunctionDataBuilder { + fn finish(self) -> WasmFunctionData { + WasmFunctionData { + v128_constants: self.v128_constants.into_boxed_slice(), + branch_table_targets: self.branch_table_targets.into_boxed_slice(), + } + } +} + struct ValidateThenVisit<'a, R: WasmModuleResources>(usize, &'a mut FunctionBuilder); macro_rules! validate_then_visit { @@ -75,11 +90,7 @@ pub(crate) fn process_operators_and_validate( return Err(builder.errors.remove(0)); } - Ok(( - builder.instructions, - WasmFunctionData { v128_constants: builder.v128_constants.into_boxed_slice() }, - builder.validator.into_allocations(), - )) + Ok((builder.instructions, builder.data.finish(), builder.validator.into_allocations())) } macro_rules! define_operand { @@ -135,7 +146,7 @@ macro_rules! define_mem_operands_simd_lane { pub(crate) struct FunctionBuilder { validator: FuncValidator, instructions: Vec, - v128_constants: Vec, + data: FunctionDataBuilder, ctx_stack: Vec, local_addr_map: Vec, errors: Vec, @@ -390,14 +401,8 @@ impl<'a, R: WasmModuleResources> wasmparser::VisitOperator<'a> for FunctionBuild let target_depths: Vec = ts; let header_ip = self.instructions.len(); - self.instructions.push(Instruction::BranchTable(0, len)); - - let target_table_ip = self.instructions.len(); - for _ in 0..len { - self.instructions.push(Instruction::BranchTableTarget(0)); - } - let default_target_ip = self.instructions.len(); - self.instructions.push(Instruction::BranchTableTarget(0)); + let branch_table_start = self.data.branch_table_targets.len() as u32; + self.instructions.push(Instruction::BranchTable(0, branch_table_start, len)); let mut seen = alloc::collections::BTreeMap::::new(); struct PadInfo { @@ -418,18 +423,13 @@ impl<'a, R: WasmModuleResources> wasmparser::VisitOperator<'a> for FunctionBuild pads.push(PadInfo { depth, pad_start, jump_or_ret_ip, is_return }); } - for (i, &depth) in target_depths.iter().enumerate() { + for &depth in &target_depths { let pad_idx = seen[&depth]; - if let Instruction::BranchTableTarget(ip) = &mut self.instructions[target_table_ip + i] { - *ip = pads[pad_idx].pad_start as u32; - } + self.data.branch_table_targets.push(pads[pad_idx].pad_start as u32); } let default_pad_idx = seen[&default_depth]; - if let Instruction::BranchTableTarget(ip) = &mut self.instructions[default_target_ip] { - *ip = pads[default_pad_idx].pad_start as u32; - } - if let Instruction::BranchTable(default_ip, _) = &mut self.instructions[header_ip] { + if let Instruction::BranchTable(default_ip, _, _) = &mut self.instructions[header_ip] { *default_ip = pads[default_pad_idx].pad_start as u32; } @@ -570,13 +570,13 @@ impl wasmparser::VisitSimdOperator<'_> for FunctionBuild } fn visit_i8x16_shuffle(&mut self, lanes: [u8; 16]) -> Self::Output { - self.instructions.push(Instruction::I8x16Shuffle(self.v128_constants.len() as u32)); - self.v128_constants.push(i128::from_le_bytes(lanes)); + self.instructions.push(Instruction::I8x16Shuffle(self.data.v128_constants.len() as u32)); + self.data.v128_constants.push(i128::from_le_bytes(lanes)); } fn visit_v128_const(&mut self, value: wasmparser::V128) -> Self::Output { - self.instructions.push(Instruction::V128Const(self.v128_constants.len() as u32)); - self.v128_constants.push(value.i128()); + self.instructions.push(Instruction::V128Const(self.data.v128_constants.len() as u32)); + self.data.v128_constants.push(value.i128()); } } @@ -593,7 +593,7 @@ impl FunctionBuilder { validator, local_addr_map, instructions: Vec::with_capacity(instr_capacity), - v128_constants: Vec::new(), + data: FunctionDataBuilder::default(), ctx_stack: Vec::with_capacity(256), errors: Vec::new(), } -- cgit v1.3.1