wasm_interp: neater creation of Value from unsigned integers

This commit is contained in:
Brian Carroll 2022-11-27 20:53:12 +00:00
parent f7dcd8f421
commit 78fbc75249
No known key found for this signature in database
GPG key ID: 5C7B2EC4101703C0
2 changed files with 21 additions and 18 deletions

View file

@ -721,6 +721,18 @@ impl Value {
}
}
impl From<u32> for Value {
fn from(x: u32) -> Self {
Value::I32(i32::from_ne_bytes(x.to_ne_bytes()))
}
}
impl From<u64> for Value {
fn from(x: u64) -> Self {
Value::I64(i64::from_ne_bytes(x.to_ne_bytes()))
}
}
/// Wasm memory alignment for load/store instructions.
/// Rust representation matches Wasm encoding.
/// It's an error to specify alignment higher than the "natural" alignment of the instruction