@@ -162,3 +162,43 @@ void dump_cfg_auto(Module* mod) {
162
162
dump_cfg (f , mod );
163
163
fclose (f );
164
164
}
165
+
166
+ static void dump_domtree_cfnode (Printer * p , CFNode * idom ) {
167
+ String name = get_abstraction_name_unsafe (idom -> node );
168
+ if (name )
169
+ print (p , "bb_%zu [label=\"%s\", shape=box];\n" , (size_t ) idom , name );
170
+ else
171
+ print (p , "bb_%zu [label=\"%%%d\", shape=box];\n" , (size_t ) idom , idom -> node -> id );
172
+
173
+ for (size_t i = 0 ; i < entries_count_list (idom -> dominates ); i ++ ) {
174
+ CFNode * child = read_list (CFNode * , idom -> dominates )[i ];
175
+ dump_domtree_cfnode (p , child );
176
+ print (p , "bb_%zu -> bb_%zu;\n" , (size_t ) (idom ), (size_t ) (child ));
177
+ }
178
+ }
179
+
180
+ void dump_domtree_scope (Printer * p , Scope * s ) {
181
+ print (p , "subgraph cluster_%s {\n" , get_abstraction_name (s -> entry -> node ));
182
+ dump_domtree_cfnode (p , s -> entry );
183
+ print (p , "}\n" );
184
+ }
185
+
186
+ void dump_domtree_module (Printer * p , Module * mod ) {
187
+ print (p , "digraph G {\n" );
188
+ struct List * scopes = build_scopes (mod );
189
+ for (size_t i = 0 ; i < entries_count_list (scopes ); i ++ ) {
190
+ Scope * scope = read_list (Scope * , scopes )[i ];
191
+ dump_domtree_scope (p , scope );
192
+ destroy_scope (scope );
193
+ }
194
+ destroy_list (scopes );
195
+ print (p , "}\n" );
196
+ }
197
+
198
+ void dump_domtree_auto (Module * mod ) {
199
+ FILE * f = fopen ("domtree.dot" , "wb" );
200
+ Printer * p = open_file_as_printer (f );
201
+ dump_domtree_module (p , mod );
202
+ destroy_printer (p );
203
+ fclose (f );
204
+ }
0 commit comments