summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorHenry <mail@henrygressmann.de>2023-12-22 00:03:03 +0100
committerHenry <mail@henrygressmann.de>2023-12-22 00:03:03 +0100
commit295a48c57672b3e7109c1d650313a00e15a6c01d (patch)
tree419a73091059fa16d8c914432d08315beeefb02a /crates
parentfcb92cab9a440931ebc90dfdb94974084d5e066b (diff)
feat: improve parser
Signed-off-by: Henry <mail@henrygressmann.de>
Diffstat (limited to 'crates')
-rw-r--r--crates/parser/src/conversion.rs62
-rw-r--r--crates/parser/src/lib.rs2
-rw-r--r--crates/parser/src/module.rs52
-rw-r--r--crates/tinywasm/tests/mvp.csv2
-rw-r--r--crates/tinywasm/tests/progress-mvp.svg6
-rw-r--r--crates/types/src/lib.rs30
6 files changed, 118 insertions, 36 deletions
diff --git a/crates/parser/src/conversion.rs b/crates/parser/src/conversion.rs
index e3dffbc..7d3215d 100644
--- a/crates/parser/src/conversion.rs
+++ b/crates/parser/src/conversion.rs
@@ -4,10 +4,40 @@ use tinywasm_types::{
BlockArgs, ConstInstruction, Export, ExternalKind, FuncType, Global, GlobalType, Import, ImportKind, Instruction,
MemArg, MemoryArch, MemoryType, TableType, ValType,
};
-use wasmparser::{FuncValidator, ValidatorResources};
+use wasmparser::{FuncValidator, OperatorsReader, ValidatorResources};
use crate::{module::CodeSection, Result};
+pub(crate) fn convert_module_data_sections<'a, T: IntoIterator<Item = wasmparser::Result<wasmparser::Data<'a>>>>(
+ data_sections: T,
+) -> Result<Vec<tinywasm_types::Data>> {
+ let data_sections = data_sections
+ .into_iter()
+ .map(|data| convert_module_data(data?))
+ .collect::<Result<Vec<_>>>()?;
+ Ok(data_sections)
+}
+
+pub(crate) fn convert_module_data(data: wasmparser::Data<'_>) -> Result<tinywasm_types::Data> {
+ Ok(tinywasm_types::Data {
+ data: data.data.to_vec().into_boxed_slice(),
+ range: data.range,
+ kind: match data.kind {
+ wasmparser::DataKind::Active {
+ memory_index,
+ offset_expr,
+ } => {
+ let offset = process_const_operators(offset_expr.get_operators_reader())?;
+ tinywasm_types::DataKind::Active {
+ mem: memory_index,
+ offset,
+ }
+ }
+ wasmparser::DataKind::Passive => tinywasm_types::DataKind::Passive,
+ },
+ })
+}
+
pub(crate) fn convert_module_imports<'a, T: IntoIterator<Item = wasmparser::Result<wasmparser::Import<'a>>>>(
imports: T,
) -> Result<Vec<Import>> {
@@ -20,8 +50,8 @@ pub(crate) fn convert_module_imports<'a, T: IntoIterator<Item = wasmparser::Resu
pub(crate) fn convert_module_import(import: wasmparser::Import<'_>) -> Result<Import> {
Ok(Import {
- module: import.module.to_string(),
- name: import.name.to_string(),
+ module: import.module.to_string().into_boxed_str(),
+ name: import.name.to_string().into_boxed_str(),
kind: match import.ty {
wasmparser::TypeRef::Func(ty) => ImportKind::Func(ty),
wasmparser::TypeRef::Table(ty) => ImportKind::Table(convert_module_table(ty)?),
@@ -90,21 +120,10 @@ pub(crate) fn convert_module_globals<'a, T: IntoIterator<Item = wasmparser::Resu
.map(|global| {
let global = global?;
let ty = convert_valtype(&global.ty.content_type);
-
- let ops = global
- .init_expr
- .get_operators_reader()
- .into_iter()
- .collect::<wasmparser::Result<Vec<_>>>()?;
-
- // In practice, the len can never be something other than 2,
- // but we'll keep this here since it's part of the spec
- // Invalid modules will be rejected by the validator anyway (there are also tests for this in the testsuite)
- assert!(ops.len() >= 2);
- assert!(matches!(ops[ops.len() - 1], wasmparser::Operator::End));
+ let ops = global.init_expr.get_operators_reader();
Ok(Global {
- init: process_const_operator(ops[ops.len() - 2].clone())?,
+ init: process_const_operators(ops)?,
ty: GlobalType {
mutable: global.ty.mutable,
ty,
@@ -215,6 +234,17 @@ pub(crate) fn convert_memarg(memarg: wasmparser::MemArg) -> MemArg {
}
}
+pub(crate) fn process_const_operators(ops: OperatorsReader) -> Result<ConstInstruction> {
+ let ops = ops.into_iter().collect::<wasmparser::Result<Vec<_>>>()?;
+ // In practice, the len can never be something other than 2,
+ // but we'll keep this here since it's part of the spec
+ // Invalid modules will be rejected by the validator anyway (there are also tests for this in the testsuite)
+ assert!(ops.len() >= 2);
+ assert!(matches!(ops[ops.len() - 1], wasmparser::Operator::End));
+
+ Ok(process_const_operator(ops[ops.len() - 2].clone())?)
+}
+
pub fn process_const_operator(op: wasmparser::Operator) -> Result<ConstInstruction> {
match op {
wasmparser::Operator::I32Const { value } => Ok(ConstInstruction::I32Const(value)),
diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs
index 36deb7f..f1477f9 100644
--- a/crates/parser/src/lib.rs
+++ b/crates/parser/src/lib.rs
@@ -126,6 +126,8 @@ impl TryFrom<ModuleReader> for TinyWasmModule {
globals: globals.into_boxed_slice(),
table_types: table_types.into_boxed_slice(),
memory_types: reader.memory_types.into_boxed_slice(),
+ imports: reader.imports.into_boxed_slice(),
+ data: reader.data.into_boxed_slice(),
})
}
}
diff --git a/crates/parser/src/module.rs b/crates/parser/src/module.rs
index 0dbd36b..fdad900 100644
--- a/crates/parser/src/module.rs
+++ b/crates/parser/src/module.rs
@@ -1,11 +1,10 @@
use crate::log::debug;
+use crate::{conversion, ParseError, Result};
use alloc::{boxed::Box, format, vec::Vec};
use core::fmt::Debug;
-use tinywasm_types::{Export, FuncType, Global, Import, Instruction, MemoryType, TableType, ValType};
+use tinywasm_types::{Data, Export, FuncType, Global, Import, Instruction, MemoryType, TableType, ValType};
use wasmparser::{Payload, Validator};
-use crate::{conversion, ParseError, Result};
-
#[derive(Debug, Clone, PartialEq)]
pub struct CodeSection {
pub locals: Box<[ValType]>,
@@ -25,9 +24,9 @@ pub struct ModuleReader {
pub table_types: Vec<TableType>,
pub memory_types: Vec<MemoryType>,
pub imports: Vec<Import>,
+ pub data: Vec<Data>,
// pub element_section: Option<ElementSectionReader<'a>>,
- // pub data_section: Option<DataSectionReader<'a>>,
pub end_reached: bool,
}
@@ -67,11 +66,19 @@ impl ModuleReader {
}
}
StartSection { func, range } => {
+ if self.start_func.is_some() {
+ return Err(ParseError::DuplicateSection("Start section".into()));
+ }
+
debug!("Found start section");
validator.start_section(func, &range)?;
self.start_func = Some(func);
}
TypeSection(reader) => {
+ if !self.func_types.is_empty() {
+ return Err(ParseError::DuplicateSection("Type section".into()));
+ }
+
debug!("Found type section");
validator.type_section(&reader)?;
self.func_types = reader
@@ -80,21 +87,37 @@ impl ModuleReader {
.collect::<Result<Vec<FuncType>>>()?;
}
FunctionSection(reader) => {
+ if !self.func_addrs.is_empty() {
+ return Err(ParseError::DuplicateSection("Function section".into()));
+ }
+
debug!("Found function section");
validator.function_section(&reader)?;
self.func_addrs = reader.into_iter().map(|f| Ok(f?)).collect::<Result<Vec<_>>>()?;
}
GlobalSection(reader) => {
+ if !self.globals.is_empty() {
+ return Err(ParseError::DuplicateSection("Global section".into()));
+ }
+
debug!("Found global section");
validator.global_section(&reader)?;
self.globals = conversion::convert_module_globals(reader)?;
}
TableSection(reader) => {
+ if !self.table_types.is_empty() {
+ return Err(ParseError::DuplicateSection("Table section".into()));
+ }
+
debug!("Found table section");
validator.table_section(&reader)?;
self.table_types = conversion::convert_module_tables(reader)?;
}
MemorySection(reader) => {
+ if !self.memory_types.is_empty() {
+ return Err(ParseError::DuplicateSection("Memory section".into()));
+ }
+
debug!("Found memory section");
validator.memory_section(&reader)?;
self.memory_types = conversion::convert_module_memories(reader)?;
@@ -105,11 +128,14 @@ impl ModuleReader {
// validator.element_section(&reader)?;
// self.element_section = Some(reader);
}
- DataSection(_reader) => {
- return Err(ParseError::UnsupportedSection("Data section".into()));
- // debug!("Found data section");
- // validator.data_section(&reader)?;
- // self.data_section = Some(reader);
+ DataSection(reader) => {
+ if !self.data.is_empty() {
+ return Err(ParseError::DuplicateSection("Data section".into()));
+ }
+
+ debug!("Found data section");
+ validator.data_section(&reader)?;
+ self.data = conversion::convert_module_data_sections(reader)?;
}
CodeSectionStart { count, range, .. } => {
debug!("Found code section ({} functions)", count);
@@ -127,11 +153,19 @@ impl ModuleReader {
.push(conversion::convert_module_code(function, func_validator)?);
}
ImportSection(reader) => {
+ if !self.imports.is_empty() {
+ return Err(ParseError::DuplicateSection("Import section".into()));
+ }
+
debug!("Found import section");
validator.import_section(&reader)?;
self.imports = conversion::convert_module_imports(reader)?;
}
ExportSection(reader) => {
+ if !self.exports.is_empty() {
+ return Err(ParseError::DuplicateSection("Export section".into()));
+ }
+
debug!("Found export section");
validator.export_section(&reader)?;
self.exports = reader
diff --git a/crates/tinywasm/tests/mvp.csv b/crates/tinywasm/tests/mvp.csv
index 0cc9b3f..fccb69d 100644
--- a/crates/tinywasm/tests/mvp.csv
+++ b/crates/tinywasm/tests/mvp.csv
@@ -1,4 +1,4 @@
0.0.3,9258,7567,[{"name":"address.wast","passed":0,"failed":54},{"name":"align.wast","passed":0,"failed":109},{"name":"binary-leb128.wast","passed":66,"failed":25},{"name":"binary.wast","passed":104,"failed":8},{"name":"block.wast","passed":0,"failed":171},{"name":"br.wast","passed":0,"failed":21},{"name":"br_if.wast","passed":0,"failed":30},{"name":"br_table.wast","passed":0,"failed":25},{"name":"call.wast","passed":0,"failed":22},{"name":"call_indirect.wast","passed":0,"failed":56},{"name":"comments.wast","passed":4,"failed":4},{"name":"const.wast","passed":702,"failed":76},{"name":"conversions.wast","passed":0,"failed":93},{"name":"custom.wast","passed":10,"failed":1},{"name":"data.wast","passed":0,"failed":61},{"name":"elem.wast","passed":0,"failed":76},{"name":"endianness.wast","passed":0,"failed":1},{"name":"exports.wast","passed":21,"failed":73},{"name":"f32.wast","passed":1005,"failed":1509},{"name":"f32_bitwise.wast","passed":1,"failed":363},{"name":"f32_cmp.wast","passed":2401,"failed":6},{"name":"f64.wast","passed":1005,"failed":1509},{"name":"f64_bitwise.wast","passed":1,"failed":363},{"name":"f64_cmp.wast","passed":2401,"failed":6},{"name":"fac.wast","passed":0,"failed":2},{"name":"float_exprs.wast","passed":269,"failed":591},{"name":"float_literals.wast","passed":34,"failed":129},{"name":"float_memory.wast","passed":0,"failed":6},{"name":"float_misc.wast","passed":138,"failed":303},{"name":"forward.wast","passed":1,"failed":4},{"name":"func.wast","passed":4,"failed":75},{"name":"func_ptrs.wast","passed":0,"failed":16},{"name":"global.wast","passed":4,"failed":49},{"name":"i32.wast","passed":0,"failed":96},{"name":"i64.wast","passed":0,"failed":42},{"name":"if.wast","passed":0,"failed":118},{"name":"imports.wast","passed":1,"failed":156},{"name":"inline-module.wast","passed":0,"failed":1},{"name":"int_exprs.wast","passed":38,"failed":70},{"name":"int_literals.wast","passed":5,"failed":46},{"name":"labels.wast","passed":1,"failed":28},{"name":"left-to-right.wast","passed":0,"failed":1},{"name":"linking.wast","passed":1,"failed":66},{"name":"load.wast","passed":0,"failed":60},{"name":"local_get.wast","passed":2,"failed":34},{"name":"local_set.wast","passed":5,"failed":48},{"name":"local_tee.wast","passed":0,"failed":42},{"name":"loop.wast","passed":0,"failed":43},{"name":"memory.wast","passed":0,"failed":34},{"name":"memory_grow.wast","passed":0,"failed":19},{"name":"memory_redundancy.wast","passed":0,"failed":1},{"name":"memory_size.wast","passed":0,"failed":6},{"name":"memory_trap.wast","passed":0,"failed":172},{"name":"names.wast","passed":484,"failed":1},{"name":"nop.wast","passed":0,"failed":5},{"name":"return.wast","passed":0,"failed":21},{"name":"select.wast","passed":0,"failed":32},{"name":"skip-stack-guard-page.wast","passed":0,"failed":11},{"name":"stack.wast","passed":0,"failed":2},{"name":"start.wast","passed":0,"failed":10},{"name":"store.wast","passed":0,"failed":59},{"name":"switch.wast","passed":1,"failed":27},{"name":"token.wast","passed":16,"failed":42},{"name":"traps.wast","passed":3,"failed":33},{"name":"type.wast","passed":1,"failed":2},{"name":"unreachable.wast","passed":0,"failed":59},{"name":"unreached-invalid.wast","passed":0,"failed":118},{"name":"unwind.wast","passed":1,"failed":49},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":0,"failed":176}]
0.0.4,9258,10909,[{"name":"address.wast","passed":0,"failed":54},{"name":"align.wast","passed":0,"failed":109},{"name":"binary-leb128.wast","passed":66,"failed":25},{"name":"binary.wast","passed":104,"failed":8},{"name":"block.wast","passed":0,"failed":171},{"name":"br.wast","passed":0,"failed":21},{"name":"br_if.wast","passed":0,"failed":30},{"name":"br_table.wast","passed":0,"failed":25},{"name":"call.wast","passed":0,"failed":22},{"name":"call_indirect.wast","passed":0,"failed":56},{"name":"comments.wast","passed":4,"failed":4},{"name":"const.wast","passed":702,"failed":76},{"name":"conversions.wast","passed":0,"failed":93},{"name":"custom.wast","passed":10,"failed":1},{"name":"data.wast","passed":0,"failed":61},{"name":"elem.wast","passed":0,"failed":76},{"name":"endianness.wast","passed":0,"failed":1},{"name":"exports.wast","passed":21,"failed":73},{"name":"f32.wast","passed":1005,"failed":1509},{"name":"f32_bitwise.wast","passed":1,"failed":363},{"name":"f32_cmp.wast","passed":2401,"failed":6},{"name":"f64.wast","passed":1005,"failed":1509},{"name":"f64_bitwise.wast","passed":1,"failed":363},{"name":"f64_cmp.wast","passed":2401,"failed":6},{"name":"fac.wast","passed":0,"failed":2},{"name":"float_exprs.wast","passed":269,"failed":591},{"name":"float_literals.wast","passed":34,"failed":129},{"name":"float_memory.wast","passed":0,"failed":6},{"name":"float_misc.wast","passed":138,"failed":303},{"name":"forward.wast","passed":1,"failed":4},{"name":"func.wast","passed":4,"failed":75},{"name":"func_ptrs.wast","passed":0,"failed":16},{"name":"global.wast","passed":4,"failed":49},{"name":"i32.wast","passed":0,"failed":96},{"name":"i64.wast","passed":0,"failed":42},{"name":"if.wast","passed":0,"failed":118},{"name":"imports.wast","passed":1,"failed":156},{"name":"inline-module.wast","passed":0,"failed":1},{"name":"int_exprs.wast","passed":38,"failed":70},{"name":"int_literals.wast","passed":5,"failed":46},{"name":"labels.wast","passed":1,"failed":28},{"name":"left-to-right.wast","passed":0,"failed":1},{"name":"linking.wast","passed":1,"failed":66},{"name":"load.wast","passed":0,"failed":60},{"name":"local_get.wast","passed":2,"failed":34},{"name":"local_set.wast","passed":5,"failed":48},{"name":"local_tee.wast","passed":0,"failed":42},{"name":"loop.wast","passed":0,"failed":43},{"name":"memory.wast","passed":0,"failed":34},{"name":"memory_grow.wast","passed":0,"failed":19},{"name":"memory_redundancy.wast","passed":0,"failed":1},{"name":"memory_size.wast","passed":0,"failed":6},{"name":"memory_trap.wast","passed":0,"failed":172},{"name":"names.wast","passed":484,"failed":1},{"name":"nop.wast","passed":0,"failed":5},{"name":"return.wast","passed":0,"failed":21},{"name":"select.wast","passed":0,"failed":32},{"name":"skip-stack-guard-page.wast","passed":0,"failed":11},{"name":"stack.wast","passed":0,"failed":2},{"name":"start.wast","passed":0,"failed":10},{"name":"store.wast","passed":0,"failed":59},{"name":"switch.wast","passed":1,"failed":27},{"name":"token.wast","passed":16,"failed":42},{"name":"traps.wast","passed":3,"failed":33},{"name":"type.wast","passed":1,"failed":2},{"name":"unreachable.wast","passed":0,"failed":59},{"name":"unreached-invalid.wast","passed":0,"failed":118},{"name":"unwind.wast","passed":1,"failed":49},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":0,"failed":176}]
0.0.5,11135,9093,[{"name":"address.wast","passed":1,"failed":259},{"name":"align.wast","passed":108,"failed":48},{"name":"binary-leb128.wast","passed":78,"failed":13},{"name":"binary.wast","passed":107,"failed":5},{"name":"block.wast","passed":170,"failed":53},{"name":"br.wast","passed":20,"failed":77},{"name":"br_if.wast","passed":29,"failed":89},{"name":"br_table.wast","passed":24,"failed":150},{"name":"call.wast","passed":18,"failed":73},{"name":"call_indirect.wast","passed":34,"failed":136},{"name":"comments.wast","passed":5,"failed":3},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":25,"failed":594},{"name":"custom.wast","passed":10,"failed":1},{"name":"data.wast","passed":22,"failed":39},{"name":"elem.wast","passed":27,"failed":72},{"name":"endianness.wast","passed":1,"failed":68},{"name":"exports.wast","passed":90,"failed":6},{"name":"f32.wast","passed":1018,"failed":1496},{"name":"f32_bitwise.wast","passed":4,"failed":360},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":1018,"failed":1496},{"name":"f64_bitwise.wast","passed":4,"failed":360},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":1,"failed":7},{"name":"float_exprs.wast","passed":275,"failed":625},{"name":"float_literals.wast","passed":112,"failed":51},{"name":"float_memory.wast","passed":0,"failed":90},{"name":"float_misc.wast","passed":138,"failed":303},{"name":"forward.wast","passed":1,"failed":4},{"name":"func.wast","passed":81,"failed":91},{"name":"func_ptrs.wast","passed":7,"failed":29},{"name":"global.wast","passed":50,"failed":60},{"name":"i32.wast","passed":85,"failed":375},{"name":"i64.wast","passed":31,"failed":385},{"name":"if.wast","passed":116,"failed":125},{"name":"imports.wast","passed":23,"failed":160},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":38,"failed":70},{"name":"int_literals.wast","passed":25,"failed":26},{"name":"labels.wast","passed":13,"failed":16},{"name":"left-to-right.wast","passed":0,"failed":96},{"name":"linking.wast","passed":5,"failed":127},{"name":"load.wast","passed":59,"failed":38},{"name":"local_get.wast","passed":18,"failed":18},{"name":"local_set.wast","passed":38,"failed":15},{"name":"local_tee.wast","passed":41,"failed":56},{"name":"loop.wast","passed":42,"failed":78},{"name":"memory.wast","passed":30,"failed":49},{"name":"memory_grow.wast","passed":11,"failed":85},{"name":"memory_redundancy.wast","passed":1,"failed":7},{"name":"memory_size.wast","passed":6,"failed":36},{"name":"memory_trap.wast","passed":1,"failed":181},{"name":"names.wast","passed":484,"failed":2},{"name":"nop.wast","passed":4,"failed":84},{"name":"return.wast","passed":20,"failed":64},{"name":"select.wast","passed":28,"failed":120},{"name":"skip-stack-guard-page.wast","passed":1,"failed":10},{"name":"stack.wast","passed":2,"failed":5},{"name":"start.wast","passed":4,"failed":16},{"name":"store.wast","passed":59,"failed":9},{"name":"switch.wast","passed":2,"failed":26},{"name":"token.wast","passed":39,"failed":19},{"name":"traps.wast","passed":4,"failed":32},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":0,"failed":64},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unwind.wast","passed":9,"failed":41},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}]
-0.0.6-alpha.0,11200,9028,[{"name":"address.wast","passed":1,"failed":259},{"name":"align.wast","passed":108,"failed":48},{"name":"binary-leb128.wast","passed":81,"failed":10},{"name":"binary.wast","passed":108,"failed":4},{"name":"block.wast","passed":170,"failed":53},{"name":"br.wast","passed":20,"failed":77},{"name":"br_if.wast","passed":29,"failed":89},{"name":"br_table.wast","passed":24,"failed":150},{"name":"call.wast","passed":18,"failed":73},{"name":"call_indirect.wast","passed":34,"failed":136},{"name":"comments.wast","passed":5,"failed":3},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":25,"failed":594},{"name":"custom.wast","passed":10,"failed":1},{"name":"data.wast","passed":22,"failed":39},{"name":"elem.wast","passed":27,"failed":72},{"name":"endianness.wast","passed":1,"failed":68},{"name":"exports.wast","passed":90,"failed":6},{"name":"f32.wast","passed":1018,"failed":1496},{"name":"f32_bitwise.wast","passed":4,"failed":360},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":1018,"failed":1496},{"name":"f64_bitwise.wast","passed":4,"failed":360},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":1,"failed":7},{"name":"float_exprs.wast","passed":275,"failed":625},{"name":"float_literals.wast","passed":112,"failed":51},{"name":"float_memory.wast","passed":0,"failed":90},{"name":"float_misc.wast","passed":138,"failed":303},{"name":"forward.wast","passed":1,"failed":4},{"name":"func.wast","passed":81,"failed":91},{"name":"func_ptrs.wast","passed":8,"failed":28},{"name":"global.wast","passed":51,"failed":59},{"name":"i32.wast","passed":85,"failed":375},{"name":"i64.wast","passed":31,"failed":385},{"name":"if.wast","passed":116,"failed":125},{"name":"imports.wast","passed":69,"failed":114},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":38,"failed":70},{"name":"int_literals.wast","passed":25,"failed":26},{"name":"labels.wast","passed":13,"failed":16},{"name":"left-to-right.wast","passed":0,"failed":96},{"name":"linking.wast","passed":13,"failed":119},{"name":"load.wast","passed":59,"failed":38},{"name":"local_get.wast","passed":18,"failed":18},{"name":"local_set.wast","passed":38,"failed":15},{"name":"local_tee.wast","passed":41,"failed":56},{"name":"loop.wast","passed":42,"failed":78},{"name":"memory.wast","passed":30,"failed":49},{"name":"memory_grow.wast","passed":11,"failed":85},{"name":"memory_redundancy.wast","passed":1,"failed":7},{"name":"memory_size.wast","passed":6,"failed":36},{"name":"memory_trap.wast","passed":1,"failed":181},{"name":"names.wast","passed":485,"failed":1},{"name":"nop.wast","passed":4,"failed":84},{"name":"return.wast","passed":20,"failed":64},{"name":"select.wast","passed":28,"failed":120},{"name":"skip-stack-guard-page.wast","passed":1,"failed":10},{"name":"stack.wast","passed":2,"failed":5},{"name":"start.wast","passed":7,"failed":13},{"name":"store.wast","passed":59,"failed":9},{"name":"switch.wast","passed":2,"failed":26},{"name":"token.wast","passed":40,"failed":18},{"name":"traps.wast","passed":4,"failed":32},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":0,"failed":64},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unwind.wast","passed":9,"failed":41},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}]
+0.0.6-alpha.0,11273,8955,[{"name":"address.wast","passed":5,"failed":255},{"name":"align.wast","passed":108,"failed":48},{"name":"binary-leb128.wast","passed":85,"failed":6},{"name":"binary.wast","passed":109,"failed":3},{"name":"block.wast","passed":170,"failed":53},{"name":"br.wast","passed":20,"failed":77},{"name":"br_if.wast","passed":29,"failed":89},{"name":"br_table.wast","passed":24,"failed":150},{"name":"call.wast","passed":18,"failed":73},{"name":"call_indirect.wast","passed":34,"failed":136},{"name":"comments.wast","passed":5,"failed":3},{"name":"const.wast","passed":778,"failed":0},{"name":"conversions.wast","passed":25,"failed":594},{"name":"custom.wast","passed":10,"failed":1},{"name":"data.wast","passed":47,"failed":14},{"name":"elem.wast","passed":27,"failed":72},{"name":"endianness.wast","passed":1,"failed":68},{"name":"exports.wast","passed":90,"failed":6},{"name":"f32.wast","passed":1018,"failed":1496},{"name":"f32_bitwise.wast","passed":4,"failed":360},{"name":"f32_cmp.wast","passed":2407,"failed":0},{"name":"f64.wast","passed":1018,"failed":1496},{"name":"f64_bitwise.wast","passed":4,"failed":360},{"name":"f64_cmp.wast","passed":2407,"failed":0},{"name":"fac.wast","passed":1,"failed":7},{"name":"float_exprs.wast","passed":279,"failed":621},{"name":"float_literals.wast","passed":112,"failed":51},{"name":"float_memory.wast","passed":6,"failed":84},{"name":"float_misc.wast","passed":138,"failed":303},{"name":"forward.wast","passed":1,"failed":4},{"name":"func.wast","passed":81,"failed":91},{"name":"func_ptrs.wast","passed":8,"failed":28},{"name":"global.wast","passed":51,"failed":59},{"name":"i32.wast","passed":85,"failed":375},{"name":"i64.wast","passed":31,"failed":385},{"name":"if.wast","passed":116,"failed":125},{"name":"imports.wast","passed":71,"failed":112},{"name":"inline-module.wast","passed":1,"failed":0},{"name":"int_exprs.wast","passed":38,"failed":70},{"name":"int_literals.wast","passed":25,"failed":26},{"name":"labels.wast","passed":13,"failed":16},{"name":"left-to-right.wast","passed":0,"failed":96},{"name":"linking.wast","passed":17,"failed":115},{"name":"load.wast","passed":59,"failed":38},{"name":"local_get.wast","passed":18,"failed":18},{"name":"local_set.wast","passed":38,"failed":15},{"name":"local_tee.wast","passed":41,"failed":56},{"name":"loop.wast","passed":42,"failed":78},{"name":"memory.wast","passed":34,"failed":45},{"name":"memory_grow.wast","passed":11,"failed":85},{"name":"memory_redundancy.wast","passed":1,"failed":7},{"name":"memory_size.wast","passed":6,"failed":36},{"name":"memory_trap.wast","passed":2,"failed":180},{"name":"names.wast","passed":485,"failed":1},{"name":"nop.wast","passed":4,"failed":84},{"name":"return.wast","passed":20,"failed":64},{"name":"select.wast","passed":28,"failed":120},{"name":"skip-stack-guard-page.wast","passed":1,"failed":10},{"name":"stack.wast","passed":2,"failed":5},{"name":"start.wast","passed":9,"failed":11},{"name":"store.wast","passed":59,"failed":9},{"name":"switch.wast","passed":2,"failed":26},{"name":"token.wast","passed":56,"failed":2},{"name":"traps.wast","passed":4,"failed":32},{"name":"type.wast","passed":3,"failed":0},{"name":"unreachable.wast","passed":0,"failed":64},{"name":"unreached-invalid.wast","passed":118,"failed":0},{"name":"unwind.wast","passed":9,"failed":41},{"name":"utf8-custom-section-id.wast","passed":176,"failed":0},{"name":"utf8-import-field.wast","passed":176,"failed":0},{"name":"utf8-import-module.wast","passed":176,"failed":0},{"name":"utf8-invalid-encoding.wast","passed":176,"failed":0}]
diff --git a/crates/tinywasm/tests/progress-mvp.svg b/crates/tinywasm/tests/progress-mvp.svg
index 71eab55..7ea5e5d 100644
--- a/crates/tinywasm/tests/progress-mvp.svg
+++ b/crates/tinywasm/tests/progress-mvp.svg
@@ -49,11 +49,11 @@ v0.0.5 (11135)
</text>
<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="648,345 648,350 "/>
<text x="875" y="355" dy="0.76em" text-anchor="middle" font-family="Victor Mono" font-size="12.096774193548388" opacity="1" fill="#000000">
-v0.0.6-alpha.0 (11200)
+v0.0.6-alpha.0 (11273)
</text>
<polyline fill="none" opacity="1" stroke="#000000" stroke-width="1" points="875,345 875,350 "/>
-<rect x="312" y="212" width="217" height="132" opacity="0.5" fill="#0000FF" stroke="none"/>
<rect x="85" y="212" width="217" height="132" opacity="0.5" fill="#0000FF" stroke="none"/>
+<rect x="312" y="212" width="217" height="132" opacity="0.5" fill="#0000FF" stroke="none"/>
+<rect x="767" y="183" width="217" height="161" opacity="0.5" fill="#0000FF" stroke="none"/>
<rect x="539" y="185" width="218" height="159" opacity="0.5" fill="#0000FF" stroke="none"/>
-<rect x="767" y="184" width="217" height="160" opacity="0.5" fill="#0000FF" stroke="none"/>
</svg>
diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs
index a6cf037..2e76ac5 100644
--- a/crates/types/src/lib.rs
+++ b/crates/types/src/lib.rs
@@ -26,9 +26,9 @@ extern crate alloc;
// }
mod instructions;
-use core::fmt::Debug;
+use core::{fmt::Debug, ops::Range};
-use alloc::{boxed::Box, string::String};
+use alloc::boxed::Box;
pub use instructions::*;
/// A TinyWasm WebAssembly Module
@@ -61,9 +61,13 @@ pub struct TinyWasmModule {
/// The memories of the WebAssembly module.
pub memory_types: Box<[MemoryType]>,
+
+ /// The imports of the WebAssembly module.
+ pub imports: Box<[Import]>,
+
+ /// Data segments of the WebAssembly module.
+ pub data: Box<[Data]>,
// pub elements: Option<ElementSectionReader<'a>>,
- // pub imports: Option<ImportSectionReader<'a>>,
- // pub data_segments: Option<DataSectionReader<'a>>,
}
/// A WebAssembly value.
@@ -337,9 +341,8 @@ pub enum MemoryArch {
#[derive(Debug, Clone)]
pub struct Import {
- /// Represents an import in a WebAssembly module.
- pub module: String,
- pub name: String,
+ pub module: Box<str>,
+ pub name: Box<str>,
pub kind: ImportKind,
}
@@ -350,3 +353,16 @@ pub enum ImportKind {
Mem(MemoryType),
Global(GlobalType),
}
+
+#[derive(Debug, Clone)]
+pub struct Data {
+ pub data: Box<[u8]>,
+ pub range: Range<usize>,
+ pub kind: DataKind,
+}
+
+#[derive(Debug, Clone)]
+pub enum DataKind {
+ Active { mem: MemAddr, offset: ConstInstruction },
+ Passive,
+}