diff options
| author | Henry <mail@henrygressmann.de> | 2026-05-03 15:42:37 +0200 |
|---|---|---|
| committer | Henry <mail@henrygressmann.de> | 2026-05-03 15:42:37 +0200 |
| commit | 539167fa2665421a061a129f1650b727150d36a8 (patch) | |
| tree | 0c1f19535d1d122f4414b6199be1a6b4f1f98377 /crates/cli | |
| parent | 1a58b1c7cb550d16380e1249d25e894f524ff1be (diff) | |
chore: unify v128 representation
Signed-off-by: Henry <mail@henrygressmann.de>
Diffstat (limited to 'crates/cli')
| -rw-r--r-- | crates/cli/src/value_parse.rs | 5 | ||||
| -rw-r--r-- | crates/cli/src/wast_runner.rs | 8 |
2 files changed, 8 insertions, 5 deletions
diff --git a/crates/cli/src/value_parse.rs b/crates/cli/src/value_parse.rs index f64d335..f9ffbbb 100644 --- a/crates/cli/src/value_parse.rs +++ b/crates/cli/src/value_parse.rs @@ -17,7 +17,10 @@ fn parse_arg(index: usize, ty: WasmType, value: &str) -> Result<WasmValue> { WasmType::I64 => value.parse::<i64>().map(WasmValue::from).map_err(|e| format_error(index, ty, value, e))?, WasmType::F32 => value.parse::<f32>().map(WasmValue::from).map_err(|e| format_error(index, ty, value, e))?, WasmType::F64 => value.parse::<f64>().map(WasmValue::from).map_err(|e| format_error(index, ty, value, e))?, - WasmType::V128 => value.parse::<i128>().map(WasmValue::from).map_err(|e| format_error(index, ty, value, e))?, + WasmType::V128 => value + .parse::<i128>() + .map(|v| WasmValue::V128(v.to_le_bytes())) + .map_err(|e| format_error(index, ty, value, e))?, WasmType::RefFunc | WasmType::RefExtern => { bail!( "unsupported CLI argument type at position {}: {}; use the embedding API for reference values", diff --git a/crates/cli/src/wast_runner.rs b/crates/cli/src/wast_runner.rs index 8a759b7..9170dce 100644 --- a/crates/cli/src/wast_runner.rs +++ b/crates/cli/src/wast_runner.rs @@ -745,7 +745,7 @@ fn wastarg2tinywasmvalue(arg: wast::WastArg) -> Result<WasmValue> { F64(f) => WasmValue::F64(f64::from_bits(f.bits)), I32(i) => WasmValue::I32(i), I64(i) => WasmValue::I64(i), - V128(i) => WasmValue::V128(i128::from_le_bytes(i.to_le_bytes())), + V128(i) => WasmValue::V128(i.to_le_bytes()), RefExtern(v) => WasmValue::RefExtern(ExternRef::new(Some(v))), RefNull(t) => match t { wast::core::HeapType::Abstract { shared: false, ty: AbstractHeapType::Func } => { @@ -760,7 +760,7 @@ fn wastarg2tinywasmvalue(arg: wast::WastArg) -> Result<WasmValue> { }) } -fn wast_i128_to_i128(i: wast::core::V128Pattern) -> i128 { +fn wast_v128_to_bytes(i: wast::core::V128Pattern) -> [u8; 16] { let res: Vec<u8> = match i { wast::core::V128Pattern::F32x4(f) => { f.iter().flat_map(|v| nanpattern2tinywasmvalue(*v).unwrap().as_f32().unwrap().to_le_bytes()).collect() @@ -773,7 +773,7 @@ fn wast_i128_to_i128(i: wast::core::V128Pattern) -> i128 { wast::core::V128Pattern::I64x2(f) => f.iter().flat_map(|v| v.to_le_bytes()).collect(), wast::core::V128Pattern::I8x16(f) => f.iter().flat_map(|v| v.to_le_bytes()).collect(), }; - i128::from_le_bytes(res.try_into().unwrap()) + res.try_into().unwrap() } fn wastret2tinywasmvalues(ret: wast::WastRet) -> Result<Vec<WasmValue>> { @@ -793,7 +793,7 @@ fn wastretcore2tinywasmvalue(ret: wast::core::WastRetCore) -> Result<WasmValue> F64(f) => nanpattern2tinywasmvalue(f)?, I32(i) => WasmValue::I32(i), I64(i) => WasmValue::I64(i), - V128(i) => WasmValue::V128(wast_i128_to_i128(i)), + V128(i) => WasmValue::V128(wast_v128_to_bytes(i)), RefNull(t) => match t { Some(wast::core::HeapType::Abstract { shared: false, ty: AbstractHeapType::Func }) => { WasmValue::RefFunc(FuncRef::null()) |
