This commit is contained in:
bjorn3 2018-08-22 12:31:45 +02:00
parent 8cd9bf3162
commit 65641b8872
4 changed files with 53 additions and 18 deletions

View File

@ -224,7 +224,10 @@ impl<'a, 'tcx: 'a, B: Backend + 'a> FunctionCx<'a, 'tcx, B> {
if let Some(val) = self.lib_call(name, input_tys, return_ty, &args) { if let Some(val) = self.lib_call(name, input_tys, return_ty, &args) {
CValue::ByVal(val, return_layout) CValue::ByVal(val, return_layout)
} else { } else {
CValue::ByRef(self.bcx.ins().iconst(self.module.pointer_type(), 0), return_layout) CValue::ByRef(
self.bcx.ins().iconst(self.module.pointer_type(), 0),
return_layout,
)
} }
} }
@ -570,7 +573,10 @@ fn codegen_intrinsic_call<'a, 'tcx: 'a>(
"copy" | "copy_nonoverlapping" => { "copy" | "copy_nonoverlapping" => {
let elem_ty = substs.type_at(0); let elem_ty = substs.type_at(0);
let elem_size: u64 = fx.layout_of(elem_ty).size.bytes(); let elem_size: u64 = fx.layout_of(elem_ty).size.bytes();
let elem_size = fx.bcx.ins().iconst(fx.module.pointer_type(), elem_size as i64); let elem_size = fx
.bcx
.ins()
.iconst(fx.module.pointer_type(), elem_size as i64);
assert_eq!(args.len(), 3); assert_eq!(args.len(), 3);
let src = args[0]; let src = args[0];
let dst = args[1]; let dst = args[1];

View File

@ -39,7 +39,7 @@ pub fn cton_type_from_ty<'a, 'tcx: 'a>(
IntTy::I32 => types::I32, IntTy::I32 => types::I32,
IntTy::I64 => types::I64, IntTy::I64 => types::I64,
IntTy::I128 => unimpl!("i128"), IntTy::I128 => unimpl!("i128"),
IntTy::Isize => pointer_ty(tcx) IntTy::Isize => pointer_ty(tcx),
}, },
TypeVariants::TyChar => types::I32, TypeVariants::TyChar => types::I32,
TypeVariants::TyFloat(size) => match size { TypeVariants::TyFloat(size) => match size {
@ -68,7 +68,10 @@ fn codegen_field<'a, 'tcx: 'a>(
let field_offset = layout.fields.offset(field.index()); let field_offset = layout.fields.offset(field.index());
let field_ty = layout.field(&*fx, field.index()); let field_ty = layout.field(&*fx, field.index());
if field_offset.bytes() > 0 { if field_offset.bytes() > 0 {
(fx.bcx.ins().iadd_imm(base, field_offset.bytes() as i64), field_ty) (
fx.bcx.ins().iadd_imm(base, field_offset.bytes() as i64),
field_ty,
)
} else { } else {
(base, field_ty) (base, field_ty)
} }
@ -101,7 +104,9 @@ impl<'tcx> CValue<'tcx> {
offset: None, offset: None,
}); });
fx.bcx.ins().stack_store(value, stack_slot, 0); fx.bcx.ins().stack_store(value, stack_slot, 0);
fx.bcx.ins().stack_addr(fx.module.pointer_type(), stack_slot, 0) fx.bcx
.ins()
.stack_addr(fx.module.pointer_type(), stack_slot, 0)
} }
} }
} }
@ -187,7 +192,12 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
size: layout.size.bytes() as u32, size: layout.size.bytes() as u32,
offset: None, offset: None,
}); });
CPlace::Addr(fx.bcx.ins().stack_addr(fx.module.pointer_type(), stack_slot, 0), layout) CPlace::Addr(
fx.bcx
.ins()
.stack_addr(fx.module.pointer_type(), stack_slot, 0),
layout,
)
} }
pub fn from_stack_slot( pub fn from_stack_slot(
@ -196,7 +206,12 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
ty: Ty<'tcx>, ty: Ty<'tcx>,
) -> CPlace<'tcx> { ) -> CPlace<'tcx> {
let layout = fx.layout_of(ty); let layout = fx.layout_of(ty);
CPlace::Addr(fx.bcx.ins().stack_addr(fx.module.pointer_type(), stack_slot, 0), layout) CPlace::Addr(
fx.bcx
.ins()
.stack_addr(fx.module.pointer_type(), stack_slot, 0),
layout,
)
} }
pub fn to_cvalue(self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>) -> CValue<'tcx> { pub fn to_cvalue(self, fx: &mut FunctionCx<'a, 'tcx, impl Backend>) -> CValue<'tcx> {
@ -254,10 +269,12 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
let from = from.expect_byref(); let from = from.expect_byref();
let mut offset = 0; let mut offset = 0;
while size - offset >= 8 { while size - offset >= 8 {
let byte = fx let byte = fx.bcx.ins().load(
.bcx fx.module.pointer_type(),
.ins() MemFlags::new(),
.load(fx.module.pointer_type(), MemFlags::new(), from.0, offset); from.0,
offset,
);
fx.bcx.ins().store(MemFlags::new(), byte, addr, offset); fx.bcx.ins().store(MemFlags::new(), byte, addr, offset);
offset += 8; offset += 8;
} }
@ -304,7 +321,10 @@ impl<'a, 'tcx: 'a> CPlace<'tcx> {
match layout.ty.sty { match layout.ty.sty {
TypeVariants::TyArray(elem_ty, _) => { TypeVariants::TyArray(elem_ty, _) => {
let elem_layout = fx.layout_of(elem_ty); let elem_layout = fx.layout_of(elem_ty);
let offset = fx.bcx.ins().imul_imm(index, elem_layout.size.bytes() as i64); let offset = fx
.bcx
.ins()
.imul_imm(index, elem_layout.size.bytes() as i64);
CPlace::Addr(fx.bcx.ins().iadd(addr, offset), elem_layout) CPlace::Addr(fx.bcx.ins().iadd(addr, offset), elem_layout)
} }
TypeVariants::TySlice(_elem_ty) => unimplemented!("place_index(TySlice)"), TypeVariants::TySlice(_elem_ty) => unimplemented!("place_index(TySlice)"),

View File

@ -134,12 +134,17 @@ fn data_id_for_alloc_id<B: Backend>(module: &mut Module<B>, alloc_id: AllocId) -
.unwrap() .unwrap()
} }
fn data_id_for_static<'a, 'tcx: 'a, B: Backend>(tcx: TyCtxt<'a, 'tcx, 'tcx>, module: &mut Module<B>, def_id: DefId) -> DataId { fn data_id_for_static<'a, 'tcx: 'a, B: Backend>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
module: &mut Module<B>,
def_id: DefId,
) -> DataId {
let symbol_name = tcx.symbol_name(Instance::mono(tcx, def_id)).as_str(); let symbol_name = tcx.symbol_name(Instance::mono(tcx, def_id)).as_str();
let is_mutable = if let ::rustc::hir::Mutability::MutMutable = tcx.is_static(def_id).unwrap() { let is_mutable = if let ::rustc::hir::Mutability::MutMutable = tcx.is_static(def_id).unwrap() {
true true
} else { } else {
!tcx.type_of(def_id).is_freeze(tcx, ParamEnv::reveal_all(), DUMMY_SP) !tcx.type_of(def_id)
.is_freeze(tcx, ParamEnv::reveal_all(), DUMMY_SP)
}; };
module module
.declare_data(&*symbol_name, Linkage::Export, is_mutable) .declare_data(&*symbol_name, Linkage::Export, is_mutable)
@ -152,7 +157,10 @@ fn cplace_for_dataid<'a, 'tcx: 'a>(
data_id: DataId, data_id: DataId,
) -> CPlace<'tcx> { ) -> CPlace<'tcx> {
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func); let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
let global_ptr = fx.bcx.ins().global_value(fx.module.pointer_type(), local_data_id); let global_ptr = fx
.bcx
.ins()
.global_value(fx.module.pointer_type(), local_data_id);
let layout = fx.layout_of(fx.monomorphize(&ty)); let layout = fx.layout_of(fx.monomorphize(&ty));
CPlace::Addr(global_ptr, layout) CPlace::Addr(global_ptr, layout)
} }

View File

@ -215,9 +215,10 @@ impl CodegenBackend for CraneliftCodegenBackend {
let mut flags_builder = settings::builder(); let mut flags_builder = settings::builder();
flags_builder.enable("is_pic").unwrap(); flags_builder.enable("is_pic").unwrap();
let flags = settings::Flags::new(flags_builder); let flags = settings::Flags::new(flags_builder);
let isa = cranelift::codegen::isa::lookup(tcx.sess.target.target.llvm_target.parse().unwrap()) let isa =
.unwrap() cranelift::codegen::isa::lookup(tcx.sess.target.target.llvm_target.parse().unwrap())
.finish(flags); .unwrap()
.finish(flags);
let mono_items = let mono_items =
collector::collect_crate_mono_items(tcx, collector::MonoItemCollectionMode::Eager).0; collector::collect_crate_mono_items(tcx, collector::MonoItemCollectionMode::Eager).0;