mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-03-15 19:20:48 +00:00
some graph structure definition
This commit is contained in:
parent
7c7a0713fc
commit
06277915da
97
src/graph.rs
Normal file
97
src/graph.rs
Normal file
@ -0,0 +1,97 @@
|
||||
//! Wasm binary graph format
|
||||
|
||||
use parity_wasm::elements;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
|
||||
enum ImportedOrDeclared<T=()> {
|
||||
Imported(String, String),
|
||||
Declared(T),
|
||||
}
|
||||
|
||||
type FuncOrigin = ImportedOrDeclared<Vec<Instruction>>;
|
||||
type GlobalOrigin = ImportedOrDeclared<Vec<Instruction>>;
|
||||
type MemoryOrigin = ImportedOrDeclared;
|
||||
type TableOrigin = ImportedOrDeclared;
|
||||
|
||||
type TypeRef = Rc<RefCell<elements::Type>>;
|
||||
type FuncRef = Rc<RefCell<Func>>;
|
||||
type GlobalRef = Rc<RefCell<Global>>;
|
||||
|
||||
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<Instruction>,
|
||||
data: Vec<u8>,
|
||||
}
|
||||
|
||||
struct ElementSegment {
|
||||
offset_expr: Vec<Instruction>,
|
||||
data: Vec<u32>,
|
||||
}
|
||||
|
||||
enum Export {
|
||||
Func(FuncRef),
|
||||
Global(GlobalRef),
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
struct Module {
|
||||
types: Vec<TypeRef>,
|
||||
funcs: Vec<FuncRef>,
|
||||
tables: Vec<Table>,
|
||||
memories: Vec<Memory>,
|
||||
globals: Vec<GlobalRef>,
|
||||
elements: Vec<ElementSegment>,
|
||||
data: Vec<DataSegment>,
|
||||
exports: Vec<Export>,
|
||||
}
|
||||
|
||||
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 {
|
||||
|
||||
}
|
@ -18,6 +18,7 @@ mod symbols;
|
||||
mod ext;
|
||||
mod pack;
|
||||
mod runtime_type;
|
||||
mod graph;
|
||||
|
||||
pub mod stack_height;
|
||||
|
||||
|
@ -30,6 +30,7 @@ fn validate_wasm(binary: &[u8]) -> Result<(), wabt::Error> {
|
||||
}
|
||||
|
||||
fn run_diff_test<F: FnOnce(&[u8]) -> Vec<u8>>(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<F: FnOnce(&[u8]) -> Vec<u8>>(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/"
|
||||
|
Loading…
x
Reference in New Issue
Block a user