This commit is contained in:
bjorn3 2018-08-11 13:59:34 +02:00
parent 2e0d6d49bf
commit 50375db36c
2 changed files with 47 additions and 45 deletions

View File

@ -272,15 +272,9 @@ pub fn codegen_fn_prelude<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, start_ebb
let ret_layout = fx.layout_of(fx.return_type()); let ret_layout = fx.layout_of(fx.return_type());
let output_pass_mode = get_pass_mode(fx.tcx, fx.self_sig().abi, fx.return_type(), true); let output_pass_mode = get_pass_mode(fx.tcx, fx.self_sig().abi, fx.return_type(), true);
let ret_param = match output_pass_mode { let ret_param = match output_pass_mode {
PassMode::NoPass => { PassMode::NoPass => None,
None PassMode::ByVal(ret_ty) => None,
} PassMode::ByRef => Some(fx.bcx.append_ebb_param(start_ebb, types::I64)),
PassMode::ByVal(ret_ty) => {
None
}
PassMode::ByRef => {
Some(fx.bcx.append_ebb_param(start_ebb, types::I64))
}
}; };
enum ArgKind { enum ArgKind {
@ -320,7 +314,10 @@ pub fn codegen_fn_prelude<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, start_ebb
PassMode::NoPass => { PassMode::NoPass => {
let null = fx.bcx.ins().iconst(types::I64, 0); let null = fx.bcx.ins().iconst(types::I64, 0);
//unimplemented!("pass mode nopass"); //unimplemented!("pass mode nopass");
fx.local_map.insert(RETURN_PLACE, CPlace::Addr(null, fx.layout_of(fx.return_type()))); fx.local_map.insert(
RETURN_PLACE,
CPlace::Addr(null, fx.layout_of(fx.return_type())),
);
} }
PassMode::ByVal(ret_ty) => { PassMode::ByVal(ret_ty) => {
let var = Variable(RETURN_PLACE); let var = Variable(RETURN_PLACE);
@ -367,20 +364,25 @@ pub fn codegen_fn_prelude<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx>, start_ebb
let place = CPlace::from_stack_slot(fx, stack_slot, ty); let place = CPlace::from_stack_slot(fx, stack_slot, ty);
match arg_kind { match arg_kind {
ArgKind::Normal(ebb_param) => { ArgKind::Normal(ebb_param) => match get_pass_mode(fx.tcx, fx.self_sig().abi, ty, false)
match get_pass_mode(fx.tcx, fx.self_sig().abi, ty, false) { {
PassMode::NoPass => unimplemented!("pass mode nopass"), PassMode::NoPass => unimplemented!("pass mode nopass"),
PassMode::ByVal(_) => place.write_cvalue(fx, CValue::ByVal(ebb_param, place.layout())), PassMode::ByVal(_) => {
PassMode::ByRef => place.write_cvalue(fx, CValue::ByRef(ebb_param, place.layout())), place.write_cvalue(fx, CValue::ByVal(ebb_param, place.layout()))
} }
} PassMode::ByRef => place.write_cvalue(fx, CValue::ByRef(ebb_param, place.layout())),
},
ArgKind::Spread(ebb_params) => { ArgKind::Spread(ebb_params) => {
for (i, ebb_param) in ebb_params.into_iter().enumerate() { for (i, ebb_param) in ebb_params.into_iter().enumerate() {
let sub_place = place.place_field(fx, mir::Field::new(i)); let sub_place = place.place_field(fx, mir::Field::new(i));
match get_pass_mode(fx.tcx, fx.self_sig().abi, sub_place.layout().ty, false) { match get_pass_mode(fx.tcx, fx.self_sig().abi, sub_place.layout().ty, false) {
PassMode::NoPass => unimplemented!("pass mode nopass"), PassMode::NoPass => unimplemented!("pass mode nopass"),
PassMode::ByVal(_) => sub_place.write_cvalue(fx, CValue::ByVal(ebb_param, sub_place.layout())), PassMode::ByVal(_) => {
PassMode::ByRef => sub_place.write_cvalue(fx, CValue::ByRef(ebb_param, sub_place.layout())), sub_place.write_cvalue(fx, CValue::ByVal(ebb_param, sub_place.layout()))
}
PassMode::ByRef => {
sub_place.write_cvalue(fx, CValue::ByRef(ebb_param, sub_place.layout()))
}
} }
} }
} }
@ -450,9 +452,9 @@ pub fn codegen_call<'a, 'tcx: 'a>(
.collect::<Vec<_>>() .collect::<Vec<_>>()
}; };
let destination = destination.as_ref().map(|(place, bb)| { let destination = destination
(trans_place(fx, place), *bb) .as_ref()
}); .map(|(place, bb)| (trans_place(fx, place), *bb));
if codegen_intrinsic_call(fx, fn_ty, sig, &args, destination) { if codegen_intrinsic_call(fx, fn_ty, sig, &args, destination) {
return; return;
@ -473,14 +475,13 @@ pub fn codegen_call<'a, 'tcx: 'a>(
let call_args: Vec<Value> = return_ptr let call_args: Vec<Value> = return_ptr
.into_iter() .into_iter()
.chain( .chain(args.into_iter().map(|arg| {
args.into_iter() match get_pass_mode(fx.tcx, sig.abi, arg.layout().ty, false) {
.map(|arg| match get_pass_mode(fx.tcx, sig.abi, arg.layout().ty, false) {
PassMode::NoPass => unimplemented!("pass mode nopass"), PassMode::NoPass => unimplemented!("pass mode nopass"),
PassMode::ByVal(_) => arg.load_value(fx), PassMode::ByVal(_) => arg.load_value(fx),
PassMode::ByRef => arg.force_stack(fx), PassMode::ByRef => arg.force_stack(fx),
}), }
).collect::<Vec<_>>(); })).collect::<Vec<_>>();
let inst = match func { let inst = match func {
CValue::Func(func, _) => fx.bcx.ins().call(func, &call_args), CValue::Func(func, _) => fx.bcx.ins().call(func, &call_args),
@ -513,7 +514,7 @@ pub fn codegen_return(fx: &mut FunctionCx) {
match get_pass_mode(fx.tcx, fx.self_sig().abi, fx.return_type(), true) { match get_pass_mode(fx.tcx, fx.self_sig().abi, fx.return_type(), true) {
PassMode::NoPass | PassMode::ByRef => { PassMode::NoPass | PassMode::ByRef => {
fx.bcx.ins().return_(&[]); fx.bcx.ins().return_(&[]);
}, }
PassMode::ByVal(_) => { PassMode::ByVal(_) => {
let place = fx.get_local_place(RETURN_PLACE); let place = fx.get_local_place(RETURN_PLACE);
let ret_val = place.to_cvalue(fx).load_value(fx); let ret_val = place.to_cvalue(fx).load_value(fx);
@ -537,10 +538,7 @@ fn codegen_intrinsic_call<'a, 'tcx: 'a>(
let ret = match destination { let ret = match destination {
Some((place, _)) => place, Some((place, _)) => place,
None => { None => {
println!( println!("codegen_call(fx, _, {:?}, {:?})", args, destination);
"codegen_call(fx, _, {:?}, {:?})",
args, destination
);
// Insert non returning intrinsics here // Insert non returning intrinsics here
match intrinsic { match intrinsic {
"abort" => { "abort" => {

View File

@ -271,7 +271,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
} }
} }
} }
std::mem::replace(&mut cx.defined_functions, Vec::new()) std::mem::replace(&mut cx.defined_functions, Vec::new())
}; };
@ -279,21 +279,25 @@ impl CodegenBackend for CraneliftCodegenBackend {
// TODO: this doesn't work most of the time // TODO: this doesn't work most of the time
if false { if false {
let call_instance = collector::collect_crate_mono_items(tcx, collector::MonoItemCollectionMode::Eager).0.into_iter().find_map(|mono_item| { let call_instance =
let inst = match mono_item { collector::collect_crate_mono_items(tcx, collector::MonoItemCollectionMode::Eager)
MonoItem::Fn(inst) => inst, .0
_ => return None, .into_iter()
}; .find_map(|mono_item| {
let inst = match mono_item {
MonoItem::Fn(inst) => inst,
_ => return None,
};
//if tcx.absolute_item_path_str(inst.def_id()) != "example::ret_42" { //if tcx.absolute_item_path_str(inst.def_id()) != "example::ret_42" {
if tcx.absolute_item_path_str(inst.def_id()) == "example::option_unwrap_or" { if tcx.absolute_item_path_str(inst.def_id()) == "example::option_unwrap_or"
Some(inst) {
} else { Some(inst)
None } else {
} None
}).unwrap(); }
}).unwrap();
let fn_ty = call_instance.ty(tcx); let fn_ty = call_instance.ty(tcx);
let sig = cton_sig_from_fn_ty(tcx, fn_ty); let sig = cton_sig_from_fn_ty(tcx, fn_ty);
let def_path_based_names = let def_path_based_names =