diff --git a/src/graph.rs b/src/graph.rs new file mode 100644 index 0000000..e5079b1 --- /dev/null +++ b/src/graph.rs @@ -0,0 +1,97 @@ +//! Wasm binary graph format + +use parity_wasm::elements; +use std::cell::RefCell; +use std::rc::Rc; + +enum ImportedOrDeclared { + Imported(String, String), + Declared(T), +} + +type FuncOrigin = ImportedOrDeclared>; +type GlobalOrigin = ImportedOrDeclared>; +type MemoryOrigin = ImportedOrDeclared; +type TableOrigin = ImportedOrDeclared; + +type TypeRef = Rc>; +type FuncRef = Rc>; +type GlobalRef = Rc>; + +struct Func { + type_ref: TypeRef, + origin: FuncOrigin, +} + +struct Global { + content: elements::ValueType, + is_mut: bool, + origin: GlobalOrigin, +} + +enum Instruction { + Plain(elements::Instruction), + Call(FuncRef), +} + +struct Memory { + limits: elements::ResizableLimits, + origin: MemoryOrigin, +} + +struct Table { + origin: TableOrigin, +} + +struct DataSegment { + offset_expr: Vec, + data: Vec, +} + +struct ElementSegment { + offset_expr: Vec, + data: Vec, +} + +enum Export { + Func(FuncRef), + Global(GlobalRef), +} + +#[derive(Default)] +struct Module { + types: Vec, + funcs: Vec, + tables: Vec, + memories: Vec, + globals: Vec, + elements: Vec, + data: Vec, + exports: Vec, +} + +impl Module { + + + fn from_elements(module: &elements::Module) -> Self { + + let mut res = Module::default(); + + for section in module.sections() { + match section { + elements::Section::Type(type_section) => { + res.types = type_section.types().iter().cloned().map(|t| Rc::new(RefCell::new(t))).collect(); + }, + _ => continue, + } + } + + res + } + +} + +#[cfg(test)] +mod tests { + +} \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 3d1c546..38f3710 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,6 +18,7 @@ mod symbols; mod ext; mod pack; mod runtime_type; +mod graph; pub mod stack_height; diff --git a/tests/diff.rs b/tests/diff.rs index 4200bb6..3c889d7 100644 --- a/tests/diff.rs +++ b/tests/diff.rs @@ -30,6 +30,7 @@ fn validate_wasm(binary: &[u8]) -> Result<(), wabt::Error> { } fn run_diff_test Vec>(test_dir: &str, name: &str, test: F) { + // FIXME: not going to work on windows? let mut fixture_path = PathBuf::from(concat!( env!("CARGO_MANIFEST_DIR"), "/tests/fixtures/", @@ -37,6 +38,7 @@ fn run_diff_test Vec>(test_dir: &str, name: &str, test: fixture_path.push(test_dir); fixture_path.push(name); + // FIXME: not going to work on windows? let mut expected_path = PathBuf::from(concat!( env!("CARGO_MANIFEST_DIR"), "/tests/expectations/"