summaryrefslogtreecommitdiff
path: root/crates/types/src
diff options
context:
space:
mode:
authorHenry Gressmann <mail@henrygressmann.de>2024-06-28 01:10:54 +0200
committerGitHub <noreply@github.com>2024-06-28 01:10:54 +0200
commit644395712a81c8f3fd56b6beafe9d3e09dfa9501 (patch)
tree15e1b62b7f96a56155d965daee0f3d4eef23fdee /crates/types/src
parentba1f2638d2979bcd86313f9429c48da22478adc8 (diff)
feat: compact value stack (#21)
Not fully done, but ready for the `next` branch now. This changes how values are represented internally, making this pr particularly large, as this touches most parts of the codebase. The parser should now also be ready for multithreaded compilation to speed this up a bit. --------- Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
Diffstat (limited to 'crates/types/src')
-rw-r--r--crates/types/src/instructions.rs66
-rw-r--r--crates/types/src/lib.rs11
2 files changed, 54 insertions, 23 deletions
diff --git a/crates/types/src/instructions.rs b/crates/types/src/instructions.rs
index d67ba83..d19326d 100644
--- a/crates/types/src/instructions.rs
+++ b/crates/types/src/instructions.rs
@@ -87,21 +87,20 @@ pub enum ConstInstruction {
#[rustfmt::skip]
pub enum Instruction {
// > Custom Instructions
- BrLabel(LabelAddr),
- // LocalGet + I32Const + I32Add
- I32LocalGetConstAdd(LocalAddr, i32),
- // LocalGet + I32Const + I32Store
- I32ConstStoreLocal { local: LocalAddr, const_i32: i32, offset: u32, mem_addr: u8 },
- // LocalGet + LocalGet + I32Store
- I32StoreLocal { local_a: LocalAddr, local_b: LocalAddr, offset: u32, mem_addr: u8 },
- // I64Xor + I64Const + I64RotL
- // Commonly used by a few crypto libraries
- I64XorConstRotl(i64),
- // LocalTee + LocalGet
- LocalTeeGet(LocalAddr, LocalAddr),
- LocalGet2(LocalAddr, LocalAddr),
- LocalGet3(LocalAddr, LocalAddr, LocalAddr),
- LocalGetSet(LocalAddr, LocalAddr),
+ // // LocalGet + I32Const + I32Add
+ // I32LocalGetConstAdd(LocalAddr, i32),
+ // // LocalGet + I32Const + I32Store
+ // I32ConstStoreLocal { local: LocalAddr, const_i32: i32, offset: u32, mem_addr: u8 },
+ // // LocalGet + LocalGet + I32Store
+ // I32StoreLocal { local_a: LocalAddr, local_b: LocalAddr, offset: u32, mem_addr: u8 },
+ // // I64Xor + I64Const + I64RotL
+ // // Commonly used by a few crypto libraries
+ // I64XorConstRotl(i64),
+ // // LocalTee + LocalGet
+ // LocalTeeGet(LocalAddr, LocalAddr),
+ // LocalGet2(LocalAddr, LocalAddr),
+ // LocalGet3(LocalAddr, LocalAddr, LocalAddr),
+ // LocalGetSet(LocalAddr, LocalAddr),
// > Control Instructions
// See <https://webassembly.github.io/spec/core/binary/instructions.html#control-instructions>
@@ -115,22 +114,45 @@ pub enum Instruction {
Br(LabelAddr),
BrIf(LabelAddr),
BrTable(BrTableDefault, BrTableLen), // has to be followed by multiple BrLabel instructions
+ BrLabel(LabelAddr),
Return,
Call(FuncAddr),
CallIndirect(TypeAddr, TableAddr),
-
+
// > Parametric Instructions
// See <https://webassembly.github.io/spec/core/binary/instructions.html#parametric-instructions>
- Drop,
- Select(Option<ValType>),
+ Drop32,
+ Drop64,
+ Drop128,
+ DropRef,
+
+ Select32,
+ Select64,
+ Select128,
+ SelectRef,
// > Variable Instructions
// See <https://webassembly.github.io/spec/core/binary/instructions.html#variable-instructions>
- LocalGet(LocalAddr),
- LocalSet(LocalAddr),
- LocalTee(LocalAddr),
+ LocalGet32(LocalAddr),
+ LocalGet64(LocalAddr),
+ LocalGet128(LocalAddr),
+ LocalGetRef(LocalAddr),
+
+ LocalSet32(LocalAddr),
+ LocalSet64(LocalAddr),
+ LocalSet128(LocalAddr),
+ LocalSetRef(LocalAddr),
+
+ LocalTee32(LocalAddr),
+ LocalTee64(LocalAddr),
+ LocalTee128(LocalAddr),
+ LocalTeeRef(LocalAddr),
+
GlobalGet(GlobalAddr),
- GlobalSet(GlobalAddr),
+ GlobalSet32(GlobalAddr),
+ GlobalSet64(GlobalAddr),
+ GlobalSet128(GlobalAddr),
+ GlobalSetRef(GlobalAddr),
// > Memory Instructions
I32Load { offset: u64, mem_addr: MemAddr },
diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs
index d447efb..785b13b 100644
--- a/crates/types/src/lib.rs
+++ b/crates/types/src/lib.rs
@@ -172,11 +172,20 @@ pub struct FuncType {
pub results: Box<[ValType]>,
}
+#[derive(Debug, Default, Clone, Copy, PartialEq)]
+#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))]
+pub struct LocalCounts {
+ pub local_32: u32,
+ pub local_64: u32,
+ pub local_128: u32,
+ pub local_ref: u32,
+}
+
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "archive", derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize), archive(check_bytes))]
pub struct WasmFunction {
pub instructions: Box<[Instruction]>,
- pub locals: Box<[ValType]>,
+ pub locals: LocalCounts,
pub ty: FuncType,
}