//! 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 { }