@@ -17,6 +17,7 @@ use rustc_front::hir;
17
17
use rustc_front:: intravisit:: { FnKind } ;
18
18
19
19
use rustc:: mir:: repr:: { BasicBlock , BasicBlockData , Mir , Statement , Terminator } ;
20
+ use rustc:: session:: Session ;
20
21
21
22
mod abs_domain;
22
23
mod dataflow;
@@ -30,6 +31,12 @@ use self::gather_moves::{MoveData};
30
31
31
32
use std:: fmt:: Debug ;
32
33
34
+ pub struct BorrowckMirData < ' tcx > {
35
+ move_data : MoveData < ' tcx > ,
36
+ flow_inits : DataflowState < MaybeInitializedLvals < ' tcx > > ,
37
+ flow_uninits : DataflowState < MaybeUninitializedLvals < ' tcx > > ,
38
+ }
39
+
33
40
pub fn borrowck_mir < ' b , ' a : ' b , ' tcx : ' a > (
34
41
bcx : & ' b mut BorrowckCtxt < ' a , ' tcx > ,
35
42
fk : FnKind ,
@@ -38,7 +45,7 @@ pub fn borrowck_mir<'b, 'a: 'b, 'tcx: 'a>(
38
45
body : & hir:: Block ,
39
46
_sp : Span ,
40
47
id : ast:: NodeId ,
41
- attributes : & [ ast:: Attribute ] ) {
48
+ attributes : & [ ast:: Attribute ] ) -> BorrowckMirData < ' tcx > {
42
49
match fk {
43
50
FnKind :: ItemFn ( name, _, _, _, _, _, _) |
44
51
FnKind :: Method ( name, _, _, _) => {
@@ -60,7 +67,6 @@ pub fn borrowck_mir<'b, 'a: 'b, 'tcx: 'a>(
60
67
bcx : bcx,
61
68
mir : mir,
62
69
node_id : id,
63
- attributes : attributes,
64
70
move_data : move_data,
65
71
flow_inits : flow_inits,
66
72
flow_uninits : flow_uninits,
@@ -72,6 +78,12 @@ pub fn borrowck_mir<'b, 'a: 'b, 'tcx: 'a>(
72
78
73
79
debug ! ( "borrowck_mir done" ) ;
74
80
81
+ return BorrowckMirData {
82
+ move_data : mbcx. move_data ,
83
+ flow_inits : mbcx. flow_inits ,
84
+ flow_uninits : mbcx. flow_uninits ,
85
+ } ;
86
+
75
87
fn do_dataflow < ' a , ' tcx , BD > ( bcx : & mut BorrowckCtxt < ' a , ' tcx > ,
76
88
mir : & ' a Mir < ' tcx > ,
77
89
node_id : NodeId ,
@@ -80,11 +92,40 @@ pub fn borrowck_mir<'b, 'a: 'b, 'tcx: 'a>(
80
92
bd : BD ) -> ( MoveData < ' tcx > , DataflowState < BD > )
81
93
where BD : BitDenotation < Ctxt =MoveData < ' tcx > > , BD :: Bit : Debug
82
94
{
95
+ use syntax:: attr:: AttrMetaMethods ;
96
+
97
+ let attr_meta_name_found = |sess : & Session , attributes : & [ ast:: Attribute ] , name| -> Option < String > {
98
+ for attr in attributes {
99
+ if attr. check_name ( "rustc_mir" ) {
100
+ let items = attr. meta_item_list ( ) ;
101
+ for item in items. iter ( ) . flat_map ( |l| l. iter ( ) ) {
102
+ if item. check_name ( name) {
103
+ if let Some ( s) = item. value_str ( ) {
104
+ return Some ( s. to_string ( ) )
105
+ } else {
106
+ sess. span_err (
107
+ item. span ,
108
+ & format ! ( "{} attribute requires a path" , item. name( ) ) ) ;
109
+ return None ;
110
+ }
111
+ }
112
+ }
113
+ }
114
+ }
115
+ return None ;
116
+ } ;
117
+
118
+ let print_preflow_to =
119
+ attr_meta_name_found ( bcx. tcx . sess , attributes, "borrowck_graphviz_preflow" ) ;
120
+ let print_postflow_to =
121
+ attr_meta_name_found ( bcx. tcx . sess , attributes, "borrowck_graphviz_postflow" ) ;
122
+
83
123
let mut mbcx = MirBorrowckCtxtPreDataflow {
84
124
bcx : bcx,
85
125
mir : mir,
86
126
node_id : node_id,
87
- attributes : attributes,
127
+ print_preflow_to : print_preflow_to,
128
+ print_postflow_to : print_postflow_to,
88
129
flow_state : DataflowStateBuilder :: new ( mir, move_data, bd) ,
89
130
} ;
90
131
@@ -99,15 +140,15 @@ pub struct MirBorrowckCtxtPreDataflow<'b, 'a: 'b, 'tcx: 'a, BD>
99
140
bcx : & ' b mut BorrowckCtxt < ' a , ' tcx > ,
100
141
mir : & ' b Mir < ' tcx > ,
101
142
node_id : ast:: NodeId ,
102
- attributes : & ' b [ ast:: Attribute ] ,
143
+ print_preflow_to : Option < String > ,
144
+ print_postflow_to : Option < String > ,
103
145
flow_state : DataflowStateBuilder < ' a , ' tcx , BD > ,
104
146
}
105
147
106
148
pub struct MirBorrowckCtxt < ' b , ' a : ' b , ' tcx : ' a > {
107
149
bcx : & ' b mut BorrowckCtxt < ' a , ' tcx > ,
108
150
mir : & ' b Mir < ' tcx > ,
109
151
node_id : ast:: NodeId ,
110
- attributes : & ' b [ ast:: Attribute ] ,
111
152
move_data : MoveData < ' tcx > ,
112
153
flow_inits : DataflowState < MaybeInitializedLvals < ' tcx > > ,
113
154
flow_uninits : DataflowState < MaybeUninitializedLvals < ' tcx > > ,
0 commit comments