@@ -55,16 +55,28 @@ where
55
55
writeln ! ( w, "{} {}Mir_{} {{" , kind, cluster, def_name) ?;
56
56
57
57
// Global graph properties
58
- writeln ! ( w, r#" graph [fontname="monospace"];"# ) ?;
59
- writeln ! ( w, r#" node [fontname="monospace"];"# ) ?;
60
- writeln ! ( w, r#" edge [fontname="monospace"];"# ) ?;
58
+ let font = r#"fontname="Courier, monospace""# ;
59
+ let mut graph_attrs = vec ! [ font] ;
60
+ let mut content_attrs = vec ! [ font] ;
61
+
62
+ let dark_mode = tcx. sess . opts . debugging_opts . graphviz_dark_mode ;
63
+ if dark_mode {
64
+ graph_attrs. push ( r#"bgcolor="black""# ) ;
65
+ content_attrs. push ( r#"color="white""# ) ;
66
+ content_attrs. push ( r#"fontcolor="white""# ) ;
67
+ }
68
+
69
+ writeln ! ( w, r#" graph [{}];"# , graph_attrs. join( " " ) ) ?;
70
+ let content_attrs_str = content_attrs. join ( " " ) ;
71
+ writeln ! ( w, r#" node [{}];"# , content_attrs_str) ?;
72
+ writeln ! ( w, r#" edge [{}];"# , content_attrs_str) ?;
61
73
62
74
// Graph label
63
75
write_graph_label ( tcx, def_id, body, w) ?;
64
76
65
77
// Nodes
66
78
for ( block, _) in body. basic_blocks ( ) . iter_enumerated ( ) {
67
- write_node ( def_id, block, body, w) ?;
79
+ write_node ( def_id, block, body, dark_mode , w) ?;
68
80
}
69
81
70
82
// Edges
84
96
pub fn write_node_label < W : Write , INIT , FINI > (
85
97
block : BasicBlock ,
86
98
body : & Body < ' _ > ,
99
+ dark_mode : bool ,
87
100
w : & mut W ,
88
101
num_cols : u32 ,
89
102
init : INIT ,
@@ -100,8 +113,9 @@ where
100
113
// Basic block number at the top.
101
114
write ! (
102
115
w,
103
- r#"<tr><td {attrs} colspan="{colspan}">{blk}</td></tr>"# ,
104
- attrs = r#"bgcolor="gray" align="center""# ,
116
+ r#"<tr><td bgcolor="{bgcolor}" {attrs} colspan="{colspan}">{blk}</td></tr>"# ,
117
+ bgcolor = if dark_mode { "dimgray" } else { "gray" } ,
118
+ attrs = r#"align="center""# ,
105
119
colspan = num_cols,
106
120
blk = block. index( )
107
121
) ?;
@@ -134,11 +148,12 @@ fn write_node<W: Write>(
134
148
def_id : DefId ,
135
149
block : BasicBlock ,
136
150
body : & Body < ' _ > ,
151
+ dark_mode : bool ,
137
152
w : & mut W ,
138
153
) -> io:: Result < ( ) > {
139
154
// Start a new node with the label to follow, in one of DOT's pseudo-HTML tables.
140
155
write ! ( w, r#" {} [shape="none", label=<"# , node( def_id, block) ) ?;
141
- write_node_label ( block, body, w, 1 , |_| Ok ( ( ) ) , |_| Ok ( ( ) ) ) ?;
156
+ write_node_label ( block, body, dark_mode , w, 1 , |_| Ok ( ( ) ) , |_| Ok ( ( ) ) ) ?;
142
157
// Close the node label and the node itself.
143
158
writeln ! ( w, ">];" )
144
159
}
0 commit comments