From 7f72605405443482add128cb66b7d09e6bb59de9 Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Sat, 2 Dec 2023 23:50:14 +0100 Subject: feat: finish parser module, switch from tracing to log Signed-off-by: Henry Gressmann --- crates/types/Cargo.toml | 2 +- crates/types/src/instructions.rs | 6 +++--- crates/types/src/lib.rs | 7 ++++--- 3 files changed, 8 insertions(+), 7 deletions(-) (limited to 'crates/types') diff --git a/crates/types/Cargo.toml b/crates/types/Cargo.toml index fa2fc6e..e34c474 100644 --- a/crates/types/Cargo.toml +++ b/crates/types/Cargo.toml @@ -4,7 +4,7 @@ version="0.0.0" edition="2021" [dependencies] -tracing={version="0.1.38", default-features=false} # logging +log="0.4.20" rkyv={version="0.7", optional=true, default-features=false} [features] diff --git a/crates/types/src/instructions.rs b/crates/types/src/instructions.rs index 993b260..dca99fe 100644 --- a/crates/types/src/instructions.rs +++ b/crates/types/src/instructions.rs @@ -1,5 +1,4 @@ use super::{FuncAddr, GlobalAddr, LabelAddr, LocalAddr, TableAddr, TypeAddr, ValType}; -use alloc::{format, vec::Vec}; #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub enum BlockArgs { @@ -9,7 +8,7 @@ pub enum BlockArgs { } /// Represents a memory immediate in a WebAssembly memory instruction. -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct MemArg { pub align: u8, pub offset: u64, @@ -18,6 +17,7 @@ pub struct MemArg { /// A WebAssembly Instruction /// See https://webassembly.github.io/spec/core/binary/instructions.html /// Currently includes all instructions from the MVP (1.0) spec +#[derive(Debug, Clone, Copy, PartialEq)] pub enum Instruction { // Control Instructions // See https://webassembly.github.io/spec/core/binary/instructions.html#control-instructions @@ -30,7 +30,7 @@ pub enum Instruction { End, Br(LabelAddr), BrIf(LabelAddr), - BrTable(Vec, LabelAddr), // not to spec, instead of a vector of labels, we have a label and a count + BrTable(u32), // not to spec, has to be followed by multiple Br instructions with labels Return, Call(FuncAddr), CallIndirect(TypeAddr, TableAddr), diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index e793b26..af5cf1a 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -7,9 +7,9 @@ pub struct TinyWasmModule { pub version: Option, pub start_func: Option, - pub types: Option>, - pub funcs: Option>, - pub exports: Option>, + pub types: Box<[FuncType]>, + pub funcs: Box<[Function]>, + pub exports: Box<[Export]>, // pub tables: Option, // pub memories: Option, // pub globals: Option, @@ -98,6 +98,7 @@ pub struct FuncType { /// A WebAssembly Function pub struct Function { + pub ty: TypeAddr, pub locals: Box<[ValType]>, pub body: Box<[Instruction]>, } -- cgit v1.3.1