2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief Write vcg representation of firm to file.
9 * @author Martin Trapp, Christian Schaefer, Goetz Lindenmaier, Hubert Schmidt,
24 #include "irgraph_t.h"
38 #include "callgraph.h"
40 #include "dbginfo_t.h"
54 * Symbolic names for the different dumping colors.
56 typedef enum ird_color_t {
58 ird_color_prog_background,
59 ird_color_block_background,
60 ird_color_dead_block_background,
61 ird_color_block_inout,
62 ird_color_default_node,
65 ird_color_controlflow,
69 ird_color_uses_memory,
79 data_edge = 0x01, /**< A data edge between two basic blocks. */
80 block_edge = 0x02, /**< An edge from a node to its basic block. */
81 cf_edge = 0x03, /**< A regularly control flow edge. */
82 exc_cf_edge = 0x04, /**< An exceptional control flow edge. */
83 mem_edge = 0x05, /**< A memory edge. */
84 dominator_edge = 0x06, /**< A dominator edge from a block to its immediate dominator. */
85 node2type_edge = 0x07, /**< An edge from an IR node to a type. */
87 ent_type_edge = 0x11, /**< An edge from an entity to its type. */
88 ent_own_edge = 0x12, /**< An edge from an entity to its owner type. */
89 ent_overwrites_edge = 0x13, /**< An edge from an entity to the entity it overwrites. */
90 ent_value_edge = 0x14, /**< An edge from an entity to its value entity. */
91 ent_corr_edge = 0x15, /**< An edge from an entity to the member entity its initializes. */
93 meth_par_edge = 0x21, /**< An edge from a method type to one of its parameter types. */
94 meth_res_edge = 0x22, /**< An edge from a method type to one of its result types. */
95 type_super_edge = 0x23, /**< An edge from a class type to its super/basis type. */
96 union_edge = 0x24, /**< An edge from a union type to its member types. */
97 ptr_pts_to_edge = 0x25, /**< An edge from a pointer type to its points-to type. */
98 arr_elt_type_edge = 0x26, /**< An edge from an array type to its element type. */
99 arr_ent_edge = 0x27, /**< An edge from a array type to its element entity. */
100 type_member_edge = 0x28, /**< An edge from a compound type to its member entities. */
102 /* additional flags */
103 intra_edge = 0, /**< Intra edge flag: edge do not cross basic block boundaries */
104 inter_edge = 0x40, /**< Inter edge flag: edge cross basic block boundaries */
105 back_edge = 0x80 /**< Backwards edge flag. */
108 /* Attributes of nodes */
109 #define PRINT_DEFAULT_NODE_ATTR
110 #define DEFAULT_NODE_ATTR " "
111 #define DEFAULT_TYPE_ATTRIBUTE " "
112 #define DEFAULT_ENUM_ITEM_ATTRIBUTE " "
114 /* Attributes of edges between Firm nodes */
115 #define INTRA_DATA_EDGE_ATTR "class:1 priority:50"
116 #define INTER_DATA_EDGE_ATTR "class:16 priority:10"
117 #define BLOCK_EDGE_ATTR "class:2 priority:50 linestyle:dotted"
118 #define CF_EDGE_ATTR "class:13 priority:60 color:red"
119 #define EXC_CF_EDGE_ATTR "class:18 priority:60 color:blue"
120 #define INTRA_MEM_EDGE_ATTR "class:14 priority:50 color:blue"
121 #define INTER_MEM_EDGE_ATTR "class:17 priority:10 color:blue"
122 #define DOMINATOR_EDGE_ATTR "class:15 color:red"
123 #define POSTDOMINATOR_EDGE_ATTR "class:19 color:red linestyle:dotted"
124 #define KEEP_ALIVE_EDGE_ATTR "class:20 priority:10 color:purple"
125 #define KEEP_ALIVE_CF_EDGE_ATTR "class:20 priority:60 color:purple"
126 #define KEEP_ALIVE_DF_EDGE_ATTR "class:20 priority:10 color:purple"
127 #define ANCHOR_EDGE_ATTR "class:20 priority:60 color:purple linestyle:dotted"
128 #define OUT_EDGE_ATTR "class:21 priority:10 color:gold linestyle:dashed"
130 #define BACK_EDGE_ATTR "linestyle:dashed "
132 /* Attributes of edges between Firm nodes and type/entity nodes */
133 #define NODE2TYPE_EDGE_ATTR "class:2 priority:2 linestyle:dotted"
135 /* Attributes of edges in type/entity graphs. */
136 #define TYPE_METH_NODE_ATTR "color: lightyellow"
137 #define TYPE_CLASS_NODE_ATTR "color: green"
138 #define TYPE_DESCRIPTION_NODE_ATTR "color: lightgreen"
139 #define ENTITY_NODE_ATTR "color: yellow"
140 #define ENUM_ITEM_NODE_ATTR "color: green"
141 #define ENT_TYPE_EDGE_ATTR "class: 3 label: \"type\" color: red"
142 #define ENT_OWN_EDGE_ATTR "class: 4 label: \"owner\" color: black"
143 #define METH_PAR_EDGE_ATTR "class: 5 label: \"param %zu\" color: green"
144 #define METH_RES_EDGE_ATTR "class: 6 label: \"res %zu\" color: green"
145 #define TYPE_SUPER_EDGE_ATTR "class: 7 label: \"supertype\" color: red"
146 #define UNION_EDGE_ATTR "class: 8 label: \"component\" color: blue"
147 #define PTR_PTS_TO_EDGE_ATTR "class: 9 label: \"points to\" color:green"
148 #define ARR_ELT_TYPE_EDGE_ATTR "class: 10 label: \"arr elt tp\" color:green"
149 #define ARR_ENT_EDGE_ATTR "class: 10 label: \"arr ent\" color: green"
150 #define ENT_OVERWRITES_EDGE_ATTR "class: 11 label: \"overwrites\" color:red"
151 #define ENT_VALUE_EDGE_ATTR "label: \"value %d\""
152 #define ENT_CORR_EDGE_ATTR "label: \"value %zu corresponds to \" "
153 #define TYPE_MEMBER_EDGE_ATTR "class: 12 label: \"member\" color:blue"
154 /* #define CALLGRAPH_EDGE_ATTR "calls" */
156 typedef struct pns_lookup {
157 long nr; /**< the proj number */
158 const char *name; /**< the name of the Proj */
161 typedef struct proj_lookup {
162 unsigned code; /**< the opcode of the Proj predecessor */
163 unsigned num_data; /**< number of data entries */
164 const pns_lookup_t *data; /**< the data */
167 #include "gen_irdump.c.inl"
169 /** Dump only irgs with names that start with this prefix. */
170 static ident *dump_file_filter_id = NULL;
172 static ir_dump_flags_t flags =
173 ir_dump_flag_blocks_as_subgraphs |
174 ir_dump_flag_keepalive_edges |
175 ir_dump_flag_ld_names |
176 ir_dump_flag_back_edges |
177 ir_dump_flag_consts_local |
178 ir_dump_flag_analysed_types |
179 ir_dump_flag_entities_in_hierarchy |
180 ir_dump_flag_number_label;
182 static ird_color_t overrule_nodecolor = ird_color_default_node;
184 /** The vcg node attribute hook. */
185 static dump_node_vcgattr_func dump_node_vcgattr_hook = NULL;
186 /** The vcg edge attribute hook. */
187 static dump_edge_vcgattr_func dump_edge_vcgattr_hook = NULL;
188 /** The vcg dump block edge hook */
189 static dump_node_edge_func dump_block_edge_hook = NULL;
190 /** The vcg dump node edge hook. */
191 static dump_node_edge_func dump_node_edge_hook = NULL;
193 void set_dump_node_edge_hook(dump_node_edge_func func)
195 dump_node_edge_hook = func;
198 dump_node_edge_func get_dump_node_edge_hook(void)
200 return dump_node_edge_hook;
203 void set_dump_block_edge_hook(dump_node_edge_func func)
205 dump_block_edge_hook = func;
208 dump_node_edge_func get_dump_block_edge_hook(void)
210 return dump_node_edge_hook;
213 void set_dump_node_vcgattr_hook(dump_node_vcgattr_func hook)
215 dump_node_vcgattr_hook = hook;
218 void set_dump_edge_vcgattr_hook(dump_edge_vcgattr_func hook)
220 dump_edge_vcgattr_hook = hook;
223 void ir_set_dump_flags(ir_dump_flags_t new_flags)
228 void ir_add_dump_flags(ir_dump_flags_t new_flags)
233 void ir_remove_dump_flags(ir_dump_flags_t to_remove)
238 ir_dump_flags_t ir_get_dump_flags(void)
243 /** Returns 0 if dump_out_edge_flag or dump_loop_information_flag
244 * are set, else returns dump_const_local_flag.
246 static bool get_opt_dump_const_local(void)
248 return (flags & ir_dump_flag_out_edges)
249 || (flags & ir_dump_flag_loops)
250 || (flags & ir_dump_flag_consts_local)
251 || (flags & ir_dump_flag_iredges);
254 static char *dump_filter;
256 void ir_set_dump_filter(const char *new_filter)
259 dump_filter = xstrdup(new_filter);
262 const char *ir_get_dump_filter(void)
267 int ir_should_dump(const char *name)
271 if (dump_filter == NULL || dump_filter[0] == '\0')
274 for (n = name, f = dump_filter; *f != '\0' && *n != '\0';
282 /* -------------- some extended helper functions ----------------- */
284 char const *get_mode_name_ex(ir_mode const *const mode)
287 return get_mode_name(mode);
291 #define CUSTOM_COLOR_BASE 100
292 static const char *color_names[ird_color_count];
293 static const char *color_rgb[ird_color_count];
294 static struct obstack color_obst;
296 /** define a custom color. */
297 static void custom_color(int num, const char *rgb_def)
299 assert(num < ird_color_count);
300 obstack_printf(&color_obst, "%d", CUSTOM_COLOR_BASE + num);
301 obstack_1grow(&color_obst, '\0');
303 color_rgb[num] = rgb_def;
304 color_names[num] = (const char*)obstack_finish(&color_obst);
307 /** Define a named color. */
308 static void named_color(int num, const char *name)
310 assert(num < ird_color_count);
311 color_rgb[num] = NULL;
312 color_names[num] = name;
315 /** Initializes the used colors. */
316 static void init_colors(void)
318 static bool initialized = 0;
322 obstack_init(&color_obst);
324 custom_color(ird_color_prog_background, "204 204 204");
325 custom_color(ird_color_block_background, "255 255 0");
326 custom_color(ird_color_dead_block_background, "190 150 150");
327 named_color(ird_color_block_inout, "lightblue");
328 named_color(ird_color_default_node, "white");
329 custom_color(ird_color_memory, "153 153 255");
330 custom_color(ird_color_controlflow, "255 153 153");
331 custom_color(ird_color_const, "204 255 255");
332 custom_color(ird_color_proj, "255 255 153");
333 custom_color(ird_color_uses_memory, "153 153 255");
334 custom_color(ird_color_phi, "105 255 105");
335 custom_color(ird_color_anchor, "100 100 255");
336 named_color(ird_color_error, "red");
337 custom_color(ird_color_entity, "204 204 255");
343 * Prints the VCG color to a file.
345 static void print_vcg_color(FILE *out, ird_color_t color)
347 assert(color < ird_color_count);
348 fprintf(out, "color:%s", color_names[color]);
351 void print_nodeid(FILE *F, const ir_node *node)
353 fprintf(F, "\"n%ld\"", get_irn_node_nr(node));
356 void print_irgid(FILE *F, const ir_graph *irg)
358 fprintf(F, "\"g%ld\"", get_irg_graph_nr(irg));
361 void print_typeid(FILE *F, const ir_type *type)
363 fprintf(F, "\"t%ld\"", get_type_nr(type));
366 void print_entityid(FILE *F, const ir_entity *entity)
368 fprintf(F, "\"e%ld\"", get_entity_nr(entity));
371 static void print_itemid(FILE *F, const ir_type *tp, size_t itemnr)
373 fprintf(F, "\"i%ldT%zu\"", get_type_nr(tp), itemnr);
377 * Prints the edge kind of a given IR node.
379 * Projs should be dumped near their predecessor, so they get "nearedge".
381 static void print_node_edge_kind(FILE *out, const ir_node *node)
384 fprintf(out, "nearedge: ");
386 fprintf(out, "edge: ");
391 * Prints the edge from a type S to a type T with additional info fmt, ...
394 static void print_type_type_edge(FILE *F, const ir_type *S, const ir_type *T, const char *fmt, ...)
399 fprintf(F, "edge: { sourcename: ");
401 fprintf(F, " targetname: ");
403 ir_vfprintf(F, fmt, ap);
409 * Prints the edge from a type tp to an entity ent with additional info fmt, ...
412 static void print_type_ent_edge(FILE *F, const ir_type *tp, const ir_entity *ent, const char *fmt, ...)
417 fprintf(F, "edge: { sourcename: ");
419 fprintf(F, " targetname: ");
420 print_entityid(F, ent);
421 ir_vfprintf(F, fmt, ap);
427 * Prints the edge from an entity ent1 to an entity ent2 with additional info fmt, ...
430 static void print_ent_ent_edge(FILE *F, const ir_entity *ent1, const ir_entity *ent2, int backedge, ird_color_t color, const char *fmt, ...)
436 fprintf(F, "backedge: { sourcename: ");
438 fprintf(F, "edge: { sourcename: ");
439 print_entityid(F, ent1);
440 fprintf(F, " targetname: ");
441 print_entityid(F, ent2);
442 ir_vfprintf(F, fmt, ap);
444 if (color != ird_color_none)
445 print_vcg_color(F, color);
451 * Prints the edge from an entity ent to a type tp with additional info fmt, ...
454 static void print_ent_type_edge(FILE *F, const ir_entity *ent, const ir_type *tp, const char *fmt, ...)
459 fprintf(F, "edge: { sourcename: ");
460 print_entityid(F, ent);
461 fprintf(F, " targetname: ");
463 ir_vfprintf(F, fmt, ap);
469 * Prints the edge from a node irn to a type tp with additional info fmt, ...
472 static void print_node_type_edge(FILE *F, const ir_node *irn, ir_type *tp, const char *fmt, ...)
477 fprintf(F, "edge: { sourcename: ");
478 print_nodeid(F, irn);
479 fprintf(F, " targetname: ");
481 ir_vfprintf(F, fmt, ap);
487 * Prints the edge from a node irn to an entity ent with additional info fmt, ...
490 static void print_node_ent_edge(FILE *F, const ir_node *irn, const ir_entity *ent, const char *fmt, ...)
495 fprintf(F, "edge: { sourcename: ");
496 print_nodeid(F, irn);
497 fprintf(F, " targetname: ");
498 print_entityid(F, ent);
499 ir_vfprintf(F, fmt, ap);
505 * Prints the edge from a type tp to an enumeration item item with additional info fmt, ...
508 static void print_enum_item_edge(FILE *F, const ir_type *tp, size_t item, const char *fmt, ...)
513 fprintf(F, "edge: { sourcename: ");
515 fprintf(F, " targetname: ");
516 print_itemid(F, tp, item);
517 ir_vfprintf(F, fmt, ap);
522 /*-----------------------------------------------------------------*/
523 /* global and ahead declarations */
524 /*-----------------------------------------------------------------*/
526 static void dump_loop_nodes_into_graph(FILE *F, ir_graph *irg);
528 /*-----------------------------------------------------------------*/
529 /* Helper functions. */
530 /*-----------------------------------------------------------------*/
533 * This map is used as a private link attr to be able to call dumper
534 * anywhere without destroying link fields.
536 static pmap *irdump_link_map = NULL;
538 /** NOT A STANDARD LIBFIRM INIT METHOD
540 * We do not want to integrate dumping into libfirm, i.e., if the dumpers
541 * are off, we want to have as few interferences as possible. Therefore the
542 * initialization is performed lazily and not called from within init_firm.
544 * Creates the link attribute map. */
545 static void init_irdump(void)
547 /* We need a new, empty map. */
548 if (irdump_link_map) pmap_destroy(irdump_link_map);
549 irdump_link_map = pmap_create();
550 if (!dump_file_filter_id)
551 dump_file_filter_id = new_id_from_str("");
555 * Returns the private link field.
557 static void *ird_get_irn_link(const ir_node *n)
559 if (irdump_link_map == NULL)
562 return pmap_get(void, irdump_link_map, n);
566 * Sets the private link field.
568 static void ird_set_irn_link(const ir_node *n, void *x)
570 if (irdump_link_map == NULL)
572 pmap_insert(irdump_link_map, n, x);
576 * Gets the private link field of an irg.
578 static void *ird_get_irg_link(const ir_graph *irg)
580 if (irdump_link_map == NULL)
583 return pmap_get(void, irdump_link_map, irg);
587 * Sets the private link field of an irg.
589 static void ird_set_irg_link(const ir_graph *irg, void *x)
591 if (irdump_link_map == NULL)
593 pmap_insert(irdump_link_map, irg, x);
597 * Walker, clears the private link field.
599 static void clear_link(ir_node *node, void *env)
602 ird_set_irn_link(node, NULL);
606 * If the entity has a ld_name, returns it if the dump_ld_name is set,
607 * else returns the name of the entity.
609 static const char *get_ent_dump_name_(const ir_entity *ent, bool dump_ld_name)
612 return "<NULL entity>";
614 /* Don't use get_entity_ld_ident (ent) as it computes the mangled name! */
615 if (ent->ld_name != NULL)
616 return get_id_str(ent->ld_name);
618 return get_id_str(ent->name);
621 const char *get_ent_dump_name(const ir_entity *ent)
623 return get_ent_dump_name_(ent, flags & ir_dump_flag_ld_names);
626 const char *get_irg_dump_name(const ir_graph *irg)
628 /* Don't use get_entity_ld_ident (ent) as it computes the mangled name! */
629 return get_ent_dump_name_(get_irg_entity(irg), true);
633 * Returns non-zero if a node is in floating state.
635 static int node_floats(const ir_node *n)
637 ir_graph *irg = get_irn_irg(n);
638 return ((get_irn_pinned(n) == op_pin_state_floats) &&
639 (get_irg_pinned(irg) == op_pin_state_floats));
643 * Walker that visits the anchors
645 static void ird_walk_graph(ir_graph *irg, irg_walk_func *pre, irg_walk_func *post, void *env)
647 if ((flags & ir_dump_flag_all_anchors)
648 || ((flags & ir_dump_flag_iredges) && edges_activated(irg))) {
649 irg_walk_anchors(irg, pre, post, env);
651 irg_walk_graph(irg, pre, post, env);
656 * Walker, allocates an array for all blocks and puts their non-floating
657 * nodes into this array.
659 static void collect_node(ir_node *node, void *env)
664 || (get_op_flags(get_irn_op(node)) & irop_flag_dump_noblock)) {
665 ir_node ** arr = (ir_node **) ird_get_irg_link(get_irn_irg(node));
666 if (!arr) arr = NEW_ARR_F(ir_node *, 0);
667 ARR_APP1(ir_node *, arr, node);
668 ird_set_irg_link(get_irn_irg(node), arr); /* arr is an l-value, APP_ARR might change it! */
670 ir_node * block = get_nodes_block(node);
673 /* this node is in a Bad block, so we must place it into the graph's list */
674 ir_node ** arr = (ir_node **) ird_get_irg_link(get_irn_irg(node));
675 if (!arr) arr = NEW_ARR_F(ir_node *, 0);
676 ARR_APP1(ir_node *, arr, node);
677 ird_set_irg_link(get_irn_irg(node), arr); /* arr is an l-value, APP_ARR might change it! */
679 ird_set_irn_link(node, ird_get_irn_link(block));
680 ird_set_irn_link(block, node);
685 /** Construct lists to walk ir block-wise.
687 * Collects all blocks, nodes not op_pin_state_pinned,
688 * Bad, NoMem and Unknown into a flexible array in link field of
689 * irg they belong to. Sets the irg link field to NULL in all
690 * graphs not visited.
691 * Free the list with DEL_ARR_F().
693 static ir_node **construct_block_lists(ir_graph *irg)
696 int walk_flag = ir_resources_reserved(irg) & IR_RESOURCE_IRN_VISITED;
699 ir_free_resources(irg, IR_RESOURCE_IRN_VISITED);
702 for (i = get_irp_n_irgs(); i > 0;)
703 ird_set_irg_link(get_irp_irg(--i), NULL);
705 ird_walk_graph(irg, clear_link, collect_node, irg);
708 ir_reserve_resources(irg, IR_RESOURCE_IRN_VISITED);
711 return (ir_node**)ird_get_irg_link(irg);
714 void dump_node_opcode(FILE *F, const ir_node *n)
716 const ir_op_ops *ops = get_op_ops(get_irn_op(n));
718 /* call the dump_node operation if available */
719 if (ops->dump_node) {
720 ops->dump_node(F, n, dump_node_opcode_txt);
724 /* implementation for default nodes */
725 switch (get_irn_opcode(n)) {
727 switch (get_SymConst_kind(n)) {
728 case symconst_addr_ent:
729 fprintf(F, "SymC &%s", get_entity_name(get_SymConst_entity(n)));
731 case symconst_ofs_ent:
732 fprintf(F, "SymC %s offset", get_entity_name(get_SymConst_entity(n)));
734 case symconst_type_size:
735 ir_fprintf(F, "SymC %+F size", get_SymConst_type(n));
737 case symconst_type_align:
738 ir_fprintf(F, "SymC %+F align", get_SymConst_type(n));
740 case symconst_enum_const:
741 fprintf(F, "SymC %s enum", get_enumeration_const_name(get_SymConst_enum(n)));
747 if (get_Load_unaligned(n) == align_non_aligned)
749 fprintf(F, "%s[%s]", get_irn_opname(n), get_mode_name_ex(get_Load_mode(n)));
752 if (get_Store_unaligned(n) == align_non_aligned)
754 fprintf(F, "%s", get_irn_opname(n));
757 if (n == get_irg_start_block(get_irn_irg(n)))
759 if (n == get_irg_end_block(get_irn_irg(n)))
761 fprintf(F, "%s%s", get_irn_opname(n),
762 (flags & ir_dump_flag_show_marks) ? (get_Block_mark(n) ? "*" : "") : "");
765 fprintf(F, "%s", get_irn_opname(n));
766 if (get_Div_no_remainder(n))
768 fprintf(F, "[%s]", get_mode_name_ex(get_Div_resmode(n)));
771 fprintf(F, "%s[%s]", get_irn_opname(n), get_mode_name_ex(get_Mod_resmode(n)));
774 fprintf(F, "%s[%s]", get_irn_opname(n), get_builtin_kind_name(get_Builtin_kind(n)));
778 fprintf(F, "%s", get_irn_opname(n));
783 * Dump the mode of a node n to a file F.
784 * Ignore modes that are "always known".
786 static void dump_node_mode(FILE *F, const ir_node *n)
788 const ir_op_ops *ops = get_op_ops(get_irn_op(n));
792 /* call the dump_node operation if available */
793 if (ops->dump_node) {
794 ops->dump_node(F, n, dump_node_mode_txt);
798 /* default implementation */
799 iro = get_irn_opcode(n);
811 mode = get_irn_mode(n);
813 if (mode != NULL && mode != mode_BB && mode != mode_ANY && mode != mode_BAD &&
814 (mode != mode_T || iro == iro_Proj))
815 fprintf(F, "%s", get_mode_name_ex(mode));
820 * Dump the type of a node n to a file F if it's known.
822 static int dump_node_typeinfo(FILE *F, const ir_node *n)
824 ir_graph *irg = get_irn_irg(n);
827 if (ir_get_dump_flags() & ir_dump_flag_analysed_types) {
828 if (get_irg_typeinfo_state(irg) == ir_typeinfo_consistent ||
829 get_irg_typeinfo_state(irg) == ir_typeinfo_inconsistent) {
830 ir_type *tp = get_irn_typeinfo_type(n);
831 if (tp != get_none_type()) {
832 ir_fprintf(F, "[%+F]", tp);
842 * Dump additional node attributes of some nodes to a file F.
844 static void dump_node_nodeattr(FILE *F, const ir_node *n)
849 const ir_op_ops *ops = get_op_ops(get_irn_op(n));
851 /* call the dump_node operation if available */
852 if (ops->dump_node) {
853 ops->dump_node(F, n, dump_node_nodeattr_txt);
857 switch (get_irn_opcode(n)) {
859 ir_fprintf(F, "%T ", get_Const_tarval(n));
863 pred = get_Proj_pred(n);
864 proj_nr = get_Proj_proj(n);
865 code = get_irn_opcode(pred);
867 if (code == iro_Proj && get_irn_opcode(get_Proj_pred(pred)) == iro_Start) {
868 fprintf(F, "Arg %ld ", proj_nr);
870 unsigned i, j, f = 0;
872 for (i = 0; i < ARRAY_SIZE(proj_lut); ++i) {
873 if (code == proj_lut[i].code) {
874 for (j = 0; j < proj_lut[i].num_data; ++j) {
875 if (proj_nr == proj_lut[i].data[j].nr) {
876 fprintf(F, "%s ", proj_lut[i].data[j].name);
885 fprintf(F, "%ld ", proj_nr);
886 if (code == iro_Cond && get_Cond_jmp_pred(pred) != COND_JMP_PRED_NONE) {
887 if (proj_nr == pn_Cond_false && get_Cond_jmp_pred(pred) == COND_JMP_PRED_FALSE)
889 if (proj_nr == pn_Cond_true && get_Cond_jmp_pred(pred) == COND_JMP_PRED_TRUE)
895 fprintf(F, "%s ", get_ent_dump_name(get_Sel_entity(n)));
898 fprintf(F, "%s ", get_relation_string(get_Cmp_relation(n)));
901 fprintf(F, "%s ", get_relation_string(get_Confirm_relation(n)));
904 ir_fprintf(F, "(%+F)", get_CopyB_type(n));
912 void dump_node_label(FILE *F, const ir_node *n)
914 dump_node_opcode(F, n);
916 dump_node_mode(F, n);
918 dump_node_typeinfo(F, n);
919 dump_node_nodeattr(F, n);
920 if (flags & ir_dump_flag_number_label) {
921 fprintf(F, "%ld", get_irn_node_nr(n));
923 if (flags & ir_dump_flag_idx_label) {
924 fprintf(F, ":%u", get_irn_idx(n));
929 * Dumps the attributes of a node n into the file F.
930 * Currently this is only the color of a node.
932 static void dump_node_vcgattr(FILE *F, const ir_node *node, const ir_node *local, bool bad)
938 print_vcg_color(F, ird_color_error);
942 if (dump_node_vcgattr_hook != NULL) {
943 dump_node_vcgattr_hook(F, node, local);
947 n = local ? local : node;
949 if (overrule_nodecolor != ird_color_default_node) {
950 print_vcg_color(F, overrule_nodecolor);
954 mode = get_irn_mode(n);
955 if (mode == mode_M) {
956 print_vcg_color(F, ird_color_memory);
959 if (mode == mode_X) {
960 print_vcg_color(F, ird_color_controlflow);
964 switch (get_irn_opcode(n)) {
967 print_vcg_color(F, ird_color_anchor);
970 print_vcg_color(F, ird_color_error);
973 print_vcg_color(F, ird_color_block_background);
976 print_vcg_color(F, ird_color_phi);
979 print_vcg_color(F, ird_color_memory);
983 print_vcg_color(F, ird_color_const);
986 print_vcg_color(F, ird_color_proj);
989 ir_op *op = get_irn_op(node);
991 if (is_op_constlike(op)) {
992 print_vcg_color(F, ird_color_const);
993 } else if (is_op_uses_memory(op)) {
994 print_vcg_color(F, ird_color_uses_memory);
995 } else if (is_op_cfopcode(op) || is_op_forking(op)) {
996 print_vcg_color(F, ird_color_controlflow);
1002 void *dump_add_node_info_callback(dump_node_info_cb_t *cb, void *data)
1004 hook_entry_t *info = XMALLOCZ(hook_entry_t);
1006 info->hook._hook_node_info = cb;
1007 info->context = data;
1008 register_hook(hook_node_info, info);
1013 void dump_remove_node_info_callback(void *handle)
1015 hook_entry_t *info = (hook_entry_t*)handle;
1016 unregister_hook(hook_node_info, info);
1021 * Dump the node information of a node n to a file F.
1023 static void dump_node_info(FILE *F, const ir_node *n)
1025 const ir_op_ops *ops = get_op_ops(get_irn_op(n));
1027 fprintf(F, " info1: \"");
1028 dump_irnode_to_file(F, n);
1029 /* call the dump_node operation if available */
1031 ops->dump_node(F, n, dump_node_info_txt);
1033 /* allow additional info to be added */
1034 hook_node_info(F, n);
1038 static int is_constlike_node(const ir_node *node)
1040 const ir_op *op = get_irn_op(node);
1041 return is_op_constlike(op);
1044 static void print_constid(FILE *F, const ir_node *user, const ir_node *node)
1046 fprintf(F, "\"n%ldb%ld\"", get_irn_node_nr(user), get_irn_node_nr(node));
1049 static void print_constblkid(FILE *F, const ir_node *node, const ir_node *block)
1051 fprintf(F, "\"n%ldb%ld\"", get_irn_node_nr(node), get_irn_node_nr(block));
1055 /** outputs the predecessors of n, that are constants, local. I.e.,
1056 generates a copy of the constant predecessors for each node called with. */
1057 static void dump_const_node_local(FILE *F, const ir_node *n)
1059 ir_graph *irg = get_irn_irg(n);
1061 if (!get_opt_dump_const_local()) return;
1063 /* Use visited flag to avoid outputting nodes twice.
1064 initialize it first. */
1065 for (i = 0; i < get_irn_arity(n); i++) {
1066 ir_node *con = get_irn_n(n, i);
1067 if (is_constlike_node(con)) {
1068 set_irn_visited(con, get_irg_visited(irg) - 1);
1072 for (i = 0; i < get_irn_arity(n); i++) {
1073 ir_node *con = get_irn_n(n, i);
1074 if (is_constlike_node(con) && !irn_visited_else_mark(con)) {
1075 /* Generate a new name for the node by appending the names of
1077 fprintf(F, "node: {title: ");
1078 print_constid(F, n, con);
1079 fprintf(F, " label: \"");
1080 dump_node_label(F, con);
1082 dump_node_info(F, con);
1083 dump_node_vcgattr(F, n, con, 0);
1089 /** If the block of an edge is a const_like node, dump it local with an edge */
1090 static void dump_const_block_local(FILE *F, const ir_node *n)
1094 if (!get_opt_dump_const_local()) return;
1096 blk = get_nodes_block(n);
1097 if (is_constlike_node(blk)) {
1098 /* Generate a new name for the node by appending the names of
1100 fprintf(F, "node: {title: ");
1101 print_constblkid(F, n, blk);
1102 fprintf(F, " label: \"");
1103 dump_node_label(F, blk);
1105 dump_node_info(F, blk);
1106 dump_node_vcgattr(F, n, blk, 0);
1109 fprintf(F, "edge: { sourcename: ");
1111 fprintf(F, " targetname: ");
1112 print_constblkid(F, n, blk);
1115 if (dump_edge_vcgattr_hook != NULL
1116 && dump_edge_vcgattr_hook(F, n, -1)) {
1121 fprintf(F, BLOCK_EDGE_ATTR "}\n");
1126 * prints the error message of a node to a file F as info2.
1128 static void print_node_error(FILE *F, const char *err_msg)
1133 fprintf(F, " info2: \"%s\"", err_msg);
1137 * prints debug messages of a node to file F as info3.
1139 static void print_dbg_info(FILE *F, dbg_info *dbg)
1143 ir_dbg_info_snprint(buf, sizeof(buf), dbg);
1145 fprintf(F, " info3: \"%s\"\n", buf);
1149 static void print_type_dbg_info(FILE *F, type_dbg_info *dbg)
1159 void dump_node(FILE *F, const ir_node *n)
1165 if (get_opt_dump_const_local() && is_constlike_node(n))
1168 /* dump this node */
1169 fputs("node: {title: ", F);
1172 fputs(" label: \"", F);
1173 irg = get_irn_irg(n);
1174 bad = ! irn_verify_irg_dump(n, irg, &p);
1175 dump_node_label(F, n);
1178 dump_node_info(F, n);
1179 print_node_error(F, p);
1180 print_dbg_info(F, get_irn_dbg_info(n));
1181 dump_node_vcgattr(F, n, NULL, bad);
1183 dump_const_node_local(F, n);
1187 /** dump the edge to the block this node belongs to */
1188 static void dump_ir_block_edge(FILE *F, const ir_node *n)
1190 if (get_opt_dump_const_local() && is_constlike_node(n)) return;
1192 ir_node *block = get_nodes_block(n);
1194 if (get_opt_dump_const_local() && is_constlike_node(block)) {
1195 dump_const_block_local(F, n);
1197 fprintf(F, "edge: { sourcename: ");
1199 fprintf(F, " targetname: ");
1200 print_nodeid(F, block);
1203 if (dump_edge_vcgattr_hook && dump_edge_vcgattr_hook(F, n, -1)) {
1208 fprintf(F, BLOCK_EDGE_ATTR "}\n");
1213 static void print_data_edge_vcgattr(FILE *F, const ir_node *from, int to)
1216 * do not use get_nodes_block() here, will fail
1217 * if the irg is not pinned.
1219 if (get_nodes_block(from) == get_nodes_block(get_irn_n(from, to)))
1220 fprintf(F, INTRA_DATA_EDGE_ATTR);
1222 fprintf(F, INTER_DATA_EDGE_ATTR);
1225 static void print_mem_edge_vcgattr(FILE *F, const ir_node *from, int to)
1228 * do not use get_nodes_block() here, will fail
1229 * if the irg is not pinned.
1231 if (get_nodes_block(from) == get_nodes_block(get_irn_n(from, to)))
1232 fprintf(F, INTRA_MEM_EDGE_ATTR);
1234 fprintf(F, INTER_MEM_EDGE_ATTR);
1237 /** Print the vcg attributes for the edge from node "from" to its "to"th input */
1238 static void print_edge_vcgattr(FILE *F, const ir_node *from, int to)
1242 if (dump_edge_vcgattr_hook)
1243 if (dump_edge_vcgattr_hook(F, from, to))
1246 if ((flags & ir_dump_flag_back_edges) && is_backedge(from, to))
1247 fprintf(F, BACK_EDGE_ATTR);
1249 switch (get_irn_opcode(from)) {
1251 fprintf(F, CF_EDGE_ATTR);
1253 case iro_Start: break;
1256 if (get_irn_mode(get_End_keepalive(from, to)) == mode_BB)
1257 fprintf(F, KEEP_ALIVE_CF_EDGE_ATTR);
1259 fprintf(F, KEEP_ALIVE_DF_EDGE_ATTR);
1263 if (is_Proj(from)) {
1264 if (get_irn_mode(from) == mode_M)
1265 print_mem_edge_vcgattr(F, from, to);
1266 else if (get_irn_mode(from) == mode_X)
1267 fprintf(F, CF_EDGE_ATTR);
1269 print_data_edge_vcgattr(F, from, to);
1271 else if (get_irn_mode(get_irn_n(from, to)) == mode_M)
1272 print_mem_edge_vcgattr(F, from, to);
1273 else if (get_irn_mode(get_irn_n(from, to)) == mode_X)
1274 fprintf(F, CF_EDGE_ATTR);
1276 print_data_edge_vcgattr(F, from, to);
1280 /** dump edges to our inputs */
1281 static void dump_ir_data_edges(FILE *F, const ir_node *n)
1285 if (dump_node_edge_hook)
1286 dump_node_edge_hook(F, n);
1288 if (!(flags & ir_dump_flag_keepalive_edges) && is_End(n)) {
1289 /* the End node has only keep-alive edges */
1293 /* dump the dependency edges. */
1294 num = get_irn_deps(n);
1295 for (i = 0; i < num; ++i) {
1296 ir_node *dep = get_irn_dep(n, i);
1299 print_node_edge_kind(F, n);
1300 fprintf(F, "{sourcename: ");
1302 fprintf(F, " targetname: ");
1303 if ((get_opt_dump_const_local()) && is_constlike_node(dep)) {
1304 print_constid(F, n, dep);
1306 print_nodeid(F, dep);
1308 fprintf(F, " label: \"%d\" ", i);
1309 fprintf(F, " color: darkgreen}\n");
1313 num = get_irn_arity(n);
1314 for (i = 0; i < num; i++) {
1315 ir_node *pred = get_irn_n(n, i);
1318 if ((flags & ir_dump_flag_back_edges) && is_backedge(n, i)) {
1319 fprintf(F, "backedge: {sourcename: ");
1321 print_node_edge_kind(F, n);
1322 fprintf(F, "{sourcename: ");
1325 fprintf(F, " targetname: ");
1326 if ((get_opt_dump_const_local()) && is_constlike_node(pred)) {
1327 print_constid(F, n, pred);
1329 print_nodeid(F, pred);
1331 fprintf(F, " label: \"%d\" ", i);
1332 print_edge_vcgattr(F, n, i);
1340 static void dump_ir_edges(ir_node *node, void *env)
1343 FILE *F = (FILE*)env;
1345 foreach_out_edge(node, edge) {
1346 ir_node *succ = get_edge_src_irn(edge);
1348 print_node_edge_kind(F, succ);
1349 fprintf(F, "{sourcename: ");
1350 print_nodeid(F, node);
1351 fprintf(F, " targetname: ");
1352 print_nodeid(F, succ);
1354 fprintf(F, " label: \"%d\" ", i);
1355 fprintf(F, OUT_EDGE_ATTR);
1362 /** Dumps a node and its edges but not the block edge */
1363 static void dump_node_wo_blockedge(FILE *F, const ir_node *n)
1366 dump_ir_data_edges(F, n);
1369 /** Dumps a node and its edges. */
1370 static void dump_node_with_edges(ir_node *n, void *env)
1372 FILE *F = (FILE*)env;
1373 dump_node_wo_blockedge(F, n);
1374 if (!node_floats(n))
1375 dump_ir_block_edge(F, n);
1378 /** Dumps a const-like node. */
1379 static void dump_const_node(ir_node *n, void *env)
1381 FILE *F = (FILE*)env;
1382 if (is_Block(n)) return;
1383 dump_node_wo_blockedge(F, n);
1386 /***********************************************************************/
1387 /* the following routines dump the nodes/irgs bracketed to graphs. */
1388 /***********************************************************************/
1390 /** Dumps a constant expression as entity initializer, array bound ... */
1391 static void dump_const_expression(FILE *F, ir_node *value)
1393 ir_graph *irg = get_const_code_irg();
1394 ir_dump_flags_t old_flags = ir_get_dump_flags();
1395 ir_remove_dump_flags(ir_dump_flag_consts_local);
1397 irg_walk(value, dump_const_node, NULL, F);
1398 /* Decrease visited flag so that we walk with the same flag for the next
1399 expression. This guarantees that we don't dump the same node twice,
1400 as for const expressions cse is performed to save memory. */
1401 set_irg_visited(irg, get_irg_visited(irg) -1);
1403 ir_set_dump_flags(old_flags);
1406 /** Dump a block as graph containing its nodes.
1408 * Expects to find nodes belonging to the block as list in its
1410 * Dumps the edges of all nodes including itself. */
1411 static void dump_whole_block(FILE *F, const ir_node *block)
1415 assert(is_Block(block));
1417 fprintf(F, "graph: { title: ");
1418 print_nodeid(F, block);
1419 fprintf(F, " label: \"");
1420 dump_node_label(F, block);
1422 fprintf(F, "\" status:clustered ");
1423 /* colorize blocks */
1424 ird_color_t const color =
1425 !get_Block_matured(block) ? ird_color_error :
1426 ird_color_block_background;
1427 print_vcg_color(F, color);
1430 /* yComp can show attributes for blocks, XVCG parses but ignores them */
1431 dump_node_info(F, block);
1432 print_dbg_info(F, get_irn_dbg_info(block));
1434 /* dump the blocks edges */
1435 dump_ir_data_edges(F, block);
1437 if (dump_block_edge_hook)
1438 dump_block_edge_hook(F, block);
1440 /* dump the nodes that go into the block */
1441 for (node = (ir_node*)ird_get_irn_link(block); node; node = (ir_node*)ird_get_irn_link(node)) {
1443 dump_ir_data_edges(F, node);
1446 /* Close the vcg information for the block */
1448 dump_const_node_local(F, block);
1452 /** dumps a graph block-wise. Expects all blockless nodes in arr in irgs link.
1453 * The outermost nodes: blocks and nodes not op_pin_state_pinned, Bad, Unknown. */
1454 static void dump_block_graph(FILE *F, ir_graph *irg)
1457 ir_node **arr = (ir_node**)ird_get_irg_link(irg);
1459 for (i = 0, n = ARR_LEN(arr); i < n; ++i) {
1460 ir_node *node = arr[i];
1461 if (is_Block(node)) {
1462 /* Dumps the block and all the nodes in the block, which are to
1463 be found in Block->link. */
1464 dump_whole_block(F, node);
1466 /* Nodes that are not in a Block. */
1468 if (!node_floats(node) && is_Bad(get_nodes_block(node))) {
1469 dump_const_block_local(F, node);
1471 dump_ir_data_edges(F, node);
1473 if ((flags & ir_dump_flag_iredges) && edges_activated(irg))
1474 dump_ir_edges(node, F);
1477 if ((flags & ir_dump_flag_loops)
1478 && irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO))
1479 dump_loop_nodes_into_graph(F, irg);
1483 * Dump the info for an irg.
1484 * Parsed by XVCG but not shown. use yComp.
1486 static void dump_graph_info(FILE *F, ir_graph *irg)
1488 fprintf(F, "info1: \"");
1489 dump_entity_to_file(F, get_irg_entity(irg));
1492 /* dump graph state */
1493 fprintf(F, "constraints:");
1494 if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_ARCH_DEP))
1495 fprintf(F, " arch_dep");
1496 if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_MODEB_LOWERED))
1497 fprintf(F, " modeb_lowered");
1498 if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_NORMALISATION2))
1499 fprintf(F, " normalisation2");
1500 if (irg_is_constrained(irg, IR_GRAPH_CONSTRAINT_OPTIMIZE_UNREACHABLE_CODE))
1501 fprintf(F, " optimize_unreachable_code");
1504 fprintf(F, "properties:");
1505 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_NO_CRITICAL_EDGES))
1506 fprintf(F, " no_critical_edges");
1507 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_NO_BADS))
1508 fprintf(F, " no_bads");
1509 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_NO_UNREACHABLE_CODE))
1510 fprintf(F, " no_unreachable_code");
1511 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_ONE_RETURN))
1512 fprintf(F, " one_return");
1513 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE))
1514 fprintf(F, " consistent_dominance");
1515 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_POSTDOMINANCE))
1516 fprintf(F, " consistent_postdominance");
1517 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_OUT_EDGES))
1518 fprintf(F, " consistent_out_edges");
1519 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_OUTS))
1520 fprintf(F, " consistent_outs");
1521 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_LOOPINFO))
1522 fprintf(F, " consistent_loopinfo");
1523 if (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_ENTITY_USAGE))
1524 fprintf(F, " consistent_entity_usage");
1528 /** Dumps an irg as a graph clustered by block nodes.
1529 * If interprocedural view edges can point to nodes out of this graph.
1531 static void dump_graph_from_list(FILE *F, ir_graph *irg)
1533 ir_entity *ent = get_irg_entity(irg);
1535 fprintf(F, "graph: { title: ");
1536 print_irgid(F, irg);
1537 fprintf(F, " label: \"%s\" status:clustered color:%s\n",
1538 get_ent_dump_name(ent), color_names[ird_color_prog_background]);
1540 dump_graph_info(F, irg);
1541 print_dbg_info(F, get_entity_dbg_info(ent));
1543 dump_block_graph(F, irg);
1545 /* Close the vcg information for the irg */
1546 fprintf(F, "}\n\n");
1549 /*******************************************************************/
1550 /* Basic type and entity nodes and edges. */
1551 /*******************************************************************/
1553 /** dumps the edges between nodes and their type or entity attributes. */
1554 static void dump_node2type_edges(ir_node *n, void *env)
1556 FILE *F = (FILE*)env;
1559 switch (get_irn_opcode(n)) {
1561 /* @@@ some consts have an entity */
1564 if (SYMCONST_HAS_TYPE(get_SymConst_kind(n)))
1565 print_node_type_edge(F,n,get_SymConst_type(n),NODE2TYPE_EDGE_ATTR);
1568 print_node_ent_edge(F,n,get_Sel_entity(n),NODE2TYPE_EDGE_ATTR);
1571 print_node_type_edge(F,n,get_Call_type(n),NODE2TYPE_EDGE_ATTR);
1574 print_node_type_edge(F,n,get_Alloc_type(n),NODE2TYPE_EDGE_ATTR);
1577 print_node_type_edge(F,n,get_Free_type(n),NODE2TYPE_EDGE_ATTR);
1584 static void print_typespecific_vcgattr(FILE *F, ir_type *tp)
1586 switch (get_type_tpop_code(tp)) {
1588 fprintf(F, " " TYPE_CLASS_NODE_ATTR);
1591 fprintf(F, " " TYPE_METH_NODE_ATTR);
1599 case tpo_enumeration:
1610 void dump_type_node(FILE *F, ir_type *tp)
1612 fprintf(F, "node: {title: ");
1613 print_typeid(F, tp);
1614 fprintf(F, " label: \"");
1615 if (tp->dbi != NULL) {
1617 ir_print_type(buf, sizeof(buf), tp);
1618 fprintf(F, "%s '%s'", get_type_tpop_name(tp), buf);
1620 ir_fprintf(F, "%+F", tp);
1622 fputs("\" info1: \"", F);
1623 dump_type_to_file(F, tp);
1625 print_type_dbg_info(F, get_type_dbg_info(tp));
1626 print_typespecific_vcgattr(F, tp);
1630 static void dump_entity_node(FILE *F, ir_entity *ent)
1632 fprintf(F, "node: {title: ");
1633 print_entityid(F, ent);
1634 fprintf(F, " label: ");
1635 fprintf(F, "\"%s\" ", get_ent_dump_name(ent));
1637 print_vcg_color(F, ird_color_entity);
1638 fprintf(F, "\n info1: \"");
1640 dump_entity_to_file(F, ent);
1643 print_dbg_info(F, get_entity_dbg_info(ent));
1647 static void dump_enum_item(FILE *F, ir_type *tp, size_t pos)
1650 ir_enum_const *ec = get_enumeration_const(tp, pos);
1651 ident *id = get_enumeration_const_nameid(ec);
1652 ir_tarval *tv = get_enumeration_value(ec);
1655 tarval_snprintf(buf, sizeof(buf), tv);
1657 strncpy(buf, "<not set>", sizeof(buf));
1658 fprintf(F, "node: {title: ");
1659 print_itemid(F, tp, pos);
1660 fprintf(F, " label: ");
1661 fprintf(F, "\"enum item %s\" " ENUM_ITEM_NODE_ATTR, get_id_str(id));
1662 fprintf(F, "\n info1: \"value: %s\"}\n", buf);
1666 * Dumps a new style initializer.
1668 static void dump_entity_initializer(FILE *F, const ir_entity *ent)
1676 * type-walker: Dumps a type or entity and its edges.
1678 static void dump_type_info(type_or_ent tore, void *env)
1680 FILE *F = (FILE*)env;
1681 size_t i = 0; /* to shutup gcc */
1683 /* dump this type or entity */
1685 switch (get_kind(tore.ent)) {
1687 ir_entity *ent = tore.ent;
1689 dump_entity_node(F, ent);
1691 /* skip this to reduce graph. Member edge of type is parallel to this edge. *
1692 fprintf(F, "edge: { sourcename: \"%p\" targetname: \"%p\" "
1693 ENT_OWN_EDGE_ATTR "}\n", ent, get_entity_owner(ent));*/
1694 print_ent_type_edge(F,ent, get_entity_type(ent), ENT_TYPE_EDGE_ATTR);
1695 if (is_Class_type(get_entity_owner(ent))) {
1696 for (i = get_entity_n_overwrites(ent); i > 0;)
1697 print_ent_ent_edge(F, ent, get_entity_overwrites(ent, --i), 0, ird_color_none, ENT_OVERWRITES_EDGE_ATTR);
1699 /* attached subgraphs */
1700 if (! (flags & ir_dump_flag_no_entity_values)) {
1701 if (ent->initializer != NULL) {
1702 /* new style initializers */
1703 dump_entity_initializer(F, ent);
1709 ir_type *tp = tore.typ;
1710 dump_type_node(F, tp);
1711 /* and now the edges */
1712 switch (get_type_tpop_code(tp)) {
1714 for (i = get_class_n_supertypes(tp); i > 0;) {
1716 print_type_type_edge(F, tp, get_class_supertype(tp, i), TYPE_SUPER_EDGE_ATTR);
1718 for (i = get_class_n_members(tp); i > 0;) {
1720 print_type_ent_edge(F, tp, get_class_member(tp, i), TYPE_MEMBER_EDGE_ATTR);
1724 for (i = get_struct_n_members(tp); i > 0;) {
1726 print_type_ent_edge(F, tp, get_struct_member(tp, i), TYPE_MEMBER_EDGE_ATTR);
1730 for (i = get_method_n_params(tp); i > 0;) {
1732 print_type_type_edge(F, tp, get_method_param_type(tp, i), METH_PAR_EDGE_ATTR,i);
1734 for (i = get_method_n_ress(tp); i > 0;) {
1736 print_type_type_edge(F, tp, get_method_res_type(tp, i), METH_RES_EDGE_ATTR,i);
1740 for (i = get_union_n_members(tp); i > 0;) {
1742 print_type_ent_edge(F, tp, get_union_member(tp, i), UNION_EDGE_ATTR);
1746 print_type_type_edge(F, tp, get_array_element_type(tp), ARR_ELT_TYPE_EDGE_ATTR);
1747 print_type_ent_edge(F, tp, get_array_element_entity(tp), ARR_ENT_EDGE_ATTR);
1748 for (i = get_array_n_dimensions(tp); i > 0;) {
1749 ir_node *upper, *lower;
1752 upper = get_array_upper_bound(tp, i);
1753 lower = get_array_lower_bound(tp, i);
1754 print_node_type_edge(F, upper, tp, "label: \"upper %zu\"", get_array_order(tp, i));
1755 print_node_type_edge(F, lower, tp, "label: \"lower %zu\"", get_array_order(tp, i));
1756 dump_const_expression(F, upper);
1757 dump_const_expression(F, lower);
1760 case tpo_enumeration:
1761 for (i = get_enumeration_n_enums(tp); i > 0;) {
1763 dump_enum_item(F, tp, i);
1764 print_enum_item_edge(F, tp, i, "label: \"item %zu\"", i);
1768 print_type_type_edge(F, tp, get_pointer_points_to_type(tp), PTR_PTS_TO_EDGE_ATTR);
1772 case tpo_uninitialized:
1777 break; /* case k_type */
1780 printf(" *** irdump, dump_type_info(l.%i), faulty type.\n", __LINE__);
1784 /** For dumping class hierarchies.
1785 * Dumps a class type node and a superclass edge.
1787 static void dump_class_hierarchy_node(type_or_ent tore, void *ctx)
1789 FILE *F = (FILE*)ctx;
1790 size_t i = 0; /* to shutup gcc */
1792 /* dump this type or entity */
1793 switch (get_kind(tore.ent)) {
1795 ir_entity *ent = tore.ent;
1796 if (get_entity_owner(ent) == get_glob_type()) break;
1797 if (!is_Method_type(get_entity_type(ent)))
1799 if (flags & ir_dump_flag_entities_in_hierarchy
1800 && is_Class_type(get_entity_owner(ent))) {
1802 dump_entity_node(F, ent);
1804 print_type_ent_edge(F, get_entity_owner(ent), ent, TYPE_MEMBER_EDGE_ATTR);
1805 for (i = get_entity_n_overwrites(ent); i > 0;) {
1807 print_ent_ent_edge(F, get_entity_overwrites(ent, i), ent, 0, ird_color_none, ENT_OVERWRITES_EDGE_ATTR);
1813 ir_type *tp = tore.typ;
1814 if (tp == get_glob_type())
1816 switch (get_type_tpop_code(tp)) {
1818 dump_type_node(F, tp);
1819 /* and now the edges */
1820 for (i = get_class_n_supertypes(tp); i > 0;) {
1822 print_type_type_edge(F,tp,get_class_supertype(tp, i),TYPE_SUPER_EDGE_ATTR);
1827 break; /* case k_type */
1830 printf(" *** irdump, dump_class_hierarchy_node(l.%i), faulty type.\n", __LINE__);
1834 /*******************************************************************/
1835 /* dump analysis information that is expressed in graph terms. */
1836 /*******************************************************************/
1838 /* dump out edges */
1839 static void dump_out_edge(ir_node *n, void *env)
1841 FILE *F = (FILE*)env;
1843 for (i = get_irn_n_outs(n) - 1; i >= 0; --i) {
1844 ir_node *succ = get_irn_out(n, i);
1846 print_node_edge_kind(F, succ);
1847 fprintf(F, "{sourcename: ");
1849 fprintf(F, " targetname: ");
1850 print_nodeid(F, succ);
1851 fprintf(F, " color: red linestyle: dashed");
1856 static void dump_loop_label(FILE *F, const ir_loop *loop)
1858 fprintf(F, "loop %u", get_loop_depth(loop));
1861 static void dump_loop_info(FILE *F, const ir_loop *loop)
1863 fprintf(F, " info1: \"");
1864 fprintf(F, " loop nr: %ld", get_loop_loop_nr(loop));
1865 #ifdef DEBUG_libfirm
1866 fprintf(F, "\n The loop was analyzed %ld times.", (long int) PTR_TO_INT(get_loop_link(loop)));
1871 void print_loopid(FILE *F, const ir_loop *loop)
1873 fprintf(F, "\"l%ld\"", get_loop_loop_nr(loop));
1876 static void dump_loop_node(FILE *F, const ir_loop *loop)
1878 fprintf(F, "node: {title: ");
1879 print_loopid(F, loop);
1880 fprintf(F, " label: \"");
1881 dump_loop_label(F, loop);
1883 dump_loop_info(F, loop);
1887 static void dump_loop_node_edge(FILE *F, const ir_loop *loop, size_t i)
1890 fprintf(F, "edge: {sourcename: ");
1891 print_loopid(F, loop);
1892 fprintf(F, " targetname: ");
1893 print_nodeid(F, get_loop_element(loop, i).node);
1894 fprintf(F, " color: green");
1898 static void dump_loop_son_edge(FILE *F, const ir_loop *loop, size_t i)
1901 fprintf(F, "edge: {sourcename: ");
1902 print_loopid(F, loop);
1903 fprintf(F, " targetname: ");
1904 print_loopid(F, get_loop_element(loop, i).son);
1905 ir_fprintf(F, " color: darkgreen label: \"%zu\"}\n", i);
1908 static void dump_loops(FILE *F, const ir_loop *loop)
1911 size_t n_elements = get_loop_n_elements(loop);
1912 /* dump this loop node */
1913 dump_loop_node(F, loop);
1915 /* dump edges to nodes in loop -- only if it is a real loop */
1916 if (get_loop_depth(loop) != 0) {
1917 for (i = n_elements; i > 0;) {
1918 loop_element element;
1920 element = get_loop_element(loop, i);
1921 if (*element.kind != k_ir_node)
1923 dump_loop_node_edge(F, loop, i);
1926 for (i = n_elements; i > 0;) {
1927 loop_element element;
1929 element = get_loop_element(loop, i);
1930 if (*element.kind != k_ir_loop)
1932 dump_loops(F, element.son);
1933 dump_loop_son_edge(F, loop, i);
1937 static void dump_loop_nodes_into_graph(FILE *F, ir_graph *irg)
1939 ir_loop *loop = get_irg_loop(irg);
1941 dump_loops(F, loop);
1945 void dump_vcg_header_colors(FILE *F)
1949 for (i = 0; i < ird_color_count; ++i) {
1950 if (color_rgb[i] != NULL) {
1951 fprintf(F, "colorentry %s: %s\n", color_names[i], color_rgb[i]);
1956 void dump_vcg_infonames(FILE *F)
1959 "infoname 1: \"Attribute\"\n"
1960 "infoname 2: \"Verification errors\"\n"
1961 "infoname 3: \"Debug info\"\n", F);
1965 * dumps the VCG header
1967 void dump_vcg_header(FILE *F, const char *name, const char *layout, const char *orientation)
1970 = (flags & ir_dump_flag_disable_edge_labels) ? "no" : "yes";
1972 if (! layout) layout = "Compilergraph";
1973 if (!orientation) orientation = "bottom_to_top";
1977 "graph: { title: \"ir graph of %s\"\n"
1978 "display_edge_labels: %s\n"
1979 "layoutalgorithm: mindepth //$ \"%s\"\n"
1980 "manhattan_edges: yes\n"
1981 "port_sharing: no\n"
1983 "classname 1: \"intrablock Data\"\n"
1984 "classname 2: \"Block\"\n"
1985 "classname 3: \"Entity type\"\n"
1986 "classname 4: \"Entity owner\"\n"
1987 "classname 5: \"Method Param\"\n"
1988 "classname 6: \"Method Res\"\n"
1989 "classname 7: \"Super\"\n"
1990 "classname 8: \"Union\"\n"
1991 "classname 9: \"Points-to\"\n"
1992 "classname 10: \"Array Element Type\"\n"
1993 "classname 11: \"Overwrites\"\n"
1994 "classname 12: \"Member\"\n"
1995 "classname 13: \"Control Flow\"\n"
1996 "classname 14: \"intrablock Memory\"\n"
1997 "classname 15: \"Dominators\"\n"
1998 "classname 16: \"interblock Data\"\n"
1999 "classname 17: \"interblock Memory\"\n"
2000 "classname 18: \"Exception Control Flow for Interval Analysis\"\n"
2001 "classname 19: \"Postdominators\"\n"
2002 "classname 20: \"Keep Alive\"\n"
2003 "classname 21: \"Out Edges\"\n"
2004 "classname 22: \"Macro Block Edges\"\n",
2005 name, label, layout, orientation);
2006 dump_vcg_infonames(F);
2007 dump_vcg_header_colors(F);
2012 * Dumps the vcg file footer
2014 void dump_vcg_footer(FILE *F)
2021 static void dump_blocks_as_subgraphs(FILE *out, ir_graph *irg)
2025 construct_block_lists(irg);
2028 * If we are in the interprocedural view, we dump not
2029 * only the requested irg but also all irgs that can be reached
2032 for (i = get_irp_n_irgs(); i > 0;) {
2033 ir_graph *other_irg = get_irp_irg(--i);
2034 ir_node **arr = (ir_node**)ird_get_irg_link(other_irg);
2038 dump_graph_from_list(out, other_irg);
2043 void dump_ir_graph_file(FILE *out, ir_graph *irg)
2045 dump_vcg_header(out, get_irg_dump_name(irg), NULL, NULL);
2048 if (flags & ir_dump_flag_blocks_as_subgraphs) {
2049 dump_blocks_as_subgraphs(out, irg);
2051 /* dump_node_with_edges must be called in post visiting predecessors */
2052 ird_walk_graph(irg, NULL, dump_node_with_edges, out);
2055 /* dump type info */
2056 if (flags & ir_dump_flag_with_typegraph) {
2057 type_walk_irg(irg, dump_type_info, NULL, out);
2058 inc_irg_visited(get_const_code_irg());
2059 /* dump edges from graph to type info */
2060 irg_walk(get_irg_end(irg), dump_node2type_edges, NULL, out);
2063 /* dump iredges out edges */
2064 if ((flags & ir_dump_flag_iredges) && edges_activated(irg)) {
2065 irg_walk_edges(get_irg_start_block(irg), dump_ir_edges, NULL, out);
2068 /* dump the out edges in a separate walk */
2069 if ((flags & ir_dump_flag_out_edges)
2070 && (irg_has_properties(irg, IR_GRAPH_PROPERTY_CONSISTENT_OUTS))) {
2071 irg_out_walk(get_irg_start(irg), dump_out_edge, NULL, out);
2074 dump_vcg_footer(out);
2077 static void dump_block_to_cfg(ir_node *block, void *env)
2079 FILE *F = (FILE*)env;
2082 if (is_Bad(block) && get_irn_mode(block) == mode_X) {
2083 dump_node(F, block);
2086 if (is_Block(block)) {
2087 /* This is a block. Dump a node for the block. */
2088 fprintf(F, "node: {title: ");
2089 print_nodeid(F, block);
2090 fprintf(F, " label: \"");
2091 if (block == get_irg_start_block(get_irn_irg(block)))
2092 fprintf(F, "Start ");
2093 if (block == get_irg_end_block(get_irn_irg(block)))
2096 fprintf(F, "%s ", get_op_name(get_irn_op(block)));
2097 print_nodeid(F, block);
2099 fprintf(F, "info1:\"");
2101 /* the generic version. */
2102 dump_irnode_to_file(F, block);
2104 fprintf(F, "\""); /* closing quote of info */
2106 if ((block == get_irg_start_block(get_irn_irg(block))) ||
2107 (block == get_irg_end_block(get_irn_irg(block))) )
2108 fprintf(F, " color:blue ");
2112 /* Dump the edges */
2113 for (i = get_Block_n_cfgpreds(block) - 1; i >= 0; --i) {
2114 ir_node *pred = get_Block_cfgpred(block, i);
2116 pred = get_nodes_block(pred);
2117 fprintf(F, "edge: { sourcename: ");
2118 print_nodeid(F, block);
2119 fprintf(F, " targetname: ");
2120 print_nodeid(F, pred);
2121 fprintf(F, "\"}\n");
2124 /* Dump dominator/postdominator edge */
2125 if (ir_get_dump_flags() & ir_dump_flag_dominance) {
2126 if (irg_has_properties(get_irn_irg(block), IR_GRAPH_PROPERTY_CONSISTENT_DOMINANCE) && get_Block_idom(block)) {
2127 ir_node *pred = get_Block_idom(block);
2128 fprintf(F, "edge: { sourcename: ");
2129 print_nodeid(F, block);
2130 fprintf(F, " targetname: ");
2131 print_nodeid(F, pred);
2132 fprintf(F, " " DOMINATOR_EDGE_ATTR "}\n");
2134 if (irg_has_properties(get_irn_irg(block), IR_GRAPH_PROPERTY_CONSISTENT_POSTDOMINANCE) && get_Block_ipostdom(block)) {
2135 ir_node *pred = get_Block_ipostdom(block);
2136 fprintf(F, "edge: { sourcename: ");
2137 print_nodeid(F, block);
2138 fprintf(F, " targetname: ");
2139 print_nodeid(F, pred);
2140 fprintf(F, " " POSTDOMINATOR_EDGE_ATTR "}\n");
2146 void dump_cfg(FILE *F, ir_graph *irg)
2148 dump_vcg_header(F, get_irg_dump_name(irg), NULL, NULL);
2150 /* walk over the blocks in the graph */
2151 irg_walk_graph(irg, dump_block_to_cfg, NULL, F);
2156 void dump_callgraph(FILE *F)
2159 ir_dump_flags_t old_flags = ir_get_dump_flags();
2161 ir_remove_dump_flags(ir_dump_flag_disable_edge_labels);
2162 dump_vcg_header(F, "Callgraph", "Hierarchic", NULL);
2164 for (i = get_irp_n_irgs(); i > 0;) {
2165 ir_graph *irg = get_irp_irg(--i);
2166 ir_entity *ent = get_irg_entity(irg);
2167 size_t j, n_callees = get_irg_n_callees(irg);
2169 dump_entity_node(F, ent);
2170 for (j = 0; j < n_callees; ++j) {
2171 ir_entity *c = get_irg_entity(get_irg_callee(irg, j));
2172 int be = is_irg_callee_backedge(irg, j);
2173 const char *attr = be
2174 ? "label:\"recursion %zu\""
2175 : "label:\"calls %zu\"";
2176 print_ent_ent_edge(F, ent, c, be, ird_color_entity, attr,
2177 get_irg_callee_loop_depth(irg, j));
2181 ir_set_dump_flags(old_flags);
2185 void dump_typegraph(FILE *out)
2187 dump_vcg_header(out, "All_types", NULL, NULL);
2188 type_walk(dump_type_info, NULL, out);
2189 dump_vcg_footer(out);
2192 void dump_class_hierarchy(FILE *out)
2194 dump_vcg_header(out, "class_hierarchy", NULL, NULL);
2195 type_walk(dump_class_hierarchy_node, NULL, out);
2196 dump_vcg_footer(out);
2199 static void dump_loops_standalone(FILE *F, ir_loop *loop)
2202 bool loop_node_started = false;
2204 size_t son_number = 0;
2206 ir_loop *son = NULL;
2208 /* Dump a new loop node. */
2209 dump_loop_node(F, loop);
2211 /* Dump the loop elements. */
2212 for (i = 0; i < get_loop_n_elements(loop); i++) {
2213 le = get_loop_element(loop, i);
2215 if (get_kind(son) == k_ir_loop) {
2217 /* We are a loop son -> Recurse */
2219 if (loop_node_started) { /* Close the "firm-nodes" node first if we started one. */
2220 fprintf(F, "\" }\n");
2221 fprintf(F, "edge: {sourcename: ");
2222 print_loopid(F, loop);
2223 fprintf(F, " targetname: \"l%ld-%lu-nodes\" label:\"%lu...%lu\"}\n",
2224 get_loop_loop_nr(loop),
2225 (unsigned long) first,
2226 (unsigned long) first,
2227 (unsigned long) i-1);
2228 loop_node_started = false;
2230 dump_loop_son_edge(F, loop, son_number++);
2231 dump_loops_standalone(F, son);
2232 } else if (get_kind(son) == k_ir_node) {
2233 /* We are a loop node -> Collect firm nodes */
2235 ir_node *n = le.node;
2236 if (!loop_node_started) {
2237 /* Start a new node which contains all firm nodes of the current loop */
2238 fprintf(F, "node: { title: \"l%ld-%lu-nodes\" color: lightyellow label: \"",
2239 get_loop_loop_nr(loop),
2241 loop_node_started = true;
2246 dump_node_label(F, n);
2247 if (has_backedges(n)) fprintf(F, "\t loop head!");
2248 } else { /* for callgraph loop tree */
2250 assert(get_kind(son) == k_ir_graph);
2252 /* We are a loop node -> Collect firm graphs */
2254 if (!loop_node_started) {
2255 /* Start a new node which contains all firm nodes of the current loop */
2256 fprintf(F, "node: { title: \"l%ld-%lu-nodes\" color: lightyellow label: \"",
2257 get_loop_loop_nr(loop),
2259 loop_node_started = true;
2263 fprintf(F, " %s", get_irg_dump_name(n));
2264 /* fprintf(F, " %s (depth %d)", get_irg_dump_name(n), n->callgraph_weighted_loop_depth); */
2268 if (loop_node_started) {
2269 fprintf(F, "\" }\n");
2270 fprintf(F, "edge: {sourcename: \"");
2271 print_loopid(F, loop);
2272 fprintf(F, "\" targetname: \"l%ld-%lu-nodes\" label:\"%lu...%lu\"}\n",
2273 get_loop_loop_nr(loop),
2274 (unsigned long) first,
2275 (unsigned long) first,
2276 (unsigned long) i-1);
2280 void dump_loop_tree(FILE *out, ir_graph *irg)
2282 ir_dump_flags_t old_flags = ir_get_dump_flags();
2284 ir_remove_dump_flags(ir_dump_flag_disable_edge_labels);
2286 dump_vcg_header(out, get_irg_dump_name(irg), "Tree", "top_to_bottom");
2288 if (get_irg_loop(irg))
2289 dump_loops_standalone(out, get_irg_loop(irg));
2291 dump_vcg_footer(out);
2293 ir_set_dump_flags(old_flags);
2296 void dump_callgraph_loop_tree(FILE *out)
2298 dump_vcg_header(out, "callgraph looptree", "Tree", "top_to_bottom");
2299 dump_loops_standalone(out, irp->outermost_cg_loop);
2300 dump_vcg_footer(out);
2303 static void collect_nodeloop(FILE *F, ir_loop *loop, pset *loopnodes)
2307 int node_number = 0;
2309 if (flags & ir_dump_flag_loops)
2310 dump_loop_node(F, loop);
2312 for (i = 0; i < get_loop_n_elements(loop); i++) {
2313 loop_element le = get_loop_element(loop, i);
2314 if (*(le.kind) == k_ir_loop) {
2315 if (flags & ir_dump_flag_loops)
2316 dump_loop_son_edge(F, loop, son_number++);
2318 collect_nodeloop(F, le.son, loopnodes);
2320 if (flags & ir_dump_flag_loops)
2321 dump_loop_node_edge(F, loop, node_number++);
2322 pset_insert_ptr(loopnodes, le.node);
2327 static void collect_nodeloop_external_nodes(ir_loop *loop, pset *loopnodes,
2333 for (i = 0; i < get_loop_n_elements(loop); i++) {
2334 loop_element le = get_loop_element(loop, i);
2335 if (*(le.kind) == k_ir_loop) {
2337 collect_nodeloop_external_nodes(le.son, loopnodes, extnodes);
2339 if (is_Block(le.node)) start = 0; else start = -1;
2340 for (j = start; j < get_irn_arity(le.node); j++) {
2341 ir_node *pred = get_irn_n(le.node, j);
2342 if (!pset_find_ptr(loopnodes, pred)) {
2343 pset_insert_ptr(extnodes, pred);
2344 if (!is_Block(pred)) {
2345 pred = get_nodes_block(pred);
2346 if (!pset_find_ptr(loopnodes, pred))
2347 pset_insert_ptr(extnodes, pred);
2355 void dump_loop(FILE *F, ir_loop *l)
2357 pset *loopnodes = pset_new_ptr_default();
2358 pset *extnodes = pset_new_ptr_default();
2361 snprintf(name, sizeof(name), "loop_%ld", get_loop_loop_nr(l));
2362 dump_vcg_header(F, name, NULL, NULL);
2364 /* collect all nodes to dump */
2365 collect_nodeloop(F, l, loopnodes);
2366 collect_nodeloop_external_nodes(l, loopnodes, extnodes);
2368 /* build block lists */
2369 foreach_pset(loopnodes, ir_node, n) {
2370 set_irn_link(n, NULL);
2372 foreach_pset(extnodes, ir_node, n) {
2373 set_irn_link(n, NULL);
2375 foreach_pset(loopnodes, ir_node, n) {
2377 ir_node *const b = get_nodes_block(n);
2378 set_irn_link(n, get_irn_link(b));
2382 foreach_pset(extnodes, ir_node, n) {
2384 ir_node *const b = get_nodes_block(n);
2385 set_irn_link(n, get_irn_link(b));
2390 foreach_pset(loopnodes, ir_node, b) {
2392 fprintf(F, "graph: { title: ");
2394 fprintf(F, " label: \"");
2395 dump_node_opcode(F, b);
2396 fprintf(F, " %ld:%u", get_irn_node_nr(b), get_irn_idx(b));
2397 fprintf(F, "\" status:clustered color:yellow\n");
2399 /* dump the blocks edges */
2400 dump_ir_data_edges(F, b);
2402 /* dump the nodes that go into the block */
2403 for (ir_node *n = (ir_node*)get_irn_link(b); n; n = (ir_node*)get_irn_link(n)) {
2404 if (pset_find_ptr(extnodes, n))
2405 overrule_nodecolor = ird_color_block_inout;
2407 overrule_nodecolor = ird_color_default_node;
2408 if (!pset_find_ptr(extnodes, n)) dump_ir_data_edges(F, n);
2411 /* Close the vcg information for the block */
2413 dump_const_node_local(F, b);
2417 foreach_pset(extnodes, ir_node, b) {
2419 fprintf(F, "graph: { title: ");
2421 fprintf(F, " label: \"");
2422 dump_node_opcode(F, b);
2423 fprintf(F, " %ld:%u", get_irn_node_nr(b), get_irn_idx(b));
2424 fprintf(F, "\" status:clustered color:lightblue\n");
2426 /* dump the nodes that go into the block */
2427 for (ir_node *n = (ir_node*)get_irn_link(b); n; n = (ir_node*)get_irn_link(n)) {
2428 if (!pset_find_ptr(loopnodes, n))
2429 overrule_nodecolor = ird_color_block_inout;
2431 overrule_nodecolor = ird_color_default_node;
2432 if (pset_find_ptr(loopnodes, n)) dump_ir_data_edges(F, n);
2435 /* Close the vcg information for the block */
2437 dump_const_node_local(F, b);
2441 del_pset(loopnodes);
2447 static bool obstack_init;
2448 static struct obstack obst;
2449 static char *dump_path;
2451 void ir_set_dump_path(const char *path)
2454 dump_path = xstrdup(path);
2457 static void add_string_escaped(const char *string)
2460 for (p = string; *p != '\0'; ++p) {
2463 obstack_1grow(&obst, '@');
2464 obstack_1grow(&obst, '1');
2465 } else if (c == '@') {
2466 obstack_1grow(&obst, '@');
2467 obstack_1grow(&obst, '2');
2469 obstack_1grow(&obst, c);
2474 static void add_dump_path(void)
2476 if (!obstack_init) {
2477 obstack_init(&obst);
2478 obstack_init = true;
2481 if (dump_path != NULL) {
2482 size_t len = strlen(dump_path);
2483 obstack_grow(&obst, dump_path, len);
2484 if (len > 0 && dump_path[len-1] != '/')
2485 obstack_1grow(&obst, '/');
2489 void dump_ir_graph_ext(ir_graph_dump_func func, ir_graph *graph,
2492 const char *dump_name = get_irg_dump_name(graph);
2496 if (!ir_should_dump(dump_name))
2501 add_string_escaped(dump_name);
2502 obstack_printf(&obst, "-%02u", graph->dump_nr++);
2504 if (suffix != NULL) {
2505 if (suffix[0] != '.')
2506 obstack_1grow(&obst, '-');
2507 add_string_escaped(suffix);
2509 obstack_1grow(&obst, '\0');
2511 file_name = (char*)obstack_finish(&obst);
2512 /* xvcg expects only <LF> so we need "b"inary mode (for win32) */
2513 out = fopen(file_name, "wb");
2514 obstack_free(&obst, file_name);
2517 fprintf(stderr, "Couldn't open '%s': %s\n", file_name, strerror(errno));
2525 void dump_ir_prog_ext(ir_prog_dump_func func, const char *suffix)
2532 obstack_printf(&obst, "%02u", irp->dump_nr++);
2533 if (suffix != NULL) {
2534 if (suffix[0] != '.')
2535 obstack_1grow(&obst, '-');
2536 add_string_escaped(suffix);
2538 obstack_1grow(&obst, '\0');
2540 file_name = (char*)obstack_finish(&obst);
2541 out = fopen(file_name, "wb");
2542 obstack_free(&obst, file_name);
2545 fprintf(stderr, "Couldn't open '%s': %s\n", file_name, strerror(errno));
2552 void dump_ir_graph(ir_graph *graph, const char *suffix)
2556 snprintf(buf, sizeof(buf), "%s.vcg", suffix);
2557 dump_ir_graph_ext(dump_ir_graph_file, graph, buf);
2560 void dump_all_ir_graphs(const char *suffix)
2562 size_t i, n_irgs = get_irp_n_irgs();
2564 for (i = 0; i < n_irgs; ++i) {
2565 ir_graph *irg = get_irp_irg(i);
2566 dump_ir_graph(irg, suffix);
2570 typedef struct pass_t {
2571 ir_prog_pass_t pass;
2576 * Wrapper around dump_all_ir_graphs().
2578 static int dump_all_ir_graphs_wrapper(ir_prog *irp, void *context)
2580 pass_t *pass = (pass_t*)context;
2583 dump_all_ir_graphs(pass->suffix);
2587 ir_prog_pass_t *dump_all_ir_graph_pass(const char *name, const char *suffix)
2589 size_t len = strlen(suffix) + 1;
2590 pass_t *pass = XMALLOCF(pass_t, suffix, len);
2591 ir_prog_pass_t *res = def_prog_pass_constructor(
2592 &pass->pass, name ? name : "dump_all_graphs", dump_all_ir_graphs_wrapper);
2594 /* this pass does not change anything, so neither dump nor verify is needed. */
2595 res->dump_irprog = ir_prog_no_dump;
2596 res->verify_irprog = ir_prog_no_verify;
2598 memcpy(pass->suffix, suffix, len);