Skip to content

Commit bdb5c29

Browse files
chore: update wirm to 5.0.0
This updates wirm to 5.0.0 to re-enable the custom section deleting functionality
1 parent 05ff80b commit bdb5c29

6 files changed

Lines changed: 50 additions & 41 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ anyhow = { version = "1.0.95", default-features = false }
1515
heck = { version = "0.5", default-features = false }
1616
rand = { version = "0.8", default-features = false }
1717
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
18-
wirm = { version = "4.0.6", default-features = false }
18+
wirm = { version = "5.0.0", default-features = false }
1919

2020
wasm-encoder = { version = "0.245.1", features = ["component-model", "std"] }
2121
wasmparser = { version = "0.245.1", features = [

crates/spidermonkey-embedding-splicer/src/bindgen.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use wit_bindgen_core::wit_parser::{
1717
WorldId, WorldItem,
1818
};
1919
use wit_component::StringEncoding;
20+
use wit_parser::Param;
2021
use wit_parser::abi::WasmType;
2122
use wit_parser::abi::{AbiVariant, WasmSignature};
2223

@@ -771,7 +772,7 @@ impl JsBindgen<'_> {
771772

772773
fn create_resource_map(&self, func: &Function) -> ResourceMap {
773774
let mut resource_map = BTreeMap::new();
774-
for wit_parser::Param { ty, .. } in func.params.iter() {
775+
for Param { ty, .. } in func.params.iter() {
775776
self.iter_resources(ty, &mut resource_map);
776777
}
777778
if let Some(ty) = func.result {

crates/spidermonkey-embedding-splicer/src/splice.rs

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ use wirm::ir::module::module_globals::GlobalKind;
99
use wirm::ir::types::{BlockType, ElementItems, InitInstr, InstrumentationMode, Value};
1010
use wirm::module_builder::AddLocal;
1111
use wirm::opcode::{Inject, InjectAt};
12-
use wirm::wasmparser::MemArg;
13-
use wirm::wasmparser::Operator;
12+
use wirm::wasmparser::{ExternalKind, MemArg, Operator};
1413
use wirm::{DataType, Opcode};
1514
use wit_component::StringEncoding;
1615
use wit_component::metadata::{Bindgen, decode};
@@ -356,6 +355,15 @@ pub fn splice(
356355
);
357356
}
358357

358+
// we reencode the WASI world component data, so strip it out from the
359+
// custom section
360+
let maybe_component_section_id = module
361+
.custom_sections
362+
.get_id("component-type:bindings".to_string());
363+
if let Some(component_section_id) = maybe_component_section_id {
364+
module.delete_custom_section(component_section_id);
365+
}
366+
359367
// Extract the native instructions from sample functions
360368
// then inline the imported functions and main import gating function
361369
// (erasing sample functions in the process)
@@ -403,7 +411,7 @@ fn get_export_fid(module: &Module, expt_id: &ExportsID) -> FunctionID {
403411
let expt = module.exports.get_by_id(*expt_id).unwrap();
404412

405413
match expt.kind {
406-
wirm::wasmparser::ExternalKind::Func => FunctionID::from(expt.index),
414+
ExternalKind::Func => FunctionID::from(expt.index),
407415
_ => panic!("Missing coreabi_get_import"),
408416
}
409417
}
@@ -472,7 +480,7 @@ fn synthesize_import_functions(
472480
.unwrap();
473481

474482
// Sets the return value on args from the stack
475-
let args_ret_i32: Vec<wirm::wasmparser::Operator> = vec![
483+
let args_ret_i32: Vec<Operator> = vec![
476484
Operator::I64ExtendI32U,
477485
Operator::I64Const {
478486
value: -545460846592,
@@ -585,7 +593,7 @@ fn synthesize_import_functions(
585593
func.i32_add();
586594
match arg {
587595
CoreTy::I32 => {
588-
func.i64_load(wirm::wasmparser::MemArg {
596+
func.i64_load(MemArg {
589597
align: 3,
590598
max_align: 0,
591599
offset: 0,
@@ -598,7 +606,7 @@ fn synthesize_import_functions(
598606
}
599607
CoreTy::F32 => {
600608
// isInt: (r.asRawBits() >> 32) == 0xFFFFFF81
601-
func.i64_load(wirm::wasmparser::MemArg {
609+
func.i64_load(MemArg {
602610
align: 3,
603611
max_align: 0,
604612
offset: 0,
@@ -621,7 +629,7 @@ fn synthesize_import_functions(
621629
}
622630
CoreTy::F64 => {
623631
// isInt: (r.asRawBits() >> 32) == 0xFFFFFF81
624-
func.i64_load(wirm::wasmparser::MemArg {
632+
func.i64_load(MemArg {
625633
align: 3,
626634
max_align: 0,
627635
offset: 0,
@@ -687,7 +695,7 @@ fn synthesize_import_functions(
687695
func.i64_extend_i32_u();
688696
func.i64_const(-511101108224);
689697
func.i64_or();
690-
func.i64_store(wirm::wasmparser::MemArg {
698+
func.i64_store(MemArg {
691699
align: 3,
692700
max_align: 0,
693701
offset: 0,
@@ -696,15 +704,15 @@ fn synthesize_import_functions(
696704
}
697705
Some(CoreTy::F32) => {
698706
func.f64_promote_f32();
699-
func.f64_store(wirm::wasmparser::MemArg {
707+
func.f64_store(MemArg {
700708
align: 3,
701709
max_align: 0,
702710
offset: 0,
703711
memory,
704712
});
705713
}
706714
Some(CoreTy::F64) => {
707-
func.f64_store(wirm::wasmparser::MemArg {
715+
func.f64_store(MemArg {
708716
align: 3,
709717
max_align: 0,
710718
offset: 0,
@@ -776,7 +784,7 @@ fn synthesize_import_functions(
776784
builder.inject_at(
777785
0,
778786
InstrumentationMode::Before,
779-
wirm::wasmparser::Operator::LocalSet {
787+
Operator::LocalSet {
780788
local_index: *idx_local,
781789
},
782790
);
@@ -789,7 +797,7 @@ fn synthesize_import_functions(
789797
{
790798
let ops_ro = builder.body.instructions.get_ops();
791799
for (idx, op) in ops_ro.iter().enumerate() {
792-
if let wirm::wasmparser::Operator::I32Const { value } = op {
800+
if let Operator::I32Const { value } = op {
793801
// we specifically need the const "around" 3393
794802
// which is the coreabi_sample_i32 table offset
795803
if *value < 1000 || *value > 5000 {
@@ -800,8 +808,7 @@ fn synthesize_import_functions(
800808
// in the base computation.
801809
let mut base = *value;
802810
if idx > 0
803-
&& let wirm::wasmparser::Operator::GlobalGet { global_index } =
804-
&ops_ro[idx - 1]
811+
&& let Operator::GlobalGet { global_index } = &ops_ro[idx - 1]
805812
&& let GlobalKind::Local(local_global) =
806813
module.globals.get_kind(GlobalID(*global_index))
807814
&& let [InitInstr::Value(Value::I32(v))] =
@@ -819,25 +826,25 @@ fn synthesize_import_functions(
819826
builder.inject_at(
820827
table_instr_idx,
821828
InstrumentationMode::Before,
822-
wirm::wasmparser::Operator::LocalGet {
829+
Operator::LocalGet {
823830
local_index: *idx_local,
824831
},
825832
);
826833
builder.inject_at(
827834
table_instr_idx + 1,
828835
InstrumentationMode::Before,
829-
wirm::wasmparser::Operator::I32Add,
836+
Operator::I32Add,
830837
);
831838

832839
if delta != 0 {
833-
builder.body.instructions.add_instr(
834-
table_instr_idx,
835-
wirm::wasmparser::Operator::I32Const { value: delta },
836-
);
837840
builder
838841
.body
839842
.instructions
840-
.add_instr(table_instr_idx, wirm::wasmparser::Operator::I32Add);
843+
.add_instr(table_instr_idx, Operator::I32Const { value: delta });
844+
builder
845+
.body
846+
.instructions
847+
.add_instr(table_instr_idx, Operator::I32Add);
841848
}
842849
}
843850

@@ -948,7 +955,7 @@ fn synthesize_export_functions(module: &mut Module, exports: &[(String, CoreFn)]
948955
func.local_get(args[idx]);
949956
match param {
950957
CoreTy::I32 => {
951-
func.i32_store(wirm::wasmparser::MemArg {
958+
func.i32_store(MemArg {
952959
align: 2,
953960
max_align: 0,
954961
offset,
@@ -957,7 +964,7 @@ fn synthesize_export_functions(module: &mut Module, exports: &[(String, CoreFn)]
957964
offset += 4;
958965
}
959966
CoreTy::I64 => {
960-
func.i64_store(wirm::wasmparser::MemArg {
967+
func.i64_store(MemArg {
961968
align: 3,
962969
offset,
963970
memory,
@@ -966,7 +973,7 @@ fn synthesize_export_functions(module: &mut Module, exports: &[(String, CoreFn)]
966973
offset += 8;
967974
}
968975
CoreTy::F32 => {
969-
func.f32_store(wirm::wasmparser::MemArg {
976+
func.f32_store(MemArg {
970977
align: 2,
971978
max_align: 0,
972979
offset,
@@ -975,7 +982,7 @@ fn synthesize_export_functions(module: &mut Module, exports: &[(String, CoreFn)]
975982
offset += 4;
976983
}
977984
CoreTy::F64 => {
978-
func.f64_store(wirm::wasmparser::MemArg {
985+
func.f64_store(MemArg {
979986
align: 3,
980987
offset,
981988
memory,
@@ -1003,31 +1010,31 @@ fn synthesize_export_functions(module: &mut Module, exports: &[(String, CoreFn)]
10031010
// value type from the retptr
10041011
match expt_sig.ret.unwrap() {
10051012
CoreTy::I32 => {
1006-
func.i32_load(wirm::wasmparser::MemArg {
1013+
func.i32_load(MemArg {
10071014
align: 2,
10081015
max_align: 0,
10091016
offset: 0,
10101017
memory,
10111018
});
10121019
}
10131020
CoreTy::I64 => {
1014-
func.i64_load(wirm::wasmparser::MemArg {
1021+
func.i64_load(MemArg {
10151022
align: 3,
10161023
max_align: 0,
10171024
offset: 0,
10181025
memory,
10191026
});
10201027
}
10211028
CoreTy::F32 => {
1022-
func.f32_load(wirm::wasmparser::MemArg {
1029+
func.f32_load(MemArg {
10231030
align: 2,
10241031
max_align: 0,
10251032
offset: 0,
10261033
memory,
10271034
});
10281035
}
10291036
CoreTy::F64 => {
1030-
func.f64_load(wirm::wasmparser::MemArg {
1037+
func.f64_load(MemArg {
10311038
align: 3,
10321039
offset: 0,
10331040
memory,

crates/spidermonkey-embedding-splicer/src/stub_wasi.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use wirm::ir::id::{FunctionID, LocalID};
88
use wirm::ir::module::module_functions::FuncKind;
99
use wirm::ir::types::{BlockType, InitExpr, Value};
1010
use wirm::module_builder::AddLocal;
11+
use wirm::wasmparser::{MemArg, TypeRef};
1112
use wirm::{DataType, InitInstr, Module, Opcode};
1213
use wit_parser::Resolve;
1314

@@ -31,7 +32,7 @@ where
3132
continue;
3233
};
3334

34-
let wirm::wasmparser::TypeRef::Func(_) = module.imports.get(iid).ty else {
35+
let TypeRef::Func(_) = module.imports.get(iid).ty else {
3536
bail!("'{full_import}#{name}' is not a function.")
3637
};
3738
let fid: FunctionID = FunctionID(*iid);
@@ -74,7 +75,7 @@ where
7475
return Ok(None);
7576
};
7677

77-
let wirm::wasmparser::TypeRef::Func(_) = module.imports.get(iid).ty else {
78+
let TypeRef::Func(_) = module.imports.get(iid).ty else {
7879
bail!("'{import}#{name}' is not a function.")
7980
};
8081
let fid: FunctionID = FunctionID(*iid);
@@ -269,7 +270,7 @@ fn stub_random(module: &mut Module) -> Result<()> {
269270

270271
// *retptr = outptr
271272
// *retptr + 1 = len
272-
body.i32_store(wirm::wasmparser::MemArg {
273+
body.i32_store(MemArg {
273274
align: 2,
274275
max_align: 0,
275276
offset: 0,
@@ -279,7 +280,7 @@ fn stub_random(module: &mut Module) -> Result<()> {
279280
body.local_get(retptr);
280281
body.local_get(num_bytes);
281282
body.i32_wrap_i64();
282-
body.i32_store(wirm::wasmparser::MemArg {
283+
body.i32_store(MemArg {
283284
align: 2,
284285
max_align: 0,
285286
offset: 4,
@@ -294,7 +295,7 @@ fn stub_random(module: &mut Module) -> Result<()> {
294295
body.loop_stmt(BlockType::Empty);
295296
body.local_get(curptr);
296297
body.call(random_u64);
297-
body.i64_store(wirm::wasmparser::MemArg {
298+
body.i64_store(MemArg {
298299
align: 3,
299300
max_align: 0,
300301
offset: 0,
@@ -351,7 +352,7 @@ fn stub_clocks(module: &mut Module) -> Result<()> {
351352
body.local_get(time_ptr);
352353
body.local_get(time_ptr);
353354
body.i64_const(i64::try_from(unix_time.as_nanos())?);
354-
body.i64_store(wirm::wasmparser::MemArg {
355+
body.i64_store(MemArg {
355356
align: 3,
356357
offset: 0,
357358
max_align: 0,

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)