Skip to content

Commit 3ba0bc0

Browse files
committed
Fixed CR comments
1 parent 26eccca commit 3ba0bc0

File tree

4 files changed

+16
-174
lines changed

4 files changed

+16
-174
lines changed

Cargo.lock

Lines changed: 0 additions & 52 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
@@ -14,7 +14,7 @@ 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-
wirm = { version = "2.1.0", features = ["parallel"] }
17+
wirm = { version = "2.1.0", default-features = false }
1818
rand = { version = "0.8", default-features = false }
1919
serde_json = { version = "1.0", default-features = false, features = ["alloc"] }
2020
wasm-encoder = { version = "0.227.1", features = [ "component-model", "std" ] }

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

Lines changed: 0 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -141,112 +141,8 @@ fn main() -> Result<()> {
141141
out_dir.join("initializer.js").display()
142142
)
143143
})?;
144-
145-
// Write exports and imports as JSON (manual serialization)
146-
let exports_json = serialize_exports(&result.exports);
147-
fs::write(out_dir.join("exports.json"), exports_json).with_context(|| {
148-
format!(
149-
"Failed to write exports file: {}",
150-
out_dir.join("exports.json").display()
151-
)
152-
})?;
153-
154-
let imports_json = serialize_imports(&result.imports);
155-
fs::write(out_dir.join("imports.json"), imports_json).with_context(|| {
156-
format!(
157-
"Failed to write imports file: {}",
158-
out_dir.join("imports.json").display()
159-
)
160-
})?;
161-
162-
println!(
163-
"Successfully generated bindings and saved to {}",
164-
out_dir.display()
165-
);
166144
}
167145
}
168146

169147
Ok(())
170148
}
171-
172-
/// Manually serialize exports to JSON
173-
fn serialize_exports(exports: &[(String, CoreFn)]) -> String {
174-
let mut result = String::from("[\n");
175-
for (i, (name, core_fn)) in exports.iter().enumerate() {
176-
if i > 0 {
177-
result.push_str(",\n");
178-
}
179-
result.push_str(" [\"");
180-
result.push_str(&name.replace('\\', "\\\\").replace('"', "\\\""));
181-
result.push_str("\", ");
182-
result.push_str(&serialize_core_fn(core_fn));
183-
result.push(']');
184-
}
185-
result.push_str("\n]");
186-
result
187-
}
188-
189-
/// Manually serialize imports to JSON
190-
fn serialize_imports(imports: &[(String, String, u32)]) -> String {
191-
let mut result = String::from("[\n");
192-
for (i, (specifier, name, arg_count)) in imports.iter().enumerate() {
193-
if i > 0 {
194-
result.push_str(",\n");
195-
}
196-
result.push_str(" [\"");
197-
result.push_str(&specifier.replace('\\', "\\\\").replace('"', "\\\""));
198-
result.push_str("\", \"");
199-
result.push_str(&name.replace('\\', "\\\\").replace('"', "\\\""));
200-
result.push_str("\", ");
201-
result.push_str(&arg_count.to_string());
202-
result.push(']');
203-
}
204-
result.push_str("\n]");
205-
result
206-
}
207-
208-
/// Manually serialize CoreFn to JSON
209-
fn serialize_core_fn(core_fn: &CoreFn) -> String {
210-
let mut result = String::from("{");
211-
212-
// params
213-
result.push_str("\"params\": [");
214-
for (i, param) in core_fn.params.iter().enumerate() {
215-
if i > 0 {
216-
result.push_str(", ");
217-
}
218-
result.push_str(&serialize_core_ty(param));
219-
}
220-
result.push_str("], ");
221-
222-
// ret
223-
result.push_str("\"ret\": ");
224-
if let Some(ref ret) = core_fn.ret {
225-
result.push_str(&serialize_core_ty(ret));
226-
} else {
227-
result.push_str("null");
228-
}
229-
result.push_str(", ");
230-
231-
// retptr
232-
result.push_str(&format!("\"retptr\": {}, ", core_fn.retptr));
233-
234-
// retsize
235-
result.push_str(&format!("\"retsize\": {}, ", core_fn.retsize));
236-
237-
// paramptr
238-
result.push_str(&format!("\"paramptr\": {}", core_fn.paramptr));
239-
240-
result.push('}');
241-
result
242-
}
243-
244-
/// Manually serialize CoreTy to JSON
245-
fn serialize_core_ty(core_ty: &CoreTy) -> String {
246-
match core_ty {
247-
CoreTy::I32 => "\"i32\"".to_string(),
248-
CoreTy::I64 => "\"i64\"".to_string(),
249-
CoreTy::F32 => "\"f32\"".to_string(),
250-
CoreTy::F64 => "\"f64\"".to_string(),
251-
}
252-
}

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use wirm::ir::id::{ExportsID, FunctionID, LocalID};
1010
use wirm::ir::module::Module;
1111
use wirm::ir::types::{BlockType, ElementItems, InstrumentationMode};
1212
use wirm::module_builder::AddLocal;
13-
use wirm::opcode::Inject;
13+
use wirm::opcode::{Inject, InjectAt};
1414
use wirm::{DataType, Opcode};
1515
use wit_component::metadata::{decode, Bindgen};
1616
use wit_component::StringEncoding;
@@ -775,11 +775,20 @@ fn synthesize_import_functions(
775775
}
776776
}
777777
}
778-
// Inject adjustments after the located instruction: add delta and add arg index
779-
builder
780-
.body
781-
.instructions
782-
.set_current_mode(table_instr_idx, InstrumentationMode::After);
778+
779+
builder.inject_at(
780+
table_instr_idx,
781+
InstrumentationMode::Before,
782+
Operator::LocalGet {
783+
local_index: *arg_idx,
784+
},
785+
);
786+
builder.inject_at(
787+
table_instr_idx + 1,
788+
InstrumentationMode::Before,
789+
Operator::I32Add,
790+
);
791+
783792
if delta != 0 {
784793
builder
785794
.body
@@ -790,17 +799,6 @@ fn synthesize_import_functions(
790799
.instructions
791800
.add_instr(table_instr_idx, Operator::I32Add);
792801
}
793-
builder.body.instructions.add_instr(
794-
table_instr_idx,
795-
Operator::LocalGet {
796-
local_index: *arg_idx,
797-
},
798-
);
799-
builder
800-
.body
801-
.instructions
802-
.add_instr(table_instr_idx, Operator::I32Add);
803-
builder.body.instructions.finish_instr(table_instr_idx);
804802
}
805803

806804
// remove unnecessary exports

0 commit comments

Comments
 (0)