This commit is contained in:
bjorn3 2018-10-10 19:07:13 +02:00
parent 4177e804e9
commit b5dffe9765
8 changed files with 70 additions and 51 deletions

View File

@ -242,7 +242,8 @@ impl<'a, 'tcx: 'a, B: Backend + 'a> FunctionCx<'a, 'tcx, B> {
self.cton_type(arg.layout().ty).unwrap(),
arg.load_value(self),
)
}).unzip();
})
.unzip();
let return_layout = self.layout_of(return_ty);
let return_ty = if let ty::Tuple(tup) = return_ty.sty {
if !tup.is_empty() {
@ -325,7 +326,8 @@ pub fn codegen_fn_prelude<'a, 'tcx: 'a>(
arg_ty,
)
}
}).collect::<Vec<(Local, ArgKind, Ty)>>();
})
.collect::<Vec<(Local, ArgKind, Ty)>>();
fx.bcx.switch_to_block(start_ebb);
@ -550,7 +552,8 @@ pub fn codegen_call_inner<'a, 'tcx: 'a>(
};
args.get(0).map(|arg| adjust_arg_for_abi(fx, sig, *arg))
}.into_iter()
}
.into_iter()
};
let call_args: Vec<Value> = return_ptr
@ -560,7 +563,8 @@ pub fn codegen_call_inner<'a, 'tcx: 'a>(
args.into_iter()
.skip(1)
.map(|arg| adjust_arg_for_abi(fx, sig, arg)),
).collect::<Vec<_>>();
)
.collect::<Vec<_>>();
let sig = fx.bcx.import_signature(cton_sig_from_fn_ty(fx.tcx, fn_ty));
let call_inst = if let Some(func_ref) = func_ref {

View File

@ -26,12 +26,10 @@ pub fn analyze<'a, 'tcx: 'a>(fx: &FunctionCx<'a, 'tcx, impl Backend>) -> HashMap
for bb in fx.mir.basic_blocks().iter() {
for stmt in bb.statements.iter() {
match &stmt.kind {
Assign(_, rval) => {
match &**rval {
Rvalue::Ref(_, _, place) => analyze_non_ssa_place(&mut flag_map, place),
_ => {}
}
}
Assign(_, rval) => match &**rval {
Rvalue::Ref(_, _, place) => analyze_non_ssa_place(&mut flag_map, place),
_ => {}
},
_ => {}
}
}

View File

@ -32,7 +32,8 @@ pub fn trans_mono_item<'a, 'tcx: 'a>(
tcx,
Some(inst.def_id()),
&mut mir,
).unwrap();
)
.unwrap();
String::from_utf8(mir.into_inner()).unwrap()
}
InstanceDef::Item(_)
@ -120,7 +121,8 @@ fn trans_fn<'a, 'tcx: 'a>(
if cfg!(debug_assertions) {
::cranelift::codegen::write::decorate_function(&mut writer, &mut cton, &func, None)
.unwrap();
let clif_file_name = concat!(env!("CARGO_MANIFEST_DIR"), "/target/out/clif/").to_string() + &tcx.symbol_name(instance).as_str();
let clif_file_name = concat!(env!("CARGO_MANIFEST_DIR"), "/target/out/clif/").to_string()
+ &tcx.symbol_name(instance).as_str();
::std::fs::write(clif_file_name, cton.as_bytes()).unwrap();
}
@ -290,27 +292,27 @@ fn codegen_fn_content<'a, 'tcx: 'a>(fx: &mut FunctionCx<'a, 'tcx, impl Backend>)
&args1[..]
};*/
let (drop_fn, fn_ty) = match ty.sty {
ty::Dynamic(..) => {
let fn_ty = drop_fn.ty(bx.cx.tcx);
let sig = common::ty_fn_sig(bx.cx, fn_ty);
let sig = bx.tcx().normalize_erasing_late_bound_regions(
ty::ParamEnv::reveal_all(),
&sig,
);
let fn_ty = FnType::new_vtable(bx.cx, sig, &[]);
let vtable = args[1];
args = &args[..1];
(meth::DESTRUCTOR.get_fn(&bx, vtable, &fn_ty), fn_ty)
}
_ => {
let value = place.to_cvalue(fx);
(callee::get_fn(bx.cx, drop_fn),
FnType::of_instance(bx.cx, &drop_fn))
}
ty::Dynamic(..) => {
let fn_ty = drop_fn.ty(bx.cx.tcx);
let sig = common::ty_fn_sig(bx.cx, fn_ty);
let sig = bx.tcx().normalize_erasing_late_bound_regions(
ty::ParamEnv::reveal_all(),
&sig,
);
let fn_ty = FnType::new_vtable(bx.cx, sig, &[]);
let vtable = args[1];
args = &args[..1];
(meth::DESTRUCTOR.get_fn(&bx, vtable, &fn_ty), fn_ty)
}
_ => {
let value = place.to_cvalue(fx);
(callee::get_fn(bx.cx, drop_fn),
FnType::of_instance(bx.cx, &drop_fn))
}
};
do_call(self, bx, fn_ty, drop_fn, args,
Some((ReturnDest::Nothing, target)),
unwind);*/
Some((ReturnDest::Nothing, target)),
unwind);*/
}
let target_ebb = fx.get_ebb(*target);
@ -592,13 +594,14 @@ fn trans_stmt<'a, 'tcx: 'a>(
let usize_layout = fx.layout_of(fx.tcx.types.usize);
let len = match place.layout().ty.sty {
ty::Array(_elem_ty, len) => {
let len = crate::constant::force_eval_const(fx, len).unwrap_usize(fx.tcx) as i64;
let len = crate::constant::force_eval_const(fx, len)
.unwrap_usize(fx.tcx) as i64;
fx.bcx.ins().iconst(fx.module.pointer_type(), len)
},
}
ty::Slice(_elem_ty) => match place {
CPlace::Addr(_, size, _) => size.unwrap(),
CPlace::Var(_, _) => unreachable!(),
}
},
_ => bug!("Rvalue::Len({:?})", place),
};
lval.write_cvalue(fx, CValue::ByVal(len, usize_layout));
@ -897,11 +900,13 @@ pub fn trans_checked_int_binop<'a, 'tcx: 'a>(
BinOp::Sub => fx.bcx.ins().isub(lhs, rhs),
BinOp::Mul => fx.bcx.ins().imul(lhs, rhs),
BinOp::Shl => fx.bcx.ins().ishl(lhs, rhs),
BinOp::Shr => if !signed {
fx.bcx.ins().ushr(lhs, rhs)
} else {
fx.bcx.ins().sshr(lhs, rhs)
},
BinOp::Shr => {
if !signed {
fx.bcx.ins().ushr(lhs, rhs)
} else {
fx.bcx.ins().sshr(lhs, rhs)
}
}
_ => bug!(
"binop {:?} on checked int/uint lhs: {:?} rhs: {:?}",
bin_op,

View File

@ -131,7 +131,8 @@ impl<'tcx> CValue<'tcx> {
size: layout.size.bytes() as u32,
offset: None,
});
let addr = fx.bcx
let addr = fx
.bcx
.ins()
.stack_addr(fx.module.pointer_type(), stack_slot, 0);
fx.bcx.ins().store(MemFlags::new(), value, addr, 0);
@ -635,7 +636,8 @@ impl<'a, 'tcx: 'a, B: Backend + 'a> fmt::Debug for FunctionCx<'a, 'tcx, B> {
&mut clif,
&self.bcx.func,
None,
).unwrap();
)
.unwrap();
writeln!(f, "\n{}", clif)
}
}

View File

@ -52,7 +52,8 @@ pub fn trans_promoted<'a, 'tcx: 'a>(
.const_eval(ParamEnv::reveal_all().and(GlobalId {
instance: fx.instance,
promoted: Some(promoted),
})).unwrap();
}))
.unwrap();
let const_ = force_eval_const(fx, const_);
trans_const_place(fx, const_)

View File

@ -1,4 +1,3 @@
use crate::prelude::*;
macro_rules! intrinsic_pat {

View File

@ -237,7 +237,8 @@ impl CodegenBackend for CraneliftCodegenBackend {
"some_file.o".to_string(),
FaerieTrapCollection::Disabled,
FaerieBuilder::default_libcall_names(),
).unwrap(),
)
.unwrap(),
);
assert_eq!(pointer_ty(tcx), faerie_module.pointer_type());
@ -282,7 +283,8 @@ impl CodegenBackend for CraneliftCodegenBackend {
writable: false,
},
metadata.clone(),
).unwrap();
)
.unwrap();
for &crate_type in sess.opts.crate_types.iter() {
match crate_type {
@ -303,14 +305,16 @@ impl CodegenBackend for CraneliftCodegenBackend {
metadata.len() as u64,
),
::std::io::Cursor::new(metadata.clone()),
).unwrap();
)
.unwrap();
if should_codegen(sess) {
let obj = artifact.emit().unwrap();
builder
.append(
&ar::Header::new(b"data.o".to_vec(), obj.len() as u64),
::std::io::Cursor::new(obj),
).unwrap();
)
.unwrap();
}
}
_ => sess.fatal(&format!("Unsupported crate type: {:?}", crate_type)),
@ -332,7 +336,10 @@ fn codegen_mono_items<'a, 'tcx: 'a>(
let mut ccx = ConstantCx::default();
let mut log = if cfg!(debug_assertions) {
Some(::std::fs::File::create(concat!(env!("CARGO_MANIFEST_DIR"), "/target/out/log.txt")).unwrap())
Some(
::std::fs::File::create(concat!(env!("CARGO_MANIFEST_DIR"), "/target/out/log.txt"))
.unwrap(),
)
} else {
None
};
@ -455,7 +462,8 @@ fn maybe_create_entry_wrapper<'a, 'tcx: 'a>(
ParamEnv::reveal_all(),
start_def_id,
tcx.intern_substs(&[main_ret_ty.into()]),
).unwrap();
)
.unwrap();
let (start_name, start_sig) = get_function_name_and_sig(tcx, start_instance);
let start_func_id = m

View File

@ -122,7 +122,8 @@ fn build_vtable<'a, 'tcx: 'a>(
&format!("vtable.{:?}.for.{:?}", trait_ref, ty),
Linkage::Local,
false,
).unwrap();
)
.unwrap();
fx.module.define_data(data_id, &data_ctx).unwrap();
data_id
}
@ -140,5 +141,6 @@ fn write_usize(tcx: TyCtxt, buf: &mut [u8], idx: usize, num: u64) {
match tcx.data_layout.endian {
layout::Endian::Little => target.write_uint::<LittleEndian>(num, usize_size),
layout::Endian::Big => target.write_uint::<BigEndian>(num, usize_size),
}.unwrap()
}
.unwrap()
}