Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: allow to specify module's interface in wasm-smith #286

Closed
wants to merge 1 commit into from
Closed
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
94 changes: 94 additions & 0 deletions crates/wasm-smith/src/ast.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/// TODO
#[derive(Debug)]
pub struct Import {
/// TODO
pub module: String,
/// TODO
pub name: Option<String>,
/// TODO
pub desc: EntityDesc,
}

/// TODO
#[non_exhaustive]
#[derive(Debug)]
pub enum EntityDesc {
/// TODO
Func(FuncType),
/// TODO
Global(GlobalType),
/// TODO
Table(TableType),
/// TODO
Memory(MemoryType),
/// TODO
Instance(InstanceType),
}

/// A function type.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct FuncType {
/// Types of parameters of the function.
pub params: Vec<ValType>,
/// Types of results of the function.
pub results: Vec<ValType>,
}

/// TODO
#[derive(Clone, Debug, PartialEq)]
pub struct GlobalType {
/// TODO
pub val_type: ValType,
/// TODO
pub mutable: bool,
}

/// Primitive WASM type.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[non_exhaustive]
pub enum ValType {
/// Signed 32-bit integer.
I32,
/// Signed 64-bit integer.
I64,
/// 32-bit floating point number.
F32,
/// 64-bit floating point number.
F64,
/// TODO:
V128,
/// TODO:
FuncRef,
/// TODO:
ExternRef,
}

/// TODO:
#[derive(Clone, Debug)]
pub struct MemoryType {
/// TODO:
pub limits: Limits,
}

/// TODO:
#[derive(Clone, Debug)]
pub struct TableType {
/// TODO:
pub limits: Limits,
/// TODO:
pub elem_ty: ValType,
}

/// TODO:
#[derive(Clone, Debug)]
pub struct Limits {
/// TODO:
pub min: u32,
/// TODO:
pub max: Option<u32>,
}

#[derive(Debug)]
pub struct InstanceType {
pub exports: indexmap::IndexMap<String, EntityDesc>,
}
12 changes: 12 additions & 0 deletions crates/wasm-smith/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use arbitrary::{Arbitrary, Result, Unstructured};

use crate::Import;

/// Configuration for a generated module.
///
/// Don't care to configure your generated modules? Just use
Expand Down Expand Up @@ -48,6 +50,16 @@ pub trait Config: Clone {
100
}

/// Return the available set of imports.
///
/// By default, returns `None` which means that any arbitrary import can be generated.
///
/// To only allow imports from a specific set, override this to return a vec of
/// each available import.
fn available_imports(&self) -> Option<Vec<Import>> {
None
}

/// The minimum number of functions to generate. Defaults to 0. This
/// includes imported functions.
fn min_funcs(&self) -> usize {
Expand Down
Loading