10745a2a4a8e7fd9bcd4edbb3edd3a9c86eceff5
[libfirm] / ir / be / beutil.c
1
2 #include <stdio.h>
3
4 #include "irgraph.h"
5 #include "irgwalk.h"
6 #include "irprintf.h"
7
8 #include "beutil.h"
9 #include "besched_t.h"
10 #include "bera_t.h"
11
12 static void dump_allocated_block(ir_node *block, void *env)
13 {
14         int i, n;
15         const ir_node *irn;
16         FILE *f = env;
17
18         ir_fprintf(f, "node:{title:\"b%N\"\nlabel:\"%n\n", block, block);
19         sched_foreach(block, irn) {
20                 const char *prefix = "";
21
22                 ir_fprintf(f, "\n");
23                 if(is_color(get_irn_color(irn)))
24                         ir_fprintf(f, "r%d = ", get_irn_color(irn));
25                 ir_fprintf(f, "%n(", irn);
26
27                 if(block != get_irg_start_block(get_irn_irg(block))) {
28                         for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
29                                 ir_node *op = get_irn_n(irn, i);
30                                 if(is_allocatable_irn(op)) {
31                                         ir_fprintf(f, "%sr%d", prefix, get_irn_color(op));
32                                         prefix = ", ";
33                                 }
34                         }
35                 }
36
37                 ir_fprintf(f, ")");
38         }
39         ir_fprintf(f, "\"}\n");
40
41         if(get_irg_start_block(get_irn_irg(block)) != block) {
42                 for(i = 0, n = get_irn_arity(block); i < n; ++i) {
43                         ir_node *pred_bl = get_nodes_block(get_irn_n(block, i));
44                         ir_fprintf(f, "edge:{sourcename:\"b%N\" targetname:\"b%N\"}\n", pred_bl, block);
45                 }
46         }
47 }
48
49 void dump_allocated_irg(ir_graph *irg)
50 {
51         char buf[1024];
52         FILE *f;
53
54         snprintf(buf, sizeof(buf), "%s-alloc.vcg", get_entity_name(get_irg_entity(irg)));
55
56         if((f = fopen(buf, "wt")) != NULL) {
57                 fprintf(f, "graph:{title:\"prg\"\n");
58                 irg_block_walk_graph(irg, dump_allocated_block, NULL, f);
59                 fprintf(f, "}\n");
60                 fclose(f);
61         }
62 }