Workaround some missing encodings in cranelift

This commit is contained in:
bjorn3 2018-09-30 16:33:55 +02:00
parent 3965a65a79
commit 69fe4d6f92
3 changed files with 27 additions and 3 deletions

View File

@ -192,3 +192,7 @@ pub struct StrWrapper {
fn str_wrapper_get(w: &StrWrapper) -> &str {
&w.s
}
fn i16_as_i8(a: i16) -> i8 {
a as i8
}

View File

@ -158,6 +158,11 @@ fn verify_func(tcx: TyCtxt, writer: crate::pretty_clif::CommentWriter, func: &Fu
fn codegen_fn_content<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx, impl Backend>) {
for (bb, bb_data) in fx.mir.basic_blocks().iter_enumerated() {
if bb_data.is_cleanup {
// Unwinding after panicking is not supported
continue;
}
let ebb = fx.get_ebb(bb);
fx.bcx.switch_to_block(ebb);
@ -523,13 +528,27 @@ fn trans_stmt<'a, 'tcx: 'a>(
lval.write_cvalue(fx, CValue::ByVal(res, dest_layout));
}
(ty::Int(_), ty::Float(_)) => {
let from_ty = fx.cton_type(from_ty).unwrap();
let from = operand.load_value(fx);
// FIXME missing encoding for fcvt_from_sint.f32.i8
let from = if from_ty == types::I8 || from_ty == types::I16 {
fx.bcx.ins().sextend(types::I32, from)
} else {
from
};
let f_type = fx.cton_type(to_ty).unwrap();
let res = fx.bcx.ins().fcvt_from_sint(f_type, from);
lval.write_cvalue(fx, CValue::ByVal(res, dest_layout));
}
(ty::Uint(_), ty::Float(_)) => {
let from_ty = fx.cton_type(from_ty).unwrap();
let from = operand.load_value(fx);
// FIXME missing encoding for fcvt_from_uint.f32.i8
let from = if from_ty == types::I8 || from_ty == types::I16 {
fx.bcx.ins().uextend(types::I32, from)
} else {
from
};
let f_type = fx.cton_type(to_ty).unwrap();
let res = fx.bcx.ins().fcvt_from_uint(f_type, from);
lval.write_cvalue(fx, CValue::ByVal(res, dest_layout));

View File

@ -116,10 +116,11 @@ impl<'tcx> CValue<'tcx> {
size: layout.size.bytes() as u32,
offset: None,
});
fx.bcx.ins().stack_store(value, stack_slot, 0);
fx.bcx
let addr = fx.bcx
.ins()
.stack_addr(fx.module.pointer_type(), stack_slot, 0)
.stack_addr(fx.module.pointer_type(), stack_slot, 0);
fx.bcx.ins().store(MemFlags::new(), value, addr, 0);
addr
}
CValue::ByValPair(value, extra, layout) => {
let stack_slot = fx.bcx.create_stack_slot(StackSlotData {