@@ -19,7 +19,6 @@ use miri::{
19
19
use rustc:: session:: Session ;
20
20
use rustc_driver:: { driver, CompilerCalls } ;
21
21
use rustc:: ty:: { TyCtxt , subst} ;
22
- use rustc:: mir:: mir_map:: MirMap ;
23
22
use rustc:: hir:: def_id:: DefId ;
24
23
25
24
struct MiriCompilerCalls ;
@@ -34,57 +33,46 @@ impl<'a> CompilerCalls<'a> for MiriCompilerCalls {
34
33
35
34
control. after_analysis . callback = Box :: new ( |state| {
36
35
state. session . abort_if_errors ( ) ;
37
- interpret_start_points ( state. tcx . unwrap ( ) , state. mir_map . unwrap ( ) ) ;
38
- } ) ;
39
-
40
- control
41
- }
42
- }
43
-
44
36
37
+ let tcx = state. tcx . unwrap ( ) ;
38
+ let mir_map = state. mir_map . unwrap ( ) ;
39
+
40
+ let ( node_id, span) = state. session . entry_fn . borrow ( ) . expect ( "no main or start function found" ) ;
41
+ debug ! ( "found `main` function at: {:?}" , span) ;
42
+
43
+ let mir = mir_map. map . get ( & node_id) . expect ( "no mir for main function" ) ;
44
+ let def_id = tcx. map . local_def_id ( node_id) ;
45
+ let mut ecx = EvalContext :: new ( tcx, mir_map) ;
46
+ let substs = tcx. mk_substs ( subst:: Substs :: empty ( ) ) ;
47
+ let return_ptr = ecx. alloc_ret_ptr ( mir. return_ty , substs) . expect ( "main function should not be diverging" ) ;
48
+
49
+ ecx. push_stack_frame ( def_id, mir. span , CachedMir :: Ref ( mir) , substs, Some ( return_ptr) ) ;
50
+
51
+ if mir. arg_decls . len ( ) == 2 {
52
+ // start function
53
+ let ptr_size = ecx. memory ( ) . pointer_size ;
54
+ let nargs = ecx. memory_mut ( ) . allocate ( ptr_size) ;
55
+ ecx. memory_mut ( ) . write_usize ( nargs, 0 ) . unwrap ( ) ;
56
+ let args = ecx. memory_mut ( ) . allocate ( ptr_size) ;
57
+ ecx. memory_mut ( ) . write_usize ( args, 0 ) . unwrap ( ) ;
58
+ ecx. frame_mut ( ) . locals [ 0 ] = nargs;
59
+ ecx. frame_mut ( ) . locals [ 1 ] = args;
60
+ }
45
61
46
- fn interpret_start_points < ' a , ' tcx > (
47
- tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
48
- mir_map : & MirMap < ' tcx > ,
49
- ) {
50
- let initial_indentation = :: log_settings:: settings ( ) . indentation ;
51
- for ( & id, mir) in & mir_map. map {
52
- for attr in tcx. map . attrs ( id) {
53
- use syntax:: attr:: AttrMetaMethods ;
54
- if attr. check_name ( "miri_run" ) {
55
- let item = tcx. map . expect_item ( id) ;
56
-
57
- :: log_settings:: settings ( ) . indentation = initial_indentation;
58
-
59
- debug ! ( "Interpreting: {}" , item. name) ;
60
-
61
- let mut ecx = EvalContext :: new ( tcx, mir_map) ;
62
- let substs = tcx. mk_substs ( subst:: Substs :: empty ( ) ) ;
63
- let return_ptr = ecx. alloc_ret_ptr ( mir. return_ty , substs) ;
64
-
65
- ecx. push_stack_frame ( tcx. map . local_def_id ( id) , mir. span , CachedMir :: Ref ( mir) , substs, return_ptr) ;
66
-
67
- loop {
68
- match step ( & mut ecx) {
69
- Ok ( true ) => { }
70
- Ok ( false ) => {
71
- match return_ptr {
72
- Some ( ptr) => if log_enabled ! ( :: log:: LogLevel :: Debug ) {
73
- ecx. memory ( ) . dump ( ptr. alloc_id ) ;
74
- } ,
75
- None => warn ! ( "diverging function returned" ) ,
76
- }
77
- break ;
78
- }
79
- // FIXME: diverging functions can end up here in some future miri
80
- Err ( e) => {
81
- report ( tcx, & ecx, e) ;
82
- break ;
83
- }
62
+ loop {
63
+ match step ( & mut ecx) {
64
+ Ok ( true ) => { }
65
+ Ok ( false ) => break ,
66
+ // FIXME: diverging functions can end up here in some future miri
67
+ Err ( e) => {
68
+ report ( tcx, & ecx, e) ;
69
+ break ;
84
70
}
85
71
}
86
72
}
87
- }
73
+ } ) ;
74
+
75
+ control
88
76
}
89
77
}
90
78
0 commit comments