Skip to content

Commit e1d5020

Browse files
authored
Updated orca_wasm into wirm latest version (#300)
1 parent 194cd9e commit e1d5020

File tree

5 files changed

+87
-55
lines changed

5 files changed

+87
-55
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ too_many_arguments = 'allow'
1414
anyhow = { version = "1.0.95", default-features = false }
1515
heck = { version = "0.5", default-features = false }
1616
js-component-bindgen = { version = "1.11.0" }
17-
orca-wasm = { version = "0.9.2", default-features = false }
17+
wirm = { version = "2.1.0", default-features = false }
1818
rand = { version = "0.8", default-features = false }
19+
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
1920
wasm-encoder = { version = "0.227.1", features = [ "component-model", "std" ] }
20-
wasmparser = { version = "0.227.1", features = ["features",
21+
wasmparser = { version = "0.239.0", features = ["features",
2122
"component-model",
2223
"hash-collections",
2324
"serde",

crates/spidermonkey-embedding-splicer/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ anyhow = { workspace = true }
1616
clap = { version = "4.5.31", features = ["suggestions", "color", "derive"] }
1717
heck = { workspace = true }
1818
js-component-bindgen = { workspace = true, features = [ "transpile-bindgen" ] }
19-
orca-wasm = { workspace = true }
19+
wirm = { workspace = true }
2020
rand = { workspace = true }
21+
serde_json = { workspace = true }
2122
wasm-encoder = { workspace = true }
2223
wasmparser = { workspace = true }
2324
wit-bindgen = { workspace = true }

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

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
use std::path::PathBuf;
22

33
use anyhow::Result;
4-
use orca_wasm::ir::function::{FunctionBuilder, FunctionModifier};
5-
use orca_wasm::ir::id::{ExportsID, FunctionID, LocalID};
6-
use orca_wasm::ir::module::Module;
7-
use orca_wasm::ir::types::{BlockType, ElementItems, InstrumentationMode};
8-
use orca_wasm::module_builder::AddLocal;
9-
use orca_wasm::opcode::{Inject, InjectAt};
10-
use orca_wasm::{DataType, Opcode};
114
use wasm_encoder::{Encode, Section};
125
use wasmparser::ExternalKind;
136
use wasmparser::MemArg;
147
use wasmparser::Operator;
8+
use wirm::ir::function::{FunctionBuilder, FunctionModifier};
9+
use wirm::ir::id::{ExportsID, FunctionID, LocalID};
10+
use wirm::ir::module::Module;
11+
use wirm::ir::types::{BlockType, ElementItems, InstrumentationMode};
12+
use wirm::module_builder::AddLocal;
13+
use wirm::opcode::{Inject, InjectAt};
14+
use wirm::{DataType, Opcode};
1515
use wit_component::metadata::{decode, Bindgen};
1616
use wit_component::StringEncoding;
1717
use wit_parser::Resolve;
@@ -725,7 +725,7 @@ fn synthesize_import_functions(
725725

726726
// create imported function table
727727
let els = module.elements.iter_mut().next().unwrap();
728-
if let ElementItems::Functions(ref mut funcs) = &mut els.1 {
728+
if let ElementItems::Functions(ref mut funcs) = &mut els.items {
729729
for fid in import_fnids {
730730
funcs.push(fid);
731731
}
@@ -757,20 +757,25 @@ fn synthesize_import_functions(
757757
.get_fn_modifier(coreabi_get_import_fid)
758758
.unwrap();
759759

760-
// walk until we get to the const representing the table index
761-
let mut table_instr_idx = 0;
762-
for (idx, instr) in builder.body.instructions.iter_mut().enumerate() {
763-
if let Operator::I32Const { value: ref mut v } = instr.op {
764-
// we specifically need the const "around" 3393
765-
// which is the coreabi_sample_i32 table offset
766-
if *v < 1000 || *v > 5000 {
767-
continue;
760+
// Find the I32Const base index and compute the delta to new base
761+
let mut table_instr_idx = 0usize;
762+
let mut delta: i32 = 0;
763+
{
764+
let ops_ro = builder.body.instructions.get_ops();
765+
for (idx, op) in ops_ro.iter().enumerate() {
766+
if let Operator::I32Const { value } = op {
767+
// we specifically need the const "around" 3393
768+
// which is the coreabi_sample_i32 table offset
769+
if *value < 1000 || *value > 5000 {
770+
continue;
771+
}
772+
delta = import_fn_table_start_idx - *value;
773+
table_instr_idx = idx;
774+
break;
768775
}
769-
*v = import_fn_table_start_idx;
770-
table_instr_idx = idx;
771-
break;
772776
}
773777
}
778+
774779
builder.inject_at(
775780
table_instr_idx,
776781
InstrumentationMode::Before,
@@ -783,6 +788,17 @@ fn synthesize_import_functions(
783788
InstrumentationMode::Before,
784789
Operator::I32Add,
785790
);
791+
792+
if delta != 0 {
793+
builder
794+
.body
795+
.instructions
796+
.add_instr(table_instr_idx, Operator::I32Const { value: delta });
797+
builder
798+
.body
799+
.instructions
800+
.add_instr(table_instr_idx, Operator::I32Add);
801+
}
786802
}
787803

788804
// remove unnecessary exports

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ use std::path::PathBuf;
33
use std::time::{SystemTime, UNIX_EPOCH};
44

55
use anyhow::{bail, Result};
6-
use orca_wasm::ir::function::FunctionBuilder;
7-
use orca_wasm::ir::id::{FunctionID, LocalID};
8-
use orca_wasm::ir::module::module_functions::FuncKind;
9-
use orca_wasm::ir::types::{BlockType, InitExpr, Value};
10-
use orca_wasm::module_builder::AddLocal;
11-
use orca_wasm::{DataType, Instructions, Module, Opcode};
126
use wasmparser::{MemArg, TypeRef};
7+
use wirm::ir::function::FunctionBuilder;
8+
use wirm::ir::id::{FunctionID, LocalID};
9+
use wirm::ir::module::module_functions::FuncKind;
10+
use wirm::ir::types::{BlockType, InitExpr, Value};
11+
use wirm::module_builder::AddLocal;
12+
use wirm::{DataType, InitInstr, Module, Opcode};
1313
use wit_parser::Resolve;
1414

1515
use crate::parse_wit;
@@ -44,14 +44,14 @@ where
4444
};
4545

4646
let ty = module.types.get(ty_id).unwrap();
47-
let (params, results) = (ty.params().to_vec(), ty.results().to_vec());
48-
let mut builder = FunctionBuilder::new(params.as_slice(), results.as_slice());
47+
let mut builder = FunctionBuilder::new(ty.params().as_slice(), ty.results().as_slice());
4948
let _args = stub(&mut builder)?;
5049

5150
builder.replace_import_in_module(module, iid);
5251

5352
return Ok(Some(fid));
5453
}
54+
5555
Ok(None)
5656
}
5757

@@ -206,7 +206,7 @@ fn stub_random(module: &mut Module) -> Result<()> {
206206
// create a mutable random seed global
207207
let seed_val: i64 = 0;
208208
let seed_global = module.add_global(
209-
InitExpr::new(vec![Instructions::Value(Value::I64(seed_val))]),
209+
InitExpr::new(vec![InitInstr::Value(Value::I64(seed_val))]),
210210
DataType::I64,
211211
true,
212212
false,

0 commit comments

Comments
 (0)