@@ -5,7 +5,7 @@ use super::int::IntKind;
5
5
use super :: item:: { Item , ItemCanonicalPath , ItemSet } ;
6
6
use super :: item_kind:: ItemKind ;
7
7
use super :: module:: { Module , ModuleKind } ;
8
- use super :: traversal:: { self , Edge , ItemTraversal } ;
8
+ use super :: traversal:: { self , Edge , ItemTraversal , Trace } ;
9
9
use super :: ty:: { FloatKind , TemplateDeclaration , Type , TypeKind } ;
10
10
use BindgenOptions ;
11
11
use cexpr;
@@ -18,6 +18,8 @@ use std::cell::Cell;
18
18
use std:: collections:: { HashMap , hash_map} ;
19
19
use std:: collections:: btree_map:: { self , BTreeMap } ;
20
20
use std:: fmt;
21
+ use std:: fs:: File ;
22
+ use std:: io:: { self , Write } ;
21
23
use std:: iter:: IntoIterator ;
22
24
use syntax:: ast:: Ident ;
23
25
use syntax:: codemap:: { DUMMY_SP , Span } ;
@@ -1109,6 +1111,33 @@ impl<'ctx> BindgenContext<'ctx> {
1109
1111
& self . options
1110
1112
}
1111
1113
1114
+ /// Output graphviz dot file.
1115
+ pub fn emit_ir_graphviz ( & self , path : String ) -> io:: Result < ( ) > {
1116
+ let file = try!( File :: create ( path) ) ;
1117
+ let mut dot_file = io:: BufWriter :: new ( file) ;
1118
+ writeln ! ( & mut dot_file, "digraph {{" ) ?;
1119
+
1120
+ let mut err: Option < io:: Result < _ > > = None ;
1121
+
1122
+ for ( id, item) in self . items ( ) {
1123
+ writeln ! ( & mut dot_file, "{} {};" , id. 0 , item. dot_attributes( self ) ) ?;
1124
+
1125
+ item. trace ( self , & mut |sub_id : ItemId , _edge_kind| {
1126
+ match writeln ! ( & mut dot_file, "{} -> {};" , id. 0 , sub_id. as_usize( ) ) {
1127
+ Ok ( _) => { } ,
1128
+ Err ( e) => err = Some ( Err ( e) ) ,
1129
+ }
1130
+ } , & ( ) ) ;
1131
+
1132
+ if err. is_some ( ) {
1133
+ return err. unwrap ( ) ;
1134
+ }
1135
+ }
1136
+
1137
+ writeln ! ( & mut dot_file, "}}" ) ?;
1138
+ Ok ( ( ) )
1139
+ }
1140
+
1112
1141
/// Tokenizes a namespace cursor in order to get the name and kind of the
1113
1142
/// namespace,
1114
1143
fn tokenize_namespace ( & self ,
0 commit comments