1
Fork 0

pass arguments to start

This commit is contained in:
Oliver Schneider 2016-06-15 12:55:04 +02:00
parent 8abd293119
commit a55ac1fea8
No known key found for this signature in database
GPG key ID: 56D6EEA0FC67AC46
4 changed files with 24 additions and 3 deletions

View file

@ -48,6 +48,17 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
ecx.push_stack_frame(def_id, mir.span, CachedMir::Ref(mir), substs, Some(return_ptr));
if mir.arg_decls.len() == 2 {
// start function
let ptr_size = ecx.memory().pointer_size;
let nargs = ecx.memory_mut().allocate(ptr_size);
ecx.memory_mut().write_usize(nargs, 0).unwrap();
let args = ecx.memory_mut().allocate(ptr_size);
ecx.memory_mut().write_usize(args, 0).unwrap();
ecx.frame_mut().locals[0] = nargs;
ecx.frame_mut().locals[1] = args;
}
loop {
match step(&mut ecx) {
Ok(true) => {}

View file

@ -154,6 +154,10 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
&self.memory
}
pub fn memory_mut(&mut self) -> &mut Memory<'tcx> {
&mut self.memory
}
pub fn stack(&self) -> &[Frame] {
&self.stack
}
@ -1373,7 +1377,7 @@ impl<'a, 'tcx> EvalContext<'a, 'tcx> {
self.stack.last().expect("no call frames exist")
}
fn frame_mut(&mut self) -> &mut Frame<'a, 'tcx> {
pub fn frame_mut(&mut self) -> &mut Frame<'a, 'tcx> {
self.stack.last_mut().expect("no call frames exist")
}

View file

@ -21,6 +21,9 @@ fn run_mode(mode: &'static str) {
let targets = &["x86_64-unknown-linux-gnu", "i686-unknown-linux-gnu"];
for &target in targets {
use std::io::Write;
let stderr = std::io::stderr();
write!(stderr.lock(), "running tests for target {}", target).unwrap();
let mut config = compiletest::default_config();
config.host_rustcflags = Some(flags.clone());
config.mode = mode.parse().expect("Invalid mode");

View file

@ -1,6 +1,9 @@
#![feature(start)]
#[start]
fn foo(_nargs: isize, _args: *const *const u8) -> isize {
return 0;
fn foo(nargs: isize, args: *const *const u8) -> isize {
if nargs > 0 {
assert!(unsafe{*args} as usize != 0);
}
0
}