Skip to content

Commit

Permalink
deps: update to wasmparser@0.100.0
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford committed Feb 28, 2024
1 parent 867641d commit 720ed9c
Show file tree
Hide file tree
Showing 15 changed files with 268 additions and 240 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Expand Up @@ -30,7 +30,7 @@ log = "0.4.8"
rayon = { version = "1.1.0", optional = true }
walrus-macro = { path = './crates/macro', version = '=0.19.0' }
wasm-encoder = "0.41.0"
wasmparser = "0.80.2"
wasmparser = "0.100.0"
gimli = "0.26.0"

[features]
Expand Down
2 changes: 1 addition & 1 deletion src/init_expr.rs
Expand Up @@ -22,7 +22,7 @@ pub enum InitExpr {
}

impl InitExpr {
pub(crate) fn eval(init: &wasmparser::InitExpr, ids: &IndicesToIds) -> Result<InitExpr> {
pub(crate) fn eval(init: &wasmparser::ConstExpr, ids: &IndicesToIds) -> Result<InitExpr> {
use wasmparser::Operator::*;
let mut reader = init.get_operators_reader();
let val = match reader.read()? {
Expand Down
25 changes: 22 additions & 3 deletions src/ir/mod.rs
Expand Up @@ -496,7 +496,7 @@ pub enum Instr {
},

/// The `atomic.fence` instruction
AtomicFence {},
AtomicFence,

/// `table.get`
TableGet {
Expand Down Expand Up @@ -717,6 +717,10 @@ pub enum BinaryOp {
I64x2ReplaceLane { idx: u8 },
F32x4ReplaceLane { idx: u8 },
F64x2ReplaceLane { idx: u8 },
I8x16RelaxedLaneselect,
I16x8RelaxedLaneselect,
I32x4RelaxedLaneselect,
I64x2RelaxedLaneselect,

I8x16Eq,
I8x16Ne,
Expand Down Expand Up @@ -817,6 +821,8 @@ pub enum BinaryOp {
F32x4Max,
F32x4PMin,
F32x4PMax,
F32x4RelaxedFma,
F32x4RelaxedFnma,
F64x2Add,
F64x2Sub,
F64x2Mul,
Expand All @@ -825,13 +831,18 @@ pub enum BinaryOp {
F64x2Max,
F64x2PMin,
F64x2PMax,
F64x2RelaxedFma,
F64x2RelaxedFnma,
F64x2MinRelaxed,
F64x2MaxRelaxed,

I8x16RelaxedSwizzle,
I8x16NarrowI16x8S,
I8x16NarrowI16x8U,
I16x8NarrowI32x4S,
I16x8NarrowI32x4U,
I8x16RoundingAverageU,
I16x8RoundingAverageU,
I8x16AvgrU,
I16x8AvgrU,

I8x16MinS,
I8x16MinU,
Expand Down Expand Up @@ -970,6 +981,10 @@ pub enum UnaryOp {
F32x4Floor,
F32x4Trunc,
F32x4Nearest,
F32x4FmaRelaxed,
F32x4FmsRelaxed,
F32x4MinRelaxed,
F32x4MaxRelaxed,
F64x2Abs,
F64x2Neg,
F64x2Sqrt,
Expand All @@ -982,6 +997,10 @@ pub enum UnaryOp {
I16x8ExtAddPairwiseI8x16U,
I32x4ExtAddPairwiseI16x8S,
I32x4ExtAddPairwiseI16x8U,
I32x4TruncSatF32x4SRelaxed,
I32x4TruncSatF32x4URelaxed,
I32x4TruncSatF64x2SZeroRelaxed,
I32x4TruncSatF64x2UZeroRelaxed,
I64x2ExtendLowI32x4S,
I64x2ExtendHighI32x4S,
I64x2ExtendLowI32x4U,
Expand Down
7 changes: 4 additions & 3 deletions src/module/data.rs
@@ -1,10 +1,11 @@
//! Data segments within a wasm module.

use crate::emit::{Emit, EmitContext};
use crate::init_expr::InitExpr;
use crate::ir::Value;
use crate::parse::IndicesToIds;
use crate::tombstone_arena::{Id, Tombstone, TombstoneArena};
use crate::{GlobalId, InitExpr, MemoryId, Module, Result, ValType};
use crate::{GlobalId, MemoryId, Module, Result, ValType};
use anyhow::{bail, Context};

/// A passive element segment identifier
Expand Down Expand Up @@ -222,15 +223,15 @@ impl Module {
}
wasmparser::DataKind::Active {
memory_index,
init_expr,
offset_expr,
} => {
data.value = segment.data.to_vec();

let memory_id = ids.get_memory(memory_index)?;
let memory = self.memories.get_mut(memory_id);
memory.data_segments.insert(data.id);

let offset = InitExpr::eval(&init_expr, ids)
let offset = InitExpr::eval(&offset_expr, ids)
.with_context(|| format!("in segment {}", i))?;
data.kind = DataKind::Active(ActiveData {
memory: memory_id,
Expand Down
16 changes: 8 additions & 8 deletions src/module/debug/expression.rs
@@ -1,6 +1,6 @@
use crate::{CodeTransform, Function, InstrLocId, ModuleFunctions};
use id_arena::Id;
use std::cmp::Ordering;
use std::{cmp::Ordering, ops::Range};

use super::dwarf::AddressSearchPreference;

Expand All @@ -22,7 +22,7 @@ pub(crate) enum CodeAddress {
/// Converts original code address to CodeAddress
pub(crate) struct CodeAddressGenerator {
/// Function range based convert table
address_convert_table: Vec<(wasmparser::Range, Id<Function>)>,
address_convert_table: Vec<(Range<usize>, Id<Function>)>,
/// Instrument based convert table
instrument_address_convert_table: Vec<(usize, InstrLocId)>,
}
Expand All @@ -31,7 +31,7 @@ impl CodeAddressGenerator {
pub(crate) fn new(funcs: &ModuleFunctions) -> Self {
let mut address_convert_table = funcs
.iter_local()
.filter_map(|(func_id, func)| func.original_range.map(|range| (range, func_id)))
.filter_map(|(func_id, func)| func.original_range.clone().map(|range| (range, func_id)))
.collect::<Vec<_>>();

let mut instrument_address_convert_table = funcs
Expand Down Expand Up @@ -75,7 +75,7 @@ impl CodeAddressGenerator {
};

// If the address is not mapped to any instruction, falling back to function-range-based comparison.
let inclusive_range_comparor = |range: &(wasmparser::Range, Id<Function>)| {
let inclusive_range_comparor = |range: &(Range<usize>, Id<Function>)| {
// range.start < address <= range.end
if range.0.end < address {
Ordering::Less
Expand All @@ -85,7 +85,7 @@ impl CodeAddressGenerator {
Ordering::Equal
}
};
let exclusive_range_comparor = |range: &(wasmparser::Range, Id<Function>)| {
let exclusive_range_comparor = |range: &(Range<usize>, Id<Function>)| {
// normal comparison: range.start <= address < range.end
if range.0.end <= address {
Ordering::Less
Expand Down Expand Up @@ -189,7 +189,7 @@ mod tests {
crate::FunctionBuilder::new(&mut module.types, &[], &[]),
);

func1.original_range = Some(wasmparser::Range { start: 20, end: 30 });
func1.original_range = Some(Range { start: 20, end: 30 });

let id1 = module.funcs.add_local(func1);

Expand All @@ -198,7 +198,7 @@ mod tests {
crate::FunctionBuilder::new(&mut module.types, &[], &[]),
);

func2.original_range = Some(wasmparser::Range { start: 30, end: 50 });
func2.original_range = Some(Range { start: 30, end: 50 });

let id2 = module.funcs.add_local(func2);

Expand Down Expand Up @@ -262,7 +262,7 @@ mod tests {
{
code_transform
.function_ranges
.push((id1, wasmparser::Range { start: 50, end: 80 }));
.push((id1, Range { start: 50, end: 80 }));
code_transform.instruction_map.push((instr_id1, 60));
code_transform.instruction_map.push((instr_id2, 65));
}
Expand Down
27 changes: 13 additions & 14 deletions src/module/elements.rs
@@ -1,9 +1,10 @@
//! Table elements within a wasm module.

use crate::emit::{Emit, EmitContext};
use crate::init_expr::InitExpr;
use crate::parse::IndicesToIds;
use crate::tombstone_arena::{Id, Tombstone, TombstoneArena};
use crate::{ir::Value, FunctionId, InitExpr, Module, Result, TableId, ValType};
use crate::{ir::Value, FunctionId, Module, Result, TableId, ValType};
use anyhow::{bail, Context};

/// A passive element segment identifier
Expand Down Expand Up @@ -116,30 +117,28 @@ impl Module {
ValType::Funcref => {}
_ => bail!("only funcref type allowed in element segments"),
}
let members = segment
.items
.get_items_reader()?
.into_iter()
.map(|e| -> Result<_> {
Ok(match e? {
wasmparser::ElementItem::Func(f) => Some(ids.get_func(f)?),
wasmparser::ElementItem::Null(_) => None,
})
})
.collect::<Result<_>>()?;
let members = match segment.items {
wasmparser::ElementItems::Functions(funcs) => funcs
.into_iter()
.map(|f| Ok(Some(ids.get_func(f?)?)))
.collect::<Result<_>>()?,
wasmparser::ElementItems::Expressions(exprs) => {
exprs.into_iter().map(|_| Ok(None)).collect::<Result<_>>()?
}
};
let id = self.elements.arena.next_id();

let kind = match segment.kind {
wasmparser::ElementKind::Passive => ElementKind::Passive,
wasmparser::ElementKind::Declared => ElementKind::Declared,
wasmparser::ElementKind::Active {
table_index,
init_expr,
offset_expr,
} => {
let table = ids.get_table(table_index)?;
self.tables.get_mut(table).elem_segments.insert(id);

let offset = InitExpr::eval(&init_expr, ids)
let offset = InitExpr::eval(&offset_expr, ids)
.with_context(|| format!("in segment {}", i))?;
match offset {
InitExpr::Value(Value::I32(_)) => {}
Expand Down
7 changes: 2 additions & 5 deletions src/module/exports.rs
Expand Up @@ -164,20 +164,17 @@ impl Module {
for entry in section {
let entry = entry?;
let item = match entry.kind {
Function => ExportItem::Function(ids.get_func(entry.index)?),
Func => ExportItem::Function(ids.get_func(entry.index)?),
Table => ExportItem::Table(ids.get_table(entry.index)?),
Memory => ExportItem::Memory(ids.get_memory(entry.index)?),
Global => ExportItem::Global(ids.get_global(entry.index)?),
Type | Module | Instance => {
unimplemented!("module linking not supported");
}
Tag => {
unimplemented!("exception handling not supported");
}
};
self.exports.arena.alloc_with_id(|id| Export {
id,
name: entry.field.to_string(),
name: entry.name.to_string(),
item,
});
}
Expand Down
23 changes: 21 additions & 2 deletions src/module/functions/local_function/emit.rs
Expand Up @@ -356,7 +356,7 @@ impl<'instr> Visitor<'instr> for Emit<'_> {
I8x16MinU => Instruction::I8x16MinU,
I8x16MaxS => Instruction::I8x16MaxS,
I8x16MaxU => Instruction::I8x16MaxU,
I8x16RoundingAverageU => Instruction::I8x16AvgrU,
I8x16AvgrU => Instruction::I8x16AvgrU,

I16x8NarrowI32x4S => Instruction::I16x8NarrowI32x4S,
I16x8NarrowI32x4U => Instruction::I16x8NarrowI32x4U,
Expand All @@ -374,7 +374,7 @@ impl<'instr> Visitor<'instr> for Emit<'_> {
I16x8MinU => Instruction::I16x8MinU,
I16x8MaxS => Instruction::I16x8MaxS,
I16x8MaxU => Instruction::I16x8MaxU,
I16x8RoundingAverageU => Instruction::I16x8AvgrU,
I16x8AvgrU => Instruction::I16x8AvgrU,

I32x4Shl => Instruction::I32x4Shl,
I32x4ShrS => Instruction::I32x4ShrS,
Expand Down Expand Up @@ -423,10 +423,21 @@ impl<'instr> Visitor<'instr> for Emit<'_> {
I32x4ExtMulHighI16x8S => Instruction::I32x4ExtMulHighI16x8S,
I32x4ExtMulLowI16x8U => Instruction::I32x4ExtMulLowI16x8U,
I32x4ExtMulHighI16x8U => Instruction::I32x4ExtMulHighI16x8U,
I8x16RelaxedSwizzle => Instruction::I8x16RelaxedSwizzle,
I64x2ExtMulLowI32x4S => Instruction::I64x2ExtMulLowI32x4S,
I64x2ExtMulHighI32x4S => Instruction::I64x2ExtMulHighI32x4S,
I64x2ExtMulLowI32x4U => Instruction::I64x2ExtMulLowI32x4U,
I64x2ExtMulHighI32x4U => Instruction::I64x2ExtMulHighI32x4U,
I8x16RelaxedLaneselect => Instruction::I8x16RelaxedLaneselect,
I16x8RelaxedLaneselect => Instruction::I16x8RelaxedLaneselect,
I32x4RelaxedLaneselect => Instruction::I32x4RelaxedLaneselect,
I64x2RelaxedLaneselect => Instruction::I64x2RelaxedLaneselect,
F64x2RelaxedFma => Instruction::F64x2RelaxedMadd,
F64x2RelaxedFnma => Instruction::F64x2RelaxedNmadd,
F64x2MinRelaxed => Instruction::F64x2RelaxedMin,
F64x2MaxRelaxed => Instruction::F64x2RelaxedMax,
F32x4RelaxedFma => Instruction::F32x4RelaxedMadd,
F32x4RelaxedFnma => Instruction::F32x4RelaxedNmadd,
}
}

Expand Down Expand Up @@ -586,6 +597,14 @@ impl<'instr> Visitor<'instr> for Emit<'_> {
F64x2ConvertLowI32x4U => Instruction::F64x2ConvertLowI32x4U,
F32x4DemoteF64x2Zero => Instruction::F32x4DemoteF64x2Zero,
F64x2PromoteLowF32x4 => Instruction::F64x2PromoteLowF32x4,
I32x4TruncSatF32x4SRelaxed => Instruction::I32x4RelaxedTruncF32x4S,
I32x4TruncSatF32x4URelaxed => Instruction::I32x4RelaxedTruncF32x4U,
I32x4TruncSatF64x2SZeroRelaxed => Instruction::I32x4RelaxedTruncF64x2SZero,
I32x4TruncSatF64x2UZeroRelaxed => Instruction::I32x4RelaxedTruncF64x2UZero,
F32x4FmaRelaxed => Instruction::F32x4RelaxedMadd,
F32x4FmsRelaxed => Instruction::F32x4RelaxedNmadd,
F32x4MinRelaxed => Instruction::F32x4RelaxedMin,
F32x4MaxRelaxed => Instruction::F32x4RelaxedMax,
}
}

Expand Down

0 comments on commit 720ed9c

Please sign in to comment.