Skip to content

Commit

Permalink
wip: (wasm-smith): allow specifying the set of valid imports
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Jul 22, 2021
1 parent ab75ebc commit ccb18b5
Show file tree
Hide file tree
Showing 5 changed files with 519 additions and 45 deletions.
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

0 comments on commit ccb18b5

Please sign in to comment.