Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion crates/gen-c/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,6 @@ impl Bindgen for FunctionBindgen<'_> {
results
.push(format!("((union {{ float a; int32_t b; }}){{ {} }}).b", op));
}
Bitcast::F32ToF64 | Bitcast::F64ToF32 => results.push(op.to_string()),
Bitcast::I64ToF64 => {
results.push(format!(
"((union {{ int64_t a; double b; }}){{ {} }}).b",
Expand Down
1 change: 0 additions & 1 deletion crates/gen-js/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,6 @@ impl Bindgen for FunctionBindgen<'_> {
let cvt = self.gen.intrinsic(Intrinsic::F32ToI32);
results.push(format!("{}({})", cvt, op));
}
Bitcast::F32ToF64 | Bitcast::F64ToF32 => results.push(op.clone()),
Bitcast::I64ToF64 => {
let cvt = self.gen.intrinsic(Intrinsic::I64ToF64);
results.push(format!("{}({})", cvt, op));
Expand Down
2 changes: 0 additions & 2 deletions crates/gen-rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,11 +957,9 @@ pub fn bitcast(casts: &[Bitcast], operands: &[String], results: &mut Vec<String>
for (cast, operand) in casts.iter().zip(operands) {
results.push(match cast {
Bitcast::None => operand.clone(),
Bitcast::F32ToF64 => format!("f64::from({})", operand),
Bitcast::I32ToI64 => format!("i64::from({})", operand),
Bitcast::F32ToI32 => format!("({}).to_bits() as i32", operand),
Bitcast::F64ToI64 => format!("({}).to_bits() as i64", operand),
Bitcast::F64ToF32 => format!("{} as f32", operand),
Bitcast::I64ToI32 => format!("{} as i32", operand),
Bitcast::I32ToF32 => format!("f32::from_bits({} as u32)", operand),
Bitcast::I64ToF64 => format!("f64::from_bits({} as u64)", operand),
Expand Down
1 change: 0 additions & 1 deletion crates/gen-wasmtime-py/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,6 @@ impl Bindgen for FunctionBindgen<'_> {
self.gen.needs_f32_to_i32 = true;
results.push(format!("_f32_to_i32({})", op));
}
Bitcast::F32ToF64 | Bitcast::F64ToF32 => results.push(op.clone()),
Bitcast::I64ToF64 => {
self.gen.needs_i64_to_f64 = true;
results.push(format!("_i64_to_f64({})", op));
Expand Down
18 changes: 7 additions & 11 deletions crates/parser/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ pub enum WasmType {
// e.g. externref, so we don't need to define them here.
}

fn unify(a: WasmType, b: WasmType) -> WasmType {
fn join(a: WasmType, b: WasmType) -> WasmType {
use WasmType::*;

match (a, b) {
(I64, _) | (_, I64) | (I32, F64) | (F64, I32) => I64,
(I32, I32) | (I64, I64) | (F32, F32) | (F64, F64) => a,

(I32, I32) | (I32, F32) | (F32, I32) => I32,
(I32, F32) | (F32, I32) => I32,

(F32, F32) => F32,
(F64, F64) | (F32, F64) | (F64, F32) => F64,
(_, I64 | F64) | (I64 | F64, _) => I64,
}
}

Expand Down Expand Up @@ -638,14 +637,12 @@ def_instruction! {
#[derive(Debug, PartialEq)]
pub enum Bitcast {
// Upcasts
F32ToF64,
F32ToI32,
F64ToI64,
I32ToI64,
F32ToI64,

// Downcasts
F64ToF32,
I32ToF32,
I64ToF64,
I64ToI32,
Expand Down Expand Up @@ -893,7 +890,7 @@ impl Interface {

for (i, ty) in temp.drain(..).enumerate() {
match result.get_mut(start + i) {
Some(prev) => *prev = unify(*prev, ty),
Some(prev) => *prev = join(*prev, ty),
None => result.push(ty),
}
}
Expand Down Expand Up @@ -1846,17 +1843,16 @@ fn cast(from: WasmType, to: WasmType) -> Bitcast {
(I32, I32) | (I64, I64) | (F32, F32) | (F64, F64) => Bitcast::None,

(I32, I64) => Bitcast::I32ToI64,
(F32, F64) => Bitcast::F32ToF64,
(F32, I32) => Bitcast::F32ToI32,
(F64, I64) => Bitcast::F64ToI64,

(I64, I32) => Bitcast::I64ToI32,
(F64, F32) => Bitcast::F64ToF32,
(I32, F32) => Bitcast::I32ToF32,
(I64, F64) => Bitcast::I64ToF64,

(F32, I64) => Bitcast::F32ToI64,
(I64, F32) => Bitcast::I64ToF32,
(F64, I32) | (I32, F64) => unreachable!(),

(F32, F64) | (F64, F32) | (F64, I32) | (I32, F64) => unreachable!(),
}
}
2 changes: 1 addition & 1 deletion crates/wasmlink/tests/no-interface.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
(type (;0;) (func (param i32 i64 f32 f64) (result i32)))
(func (;0;) (type 0) (param i32 i64 f32 f64) (result i32)
unreachable)
(export "f1" (func 0)))
(export "f1" (func 0)))
2 changes: 1 addition & 1 deletion crates/wasmlink/tests/not-adapted.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
(type (;0;) (func (param i32 i64 f32 f64) (result i32)))
(func (;0;) (type 0) (param i32 i64 f32 f64) (result i32)
unreachable)
(export "f1" (func 0)))
(export "f1" (func 0)))
2 changes: 1 addition & 1 deletion crates/wasmlink/tests/retptr.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
i64.load (memory 1) offset=8
i64.store offset=8)
(export "memory" (memory 1))
(export "f1" (func 1)))
(export "f1" (func 1)))
6 changes: 5 additions & 1 deletion crates/wasmlink/tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@ fn wasmlink_file_tests() -> Result<()> {
let mut wit_path = path.clone();
assert!(wit_path.set_extension("wit"));

let output = match adapt(stem, &bytes, &wit_path) {
let mut output = match adapt(stem, &bytes, &wit_path) {
Ok(adapted) => print_bytes(&adapted.finish())?,
Err(e) => e.to_string(),
};

let baseline_path = path.with_extension("baseline");
if env::var_os("BLESS").is_some() {
if !output.ends_with("\n") {
output.push_str("\n");
}

fs::write(&baseline_path, output)?;
} else {
let expected = fs::read_to_string(&baseline_path)
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmlink/tests/string.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@
(export "memory" (memory 1))
(export "canonical_abi_realloc" (func 1))
(export "canonical_abi_free" (func 2))
(export "f1" (func 4)))
(export "f1" (func 4)))
8 changes: 4 additions & 4 deletions crates/wasmlink/tests/variants.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
(type (;2;) (func (param i32 i32)))
(type (;3;) (func (param i32 i32 i32)))
(type (;4;) (func (param i32 i32 i32 i32 i32 i32 i32 i32 f32 i32 i32 i32 i32 i32 i32)))
(type (;5;) (func (param i32 i32 i32 f64 i32 i64 i32 i64 i32 i64 i32 i32 i32 i32)))
(type (;5;) (func (param i32 i32 i32 i64 i32 i64 i32 i64 i32 i64 i32 i32 i32 i32)))
(type (;6;) (func (param i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32)))
(type (;7;) (func (param i32 i32 i32 i32) (result i32)))
(import "$parent" "memory" (memory (;0;) 0))
Expand All @@ -16,7 +16,7 @@
(type (;3;) (func (result i32)))
(type (;4;) (func (param i32 i32)))
(type (;5;) (func (param i32 i32 i32 i32 i32 i32 i32 i32 f32 i32 i32 i32 i32 i32 i32)))
(type (;6;) (func (param i32 i32 i32 f64 i32 i64 i32 i64 i32 i64 i32 i32 i32) (result i32)))
(type (;6;) (func (param i32 i32 i32 i64 i32 i64 i32 i64 i32 i64 i32 i32 i32) (result i32)))
(type (;7;) (func (param i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32)))
(func (;0;) (type 0) (param i32 i32 i32 i32) (result i32)
unreachable)
Expand All @@ -42,7 +42,7 @@
unreachable)
(func (;11;) (type 3) (result i32)
unreachable)
(func (;12;) (type 6) (param i32 i32 i32 f64 i32 i64 i32 i64 i32 i64 i32 i32 i32) (result i32)
(func (;12;) (type 6) (param i32 i32 i32 i64 i32 i64 i32 i64 i32 i64 i32 i32 i32) (result i32)
unreachable)
(func (;13;) (type 7) (param i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32)
unreachable)
Expand Down Expand Up @@ -269,7 +269,7 @@
local.get 1
i64.load (memory 1) offset=112
i64.store offset=112)
(func (;26;) (type 5) (param i32 i32 i32 f64 i32 i64 i32 i64 i32 i64 i32 i32 i32 i32)
(func (;26;) (type 5) (param i32 i32 i32 i64 i32 i64 i32 i64 i32 i64 i32 i32 i32 i32)
(local i32)
local.get 0
local.get 1
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmlink/tests/variants.wat
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
(func (export "option-result") (result i32)
unreachable
)
(func (export "casts") (param i32 i32 i32 f64 i32 i64 i32 i64 i32 i64 i32 i32 i32) (result i32)
(func (export "casts") (param i32 i32 i32 i64 i32 i64 i32 i64 i32 i64 i32 i32 i32) (result i32)
unreachable
)
(func (export "expected-arg") (param i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32)
Expand Down