diff options
| author | Henry Gressmann <mail@henrygressmann.de> | 2023-12-13 17:38:39 +0100 |
|---|---|---|
| committer | Henry Gressmann <mail@henrygressmann.de> | 2023-12-13 17:38:39 +0100 |
| commit | 6e8ea78de0336bcbe8f1e3ef053b41d90a022b17 (patch) | |
| tree | 7d835110903a78ab6499145875477c4ccccd06bc /crates/types/src | |
| parent | 97fb3cc56442c4d831ef2c9e1599cc8105ff2b96 (diff) | |
feat: new new instruction types for blocks/ends
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
Diffstat (limited to 'crates/types/src')
| -rw-r--r-- | crates/types/src/instructions.rs | 19 |
1 files changed, 13 insertions, 6 deletions
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 <https://webassembly.github.io/spec/core/binary/instructions.html> #[derive(Debug, Clone, Copy, PartialEq)] @@ -33,11 +39,12 @@ pub enum Instruction { // See <https://webassembly.github.io/spec/core/binary/instructions.html#control-instructions> 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 |
