Merge pull request #3102 from afonso360/fix-bool-trampolines
cranelift: Fix trampoline args for b1 types
This commit is contained in:
@@ -66,10 +66,18 @@ impl DataValue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return true if the value is a bool (i.e. `DataValue::B`).
|
||||||
|
pub fn is_bool(&self) -> bool {
|
||||||
|
match self {
|
||||||
|
DataValue::B(_) => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Write a [DataValue] to a memory location.
|
/// Write a [DataValue] to a memory location.
|
||||||
pub unsafe fn write_value_to(&self, p: *mut u128) {
|
pub unsafe fn write_value_to(&self, p: *mut u128) {
|
||||||
match self {
|
match self {
|
||||||
DataValue::B(b) => ptr::write(p as *mut bool, *b),
|
DataValue::B(b) => ptr::write(p, if *b { -1i128 as u128 } else { 0u128 }),
|
||||||
DataValue::I8(i) => ptr::write(p as *mut i8, *i),
|
DataValue::I8(i) => ptr::write(p as *mut i8, *i),
|
||||||
DataValue::I16(i) => ptr::write(p as *mut i16, *i),
|
DataValue::I16(i) => ptr::write(p as *mut i16, *i),
|
||||||
DataValue::I32(i) => ptr::write(p as *mut i32, *i),
|
DataValue::I32(i) => ptr::write(p as *mut i32, *i),
|
||||||
@@ -90,7 +98,7 @@ impl DataValue {
|
|||||||
types::I64 => DataValue::I64(ptr::read(p as *const i64)),
|
types::I64 => DataValue::I64(ptr::read(p as *const i64)),
|
||||||
types::F32 => DataValue::F32(ptr::read(p as *const Ieee32)),
|
types::F32 => DataValue::F32(ptr::read(p as *const Ieee32)),
|
||||||
types::F64 => DataValue::F64(ptr::read(p as *const Ieee64)),
|
types::F64 => DataValue::F64(ptr::read(p as *const Ieee64)),
|
||||||
_ if ty.is_bool() => DataValue::B(ptr::read(p as *const bool)),
|
_ if ty.is_bool() => DataValue::B(ptr::read(p) != 0),
|
||||||
_ if ty.is_vector() && ty.bytes() == 16 => {
|
_ if ty.is_vector() && ty.bytes() == 16 => {
|
||||||
DataValue::V128(ptr::read(p as *const [u8; 16]))
|
DataValue::V128(ptr::read(p as *const [u8; 16]))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,10 +90,8 @@ block2:
|
|||||||
; run: %brz_i8(-1) == false
|
; run: %brz_i8(-1) == false
|
||||||
|
|
||||||
|
|
||||||
; TODO: Merge this with brz_b1_false when we are able to pass bool imm's in test params
|
function %brz_b1(b1) -> b1 {
|
||||||
function %brz_b1_true() -> b1 {
|
block0(v1: b1):
|
||||||
block0:
|
|
||||||
v1 = bconst.b1 true
|
|
||||||
brz v1, block1
|
brz v1, block1
|
||||||
jump block2
|
jump block2
|
||||||
|
|
||||||
@@ -105,24 +103,8 @@ block2:
|
|||||||
v3 = bconst.b1 false
|
v3 = bconst.b1 false
|
||||||
return v3
|
return v3
|
||||||
}
|
}
|
||||||
; run: %brz_b1_true() == false
|
; run: %brz_b1(true) == false
|
||||||
|
; run: %brz_b1(false) == true
|
||||||
function %brz_b1_false() -> b1 {
|
|
||||||
block0:
|
|
||||||
v1 = bconst.b1 false
|
|
||||||
brz v1, block1
|
|
||||||
jump block2
|
|
||||||
|
|
||||||
block1:
|
|
||||||
v2 = bconst.b1 true
|
|
||||||
return v2
|
|
||||||
|
|
||||||
block2:
|
|
||||||
v3 = bconst.b1 false
|
|
||||||
return v3
|
|
||||||
}
|
|
||||||
; run: %brz_b1_false() == true
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function %brnz_i64(i64) -> b1 {
|
function %brnz_i64(i64) -> b1 {
|
||||||
@@ -194,10 +176,8 @@ block2:
|
|||||||
; run: %brnz_i8(-1) == true
|
; run: %brnz_i8(-1) == true
|
||||||
|
|
||||||
|
|
||||||
; TODO: Merge this with brz_b1_false when we are able to pass bool imm's in test params
|
function %brnz_b1(b1) -> b1 {
|
||||||
function %brnz_b1_true() -> b1 {
|
block0(v1: b1):
|
||||||
block0:
|
|
||||||
v1 = bconst.b1 true
|
|
||||||
brnz v1, block1
|
brnz v1, block1
|
||||||
jump block2
|
jump block2
|
||||||
|
|
||||||
@@ -209,20 +189,5 @@ block2:
|
|||||||
v3 = bconst.b1 false
|
v3 = bconst.b1 false
|
||||||
return v3
|
return v3
|
||||||
}
|
}
|
||||||
; run: %brnz_b1_true() == true
|
; run: %brnz_b1(true) == true
|
||||||
|
; run: %brnz_b1(false) == false
|
||||||
function %brnz_b1_false() -> b1 {
|
|
||||||
block0:
|
|
||||||
v1 = bconst.b1 false
|
|
||||||
brnz v1, block1
|
|
||||||
jump block2
|
|
||||||
|
|
||||||
block1:
|
|
||||||
v2 = bconst.b1 true
|
|
||||||
return v2
|
|
||||||
|
|
||||||
block2:
|
|
||||||
v3 = bconst.b1 false
|
|
||||||
return v3
|
|
||||||
}
|
|
||||||
; run: %brnz_b1_false() == false
|
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ impl UnboxedValues {
|
|||||||
// Store the argument values into `values_vec`.
|
// Store the argument values into `values_vec`.
|
||||||
for ((arg, slot), param) in arguments.iter().zip(&mut values_vec).zip(&signature.params) {
|
for ((arg, slot), param) in arguments.iter().zip(&mut values_vec).zip(&signature.params) {
|
||||||
assert!(
|
assert!(
|
||||||
arg.ty() == param.value_type || arg.is_vector(),
|
arg.ty() == param.value_type || arg.is_vector() || arg.is_bool(),
|
||||||
"argument type mismatch: {} != {}",
|
"argument type mismatch: {} != {}",
|
||||||
arg.ty(),
|
arg.ty(),
|
||||||
param.value_type
|
param.value_type
|
||||||
|
|||||||
Reference in New Issue
Block a user