From 6e8ea78de0336bcbe8f1e3ef053b41d90a022b17 Mon Sep 17 00:00:00 2001 From: Henry Gressmann Date: Wed, 13 Dec 2023 17:38:39 +0100 Subject: feat: new new instruction types for blocks/ends Signed-off-by: Henry Gressmann --- crates/types/src/instructions.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'crates/types') diff --git a/crates/types/src/instructions.rs b/crates/types/src/instructions.rs index 6db5e6b..6f11817 100644 --- a/crates/types/src/instructions.rs +++ b/crates/types/src/instructions.rs @@ -16,12 +16,18 @@ pub struct MemArg { type BrTableDefault = u32; type BrTableLen = usize; +type EndOffset = usize; /// A WebAssembly Instruction /// /// These are our own internal bytecode instructions so they may not match the spec exactly. /// Wasm Bytecode can map to multiple of these instructions. -/// For example, `br_table` stores the jump lables in the following `br_label` instructions to keep this enum small. +/// +/// # Differences to the spec +/// * `br_table` stores the jump lables in the following `br_label` instructions to keep this enum small. +/// * Lables/Blocks: we store the label end offset in the instruction itself and +/// have seperate EndBlockFrame and EndFunc instructions to mark the end of a block or function. +/// This makes it easier to implement the label stack (we call it BlockFrameStack) iteratively. /// /// See #[derive(Debug, Clone, Copy, PartialEq)] @@ -33,11 +39,12 @@ pub enum Instruction { // See Unreachable, Nop, - Block(BlockArgs), - Loop(BlockArgs), - If(BlockArgs), - Else, - End, + Block(BlockArgs, EndOffset), + Loop(BlockArgs, EndOffset), + If(BlockArgs, EndOffset), + Else(EndOffset), + EndBlockFrame, + EndFunc, Br(LabelAddr), BrIf(LabelAddr), BrTable(BrTableDefault, BrTableLen), // has to be followed by multiple BrLabel instructions -- cgit v1.3.1