This commit is contained in:
bjorn3 2018-09-08 17:24:52 +02:00
parent 252607ae41
commit 62a0203a5a
5 changed files with 28 additions and 22 deletions

View File

@ -194,7 +194,7 @@ static mut MY_TINY_HEAP: [u8; 16] = [0; 16];
#[lang = "exchange_malloc"]
unsafe fn allocate(size: usize, _align: usize) -> *mut u8 {
&mut MY_TINY_HEAP as *mut [u8; 16] as *mut u8
&mut MY_TINY_HEAP as *mut [u8; 16] as *mut u8
}
pub mod intrinsics {

View File

@ -90,7 +90,8 @@ pub fn cton_sig_from_fn_ty<'a, 'tcx: 'a>(
),
PassMode::ByRef => {
(
Some(pointer_ty(tcx)).into_iter() // First param is place to put return val
Some(pointer_ty(tcx)) // First param is place to put return val
.into_iter()
.chain(inputs)
.map(AbiParam::new)
.collect(),
@ -182,7 +183,9 @@ impl<'a, 'tcx: 'a, B: Backend + 'a> FunctionCx<'a, 'tcx, B> {
) -> Option<Value> {
let sig = Signature {
params: input_tys.iter().cloned().map(AbiParam::new).collect(),
returns: output_ty.map(|output_ty| vec![AbiParam::new(output_ty)]).unwrap_or(Vec::new()),
returns: output_ty
.map(|output_ty| vec![AbiParam::new(output_ty)])
.unwrap_or(Vec::new()),
call_conv: CallConv::SystemV,
};
let func_id = self
@ -606,7 +609,7 @@ fn codegen_intrinsic_call<'a, 'tcx: 'a>(
let len = args[0].load_value_pair(fx).1;
let elem_size = fx.layout_of(elem).size.bytes();
fx.bcx.ins().imul_imm(len, elem_size as i64)
},
}
ty => unimplemented!("size_of_val for {:?}", ty),
};
ret.write_cvalue(fx, CValue::ByVal(size, usize_layout));

View File

@ -23,7 +23,9 @@ pub fn trans_mono_item<'a, 'tcx: 'a>(
match inst.def {
InstanceDef::Item(_)
| InstanceDef::DropGlue(_, _)
| InstanceDef::Virtual(_, _) if inst.def_id().krate == LOCAL_CRATE => {
| InstanceDef::Virtual(_, _)
if inst.def_id().krate == LOCAL_CRATE =>
{
let mut mir = ::std::io::Cursor::new(Vec::new());
::rustc_mir::util::write_mir_pretty(tcx, Some(inst.def_id()), &mut mir)
.unwrap();
@ -35,8 +37,8 @@ pub fn trans_mono_item<'a, 'tcx: 'a>(
| InstanceDef::FnPtrShim(_, _)
| InstanceDef::ClosureOnceShim { .. }
| InstanceDef::CloneShim(_, _) => {
// FIXME fix write_mir_pretty for these instances
format!("{:#?}", tcx.instance_mir(inst.def))
// FIXME fix write_mir_pretty for these instances
format!("{:#?}", tcx.instance_mir(inst.def))
}
InstanceDef::Intrinsic(_) => bug!("tried to codegen intrinsic"),
}
@ -507,7 +509,9 @@ fn trans_stmt<'a, 'tcx: 'a>(
let def_id = match fx.tcx.lang_items().require(ExchangeMallocFnLangItem) {
Ok(id) => id,
Err(s) => {
fx.tcx.sess.fatal(&format!("allocation of `{}` {}", box_layout.ty, s));
fx.tcx
.sess
.fatal(&format!("allocation of `{}` {}", box_layout.ty, s));
}
};
let instance = ty::Instance::mono(fx.tcx, def_id);
@ -515,7 +519,7 @@ fn trans_stmt<'a, 'tcx: 'a>(
let call = fx.bcx.ins().call(func_ref, &[llsize, llalign]);
let ptr = fx.bcx.inst_results(call)[0];
lval.write_cvalue(fx, CValue::ByVal(ptr, box_layout));
},
}
Rvalue::NullaryOp(NullOp::SizeOf, ty) => {
assert!(
lval.layout()

View File

@ -143,16 +143,17 @@ impl<'tcx> CValue<'tcx> {
{
match self {
CValue::ByRef(addr, layout) => {
let cton_ty = fx
.cton_type(layout.ty)
.unwrap_or_else(|| {
if layout.ty.is_box() && !fx.layout_of(layout.ty.builtin_deref(true).unwrap().ty).is_unsized() {
// Consider sized box to be a ptr
pointer_ty(fx.tcx)
} else {
panic!("load_value of type {:?}", layout.ty);
}
});
let cton_ty = fx.cton_type(layout.ty).unwrap_or_else(|| {
if layout.ty.is_box() && !fx
.layout_of(layout.ty.builtin_deref(true).unwrap().ty)
.is_unsized()
{
// Consider sized box to be a ptr
pointer_ty(fx.tcx)
} else {
panic!("load_value of type {:?}", layout.ty);
}
});
fx.bcx.ins().load(cton_ty, MemFlags::new(), addr, 0)
}
CValue::ByVal(value, _layout) => value,

View File

@ -82,9 +82,7 @@ mod prelude {
};
pub use cranelift::codegen::Context;
pub use cranelift::prelude::*;
pub use cranelift_module::{
Backend, DataContext, DataId, FuncId, Linkage, Module,
};
pub use cranelift_module::{Backend, DataContext, DataId, FuncId, Linkage, Module};
pub use cranelift_simplejit::{SimpleJITBackend, SimpleJITBuilder};
pub use crate::abi::*;