mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-19 11:51:22 +00:00
Improve panic/unreachable/unimplemented usage. Refactor a little.
This commit is contained in:
@ -108,7 +108,7 @@ impl From<Converter<ir::Type>> for Type {
|
|||||||
ir::types::F32 => Type::F32,
|
ir::types::F32 => Type::F32,
|
||||||
ir::types::F64 => Type::F64,
|
ir::types::F64 => Type::F64,
|
||||||
ir::types::I32X4 => Type::V128,
|
ir::types::I32X4 => Type::V128,
|
||||||
_ => panic!("unsupported wasm type"),
|
_ => unimplemented!("unsupported wasm type"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,12 +111,11 @@ fn trunc_sat(
|
|||||||
// int_min or int_max.
|
// int_min or int_max.
|
||||||
|
|
||||||
let is_signed = int_min_value != 0;
|
let is_signed = int_min_value != 0;
|
||||||
|
let ivec_element_ty = ivec_ty.get_element_type().into_int_type();
|
||||||
let int_min_value = splat_vector(
|
let int_min_value = splat_vector(
|
||||||
builder,
|
builder,
|
||||||
intrinsics,
|
intrinsics,
|
||||||
ivec_ty
|
ivec_element_ty
|
||||||
.get_element_type()
|
|
||||||
.into_int_type()
|
|
||||||
.const_int(int_min_value, is_signed)
|
.const_int(int_min_value, is_signed)
|
||||||
.as_basic_value_enum(),
|
.as_basic_value_enum(),
|
||||||
ivec_ty,
|
ivec_ty,
|
||||||
@ -125,9 +124,7 @@ fn trunc_sat(
|
|||||||
let int_max_value = splat_vector(
|
let int_max_value = splat_vector(
|
||||||
builder,
|
builder,
|
||||||
intrinsics,
|
intrinsics,
|
||||||
ivec_ty
|
ivec_element_ty
|
||||||
.get_element_type()
|
|
||||||
.into_int_type()
|
|
||||||
.const_int(int_max_value, is_signed)
|
.const_int(int_max_value, is_signed)
|
||||||
.as_basic_value_enum(),
|
.as_basic_value_enum(),
|
||||||
ivec_ty,
|
ivec_ty,
|
||||||
@ -135,38 +132,26 @@ fn trunc_sat(
|
|||||||
);
|
);
|
||||||
let lower_bound = if is_signed {
|
let lower_bound = if is_signed {
|
||||||
builder.build_signed_int_to_float(
|
builder.build_signed_int_to_float(
|
||||||
ivec_ty
|
ivec_element_ty.const_int(lower_bound, is_signed),
|
||||||
.get_element_type()
|
|
||||||
.into_int_type()
|
|
||||||
.const_int(lower_bound, is_signed),
|
|
||||||
fvec_ty.get_element_type().into_float_type(),
|
fvec_ty.get_element_type().into_float_type(),
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
builder.build_unsigned_int_to_float(
|
builder.build_unsigned_int_to_float(
|
||||||
ivec_ty
|
ivec_element_ty.const_int(lower_bound, is_signed),
|
||||||
.get_element_type()
|
|
||||||
.into_int_type()
|
|
||||||
.const_int(lower_bound, is_signed),
|
|
||||||
fvec_ty.get_element_type().into_float_type(),
|
fvec_ty.get_element_type().into_float_type(),
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
let upper_bound = if is_signed {
|
let upper_bound = if is_signed {
|
||||||
builder.build_signed_int_to_float(
|
builder.build_signed_int_to_float(
|
||||||
ivec_ty
|
ivec_element_ty.const_int(upper_bound, is_signed),
|
||||||
.get_element_type()
|
|
||||||
.into_int_type()
|
|
||||||
.const_int(upper_bound, is_signed),
|
|
||||||
fvec_ty.get_element_type().into_float_type(),
|
fvec_ty.get_element_type().into_float_type(),
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
builder.build_unsigned_int_to_float(
|
builder.build_unsigned_int_to_float(
|
||||||
ivec_ty
|
ivec_element_ty.const_int(upper_bound, is_signed),
|
||||||
.get_element_type()
|
|
||||||
.into_int_type()
|
|
||||||
.const_int(upper_bound, is_signed),
|
|
||||||
fvec_ty.get_element_type().into_float_type(),
|
fvec_ty.get_element_type().into_float_type(),
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
@ -3948,7 +3933,7 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
|
|||||||
Operator::I16x8AllTrue => intrinsics.i16x8_ty,
|
Operator::I16x8AllTrue => intrinsics.i16x8_ty,
|
||||||
Operator::I32x4AllTrue => intrinsics.i32x4_ty,
|
Operator::I32x4AllTrue => intrinsics.i32x4_ty,
|
||||||
Operator::I64x2AllTrue => intrinsics.i64x2_ty,
|
Operator::I64x2AllTrue => intrinsics.i64x2_ty,
|
||||||
_ => panic!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
let v = state.pop1()?.into_int_value();
|
let v = state.pop1()?.into_int_value();
|
||||||
let lane_int_ty = context.custom_width_int_type(vec_ty.get_size());
|
let lane_int_ty = context.custom_width_int_type(vec_ty.get_size());
|
||||||
|
@ -402,7 +402,7 @@ pub unsafe extern "C" fn wasmer_export_func_call(
|
|||||||
tag: wasmer_value_tag::WASM_F64,
|
tag: wasmer_value_tag::WASM_F64,
|
||||||
value: wasmer_value { F64: x },
|
value: wasmer_value { F64: x },
|
||||||
},
|
},
|
||||||
_ => panic!("not implemented"),
|
Value::V128(_) => unimplemented!("returning V128 type"),
|
||||||
};
|
};
|
||||||
results[0] = ret;
|
results[0] = ret;
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ pub unsafe extern "C" fn wasmer_instance_call(
|
|||||||
tag: wasmer_value_tag::WASM_F64,
|
tag: wasmer_value_tag::WASM_F64,
|
||||||
value: wasmer_value { F64: x },
|
value: wasmer_value { F64: x },
|
||||||
},
|
},
|
||||||
_ => panic!("not implemented"),
|
Value::V128(_) => unimplemented!("calling function with V128 parameter"),
|
||||||
};
|
};
|
||||||
results[0] = ret;
|
results[0] = ret;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ impl From<wasmer_value_t> for Value {
|
|||||||
tag: wasmer_value_tag::WASM_F64,
|
tag: wasmer_value_tag::WASM_F64,
|
||||||
value: wasmer_value { F64 },
|
value: wasmer_value { F64 },
|
||||||
} => Value::F64(F64),
|
} => Value::F64(F64),
|
||||||
_ => panic!("not implemented"),
|
_ => unreachable!("unknown WASM type"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,7 +76,7 @@ impl From<Value> for wasmer_value_t {
|
|||||||
tag: wasmer_value_tag::WASM_F64,
|
tag: wasmer_value_tag::WASM_F64,
|
||||||
value: wasmer_value { F64: x },
|
value: wasmer_value { F64: x },
|
||||||
},
|
},
|
||||||
_ => panic!("not implemented"),
|
Value::V128(_) => unimplemented!("V128 not supported in C API"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -89,7 +89,7 @@ impl From<Type> for wasmer_value_tag {
|
|||||||
Type::I64 => wasmer_value_tag::WASM_I64,
|
Type::I64 => wasmer_value_tag::WASM_I64,
|
||||||
Type::F32 => wasmer_value_tag::WASM_F32,
|
Type::F32 => wasmer_value_tag::WASM_F32,
|
||||||
Type::F64 => wasmer_value_tag::WASM_F64,
|
Type::F64 => wasmer_value_tag::WASM_F64,
|
||||||
_ => panic!("not implemented"),
|
Type::V128 => unreachable!("V128 not supported in C API"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -102,7 +102,7 @@ impl From<wasmer_value_tag> for Type {
|
|||||||
wasmer_value_tag::WASM_I64 => Type::I64,
|
wasmer_value_tag::WASM_I64 => Type::I64,
|
||||||
wasmer_value_tag::WASM_F32 => Type::F32,
|
wasmer_value_tag::WASM_F32 => Type::F32,
|
||||||
wasmer_value_tag::WASM_F64 => Type::F64,
|
wasmer_value_tag::WASM_F64 => Type::F64,
|
||||||
_ => panic!("not implemented"),
|
_ => unreachable!("unknown WASM type"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -114,7 +114,7 @@ impl From<&wasmer_runtime::wasm::Type> for wasmer_value_tag {
|
|||||||
Type::I64 => wasmer_value_tag::WASM_I64,
|
Type::I64 => wasmer_value_tag::WASM_I64,
|
||||||
Type::F32 => wasmer_value_tag::WASM_F32,
|
Type::F32 => wasmer_value_tag::WASM_F32,
|
||||||
Type::F64 => wasmer_value_tag::WASM_F64,
|
Type::F64 => wasmer_value_tag::WASM_F64,
|
||||||
_ => panic!("not implemented"),
|
Type::V128 => unimplemented!("V128 not supported in C API"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -618,7 +618,7 @@ fn call_func_with_index(
|
|||||||
Type::I64 => Value::I64(raw as i64),
|
Type::I64 => Value::I64(raw as i64),
|
||||||
Type::F32 => Value::F32(f32::from_bits(raw as u32)),
|
Type::F32 => Value::F32(f32::from_bits(raw as u32)),
|
||||||
Type::F64 => Value::F64(f64::from_bits(raw)),
|
Type::F64 => Value::F64(f64::from_bits(raw)),
|
||||||
_ => unreachable!(),
|
Type::V128 => unreachable!("V128 does not map to any single value"),
|
||||||
};
|
};
|
||||||
|
|
||||||
match signature.returns() {
|
match signature.returns() {
|
||||||
|
@ -83,9 +83,10 @@ impl Instance for LocalInstance {
|
|||||||
match args_u64.len() {
|
match args_u64.len() {
|
||||||
0 => (transmute::<_, extern "C" fn() -> u128>(addr))(),
|
0 => (transmute::<_, extern "C" fn() -> u128>(addr))(),
|
||||||
1 => (transmute::<_, extern "C" fn(u64) -> u128>(addr))(args_u64[0]),
|
1 => (transmute::<_, extern "C" fn(u64) -> u128>(addr))(args_u64[0]),
|
||||||
2 => {
|
2 => (transmute::<_, extern "C" fn(u64, u64) -> u128>(addr))(
|
||||||
(transmute::<_, extern "C" fn(u64, u64) -> u128>(addr))(args_u64[0], args_u64[1])
|
args_u64[0],
|
||||||
}
|
args_u64[1],
|
||||||
|
),
|
||||||
3 => (transmute::<_, extern "C" fn(u64, u64, u64) -> u128>(addr))(
|
3 => (transmute::<_, extern "C" fn(u64, u64, u64) -> u128>(addr))(
|
||||||
args_u64[0],
|
args_u64[0],
|
||||||
args_u64[1],
|
args_u64[1],
|
||||||
|
Reference in New Issue
Block a user