1
Fork 0
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"] #[lang = "exchange_malloc"]
unsafe fn allocate(size: usize, _align: usize) -> *mut u8 { 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 { pub mod intrinsics {

View file

@ -90,7 +90,8 @@ pub fn cton_sig_from_fn_ty<'a, 'tcx: 'a>(
), ),
PassMode::ByRef => { 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) .chain(inputs)
.map(AbiParam::new) .map(AbiParam::new)
.collect(), .collect(),
@ -182,7 +183,9 @@ impl<'a, 'tcx: 'a, B: Backend + 'a> FunctionCx<'a, 'tcx, B> {
) -> Option<Value> { ) -> Option<Value> {
let sig = Signature { let sig = Signature {
params: input_tys.iter().cloned().map(AbiParam::new).collect(), 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, call_conv: CallConv::SystemV,
}; };
let func_id = self 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 len = args[0].load_value_pair(fx).1;
let elem_size = fx.layout_of(elem).size.bytes(); let elem_size = fx.layout_of(elem).size.bytes();
fx.bcx.ins().imul_imm(len, elem_size as i64) fx.bcx.ins().imul_imm(len, elem_size as i64)
}, }
ty => unimplemented!("size_of_val for {:?}", ty), ty => unimplemented!("size_of_val for {:?}", ty),
}; };
ret.write_cvalue(fx, CValue::ByVal(size, usize_layout)); 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 { match inst.def {
InstanceDef::Item(_) InstanceDef::Item(_)
| InstanceDef::DropGlue(_, _) | 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()); let mut mir = ::std::io::Cursor::new(Vec::new());
::rustc_mir::util::write_mir_pretty(tcx, Some(inst.def_id()), &mut mir) ::rustc_mir::util::write_mir_pretty(tcx, Some(inst.def_id()), &mut mir)
.unwrap(); .unwrap();
@ -35,8 +37,8 @@ pub fn trans_mono_item<'a, 'tcx: 'a>(
| InstanceDef::FnPtrShim(_, _) | InstanceDef::FnPtrShim(_, _)
| InstanceDef::ClosureOnceShim { .. } | InstanceDef::ClosureOnceShim { .. }
| InstanceDef::CloneShim(_, _) => { | InstanceDef::CloneShim(_, _) => {
// FIXME fix write_mir_pretty for these instances // FIXME fix write_mir_pretty for these instances
format!("{:#?}", tcx.instance_mir(inst.def)) format!("{:#?}", tcx.instance_mir(inst.def))
} }
InstanceDef::Intrinsic(_) => bug!("tried to codegen intrinsic"), 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) { let def_id = match fx.tcx.lang_items().require(ExchangeMallocFnLangItem) {
Ok(id) => id, Ok(id) => id,
Err(s) => { 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); 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 call = fx.bcx.ins().call(func_ref, &[llsize, llalign]);
let ptr = fx.bcx.inst_results(call)[0]; let ptr = fx.bcx.inst_results(call)[0];
lval.write_cvalue(fx, CValue::ByVal(ptr, box_layout)); lval.write_cvalue(fx, CValue::ByVal(ptr, box_layout));
}, }
Rvalue::NullaryOp(NullOp::SizeOf, ty) => { Rvalue::NullaryOp(NullOp::SizeOf, ty) => {
assert!( assert!(
lval.layout() lval.layout()

View file

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

View file

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