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
37 changes: 26 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,41 @@ edition = "2018"
repository = "https://github.com/bytecodealliance/waffle"

[dependencies]
wasmparser = "0.212"
wasm-encoder = "0.212"
wasmparser = { version = "0.248", default-features = false, features = ["std", "validate", "simd"] }
wasm-encoder = { version = "0.248", default-features = false }
anyhow = "1.0"
structopt = "0.3"
log = "0.4"
env_logger = "0.11"
fxhash = "0.2"
smallvec = "1.13"
rayon = "1.10"
lazy_static = "1.4"
libc = "0.2"
addr2line = "0.21"

# For fuzzing only. Versions must match those in fuzz/Cargo.toml.
# Optional dependencies below.

rayon = { version = "1.10", optional = true }
addr2line = { version = "0.21", optional = true }
structopt = { version = "0.3", optional = true }
env_logger = { version = "0.11", optional = true }
libfuzzer-sys = { version = "0.4.7", optional = true }
wasm-smith = { version = "0.202", optional = true }
wasm-smith = { version = "0.248", optional = true }

[dev-dependencies]
wat = "1.212.0"
wat = "1.248.0"
env_logger = "0.11"

[features]
default = []

# Enable parallelism in the backend via rayon.
parallel = ["dep:rayon"]

# Enable DWARF debug-info parsing/preservation via addr2line/gimli.
dwarf = ["dep:addr2line"]

# Enable the `waffle-util` command-line tool.
cli = ["dep:structopt", "dep:env_logger"]

# Enable fuzzing entrypoints.
fuzzing = ["libfuzzer-sys", "wasm-smith"]

[[bin]]
name = "waffle-util"
required-features = ["cli"]
8 changes: 4 additions & 4 deletions fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ cargo-fuzz = true
[dependencies]
libfuzzer-sys = { version = "0.4.7" }
arbitrary = { version = "1.3.2", features = ["derive"] }
wasm-smith = "0.202.0"
env_logger = "0.9"
wasm-smith = "0.248.0"
env_logger = "0.11"
log = "0.4"
wasmparser = "0.202.0"
wasmtime = "19.0"
wasmparser = "0.248.0"
wasmtime = "44.0"

[dependencies.waffle]
path = ".."
Expand Down
2 changes: 1 addition & 1 deletion fuzz/fuzz_targets/irreducible.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct CFG {
}

impl CFG {
fn to_module(&self) -> Option<Module> {
fn to_module(&self) -> Option<Module<'_>> {
let mut module = Module::empty();
let sig = module.signatures.push(SignatureData {
params: vec![Type::I32],
Expand Down
42 changes: 28 additions & 14 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ use crate::entity::EntityRef;
use crate::ir::{ExportKind, FuncDecl, FunctionBody, ImportKind, Module, Type, Value, ValueDef};
use crate::Operator;
use anyhow::Result;
#[cfg(feature = "parallel")]
use rayon::prelude::*;
use std::borrow::Cow;
use std::convert::TryFrom;

pub mod reducify;
use reducify::Reducifier;
Expand Down Expand Up @@ -385,12 +387,12 @@ impl<'a> WasmFuncBackend<'a> {
Operator::I64Const { value } => {
Some(wasm_encoder::Instruction::I64Const(*value as i64))
}
Operator::F32Const { value } => {
Some(wasm_encoder::Instruction::F32Const(f32::from_bits(*value)))
}
Operator::F64Const { value } => {
Some(wasm_encoder::Instruction::F64Const(f64::from_bits(*value)))
}
Operator::F32Const { value } => Some(wasm_encoder::Instruction::F32Const(
f32::from_bits(*value).into(),
)),
Operator::F64Const { value } => Some(wasm_encoder::Instruction::F64Const(
f64::from_bits(*value).into(),
)),

Operator::I32Eqz => op!(I32Eqz),
Operator::I32Eq => op!(I32Eq),
Expand Down Expand Up @@ -996,7 +998,7 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result<Vec<u8>> {
.returns
.iter()
.map(|&ty| wasm_encoder::ValType::from(ty));
types.function(params, returns);
types.ty().function(params, returns);
}
into_mod.section(&types);

Expand All @@ -1020,6 +1022,7 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result<Vec<u8>> {
minimum: table.initial,
maximum: table.max,
table64: false,
shared: false,
})
}
&ImportKind::Global(global) => {
Expand Down Expand Up @@ -1069,6 +1072,7 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result<Vec<u8>> {
minimum: table_data.initial,
maximum: table_data.max,
table64: false,
shared: false,
});
}
into_mod.section(&tables);
Expand Down Expand Up @@ -1150,7 +1154,9 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result<Vec<u8>> {
elem.active(
Some(table.index() as u32),
&wasm_encoder::ConstExpr::i32_const(i as i32),
wasm_encoder::Elements::Functions(&[elt.index() as u32]),
wasm_encoder::Elements::Functions(std::borrow::Cow::Borrowed(&[
u32::try_from(elt.index()).unwrap(),
])),
);
}
Type::TypedFuncRef(..) => {
Expand All @@ -1159,7 +1165,11 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result<Vec<u8>> {
&wasm_encoder::ConstExpr::i32_const(i as i32),
wasm_encoder::Elements::Expressions(
table_data.ty.into(),
&[wasm_encoder::ConstExpr::ref_func(elt.index() as u32)],
std::borrow::Cow::Borrowed(&[
wasm_encoder::ConstExpr::ref_func(
u32::try_from(elt.index()).unwrap(),
),
]),
),
);
}
Expand All @@ -1173,12 +1183,16 @@ pub fn compile(module: &Module<'_>) -> anyhow::Result<Vec<u8>> {

let mut code = wasm_encoder::CodeSection::new();

let bodies = module
let entries = module
.funcs
.entries()
.skip(num_func_imports)
.collect::<Vec<_>>()
.par_iter()
.collect::<Vec<_>>();
#[cfg(feature = "parallel")]
let iter = entries.par_iter();
#[cfg(not(feature = "parallel"))]
let iter = entries.iter();
let bodies = iter
.map(|(func, func_decl)| -> Result<_> {
match func_decl {
FuncDecl::Lazy(_, _name, reader) => {
Expand Down Expand Up @@ -1237,8 +1251,8 @@ fn const_init(ty: Type, value: Option<u64>) -> wasm_encoder::ConstExpr {
match ty {
Type::I32 => wasm_encoder::ConstExpr::i32_const(bits as u32 as i32),
Type::I64 => wasm_encoder::ConstExpr::i64_const(bits as i64),
Type::F32 => wasm_encoder::ConstExpr::f32_const(f32::from_bits(bits as u32)),
Type::F64 => wasm_encoder::ConstExpr::f64_const(f64::from_bits(bits as u64)),
Type::F32 => wasm_encoder::ConstExpr::f32_const(f32::from_bits(bits as u32).into()),
Type::F64 => wasm_encoder::ConstExpr::f64_const(f64::from_bits(bits as u64).into()),
Type::TypedFuncRef(true, sig) if bits == 0 => {
let hty = wasm_encoder::HeapType::Concrete(sig);
wasm_encoder::ConstExpr::ref_null(hty)
Expand Down
Loading
Loading