summaryrefslogtreecommitdiff
path: root/crates/parser
diff options
context:
space:
mode:
Diffstat (limited to 'crates/parser')
-rw-r--r--crates/parser/Cargo.toml3
-rw-r--r--crates/parser/README.md19
2 files changed, 16 insertions, 6 deletions
diff --git a/crates/parser/Cargo.toml b/crates/parser/Cargo.toml
index 26bdd51..1c228c4 100644
--- a/crates/parser/Cargo.toml
+++ b/crates/parser/Cargo.toml
@@ -1,7 +1,7 @@
[package]
name="tinywasm-parser"
version.workspace=true
-description="TinyWasm parser"
+description="Parser and lowering pipeline for TinyWasm"
edition.workspace=true
license.workspace=true
authors.workspace=true
@@ -9,6 +9,7 @@ repository.workspace=true
rust-version.workspace=true
keywords.workspace=true
categories.workspace=true
+readme="README.md"
[dependencies]
wasmparser={workspace=true, features=["validate", "features", "simd"]}
diff --git a/crates/parser/README.md b/crates/parser/README.md
index c7eef8d..91145f1 100644
--- a/crates/parser/README.md
+++ b/crates/parser/README.md
@@ -1,20 +1,29 @@
# `tinywasm-parser`
-This crate provides a compiler that can convert WebAssembly modules into a `tinywasm` modules.
+This crate provides the parser and lowering pipeline that converts WebAssembly binaries into `tinywasm` modules.
## Features
- `std`: Enables the use of `std` and `std::io` for parsing from files and streams.
- `log`: Enables logging of the parsing process using the `log` crate.
+- `parallel`: Enables multithreaded parsing and validation when `std` is available.
## Usage
```rust
-use tinywasm_parser::Parser;
+use tinywasm_parser::{Parser, ParserOptions};
+
let bytes = include_bytes!("./file.wasm");
let parser = Parser::new();
-let module = parser.parse_module_bytes(bytes).unwrap();
-let module = parser.parse_module_file("path/to/file.wasm").unwrap();
-let module = parser.parse_module_stream(&mut stream).unwrap();
+let module = parser.parse_module_bytes(bytes)?;
+
+let parser = Parser::with_options(ParserOptions::default().with_rewrite_optimization(false));
+let module = parser.parse_module_bytes(bytes)?;
+
+let module = parser.parse_module_file("path/to/file.wasm")?;
+let mut stream = std::fs::File::open("path/to/file.wasm")?;
+let module = parser.parse_module_stream(&mut stream)?;
```
+
+If you just want the default configuration, the top-level `parse_bytes`, `parse_file`, and `parse_stream` helpers are thin wrappers around `Parser::new()`.