summaryrefslogtreecommitdiff
path: root/crates/parser
diff options
context:
space:
mode:
authorHenry Gressmann <mail@henrygressmann.de>2024-03-09 13:51:32 +0100
committerHenry Gressmann <mail@henrygressmann.de>2024-03-09 13:51:32 +0100
commit735c7cb636edfd4704460c94a9c7d65e5bf4df48 (patch)
tree5b60de853a4bb62649d2d1ce4732bdfa49ce29fb /crates/parser
parentc50bae752f3e788faf66b376d065374cc4085931 (diff)
chore: improve documentation, tests
Closes #6 Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
Diffstat (limited to 'crates/parser')
-rw-r--r--crates/parser/src/conversion.rs8
-rw-r--r--crates/parser/src/lib.rs18
-rw-r--r--crates/parser/src/std.rs5
-rw-r--r--crates/parser/src/visit.rs8
4 files changed, 15 insertions, 24 deletions
diff --git a/crates/parser/src/conversion.rs b/crates/parser/src/conversion.rs
index c13d08f..ccdc308 100644
--- a/crates/parser/src/conversion.rs
+++ b/crates/parser/src/conversion.rs
@@ -187,6 +187,7 @@ pub(crate) fn convert_module_type(ty: wasmparser::RecGroup) -> Result<FuncType>
));
}
let ty = types.next().unwrap().unwrap_func();
+
let params =
ty.params().iter().map(|p| Ok(convert_valtype(p))).collect::<Result<Vec<ValType>>>()?.into_boxed_slice();
@@ -197,11 +198,10 @@ pub(crate) fn convert_module_type(ty: wasmparser::RecGroup) -> Result<FuncType>
}
pub(crate) fn convert_blocktype(blocktype: wasmparser::BlockType) -> BlockArgs {
- use wasmparser::BlockType::*;
match blocktype {
- Empty => BlockArgs::Empty,
- Type(ty) => BlockArgs::Type(convert_valtype(&ty)),
- FuncType(ty) => BlockArgs::FuncType(ty),
+ wasmparser::BlockType::Empty => BlockArgs::Empty,
+ wasmparser::BlockType::Type(ty) => BlockArgs::Type(convert_valtype(&ty)),
+ wasmparser::BlockType::FuncType(ty) => BlockArgs::FuncType(ty),
}
}
diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs
index 7beb5f8..5fb3c48 100644
--- a/crates/parser/src/lib.rs
+++ b/crates/parser/src/lib.rs
@@ -8,9 +8,11 @@
#![cfg_attr(not(feature = "std"), feature(error_in_core))]
//! See [`tinywasm`](https://docs.rs/tinywasm) for documentation.
-mod std;
extern crate alloc;
+#[cfg(feature = "std")]
+extern crate std;
+
// log for logging (optional).
#[cfg(feature = "logging")]
#[allow(clippy::single_component_path_imports)]
@@ -32,7 +34,7 @@ mod visit;
use alloc::{string::ToString, vec::Vec};
pub use error::*;
use module::ModuleReader;
-use tinywasm_types::{TypedWasmFunction, WasmFunction};
+use tinywasm_types::WasmFunction;
use wasmparser::{Validator, WasmFeatures};
pub use tinywasm_types::TinyWasmModule;
@@ -156,13 +158,10 @@ impl TryFrom<ModuleReader> for TinyWasmModule {
.code
.into_iter()
.zip(code_type_addrs)
- .map(|((instructions, locals), ty_idx)| TypedWasmFunction {
- type_addr: ty_idx,
- wasm_function: WasmFunction {
- instructions,
- locals,
- ty: reader.func_types.get(ty_idx as usize).expect("No func type for func, this is a bug").clone(),
- },
+ .map(|((instructions, locals), ty_idx)| WasmFunction {
+ instructions,
+ locals,
+ ty: reader.func_types.get(ty_idx as usize).expect("No func type for func, this is a bug").clone(),
})
.collect::<Vec<_>>();
@@ -175,7 +174,6 @@ impl TryFrom<ModuleReader> for TinyWasmModule {
globals: globals.into_boxed_slice(),
table_types: table_types.into_boxed_slice(),
imports: reader.imports.into_boxed_slice(),
- version: reader.version,
start_func: reader.start_func,
data: reader.data.into_boxed_slice(),
exports: reader.exports.into_boxed_slice(),
diff --git a/crates/parser/src/std.rs b/crates/parser/src/std.rs
deleted file mode 100644
index 16a7058..0000000
--- a/crates/parser/src/std.rs
+++ /dev/null
@@ -1,5 +0,0 @@
-#[cfg(feature = "std")]
-extern crate std;
-
-#[cfg(feature = "std")]
-pub(crate) use std::*;
diff --git a/crates/parser/src/visit.rs b/crates/parser/src/visit.rs
index cc9f0e2..b438fc1 100644
--- a/crates/parser/src/visit.rs
+++ b/crates/parser/src/visit.rs
@@ -10,7 +10,6 @@ struct ValidateThenVisit<'a, T, U>(T, &'a mut U);
macro_rules! validate_then_visit {
($( @$proposal:ident $op:ident $({ $($arg:ident: $argty:ty),* })? => $visit:ident)*) => {
$(
- #[inline]
fn $visit(&mut self $($(,$arg: $argty)*)?) -> Self::Output {
self.0.$visit($($($arg.clone()),*)?)?;
Ok(self.1.$visit($($($arg),*)?))
@@ -103,7 +102,7 @@ pub(crate) struct FunctionBuilder {
impl FunctionBuilder {
pub(crate) fn new(instr_capacity: usize) -> Self {
- Self { instructions: Vec::with_capacity(instr_capacity), label_ptrs: Vec::with_capacity(128) }
+ Self { instructions: Vec::with_capacity(instr_capacity), label_ptrs: Vec::with_capacity(256) }
}
#[cold]
@@ -391,7 +390,6 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder {
self.visit(Instruction::Else(0))
}
- #[inline]
fn visit_end(&mut self) -> Self::Output {
let Some(label_pointer) = self.label_ptrs.pop() else {
return self.visit(Instruction::EndFunc);
@@ -422,11 +420,11 @@ impl<'a> wasmparser::VisitOperator<'a> for FunctionBuilder {
*else_offset = (label_pointer - if_label_pointer)
.try_into()
- .expect("else_instr_end_offset is too large, tinywasm does not support blocks that large");
+ .expect("else_instr_end_offset is too large, tinywasm does not support blocks that large");
*end_offset = (current_instr_ptr - if_label_pointer)
.try_into()
- .expect("else_instr_end_offset is too large, tinywasm does not support blocks that large");
+ .expect("else_instr_end_offset is too large, tinywasm does not support blocks that large");
}
Instruction::Block(_, ref mut end_offset)
| Instruction::Loop(_, ref mut end_offset)