Skip to content

Commit

Permalink
Allow constructing V128 from byte array
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Dec 9, 2020
1 parent e1c9273 commit 2a374f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 1 addition & 3 deletions lib/compiler/src/translator/sections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,7 @@ pub fn parse_global_section(
Operator::I64Const { value } => GlobalInit::I64Const(value),
Operator::F32Const { value } => GlobalInit::F32Const(f32::from_bits(value.bits())),
Operator::F64Const { value } => GlobalInit::F64Const(f64::from_bits(value.bits())),
Operator::V128Const { value } => {
GlobalInit::V128Const(V128::from(value.bytes().to_vec().as_slice()))
}
Operator::V128Const { value } => GlobalInit::V128Const(V128::from(*value.bytes())),
Operator::RefNull { ty: _ } => GlobalInit::RefNullConst,
Operator::RefFunc { function_index } => {
GlobalInit::RefFunc(FunctionIndex::from_u32(function_index))
Expand Down
6 changes: 6 additions & 0 deletions lib/wasmer-types/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ impl V128 {
}
}

impl From<[u8; 16]> for V128 {
fn from(array: [u8; 16]) -> Self {
Self(array)
}
}

impl From<&[u8]> for V128 {
fn from(slice: &[u8]) -> Self {
assert_eq!(slice.len(), 16);
Expand Down

0 comments on commit 2a374f8

Please sign in to comment.