+static int weight_overall(int rec, int loop) {
+ return 2*rec + loop;
+}
+
+static int compute_color (int my, int max) {
+ int color;
+ if (!max) {
+ color = 0;
+ } else {
+ /* if small, scale to the full color range. */
+ if (max < n_colors)
+ my = my * (n_colors/max);
+
+ int step = 1 + (max / n_colors);
+
+ color = my/step;
+ }
+ return base_color + n_colors - color;
+}
+
+static int get_entity_color(entity *ent) {
+ assert(get_entity_irg(ent));
+ ir_graph *irg = get_entity_irg(ent);
+
+ int rec_depth = get_irg_recursion_depth(irg);
+ int loop_depth = get_irg_loop_depth(irg);
+ int overall_depth = weight_overall(rec_depth, loop_depth);
+
+ int max_rec_depth = irp->max_callgraph_recursion_depth;
+ int max_loop_depth = irp->max_callgraph_loop_depth;
+ int max_overall_depth = weight_overall(max_rec_depth, max_loop_depth);
+
+ int my_rec_color = compute_color(rec_depth, max_rec_depth);
+ int my_loop_color = compute_color(loop_depth, max_loop_depth);
+ int my_overall_color = compute_color(overall_depth, max_overall_depth);;
+
+ return my_overall_color;
+}
+
+void dump_callgraph(const char *suffix) {
+ FILE *F;
+ int i, n_irgs = get_irp_n_irgs();
+ int rem = edge_label;
+ edge_label = 1;
+ //ident *prefix = new_id_from_str("java/");
+
+ F = vcg_open_name("Callgraph", suffix);
+ dump_vcg_header(F, "Callgraph", NULL);
+
+ for (i = 0; i < n_irgs; ++i) {
+ ir_graph *irg = get_irp_irg(i);
+ entity *ent = get_irg_entity(irg);
+ int j, n_callees = get_irg_n_callees(irg);
+
+ /* Do not dump runtime system. */
+ //if (id_is_prefix(prefix, get_entity_ld_ident(ent))) continue;
+
+ dump_entity_node(F, ent, get_entity_color(ent));
+ for (j = 0; j < n_callees; ++j) {
+ entity *c = get_irg_entity(get_irg_callee(irg, j));
+ //if (id_is_prefix(prefix, get_entity_ld_ident(c))) continue;
+ int be = is_irg_callee_backedge(irg, j);
+ char *attr;
+ attr = (be) ?
+ "label:\"recursion %d\" color: %d" :
+ "label:\"calls %d\" color: %d";
+ print_ent_ent_edge(F, ent, c, be, attr, get_irg_callee_loop_depth(irg, j), get_entity_color(ent));
+ }
+ }