Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
186 commits
Select commit Hold shift + click to select a range
c40e9c4
initial commit
Robbepop Aug 16, 2025
1842706
remove indoc dependency
Robbepop Aug 19, 2025
593836d
initial commit
Robbepop Aug 20, 2025
5fefcae
fix codegen for unary ops
Robbepop Aug 20, 2025
56aa708
add wasmi_ir2 crate contents
Robbepop Aug 20, 2025
541a258
rename files and Instruction -> Op
Robbepop Aug 20, 2025
bf03002
add codegen for binary ops
Robbepop Aug 20, 2025
4acf525
add cmp+branch ops codegen
Robbepop Aug 20, 2025
5fab8a4
add Copy and Clone impls for Op
Robbepop Aug 20, 2025
1505d45
add cmp+select ops codegen
Robbepop Aug 20, 2025
5e1dfcf
add load ops codegen
Robbepop Aug 20, 2025
c7187d8
fix load ops codegen
Robbepop Aug 20, 2025
1bd29bc
add DisplayIdent for LoadOp
Robbepop Aug 20, 2025
b9809fc
add Maybe utility type
Robbepop Aug 20, 2025
7103aca
add Display for Field
Robbepop Aug 20, 2025
54a6902
rename result_ident -> ident_prefix
Robbepop Aug 20, 2025
26dcf94
add DisplayIndented utility type
Robbepop Aug 20, 2025
b2dbb1c
remove unused code
Robbepop Aug 20, 2025
8fd2108
apply rustfmt
Robbepop Aug 20, 2025
ac26378
add store ops codegen
Robbepop Aug 20, 2025
9eaf2db
add missing unary and binary ops
Robbepop Aug 20, 2025
fa61ce8
fix codegen
Robbepop Aug 20, 2025
1a1e0d7
remove lots of unused code and imports
Robbepop Aug 20, 2025
2c26901
clean-up codegen a bit
Robbepop Aug 20, 2025
39ecb31
add reserve to Isa
Robbepop Aug 20, 2025
ea69a0d
generalize DisplayIndented -> DisplayPair
Robbepop Aug 21, 2025
f10dbcf
add GenericOp::new
Robbepop Aug 21, 2025
7e5704a
add control and copy ops to ISA
Robbepop Aug 21, 2025
f5446d8
add DisplaySequence utility
Robbepop Aug 21, 2025
496cfc8
add control and copy ops codegen
Robbepop Aug 21, 2025
51e238d
add GenericOp with 5 fields
Robbepop Aug 21, 2025
80291b7
add some table ops codegen
Robbepop Aug 21, 2025
8253a22
add From<GenericOp<N>> for Op impls
Robbepop Aug 21, 2025
af243ba
use new generic from impls
Robbepop Aug 21, 2025
2937694
change immediate index type of Table{Get,Set} to u32
Robbepop Aug 21, 2025
6f329ee
add remaining table ops codegen
Robbepop Aug 21, 2025
8a87480
add more from impls for Op
Robbepop Aug 21, 2025
1d9c6ef
define Op via macro
Robbepop Aug 21, 2025
a204dc3
add memory ops codegen
Robbepop Aug 21, 2025
3e8b85c
add size_of and align_of test for Op
Robbepop Aug 21, 2025
329cc95
use DisplaySequence in DisplayEnum<Isa> impl
Robbepop Aug 21, 2025
e766d5a
fix formatting issues in generated code
Robbepop Aug 21, 2025
2425d43
add call ops codegen
Robbepop Aug 21, 2025
fd96631
unsilence warnings and fix lots of warnings
Robbepop Aug 21, 2025
83ec4b2
add global ops codegen
Robbepop Aug 21, 2025
fb4390c
add ref.func op codegen
Robbepop Aug 21, 2025
926bac1
remove more unused code
Robbepop Aug 21, 2025
0fbfa18
remove unused input_ty method
Robbepop Aug 21, 2025
c6a97af
apply some clippy suggestions
Robbepop Aug 21, 2025
a353459
use into_maybe where applicable
Robbepop Aug 21, 2025
2c93265
refactor Maybe -> DisplayMaybe and put into display module
Robbepop Aug 21, 2025
3f59b39
replace DisplayPair with the more generic DisplayConcat
Robbepop Aug 21, 2025
f807a9d
move display.rs -> display/mod.rs
Robbepop Aug 21, 2025
cea6041
move Display utils into utils sub-module
Robbepop Aug 21, 2025
7456662
fix superflous newlines in codegen
Robbepop Aug 21, 2025
cc5bc1d
clean-up DisplayEnum<LoadOp> impl
Robbepop Aug 21, 2025
fafbb69
remove , from Field Display impl
Robbepop Aug 21, 2025
cb22a02
improve DisplayIdent impls
Robbepop Aug 21, 2025
85414fd
make DisplayIdent case aware
Robbepop Aug 21, 2025
8fbb8fd
move DisplayIdent into ident submodule
Robbepop Aug 21, 2025
f6662d0
add cased Sep (separator) display utility
Robbepop Aug 22, 2025
6c5cd0a
use new cased separator utilit in DisplayIdent
Robbepop Aug 22, 2025
b235651
add more return ops for returning single values
Robbepop Aug 22, 2025
ce3e07f
unsilence more warnings
Robbepop Aug 22, 2025
4671a8b
simplify DisplayEnum impl for UnaryOp
Robbepop Aug 22, 2025
bd31844
remove From impls from DisplayConcat
Robbepop Aug 22, 2025
088246f
no longer use raw identifiers in define_ident macro
Robbepop Aug 22, 2025
2dbcee0
add DisplayIdent<UnaryOp> impl and use it
Robbepop Aug 22, 2025
f895a80
fix warnings in wasmi_ir2
Robbepop Aug 22, 2025
1f16271
impl Display for DisplayIdent<BinaryOp> and use it
Robbepop Aug 22, 2025
070e0ab
add Display impl for DisplayIdent<CmpBranchOp>
Robbepop Aug 22, 2025
6cc3bd5
impl Display for DisplayIdent<CmpSelectOp>
Robbepop Aug 22, 2025
bb29969
implement DisplayIdent for the remaining ops
Robbepop Aug 23, 2025
4220e21
add BranchTable[Span] ops
Robbepop Aug 23, 2025
ecfe12c
rename len -> len_targets
Robbepop Aug 23, 2025
6621330
add wide-arithmetic ops codegen
Robbepop Aug 23, 2025
1da2118
allocate just once for contents
Robbepop Aug 23, 2025
5b9991c
use reserve_exact (since we know exactly how many ops)
Robbepop Aug 23, 2025
1dc8d66
make Field fields pub
Robbepop Aug 25, 2025
153aadd
move Field defs more to top
Robbepop Aug 25, 2025
5bb614d
add field getters to all op types
Robbepop Aug 25, 2025
8a1f73a
move Indent to utils submodule
Robbepop Aug 25, 2025
baa1cec
rename DisplayEnum -> DisplayOp
Robbepop Aug 25, 2025
3f6cb21
move DisplayOp impls into its own submodule
Robbepop Aug 25, 2025
62c0c43
fix GlobalSet ops fields
Robbepop Aug 25, 2025
01140ed
take reference for DisplayOp<Isa>
Robbepop Aug 25, 2025
eacc2ba
remove unused import
Robbepop Aug 25, 2025
dc46fca
add DisplayResultMut codegen
Robbepop Aug 25, 2025
869a90d
add fields methods to all ops
Robbepop Aug 26, 2025
e278bdb
use offset_field in DisplayOp<CmpBranchOp>
Robbepop Aug 26, 2025
4ca1e27
add Op constructor codegen
Robbepop Aug 26, 2025
773ddd5
add indent to DisplayOp codegen
Robbepop Aug 26, 2025
6e2650f
simplify DisplayOp via fields methods
Robbepop Aug 26, 2025
de136b6
remove DisplayOp::scoped utility
Robbepop Aug 26, 2025
f16feca
add separator field to DisplaySequence
Robbepop Aug 26, 2025
9ac2e0a
use new DisplaySequence separator
Robbepop Aug 26, 2025
ce7b350
fix intendation for Op type in codegen
Robbepop Aug 26, 2025
db1f116
add wasmi_ir2::{Encoder, Encode} traits and impls
Robbepop Aug 26, 2025
382998a
add OpCode enum codegen
Robbepop Aug 26, 2025
eb1acd0
add Encoder::encode_op_code and Encode impl for OpCode
Robbepop Aug 26, 2025
193f063
add From<OpCode> for u16 impl
Robbepop Aug 26, 2025
780aa20
add Encode impls for f{32,64} and NonZero<{u32,64}>
Robbepop Aug 26, 2025
b885522
add impl Encode for Op codegen
Robbepop Aug 26, 2025
7d320e9
reserve proper amount for contents
Robbepop Aug 26, 2025
987b2a3
generate encode.rs in its own file
Robbepop Aug 27, 2025
6a6a455
use Config instead of &Path
Robbepop Aug 27, 2025
f4dd769
add `simd` feature support and a demo simd copy128 op
Robbepop Aug 27, 2025
9d723ea
reduce amount of code generated for Encode impls
Robbepop Aug 27, 2025
28ed682
add u128 and i128 Encode impls
Robbepop Aug 27, 2025
3940455
apply clippy suggestions
Robbepop Aug 27, 2025
e9603b0
change/fix Encode impl for BoundedStackSpan
Robbepop Aug 27, 2025
7b5c26b
add trivial Offset16 from impl
Robbepop Aug 27, 2025
98a2ea1
make Sign::new crate public
Robbepop Aug 27, 2025
6086dab
add FixedStackSpan::new_unchecked constructor
Robbepop Aug 27, 2025
9ae7957
add Decode and Decoder traits and impls
Robbepop Aug 27, 2025
a0f5137
use Self where applicate in matchers
Robbepop Aug 27, 2025
8bc4db6
add decode codegen
Robbepop Aug 28, 2025
13848cd
add Encode impls for tuples
Robbepop Aug 28, 2025
ffcd62b
add generic Encode impl for &T
Robbepop Aug 28, 2025
c1aa506
drastically reduce codegen for Encode impls
Robbepop Aug 28, 2025
82924b9
inline crate re-exports
Robbepop Aug 28, 2025
dc4ef98
fix indentation of OpCode enum
Robbepop Aug 28, 2025
7c75d14
fix idents of some div/rem ops
Robbepop Aug 28, 2025
52cac2a
fix broken doc link
Robbepop Aug 28, 2025
b789102
move Input more to top of file
Robbepop Aug 29, 2025
ed49ba9
rename Input -> OperandKind
Robbepop Aug 29, 2025
eadc809
add v128.splat ops codegen
Robbepop Aug 29, 2025
475a383
apply clippy suggestion
Robbepop Aug 29, 2025
69fa547
fix invalid doc link
Robbepop Aug 29, 2025
537905b
use TrapCode and u8 conversions in wasmi_ir2
Robbepop Aug 29, 2025
1085222
rename V128Splat -> V128SplatOp
Robbepop Aug 29, 2025
74dd307
add Encode and Decode impls for ImmLaneIdx type
Robbepop Aug 29, 2025
607d798
add extract_lane simd ops codegen
Robbepop Aug 29, 2025
742a861
improve comment
Robbepop Aug 29, 2025
20d5f1a
add v128.replace_lane ops codegen
Robbepop Aug 29, 2025
005b815
deduplicate lots of code in build.rs
Robbepop Aug 30, 2025
ca9e17c
refactor and clean-up isa construction
Robbepop Aug 30, 2025
2277f8f
clean-up add_simd_replace_lane_ops
Robbepop Aug 30, 2025
8b5acd8
move add_simd_ops to top of simd construction
Robbepop Aug 30, 2025
7c476be
add Encode and Decode for arrays
Robbepop Aug 30, 2025
654f151
add more binary simd ops to isa
Robbepop Aug 30, 2025
ac00b98
rename val -> value
Robbepop Aug 30, 2025
2354ce1
reorder macro generated Op impls
Robbepop Aug 30, 2025
5b38f4c
generate code for DisplayOp for Op
Robbepop Aug 30, 2025
178ec01
refactor and clean-up ident_prefix queries
Robbepop Aug 30, 2025
4d5a127
add comments to signal splits
Robbepop Aug 30, 2025
253ee88
add binary simd ops codegen
Robbepop Aug 30, 2025
533d1cc
adjust expected generated file sizes
Robbepop Aug 30, 2025
07eac12
deduplicate codegen code
Robbepop Aug 30, 2025
fba95a9
apply rustfmt
Robbepop Aug 30, 2025
ca154fd
add simd shift ops codegen
Robbepop Aug 30, 2025
c870f16
add #[track_caller] for write_to_buffer
Robbepop Aug 30, 2025
3c5179c
add unary SIMD ops codegen
Robbepop Aug 30, 2025
db35ebf
rename UnaryOpKind::input_ty -> value_ty
Robbepop Aug 30, 2025
254a3b9
remove V128SplatOp and use UnaryOp instead + clean-ups
Robbepop Aug 30, 2025
5fec297
add partial v128.load ops codegen
Robbepop Sep 1, 2025
9f5a86f
refactor ReplaceLaneWidth -> LaneWidth
Robbepop Sep 1, 2025
463c9be
add V128LoadLane simd ops codegen
Robbepop Sep 1, 2025
1c703e9
dedup constructor codegen with macro
Robbepop Sep 2, 2025
e76033f
dedup encode codegen with macro
Robbepop Sep 2, 2025
cedcef9
dedup variant codegen with macro
Robbepop Sep 2, 2025
0713774
add StoreNLane simd ops codegen
Robbepop Sep 2, 2025
4d404ad
add relaxed-simd ops codegen
Robbepop Sep 2, 2025
4821995
rename submodule: token -> ident
Robbepop Sep 2, 2025
153fc82
apply clippy suggestion
Robbepop Sep 2, 2025
ffa4b44
rename [{Bounded,Fixed}]Stack[Span]: Stack -> Slot
Robbepop Sep 3, 2025
6f8c520
add TryFrom<u16> impl for OpCode
Robbepop Sep 3, 2025
1f19cce
add Decode impl for OpCode
Robbepop Sep 3, 2025
fd0dc76
split generated op.rs into op.rs and op_code.rs
Robbepop Sep 3, 2025
2a12454
add docs to Op and OpCode types
Robbepop Sep 3, 2025
cf1e604
fix codegen indentation
Robbepop Sep 3, 2025
30b9c2a
add missing f{32,64}.not_{lt,le} operators
Robbepop Sep 3, 2025
5cce09d
bump simd capacity requirements
Robbepop Sep 3, 2025
1547479
fix identifiers of select operators
Robbepop Sep 4, 2025
a74f09d
no longer generate icmp select instructions with lhs immediates
Robbepop Sep 4, 2025
170cff7
apply rustfmt
Robbepop Sep 4, 2025
2ea156d
fix Ident::NotEq snake case identifier
Robbepop Sep 4, 2025
3f7499e
fix ReturnSpan field
Robbepop Sep 4, 2025
f2ae148
reorder some CmpOpKind variants
Robbepop Sep 4, 2025
6b25566
remove unnecessary angle brackets
Robbepop Sep 4, 2025
e0fbbf8
simplify Encode impl for BoundedSlotSpan
Robbepop Sep 4, 2025
b4f0ec5
add proper Encode/Decode impls for FixedSlotSpan<N>
Robbepop Sep 4, 2025
069522c
add BranchTableTarget type
Robbepop Sep 4, 2025
5705e82
reorder macro parameters
Robbepop Sep 4, 2025
7c76b75
slightly simplify macro generated Encode impls
Robbepop Sep 4, 2025
0e1e32d
ignore coverage stats of wasmi_ir2 since it has not yet been integrated
Robbepop Sep 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"crates/wasmi",
"crates/wasi",
"crates/ir",
"crates/ir2",
"crates/fuzz",
"crates/wast",
"fuzz",
Expand All @@ -34,6 +35,7 @@ wasmi = { version = "0.51.0", path = "crates/wasmi", default-features = false }
wasmi_wasi = { version = "0.51.0", path = "crates/wasi", default-features = false }
wasmi_core = { version = "0.51.0", path = "crates/core", default-features = false }
wasmi_ir = { version = "0.51.0", path = "crates/ir", default-features = false }
wasmi_ir2 = { version = "0.51.0", path = "crates/ir2", default-features = false }
wasmi_collections = { version = "0.51.0", path = "crates/collections", default-features = false }
wasmi_c_api_impl = { version = "0.51.0", path = "crates/c_api" }
wasmi_c_api_macros = { version = "0.51.0", path = "crates/c_api/macro" }
Expand Down
9 changes: 9 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
coverage:
status:
project:
default:
target: auto
threshold: 1%

ignore:
- "crates/ir2/**"
32 changes: 32 additions & 0 deletions crates/ir2/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "wasmi_ir2"
version.workspace = true
rust-version.workspace = true
documentation = "https://docs.rs/wasmi_ir2/"
description = "WebAssembly interpreter internal bytecode representation"
authors.workspace = true
repository.workspace = true
edition.workspace = true
readme.workspace = true
license.workspace = true
keywords.workspace = true
categories.workspace = true
exclude = [
"benches/wat",
"benches/wasm",
"tests/spec/testsuite",
"**.wast",
]

[dependencies]
wasmi_core = { workspace = true }

[features]
default = ["std"]
std = [
"wasmi_core/std",
]
simd = ["wasmi_core/simd"]

[package.metadata.docs.rs]
features = ["std", "simd"]
32 changes: 32 additions & 0 deletions crates/ir2/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use self::build::Config;
use std::{fs, path::Path};

#[path = "build/mod.rs"]
mod build;

fn main() {
watch_dir_recursively(Path::new("build"));
let config = Config::default();
build::generate_code(&config).unwrap()
}

fn watch_dir_recursively(path: &Path) {
if !path.is_dir() {
return;
}
let entries = match fs::read_dir(path) {
Ok(entries) => entries,
Err(error) => panic!("failed to read directory: {error}"),
};
for entry in entries {
let entry = match entry {
Ok(entry) => entry,
Err(error) => panic!("failed to read directory entry: {error}"),
};
let path = entry.path();
if path.is_file() {
println!("cargo:rerun-if-changed={}", path.display());
}
watch_dir_recursively(&path);
}
}
119 changes: 119 additions & 0 deletions crates/ir2/build/display/constructors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
use crate::build::{
display::{ident::DisplayIdent, utils::DisplaySequence, Indent},
ident::SnakeCase,
isa::Isa,
op::{
BinaryOp,
CmpBranchOp,
CmpSelectOp,
Field,
GenericOp,
LoadOp,
StoreOp,
TableGetOp,
TableSetOp,
UnaryOp,
V128LoadLaneOp,
V128ReplaceLaneOp,
},
};
use core::fmt::{self, Display};

pub struct DisplayConstructor<T> {
pub value: T,
pub indent: Indent,
}

impl<T> DisplayConstructor<T> {
pub fn new(value: T, indent: Indent) -> Self {
Self { value, indent }
}

pub fn map<V>(&self, value: V) -> DisplayConstructor<V> {
DisplayConstructor {
value,
indent: self.indent,
}
}
}

impl<'a, T> DisplayConstructor<&'a T> {
fn display_constructor(&self, f: &mut fmt::Formatter, fields: &[Option<Field>]) -> fmt::Result
where
DisplayIdent<&'a T>: Display,
{
let indent = self.indent;
let snake_ident = DisplayIdent::snake(self.value);
let camel_ident = DisplayIdent::camel(self.value);
let fn_params = DisplaySequence::new(", ", fields.iter().filter_map(Option::as_ref));
let struct_params = DisplaySequence::new(
", ",
fields
.iter()
.filter_map(Option::as_ref)
.map(|param| param.ident)
.map(SnakeCase),
);
write!(
f,
"\
{indent}pub fn {snake_ident}({fn_params}) -> Self {{\n\
{indent} Self::{camel_ident} {{ {struct_params} }}\n\
{indent}}}\n\
"
)
}
}

impl Display for DisplayConstructor<&'_ Isa> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let indent = self.indent;
let variants = DisplaySequence::new(
"",
self.value
.ops
.iter()
.map(|op| DisplayConstructor::new(op, indent.inc_by(1))),
);
write!(
f,
"\
{indent}impl Op {{\n\
{variants}\
{indent}}}\n\
"
)
}
}

macro_rules! impl_display_constructor {
( $($ty:ty),* $(,)? ) => {
$(
impl Display for DisplayConstructor<&'_ $ty> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let fields = self.value.fields().map(Option::from);
self.display_constructor(f, &fields)
}
}
)*
};
}
impl_display_constructor! {
UnaryOp,
BinaryOp,
CmpBranchOp,
CmpSelectOp,
LoadOp,
StoreOp,
TableGetOp,
TableSetOp,
V128ReplaceLaneOp,
V128LoadLaneOp,
}

impl<const N: usize> Display for DisplayConstructor<&'_ GenericOp<N>> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let fields = self.value.fields.map(Option::from);
self.display_constructor(f, &fields)
}
}
Loading
Loading