@@ -55,16 +55,28 @@ where
5555 writeln ! ( w, "{} {}Mir_{} {{" , kind, cluster, def_name) ?;
5656
5757 // 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) ?;
6173
6274 // Graph label
6375 write_graph_label ( tcx, def_id, body, w) ?;
6476
6577 // Nodes
6678 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) ?;
6880 }
6981
7082 // Edges
8496pub fn write_node_label < W : Write , INIT , FINI > (
8597 block : BasicBlock ,
8698 body : & Body < ' _ > ,
99+ dark_mode : bool ,
87100 w : & mut W ,
88101 num_cols : u32 ,
89102 init : INIT ,
@@ -100,8 +113,9 @@ where
100113 // Basic block number at the top.
101114 write ! (
102115 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""# ,
105119 colspan = num_cols,
106120 blk = block. index( )
107121 ) ?;
@@ -134,11 +148,12 @@ fn write_node<W: Write>(
134148 def_id : DefId ,
135149 block : BasicBlock ,
136150 body : & Body < ' _ > ,
151+ dark_mode : bool ,
137152 w : & mut W ,
138153) -> io:: Result < ( ) > {
139154 // Start a new node with the label to follow, in one of DOT's pseudo-HTML tables.
140155 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 ( ( ) ) ) ?;
142157 // Close the node label and the node itself.
143158 writeln ! ( w, ">];" )
144159}
0 commit comments