Improve panic/unreachable/unimplemented usage. Refactor a little.

This commit is contained in:
Nick Lewycky 2019-07-22 12:15:56 -07:00
parent 4535274cf3
commit 18307bb79c
7 changed files with 21 additions and 35 deletions

View File

@ -108,7 +108,7 @@ impl From<Converter<ir::Type>> for Type {
ir::types::F32 => Type::F32,
ir::types::F64 => Type::F64,
ir::types::I32X4 => Type::V128,
_ => panic!("unsupported wasm type"),
_ => unimplemented!("unsupported wasm type"),
}
}
}

View File

@ -111,12 +111,11 @@ fn trunc_sat(
// int_min or int_max.
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(
builder,
intrinsics,
ivec_ty
.get_element_type()
.into_int_type()
ivec_element_ty
.const_int(int_min_value, is_signed)
.as_basic_value_enum(),
ivec_ty,
@ -125,9 +124,7 @@ fn trunc_sat(
let int_max_value = splat_vector(
builder,
intrinsics,
ivec_ty
.get_element_type()
.into_int_type()
ivec_element_ty
.const_int(int_max_value, is_signed)
.as_basic_value_enum(),
ivec_ty,
@ -135,38 +132,26 @@ fn trunc_sat(
);
let lower_bound = if is_signed {
builder.build_signed_int_to_float(
ivec_ty
.get_element_type()
.into_int_type()
.const_int(lower_bound, is_signed),
ivec_element_ty.const_int(lower_bound, is_signed),
fvec_ty.get_element_type().into_float_type(),
"",
)
} else {
builder.build_unsigned_int_to_float(
ivec_ty
.get_element_type()
.into_int_type()
.const_int(lower_bound, is_signed),
ivec_element_ty.const_int(lower_bound, is_signed),
fvec_ty.get_element_type().into_float_type(),
"",
)
};
let upper_bound = if is_signed {
builder.build_signed_int_to_float(
ivec_ty
.get_element_type()
.into_int_type()
.const_int(upper_bound, is_signed),
ivec_element_ty.const_int(upper_bound, is_signed),
fvec_ty.get_element_type().into_float_type(),
"",
)
} else {
builder.build_unsigned_int_to_float(
ivec_ty
.get_element_type()
.into_int_type()
.const_int(upper_bound, is_signed),
ivec_element_ty.const_int(upper_bound, is_signed),
fvec_ty.get_element_type().into_float_type(),
"",
)
@ -3948,7 +3933,7 @@ impl FunctionCodeGenerator<CodegenError> for LLVMFunctionCodeGenerator {
Operator::I16x8AllTrue => intrinsics.i16x8_ty,
Operator::I32x4AllTrue => intrinsics.i32x4_ty,
Operator::I64x2AllTrue => intrinsics.i64x2_ty,
_ => panic!(),
_ => unreachable!(),
};
let v = state.pop1()?.into_int_value();
let lane_int_ty = context.custom_width_int_type(vec_ty.get_size());

View File

@ -402,7 +402,7 @@ pub unsafe extern "C" fn wasmer_export_func_call(
tag: wasmer_value_tag::WASM_F64,
value: wasmer_value { F64: x },
},
_ => panic!("not implemented"),
Value::V128(_) => unimplemented!("returning V128 type"),
};
results[0] = ret;
}

View File

@ -173,7 +173,7 @@ pub unsafe extern "C" fn wasmer_instance_call(
tag: wasmer_value_tag::WASM_F64,
value: wasmer_value { F64: x },
},
_ => panic!("not implemented"),
Value::V128(_) => unimplemented!("calling function with V128 parameter"),
};
results[0] = ret;
}

View File

@ -51,7 +51,7 @@ impl From<wasmer_value_t> for Value {
tag: wasmer_value_tag::WASM_F64,
value: wasmer_value { 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,
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::F32 => wasmer_value_tag::WASM_F32,
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_F32 => Type::F32,
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::F32 => wasmer_value_tag::WASM_F32,
Type::F64 => wasmer_value_tag::WASM_F64,
_ => panic!("not implemented"),
Type::V128 => unimplemented!("V128 not supported in C API"),
}
}
}

View File

@ -618,7 +618,7 @@ fn call_func_with_index(
Type::I64 => Value::I64(raw as i64),
Type::F32 => Value::F32(f32::from_bits(raw as u32)),
Type::F64 => Value::F64(f64::from_bits(raw)),
_ => unreachable!(),
Type::V128 => unreachable!("V128 does not map to any single value"),
};
match signature.returns() {

View File

@ -83,9 +83,10 @@ impl Instance for LocalInstance {
match args_u64.len() {
0 => (transmute::<_, extern "C" fn() -> u128>(addr))(),
1 => (transmute::<_, extern "C" fn(u64) -> u128>(addr))(args_u64[0]),
2 => {
(transmute::<_, extern "C" fn(u64, u64) -> u128>(addr))(args_u64[0], args_u64[1])
}
2 => (transmute::<_, extern "C" fn(u64, u64) -> u128>(addr))(
args_u64[0],
args_u64[1],
),
3 => (transmute::<_, extern "C" fn(u64, u64, u64) -> u128>(addr))(
args_u64[0],
args_u64[1],