fix various small nits
This commit is contained in:
parent
633a34d6d3
commit
24a9a14dfa
3 changed files with 25 additions and 24 deletions
|
@ -95,8 +95,8 @@ fn after_analysis<'a, 'tcx>(state: &mut CompileState<'a, 'tcx>) {
|
|||
state.hir_crate.unwrap().visit_all_item_likes(&mut Visitor(limits, tcx, state));
|
||||
} else if let Some((entry_node_id, _)) = *state.session.entry_fn.borrow() {
|
||||
let entry_def_id = tcx.hir.local_def_id(entry_node_id);
|
||||
let start_wrapper = tcx.lang_items.start_fn()
|
||||
.and_then(|start_fn| if tcx.is_mir_available(start_fn) { Some(start_fn) } else { None });
|
||||
let start_wrapper = tcx.lang_items.start_fn().and_then(|start_fn|
|
||||
if tcx.is_mir_available(start_fn) { Some(start_fn) } else { None });
|
||||
miri::eval_main(tcx, entry_def_id, start_wrapper, limits);
|
||||
|
||||
state.session.abort_if_errors();
|
||||
|
|
|
@ -1558,6 +1558,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
|||
}
|
||||
|
||||
pub(super) fn dump_local(&self, lvalue: Lvalue<'tcx>) {
|
||||
// Debug output
|
||||
if let Lvalue::Local { frame, local, field } = lvalue {
|
||||
let mut allocs = Vec::new();
|
||||
let mut msg = format!("{:?}", local);
|
||||
|
@ -1744,17 +1745,14 @@ pub fn eval_main<'a, 'tcx: 'a>(
|
|||
let ty = ecx.tcx.types.isize;
|
||||
let layout = ecx.type_layout(ty)?;
|
||||
let size = layout.size(&ecx.tcx.data_layout).bytes();
|
||||
let align = layout.align(&ecx.tcx.data_layout).pref(); // FIXME is this right?
|
||||
let align = layout.align(&ecx.tcx.data_layout).abi();
|
||||
ecx.memory.allocate(size, align)?
|
||||
};
|
||||
ecx.frame_mut().return_lvalue = Lvalue::from_ptr(ret_ptr);
|
||||
|
||||
loop {
|
||||
if !ecx.step()? {
|
||||
ecx.memory.deallocate(ret_ptr)?;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
while ecx.step()? {}
|
||||
ecx.memory.deallocate(ret_ptr)?;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let mut ecx = EvalContext::new(tcx, limits);
|
||||
|
|
|
@ -131,7 +131,8 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Decides whether it is okay to call the method with signature `real_sig` using signature `sig`
|
||||
/// Decides whether it is okay to call the method with signature `real_sig` using signature `sig`.
|
||||
/// FIXME: This should take into account the platform-dependent ABI description.
|
||||
fn check_sig_compat(
|
||||
&mut self,
|
||||
sig: ty::FnSig<'tcx>,
|
||||
|
@ -284,12 +285,6 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
|||
trace!("arg_locals: {:?}", self.frame().mir.args_iter().collect::<Vec<_>>());
|
||||
trace!("arg_operands: {:?}", arg_operands);
|
||||
match sig.abi {
|
||||
Abi::Rust | Abi::C => {
|
||||
for (arg_local, (arg_val, arg_ty)) in arg_locals.zip(args) {
|
||||
let dest = self.eval_lvalue(&mir::Lvalue::Local(arg_local))?;
|
||||
self.write_value(arg_val, dest, arg_ty)?;
|
||||
}
|
||||
}
|
||||
Abi::RustCall => {
|
||||
assert_eq!(args.len(), 2);
|
||||
|
||||
|
@ -332,8 +327,13 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
|||
} else {
|
||||
bug!("rust-call ABI tuple argument was {:?}, {:?}", arg_ty, layout);
|
||||
}
|
||||
},
|
||||
_ => {
|
||||
for (arg_local, (arg_val, arg_ty)) in arg_locals.zip(args) {
|
||||
let dest = self.eval_lvalue(&mir::Lvalue::Local(arg_local))?;
|
||||
self.write_value(arg_val, dest, arg_ty)?;
|
||||
}
|
||||
}
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
|
@ -520,7 +520,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
|||
// Still, we can make many things mostly work by "emulating" or ignoring some functions.
|
||||
match &path[..] {
|
||||
"std::io::_print" => {
|
||||
trace!("Ignoring output.");
|
||||
trace!("Ignoring output. To run programs that print, make sure you have a libstd with full MIR.");
|
||||
self.goto_block(destination.unwrap().1);
|
||||
Ok(())
|
||||
},
|
||||
|
@ -595,15 +595,16 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
|||
}
|
||||
|
||||
"__rust_maybe_catch_panic" => {
|
||||
// fn __rust_maybe_catch_panic(f: fn(*mut u8), data: *mut u8, data_ptr: *mut usize, vtable_ptr: *mut usize) -> u32
|
||||
// We abort on panic, so not much is going on here, but we still have to call the closure
|
||||
let u8_ptr_ty = self.tcx.mk_mut_ptr(self.tcx.types.u8);
|
||||
let f = args[0].read_ptr(&self.memory)?;
|
||||
let data = args[1].read_ptr(&self.memory)?; // FIXME: Why does value_to_primval(args[2], u8_ptr_ty)?.to_ptr()? here end up doing the Wrong Thing (TM)?
|
||||
let data = args[1].read_ptr(&self.memory)?;
|
||||
let f_instance = self.memory.get_fn(f.alloc_id)?;
|
||||
self.write_primval(dest, PrimVal::Bytes(0), dest_ty)?;
|
||||
|
||||
// Now we make a functon call. TODO: Consider making this re-usable? EvalContext::step does sth. similar for the TLS dtors,
|
||||
// and of coruse eval_main.
|
||||
// Now we make a function call. TODO: Consider making this re-usable? EvalContext::step does sth. similar for the TLS dtors,
|
||||
// and of course eval_main.
|
||||
let mir = self.load_mir(f_instance.def)?;
|
||||
self.push_stack_frame(
|
||||
f_instance,
|
||||
|
@ -614,11 +615,13 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
|
|||
)?;
|
||||
|
||||
let arg_local = self.frame().mir.args_iter().next().ok_or(EvalError::AbiViolation("Argument to __rust_maybe_catch_panic does not take enough arguments.".to_owned()))?;
|
||||
let dest = self.eval_lvalue(&mir::Lvalue::Local(arg_local))?;
|
||||
self.write_value(Value::ByVal(PrimVal::Ptr(data)), dest, u8_ptr_ty)?;
|
||||
let arg_dest = self.eval_lvalue(&mir::Lvalue::Local(arg_local))?;
|
||||
self.write_value(Value::ByVal(PrimVal::Ptr(data)), arg_dest, u8_ptr_ty)?;
|
||||
|
||||
// We ourselbes return 0
|
||||
self.write_primval(dest, PrimVal::Bytes(0), dest_ty)?;
|
||||
|
||||
// Don't fall through
|
||||
// FIXME: Do we have to do self.dump_local(ret) anywhere?
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue