doxygen docu fixed
[libfirm] / ir / ir / irdump.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/irdump.h
4  * Purpose:     Write vcg representation of firm to file.
5  * Author:      Martin Trapp, Christian Schaefer
6  * Modified by: Goetz Lindenmaier, Hubert Schmidt
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1998-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13
14 /**
15  * @file irdump.h
16  *
17  * Dump routines for the ir graph and all type information.
18  *
19  * @author Martin Trapp, Christian Schaefer
20  *
21  * The dump format of most functions is vcg.  This is a text based graph
22  * representation. Some use the original format,
23  * but most generate an extended format that is only read by some special
24  * versions of xvcg or by the comercialized version now calles aiSee.
25  * A test version of aiSee is available at
26  * http://www.absint.de/aisee/download/index.htm.
27  *
28  * Most routines use the name of the passed entity as the name of the
29  * file dumped to.
30  */
31
32
33 # ifndef _IRDUMP_H_
34 # define _IRDUMP_H_
35
36 # include "irnode.h"
37 # include "irgraph.h"
38 # include "irloop.h"
39
40
41 /* **************************************************************************** */
42 /*                                 GRAPH DUMPERS                                */
43 /* **************************************************************************** */
44
45 /**
46  * This hook is called to insert some special nodes into dumped graph
47  */
48 typedef int (*DUMP_IR_GRAPH_FUNC)(FILE *F, ir_graph *irg);
49 /**
50  * This hook is called to dump the vcg attributes of a node to a file.
51  * If this function returns zero, the default attributes are added, else
52  * removed.
53  */
54 typedef int (*DUMP_NODE_VCGATTR_FUNC)(FILE *F, ir_node *node, ir_node *local);
55 /**
56  * This hook is called to dump the vcg attributes of an edge to a file.
57  * If this function returns zero, the default attributes are added, else
58  * removed.
59  */
60 typedef int (*DUMP_EDGE_VCGATTR_FUNC)(FILE *F, ir_node *node, int to);
61
62 /** Set the ir graph dump hook. */
63 void set_dump_ir_graph_hook(DUMP_IR_GRAPH_FUNC hook);
64 /** Set the node_vcgattr hook. */
65 void set_dump_node_vcgattr_hook(DUMP_NODE_VCGATTR_FUNC hook);
66 /** Set the edge_vcgattr hook. */
67 void set_dump_edge_vcgattr_hook(DUMP_EDGE_VCGATTR_FUNC hook);
68
69 typedef int (*DUMP_NODE_EDGE_FUNC)(FILE *f, ir_node *node);
70
71 /**
72  * Set the hook to be called to dump additional edges to a node.
73  * @param func The hook to be called.
74  */
75 void set_dump_node_edge_hook(DUMP_NODE_EDGE_FUNC func);
76
77 /**
78  * Get the additional edge dump hook.
79  * @return The current additional edge dump hook.]
80  */
81 DUMP_NODE_EDGE_FUNC get_dump_node_edge_hook(void);
82
83 /** Dump a firm graph.
84  *
85  *  @param irg     The firm graph to be dumped.
86  *  @param suffix  A suffix for the file name.
87  *
88  *  @return
89  *     A file containing the firm graph in vcg format.
90  *
91  *  Dumps all Firm nodes of a single graph for a single procedure in
92  *  standard xvcg format.  Dumps the graph to a file.  The file name
93  *  is constructed from the name of the entity describing the
94  *  procedure (irg->entity) and the ending -pure<-ip>.vcg.  Eventually
95  *  overwrites existing files.  Visits all nodes in
96  *  interprocedural_view.
97  *
98  * @see turn_off_edge_labels()
99  */
100 void dump_ir_graph (ir_graph *irg, const char *suffix);
101
102 /** Dump a firm graph without explicit block nodes.
103  *
104  *  @param irg     The firm graph to be dumped.
105  *  @param suffix  A suffix for the file name.
106  *
107  *  @return
108  *     A file containing the firm graph in vcg format.
109  *
110  *  Dumps all Firm nodes of a single graph for a single procedure in
111  *  extended xvcg format.
112  *  Dumps the graph to a file.  The file name is constructed from the
113  *  name of the entity describing the procedure (irg->entity) and the
114  *  ending <-ip>.vcg.  Eventually overwrites existing files.  Dumps several
115  *  procedures in boxes if interprocedural_view.
116  *
117  * @see turn_off_edge_labels()
118  */
119 void dump_ir_block_graph (ir_graph *irg, const char *suffix);
120
121 /** Dump a firm graph without explicit block nodes but grouped in extended blocks.
122  *
123  *  @param irg   The firm graph to be dumped.
124  *
125  *  @return
126  *     A file containing the firm graph in vcg format.
127  *
128  *  Dumps all Firm nodes of a single graph for a single procedure in
129  *  extended xvcg format.
130  *  Dumps the graph to a file.  The file name is constructed from the
131  *  name of the entity describing the procedure (irg->entity) and the
132  *  ending <-ip>.vcg.  Eventually overwrites existing files.  Dumps several
133  *  procedures in boxes if interprocedural_view.
134  *
135  * @see turn_off_edge_labels()
136  */
137 void dump_ir_extblock_graph (ir_graph *irg, const char *suffix);
138
139 /** Dumps all graphs in interprocedural view to a file named All_graphs<suffix>.vcg.
140  *
141  * @param suffix  A suffix for the file name.
142  */
143 void dump_all_cg_block_graph(const char *suffix);
144
145 /** Dumps a firm graph and  all the type information needed for Calls,
146  *  Sels, ... in this graph.
147  *
148  *  @param irg     The firm graph to be dumped with its type information.
149  *  @param suffix  A suffix for the file name.
150  *
151  *  @return
152  *      A file containing the firm graph and the type information of the firm graph in vcg format.
153  *
154  *  Dumps the graph to a file.  The file name is constructed from the
155  *  name of the entity describing the procedure (irg->entity) and the
156  *  ending -all.vcg.  Eventually overwrites existing files.
157  *
158  * @see turn_off_edge_labels()
159  */
160 void dump_ir_graph_w_types (ir_graph *irg, const char *suffix);
161
162 /** Dumps a firm graph and  all the type information needed for Calls,
163  *  Sels, ... in this graph.
164  *
165  *  @param irg     The firm graph to be dumped with its type information.
166  *  @param suffix  A suffix for the file name.
167  *
168  *  @return
169  *      A file containing the firm graph and the type information of the firm graph in vcg format.
170  *
171  *  The graph is in blocked format.
172  *  Dumps the graph to a file.  The file name is constructed from the
173  *  name of the entity describing the procedure (irg->entity) and the
174  *  ending -all.vcg.  Eventually overwrites existing files.
175  *
176  * @see turn_off_edge_labels()
177  */
178 void dump_ir_block_graph_w_types (ir_graph *irg, const char *suffix);
179
180 /** The type of a dump function that is called for each graph.
181  *
182  *  @param irg     current visited graph
183  *  @param suffix  A suffix for the file name.
184  */
185 typedef void dump_graph_func(ir_graph *irg, const char *suffix);
186
187 /**
188  * A walker that calls a dumper for each graph.
189  *
190  * @param dump_graph    The dumper to be used for dumping.
191  * @param suffix        A suffix for the file name.
192  *
193  * @return
194  *      Whatever the dumper creates.
195  *
196  *  Walks over all firm graphs and  calls a dumper for each graph.
197  *  The following dumpers can be passed as arguments:
198  *   - dump_ir_graph()
199  *   - dump_ir_block_graph()
200  *   - dump_cfg()
201  *   - dump_type_graph()
202  *   - dump_ir_graph_w_types()
203  *
204  * @see turn_off_edge_labels()
205  */
206 void dump_all_ir_graphs (dump_graph_func *dump_graph, const char *suffix);
207
208
209 /**
210  * Dump the control flow graph of a procedure.
211  *
212  * @param irg     The firm graph whose CFG shall be dumped.
213  * @param suffix  A suffix for the file name.
214  *
215  * @return
216  *      A file containing the CFG in vcg format.
217  *
218  * Dumps the control flow graph of a procedure in standard xvcg format.
219  * Dumps the graph to a file.  The file name is constructed from the
220  * name of the entity describing the procedure (irg->entity) and the
221  * ending -cfg.vcg.  Eventually overwrites existing files.
222  *
223  * @see turn_off_edge_labels()
224  */
225 void dump_cfg (ir_graph *irg, const char *suffix);
226
227 /**
228  * Dump a node and its predecessors forming a subgraph to a vcg file.
229  *
230  * @param root   The node serving as root for the subgraph.
231  * @param depth  Dump nodes on paths starting at root with length depth.
232  * @param suffix A suffix for the file name.
233  *
234  * Dumps the graph to a file.  The file name is constructed from the
235  * name of the entity describing the procedure the passed node is
236  * in, suffix and the ending -subg_<nr>.vcg.  nr is a unique number
237  * for each graph dumped. Eventually overwrites existing files.
238  *
239  * @return
240  *      A file containing the subgraph in vcg format.
241  */
242 void dump_subgraph (ir_node *root, int depth, const char *suffix);
243
244 /* **************************************************************************** */
245 /*                              CALLGRAPH DUMPERS                               */
246 /* **************************************************************************** */
247
248
249 /** Dump the call graph.
250  *
251  * Dumps the callgraph to a file "Callgraph"<suffix>".vcg".
252  *
253  * @param suffix A suffix for the file name.
254  *
255  * @see dump_callgraph_loop_tree(const char *suffix)
256  */
257 void dump_callgraph(const char *suffix);
258
259 /* **************************************************************************** */
260 /*                              TYPEGRAPH DUMPERS                               */
261 /* **************************************************************************** */
262
263 /**
264  * Dumps all the type information needed for Calls, Sels, ... in this graph.
265  * Does not dump the graph!
266  *
267  * @param irg    The firm graph whose type information is to be dumped.
268  * @param suffix A suffix for the file name.
269  *
270  * @return
271  *      A file containing the type information of the firm graph in vcg format.
272  *
273  *  Dumps this graph to a file.  The file name is constructed from the
274  *  name of the entity describing the procedure (irg->entity) and the
275  *  ending -type.vcg.  Eventually overwrites existing files.
276  *
277  * @see turn_off_edge_labels()
278  */
279 void dump_type_graph (ir_graph *irg, const char *suffix);
280
281 /**
282  * Dumps all type information.
283  *
284  * @param suffix A suffix for the file name.
285  *
286  * @return
287  *      A file containing all type information for the program in standard
288  *      vcg format.
289  *
290  * Dumps all type information that is somehow reachable in standard vcg
291  * format.
292  * Dumps the graph to a file named All_types.vcg.
293  *
294  * @see turn_off_edge_labels()
295  */
296 void dump_all_types (const char *suffix);
297
298 /**
299  * Dumps the class hierarchy with or without entities.
300  *
301  * @param entities    Flag whether to dump the entities.
302  * @param suffix      A suffix for the file name.
303  *
304  * @return
305  *      A file containing the class hierarchy tree for the program in standard
306  *      vcg format.
307  *
308  * Does not dump the global type.
309  * Dumps a node for all classes and the sub/supertype relations.  If
310  * entities is set to true also dumps the entities of classes, but without
311  * any additional information as the entities type.  The overwrites relation
312  * is dumped along with the entities.
313  * Dumps to a file class_hierarchy.vcg
314  */
315 void dump_class_hierarchy (bool entities, const char *suffix);
316
317 /* **************************************************************************** */
318 /*                              LOOPTREE DUMPERS                                */
319 /* **************************************************************************** */
320
321 /**
322  * Dump a standalone loop tree, which contains the loop nodes and the firm nodes
323  * belonging to one loop packed together in one subgraph.  Dumps to file
324  * <name of irg><suffix>-looptree.vcg
325  * Turns on edge labels by default.
326  *
327  * Implementing this dumper was stimulated by Florian Liekwegs similar dumper.
328  *
329  * @param irg     Dump the loop tree for this graph.
330  * @param suffix  A suffix for the file name.
331  */
332 void dump_loop_tree(ir_graph *irg, const char *suffix);
333
334 /** Dumps the firm nodes in the sub-loop-tree of loop to a graph.
335  *
336  * Dumps the loop nodes if dump_loop_information() is set.
337  * The name of the file is loop_<loop_nr><suffix>.vcg.
338  *
339  * @param l       Dump the loop tree for this loop.
340  * @param suffix  A suffix for the file name.
341  */
342 void dump_loop (ir_loop *l, const char *suffix);
343
344 /** Dumps the loop tree over the call graph.
345  *
346  * See for yourself what you can use this for.
347  * The filename is "Callgraph_looptree<suffix>.vcg".
348  *
349  * @param suffix  A suffix for the file name.
350  */
351 void dump_callgraph_loop_tree(const char *suffix);
352
353
354 /* **************************************************************************** */
355 /*                                TEXT DUMPERS                                  */
356 /* **************************************************************************** */
357
358
359 /** Write the irnode and all its attributes to the file passed.
360  * */
361 int dump_irnode_to_file (FILE *f, ir_node *n);
362
363 /** Write the irnode and all its attributes to stdout.
364  *  */
365 void dump_irnode (ir_node *n);
366
367 /** Write the graph and all its attributes to the file passed.
368  *  Does not write the nodes.
369  * */
370 void dump_graph_to_file(FILE *F, ir_graph *irg);
371
372 /** Write the graph and all its attributes to stdout.
373  *  Does not write the nodes.
374  *  */
375 void dump_graph(ir_graph *g);
376
377
378 /** Dump graph information as text.
379  *
380  *  Often graphs are unhandy in their vcg representation.  The text
381  *  dumper represents the information for the firm nodes more compact,
382  *  but the relations between the nodes only implicitly.
383  *
384  *  The file name is the graph name (get_entity_name()), appended by
385  *  <suffix>.txt.
386  */
387 void dump_graph_as_text(ir_graph *irg, const char *suffix);
388
389
390 /** Verbosity for text dumpers */
391 typedef enum {
392   dump_verbosity_onlynames         = 0x00000001,   /**< only dump names. turns off all other
393                                                       flags up to 0x00010000. */
394   dump_verbosity_fields            = 0x00000002,   /**< dump types and fields (like a type declaration) */
395   dump_verbosity_methods           = 0x00000004,   /**< dump types and methods (like a type declaration) */
396   dump_verbosity_nostatic          = 0x00000040,   /**< dump types and dynamic allocated fields (like a
397                                                         type declaration). This excludes methods and
398                                                         static, polymorphic fields. */
399   dump_verbosity_typeattrs         = 0x00000008,   /**< dump all type attributes */
400   dump_verbosity_entattrs          = 0x00000010,   /**< dump all entity attributes */
401   dump_verbosity_entconsts         = 0x00000020,   /**< dump entity constants */
402
403   dump_verbosity_accessStats       = 0x00000100,   /**< dump entity access statistics */
404   dump_verbosity_csv               = 0x00000200,   /**< dump access statistics as comma separated list */
405
406   dump_verbosity_noClassTypes      = 0x00001000,   /**< dump no class       types */
407   dump_verbosity_noStructTypes     = 0x00002000,   /**< dump no struct      types */
408   dump_verbosity_noUnionTypes      = 0x00004000,   /**< dump no union       types */
409   dump_verbosity_noArrayTypes      = 0x00008000,   /**< dump no array       types */
410   dump_verbosity_noPointerTypes    = 0x00010000,   /**< dump no pointer     types */
411   dump_verbosity_noMethodTypes     = 0x00020000,   /**< dump no method      types */
412   dump_verbosity_noPrimitiveTypes  = 0x00040000,   /**< dump no primitive   types */
413   dump_verbosity_noEnumerationTypes= 0x00080000,   /**< dump no enumeration types */
414
415   dump_verbosity_onlyClassTypes     = 0x000FE000,  /**< dump only class     types */
416   dump_verbosity_onlyStructTypes    = 0x000FD000,  /**< dump only struct    types */
417   dump_verbosity_onlyUnionTypes     = 0x000FB000,  /**< dump only union     types */
418   dump_verbosity_onlyArrayTypes     = 0x000F7000,  /**< dump only array     types */
419   dump_verbosity_onlyPointerTypes   = 0x000EF000,  /**< dump only pointer   types */
420   dump_verbosity_onlyMethodTypes    = 0x000DF000,  /**< dump only method    types */
421   dump_verbosity_onlyPrimitiveTypes = 0x000BF000,  /**< dump only primitive types */
422   dump_verbosity_onlyEnumerationTypes=0x0007F000,  /**< dump only enumeration types */
423
424   dump_verbosity_max                = 0x4FF00FBE   /**< turn on all verbosity.
425                                                         Do not turn on negative flags!
426                                                         @@@ Because of a bug in gcc 3.2 we can not set the
427                                                         first two bits. */
428 } dump_verbosity;
429
430
431 /** Write the entity and all its attributes to the passed file.
432  *  */
433 void    dump_entity_to_file (FILE *F, entity *ent, unsigned verbosity);
434
435 /** Write the entity and all its attributes to the stdout.
436  *
437  *  Calls dump_entity_to_file().  */
438 void    dump_entity (entity *ent);
439
440 /** Write the type and all its attributes to the file passed.
441  * */
442 void    dump_type_to_file (FILE *f, type *tp, dump_verbosity verbosity);
443
444 /** Write the type and all its attributes to stdout.
445  *  */
446 void    dump_type (type *tp);
447
448
449 /** Dump type information as text.
450  *
451  *  Often type graphs are unhandy in their vcg representation.  The text
452  *  dumper represents the information for a single type more compact, but
453  *  the relations between the types only implicitly.
454  *  Dumps only 'real' types, i.e., those in the type list.  Does not dump
455  *  the global type nor frame types or the like.
456  *
457  *  The file name is the program name (get_irp_name()), or 'TextTypes'
458  *  if the program name is not set, appended by <suffix>-types.txt.
459  *  For verbosity see the documentation of the verbosity flags above.
460  */
461 void dump_types_as_text(unsigned verbosity, const char *suffix);
462
463 /** Dumps all global variables as text.
464  *
465  * @param suffix  A suffix for the file name.
466  *
467  * Dumps a text representation of the entities in the global type.
468  *
469  * The file name is the program name (get_irp_name()), or 'TextTypes'
470  * if the program name is not set, appended by <suffix>-globals.txt.
471  * For verbosity see the documentation of the verbosity flags above.
472  */
473 void dump_globals_as_text(unsigned verbosity, const char *suffix);
474
475 /* **************************************************************************** */
476 /*                                    FLAGS                                     */
477 /* **************************************************************************** */
478
479 /** Output a selected graph.
480  *
481  * All graph dumpers check this name.  If the name is != "" and
482  * not a prefix of the graph to be dumped, the dumper does not
483  * dump the graph.
484  *
485  * @param name The prefix of the name (not the ld_name) of the method
486  *              entity to be dumped.
487  */
488 void   only_dump_method_with_name(ident *name);
489
490 /** Returns the name set with only_dump_method_with_name(). */
491 ident *get_dump_file_filter_ident(void);
492
493 /** Returns true if dump file filter is not set, or if it is a
494  *  prefix of name. */
495 int is_filtered_dump_name(ident *name);
496
497 /** Sets the vcg flag "display_edge_labels" to no.
498  *
499  * This is necessary as xvcg and aisee both fail to display graphs
500  * with self-edges if these edges have labels.
501  */
502 void turn_off_edge_labels(void);
503
504 /**
505  * If set to true constants will be replicated for every use. In non
506  * blocked view edges from constant to block are skipped.  Vcg then
507  * layouts the graphs more compact, this makes them better readable.
508  * The flag is automatically and temporarily set to false if other
509  * edges are dumped, as outs, loop, ...
510  * Default setting: false.
511  */
512 void dump_consts_local(bool b);
513
514 /**
515  * Returns false if dump_out_edge_flag or dump_loop_information_flag
516  * are set, else returns dump_const_local_flag.
517  */
518 bool get_opt_dump_const_local(void);
519
520 /**  Turns off dumping the values of constant entities. Makes type graphs
521  *   better readable.
522  */
523 void dump_constant_entity_values(bool b);
524
525 /**  Turns on dumping the edges from the End node to nodes to be kept
526  *   alive.
527  */
528 void dump_keepalive_edges(bool b);
529 bool get_opt_dump_keepalive_edges(void);
530
531 /** Turns on dumping the out edges starting from the Start block in
532  *  dump_ir_graph.
533  *
534  *  To test the consistency of the out data structure.
535  */
536 void dump_out_edges(bool b);
537
538 /** If this flag is set the dumper dumps edges to immediate dominator in cfg.
539  */
540 void dump_dominator_information(bool b);
541
542 /** If this flag is set the dumper dumps loop nodes and edges from
543  *  these nodes to the contained ir nodes.
544  *
545  *  If the loops are interprocedural nodes can be missing.
546  */
547 void dump_loop_information(bool b);
548
549 /** If set and backedge info is computed, backedges are dumped dashed
550  *  and as vcg 'backedge' construct.
551  *
552  *  Default: set.
553  */
554 void dump_backedge_information(bool b);
555
556 /** Dump the information of type field specified in ana/irtypeinfo.h.
557  *
558  *  If the flag is set, the type name is output in [] in the node label,
559  *  else it is output as info.
560  */
561 void set_opt_dump_analysed_type_info(bool b);
562
563 /** Write the address of a node into the vcg info.
564  *
565  *  This is off per default for automatic comparisons of
566  *  vcg graphs -- these will differ in the pointer values!
567  */
568 void dump_pointer_values_to_info(bool b);
569
570 /** Dumps ld_names of entities instead of there names.
571  *
572  * This option is on per default.
573  */
574 void dump_ld_names(bool b);
575
576 # endif /* _IRDUMP_H_ */