}
impl PassMode {
- fn get_param_ty(self, _fx: &FunctionCx<impl Backend>) -> Type {
+ fn get_param_ty(self, fx: &FunctionCx<impl Backend>) -> Type {
match self {
PassMode::NoPass => unimplemented!("pass mode nopass"),
PassMode::ByVal(cton_type) => cton_type,
- PassMode::ByRef => types::I64,
+ PassMode::ByRef => fx.module.pointer_type(),
}
}
}
.filter_map(|ty| match get_pass_mode(tcx, sig.abi, ty, false) {
PassMode::ByVal(cton_ty) => Some(cton_ty),
PassMode::NoPass => unimplemented!("pass mode nopass"),
- PassMode::ByRef => Some(types::I64),
+ PassMode::ByRef => Some(pointer_ty(tcx)),
});
let (params, returns) = match get_pass_mode(tcx, sig.abi, output, true) {
),
PassMode::ByRef => {
(
- Some(types::I64).into_iter() // First param is place to put return val
+ Some(pointer_ty(tcx)).into_iter() // First param is place to put return val
.chain(inputs)
.map(AbiParam::new)
.collect(),
if let Some(val) = self.lib_call(name, input_tys, return_ty, &args) {
CValue::ByVal(val, return_layout)
} else {
- CValue::ByRef(self.bcx.ins().iconst(types::I64, 0), return_layout)
+ CValue::ByRef(self.bcx.ins().iconst(self.module.pointer_type(), 0), return_layout)
}
}
let ret_param = match output_pass_mode {
PassMode::NoPass => None,
PassMode::ByVal(_) => None,
- PassMode::ByRef => Some(fx.bcx.append_ebb_param(start_ebb, types::I64)),
+ PassMode::ByRef => Some(fx.bcx.append_ebb_param(start_ebb, fx.module.pointer_type())),
};
enum ArgKind {
match output_pass_mode {
PassMode::NoPass => {
- let null = fx.bcx.ins().iconst(types::I64, 0);
+ let null = fx.bcx.ins().iconst(fx.module.pointer_type(), 0);
//unimplemented!("pass mode nopass");
fx.local_map.insert(
RETURN_PLACE,
PassMode::NoPass => None,
PassMode::ByRef => match destination {
Some((place, _)) => Some(place.expect_addr()),
- None => Some(fx.bcx.ins().iconst(types::I64, 0)),
+ None => Some(fx.bcx.ins().iconst(fx.module.pointer_type(), 0)),
},
PassMode::ByVal(_) => None,
};
"copy" | "copy_nonoverlapping" => {
let elem_ty = substs.type_at(0);
let elem_size: u64 = fx.layout_of(elem_ty).size.bytes();
- let elem_size = fx.bcx.ins().iconst(types::I64, elem_size as i64);
+ let elem_size = fx.bcx.ins().iconst(fx.module.pointer_type(), elem_size as i64);
assert_eq!(args.len(), 3);
let src = args[0];
let dst = args[1];
Rvalue::Repeat(operand, times) => {
let operand = trans_operand(fx, operand);
for i in 0..*times {
- let index = fx.bcx.ins().iconst(types::I64, i as i64);
+ let index = fx.bcx.ins().iconst(fx.module.pointer_type(), i as i64);
let to = lval.place_index(fx, index);
to.write_cvalue(fx, operand);
}
AggregateKind::Array(_ty) => {
for (i, operand) in operands.into_iter().enumerate() {
let operand = trans_operand(fx, operand);
- let index = fx.bcx.ins().iconst(types::I64, i as i64);
+ let index = fx.bcx.ins().iconst(fx.module.pointer_type(), i as i64);
let to = lval.place_index(fx, index);
to.write_cvalue(fx, operand);
}
Variable::with_u32(loc.index() as u32)
}
+pub fn pointer_ty(tcx: TyCtxt) -> types::Type {
+ match tcx.data_layout.pointer_size.bits() {
+ 16 => types::I16,
+ 32 => types::I32,
+ 64 => types::I64,
+ bits => bug!("ptr_sized_integer: unknown pointer bit size {}", bits),
+ }
+}
+
pub fn cton_type_from_ty<'a, 'tcx: 'a>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
ty: Ty<'tcx>,
UintTy::U32 => types::I32,
UintTy::U64 => types::I64,
UintTy::U128 => unimpl!("u128"),
- UintTy::Usize => types::I64,
+ UintTy::Usize => pointer_ty(tcx),
},
TypeVariants::TyInt(size) => match size {
IntTy::I8 => types::I8,
IntTy::I32 => types::I32,
IntTy::I64 => types::I64,
IntTy::I128 => unimpl!("i128"),
- IntTy::Isize => types::I64,
+ IntTy::Isize => pointer_ty(tcx)
},
TypeVariants::TyChar => types::I32,
TypeVariants::TyFloat(size) => match size {
FloatTy::F32 => types::F32,
FloatTy::F64 => types::F64,
},
- TypeVariants::TyFnPtr(_) => types::I64,
+ TypeVariants::TyFnPtr(_) => pointer_ty(tcx),
TypeVariants::TyRawPtr(TypeAndMut { ty, mutbl: _ }) | TypeVariants::TyRef(_, ty, _) => {
if ty.is_sized(tcx.at(DUMMY_SP), ParamEnv::reveal_all()) {
- types::I64
+ pointer_ty(tcx)
} else {
return None;
}
let field_offset = layout.fields.offset(field.index());
let field_ty = layout.field(&*fx, field.index());
if field_offset.bytes() > 0 {
- let field_offset = fx.bcx.ins().iconst(types::I64, field_offset.bytes() as i64);
+ let field_offset = fx.bcx.ins().iconst(fx.module.pointer_type(), field_offset.bytes() as i64);
(fx.bcx.ins().iadd(base, field_offset), field_ty)
} else {
(base, field_ty)
offset: None,
});
fx.bcx.ins().stack_store(value, stack_slot, 0);
- fx.bcx.ins().stack_addr(types::I64, stack_slot, 0)
+ fx.bcx.ins().stack_addr(fx.module.pointer_type(), stack_slot, 0)
}
}
}
size: layout.size.bytes() as u32,
offset: None,
});
- CPlace::Addr(fx.bcx.ins().stack_addr(types::I64, stack_slot, 0), layout)
+ CPlace::Addr(fx.bcx.ins().stack_addr(fx.module.pointer_type(), stack_slot, 0), layout)
}
pub fn from_stack_slot(
ty: Ty<'tcx>,
) -> CPlace<'tcx> {
let layout = fx.layout_of(ty);
- CPlace::Addr(fx.bcx.ins().stack_addr(types::I64, 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> {
let byte = fx
.bcx
.ins()
- .load(types::I64, MemFlags::new(), from.0, offset);
+ .load(fx.module.pointer_type(), MemFlags::new(), from.0, offset);
fx.bcx.ins().store(MemFlags::new(), byte, addr, offset);
offset += 8;
}
let size = fx
.bcx
.ins()
- .iconst(types::I64, elem_layout.size.bytes() as i64);
+ .iconst(fx.module.pointer_type(), elem_layout.size.bytes() as i64);
let offset = fx.bcx.ins().imul(size, index);
CPlace::Addr(fx.bcx.ins().iadd(addr, offset), elem_layout)
}
let func_ref = fx.get_function_ref(
Instance::resolve(fx.tcx, ParamEnv::reveal_all(), def_id, substs).unwrap(),
);
- let func_addr = fx.bcx.ins().func_addr(types::I64, func_ref);
+ let func_addr = fx.bcx.ins().func_addr(fx.module.pointer_type(), func_ref);
CValue::ByVal(func_addr, layout)
}
_ => trans_const_place(fx, const_).to_cvalue(fx),
data_id: DataId,
) -> CPlace<'tcx> {
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
- let global_ptr = fx.bcx.ins().global_value(types::I64, 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));
CPlace::Addr(global_ptr, layout)
}
if std::env::var("SHOULD_RUN").is_ok() {
let mut jit_module: Module<SimpleJITBackend> = Module::new(SimpleJITBuilder::new());
+ assert_eq!(pointer_ty(tcx), jit_module.pointer_type());
codegen_mono_items(tcx, &mut jit_module, &mono_items);
let sig = Signature {
params: vec![
- AbiParam::new(types::I64 /*usize*/),
- AbiParam::new(types::I64 /* *const _*/),
+ AbiParam::new(jit_module.pointer_type()),
+ AbiParam::new(jit_module.pointer_type()),
],
- returns: vec![AbiParam::new(types::I64 /*isize*/)],
+ returns: vec![AbiParam::new(jit_module.pointer_type() /*isize*/)],
call_conv: CallConv::SystemV,
argument_bytes: None,
};
FaerieBuilder::default_libcall_names(),
).unwrap(),
);
+ assert_eq!(pointer_ty(tcx), faerie_module.pointer_type());
codegen_mono_items(tcx, &mut faerie_module, &mono_items);
let cmain_sig = Signature {
params: vec![
- AbiParam::new(types::I64 /*usize*/),
- AbiParam::new(types::I64 /* *const _*/),
+ AbiParam::new(m.pointer_type()),
+ AbiParam::new(m.pointer_type()),
],
- returns: vec![AbiParam::new(types::I64 /*isize*/)],
+ returns: vec![AbiParam::new(m.pointer_type() /*isize*/)],
call_conv: CallConv::SystemV,
argument_bytes: None,
};
let ebb = bcx.create_ebb();
bcx.switch_to_block(ebb);
- let arg_argc = bcx.append_ebb_param(ebb, types::I64 /*usize*/);
- let arg_argv = bcx.append_ebb_param(ebb, types::I64 /* *const _*/);
+ let arg_argc = bcx.append_ebb_param(ebb, m.pointer_type());
+ let arg_argv = bcx.append_ebb_param(ebb, m.pointer_type());
let main_func_ref = m.declare_func_in_func(main_func_id, &mut bcx.func);
.declare_function(&start_name, Linkage::Import, &start_sig)
.unwrap();
- let main_val = bcx.ins().func_addr(types::I64, main_func_ref);
+ let main_val = bcx.ins().func_addr(m.pointer_type(), main_func_ref);
let func_ref = m.declare_func_in_func(start_func_id, &mut bcx.func);
bcx.ins().call(func_ref, &[main_val, arg_argc, arg_argv])