new verbosity flags
[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 /** Dump a firm graph.
46  *
47  *  @param irg  The firm graph to be dumped.
48  *
49  *  @return
50  *     A file containing the firm graph in vcg format.
51  *
52  *  Dumps all Firm nodes of a single graph for a single procedure in
53  *  standard xvcg format.  Dumps the graph to a file.  The file name
54  *  is constructed from the name of the entity describing the
55  *  procedure (irg->entity) and the ending -pure<-ip>.vcg.  Eventually
56  *  overwrites existing files.  Visits all nodes in
57  *  interprocedural_view.
58  *
59  * @see turn_off_edge_labels()
60  */
61 void dump_ir_graph (ir_graph *irg, const char *suffix);
62
63 /** Dump a firm graph without explicit block nodes.
64  *
65  *  @param irg   The firm graph to be dumped.
66  *
67  *  @return
68  *     A file containing the firm graph in vcg format.
69  *
70  *  Dumps all Firm nodes of a single graph for a single procedure in
71  *  extended xvcg format.
72  *  Dumps the graph to a file.  The file name is constructed from the
73  *  name of the entity describing the procedure (irg->entity) and the
74  *  ending <-ip>.vcg.  Eventually overwrites existing files.  Dumps several
75  *  procedures in boxes if interprocedural_view.
76  *
77  * @see turn_off_edge_labels()
78  */
79 void dump_ir_block_graph (ir_graph *irg, const char *suffix);
80
81 /** Dumps all graphs in interprocedural view to a file named All_graphs.vcg.
82  */
83 void dump_all_cg_block_graph(const char *suffix);
84
85 /** Dumps a firm graph and  all the type information needed for Calls,
86  *  Sels, ... in this graph.
87  *
88  *  @param irg   The firm graph to be dumped with its type information.
89  *
90  *  @return
91  *      A file containing the firm graph and the type information of the firm graph in vcg format.
92  *
93  *  Dumps the graph to a file.  The file name is constructed from the
94  *  name of the entity describing the procedure (irg->entity) and the
95  *  ending -all.vcg.  Eventually overwrites existing files.
96  *
97  * @see turn_off_edge_labels()
98  */
99 void dump_ir_graph_w_types (ir_graph *irg, const char *suffix);
100
101 /** Dumps a firm graph and  all the type information needed for Calls,
102  *  Sels, ... in this graph.
103  *
104  *  @param irg   The firm graph to be dumped with its type information.
105  *
106  *  @return
107  *      A file containing the firm graph and the type information of the firm graph in vcg format.
108  *
109  *  The graph is in blocked format.
110  *  Dumps the graph to a file.  The file name is constructed from the
111  *  name of the entity describing the procedure (irg->entity) and the
112  *  ending -all.vcg.  Eventually overwrites existing files.
113  *
114  * @see turn_off_edge_labels()
115  */
116 void dump_ir_block_graph_w_types (ir_graph *irg, const char *suffix);
117
118 /** The type of a walker function that is called for each graph.
119  *
120  *  @param irg   current visited graph
121  */
122 typedef void dump_graph_func(ir_graph *irg, const char *suffix);
123
124 /**  A walker that calls a dumper for each graph.
125  *
126  *   @param dump_graph    The dumper to be used for dumping.
127  *
128  *   @return
129  *      Whatever the dumper creates.
130  *
131  *   Walks over all firm graphs and  calls a dumper for each graph.
132  *   The following dumpers can be passed as arguments:
133  *   - dump_ir_graph()
134  *   - dump_ir_block_graph()
135  *   - dump_cfg()
136  *   - dump_type_graph()
137  *   - dump_ir_graph_w_types()
138  *
139  * @see turn_off_edge_labels()
140  */
141 void dump_all_ir_graphs (dump_graph_func *dump_graph, const char *suffix);
142
143
144 /**  Dump the control flow graph of a procedure.
145  *
146  *   @param irg  The firm graph whose CFG shall be dumped.
147  *
148  *   @return
149  *      A file containing the CFG in vcg format.
150  *
151  *   Dumps the control flow graph of a procedure in standard xvcg format.
152  *   Dumps the graph to a file.  The file name is constructed from the
153  *   name of the entity describing the procedure (irg->entity) and the
154  *   ending -cfg.vcg.  Eventually overwrites existing files.
155  *
156  * @see turn_off_edge_labels()
157  */
158 void dump_cfg (ir_graph *irg, const char *suffix);
159
160
161 /* **************************************************************************** */
162 /*                              CALLGRAPH DUMPERS                               */
163 /* **************************************************************************** */
164
165
166 /** Dump the call graph.
167  *
168  * Dumps the callgraph to a file "Callgraph"<suffix>".vcg".
169  */
170 void dump_callgraph(const char *suffix);
171
172 /* **************************************************************************** */
173 /*                              TYPEGRAPH DUMPERS                               */
174 /* **************************************************************************** */
175
176 /**
177  *  Dumps all the type information needed for Calls, Sels, ... in this graph.
178  *  Does not dump the graph!
179  *
180  *  @param irg   The firm graph whose type information is to be dumped.
181  *  @return
182  *      A file containing the type information of the firm graph in vcg format.
183  *
184  *  Dumps this graph to a file.  The file name is constructed from the
185  *  name of the entity describing the procedure (irg->entity) and the
186  *  ending -type.vcg.  Eventually overwrites existing files.
187  *
188  * @see turn_off_edge_labels()
189  */
190 void dump_type_graph (ir_graph *irg, const char *suffix);
191
192 /**  Dumps all type information.
193  *
194  *   @return
195  *      A file containing all type information for the program in standard
196  *      vcg format.
197  *
198  *   Dumps all type information that is somehow reachable in standard vcg
199  *   format.
200  *   Dumps the graph to a file named All_types.vcg.
201  *
202  * @see turn_off_edge_labels()
203  */
204 void dump_all_types (const char *suffix);
205
206 /**  Dumps the class hierarchy with or without entities.
207  *
208  *   @param entities    Flag whether to dump the entities.
209  *
210  *   @return
211  *      A file containing the class hierarchy tree for the program in standard
212  *      vcg format.
213  *
214  *   Does not dump the global type.
215  *   Dumps a node for all classes and the sub/supertype relations.  If
216  *   entities is set to true also dumps the entities of classes, but without
217  *   any additional information as the entities type.  The overwrites relation
218  *   is dumped along with the entities.
219  *   Dumps to a file class_hierarchy.vcg
220  */
221 void dump_class_hierarchy (bool entities, const char *suffix);
222
223 /* **************************************************************************** */
224 /*                              LOOPTREE DUMPERS                                */
225 /* **************************************************************************** */
226
227 /**
228  * Dump a standalone loop tree, which contains the loop nodes and the firm nodes
229  * belonging to one loop packed together in one subgraph.  Dumps to file
230  * <name of irg><suffix>-looptree.vcg
231  * Turns on edge labels by default.
232  *
233  * Implementing this dumper was stimulated by Florian Liekwegs similar dumper.
234  *
235  * @arg irg     Dump the loop tree for this graph.
236  * @arg suffix  Suffix to filename.
237  */
238 void dump_loop_tree(ir_graph *irg, const char *suffix);
239
240 /** Dumps the firm nodes in the sub-loop-tree of loop to a graph.
241  *
242  *  Dumps the loop nodes if dump_loop_information() is set.
243  *  The name of the file is loop_<loop_nr><suffix>.vcg.
244  *
245  *  @arg loop    Dump the loop tree for this loop.
246  *  @arg suffix  Suffix to filename.
247  */
248 void dump_loop (ir_loop *l, const char *suffix);
249
250 /** Dumps the loop tree over the call graph.
251  *
252  *  See for yourself what you can use this for.
253  *  The filename is "Callgraph_looptree<suffix>.vcg".
254  *
255  *  @arg suffix  Suffix to filename.
256  */
257 void dump_callgraph_loop_tree(const char *suffix);
258
259
260 /* **************************************************************************** */
261 /*                                TEXT DUMPERS                                  */
262 /* **************************************************************************** */
263
264 /** Verbosity for text dumpers */
265 typedef enum {
266   dump_verbosity_onlynames         = 0x00000001,   /**< only dump names. turns off all other
267                                                       flags up to 0x00010000. */
268   dump_verbosity_fields            = 0x00000002,   /**< dump types and fields (like a type declaration) */
269   dump_verbosity_methods           = 0x00000004,   /**< dump types and methods (like a type declaration) */
270   dump_verbosity_typeattrs         = 0x00000008,   /**< dump all type attributes */
271   dump_verbosity_entattrs          = 0x00000010,   /**< dump all entity attributes */
272   dump_verbosity_entconsts         = 0x00000020,   /**< dump entity constants */
273
274   dump_verbosity_accessStats       = 0x00000100,   /**< dump entity access statistics */
275
276   dump_verbosity_noClassTypes      = 0x00001000,   /**< dump no class       types */
277   dump_verbosity_noStructTypes     = 0x00002000,   /**< dump no struct      types */
278   dump_verbosity_noUnionTypes      = 0x00004000,   /**< dump no union       types */
279   dump_verbosity_noArrayTypes      = 0x00008000,   /**< dump no array       types */
280   dump_verbosity_noPointerTypes    = 0x00010000,   /**< dump no pointer     types */
281   dump_verbosity_noMethodTypes     = 0x00020000,   /**< dump no method      types */
282   dump_verbosity_noPrimitiveTypes  = 0x00040000,   /**< dump no primitive   types */
283   dump_verbosity_noEnumerationTypes= 0x00080000,   /**< dump no enumeration types */
284
285   dump_verbosity_onlyClassTypes     = 0x000FE000,  /**< dump only class     types */
286   dump_verbosity_onlyStructTypes    = 0x000FD000,  /**< dump only struct    types */
287   dump_verbosity_onlyUnionTypes     = 0x000FB000,  /**< dump only union     types */
288   dump_verbosity_onlyArrayTypes     = 0x000F7000,  /**< dump only array     types */
289   dump_verbosity_onlyPointerTypes   = 0x000EF000,  /**< dump only pointer   types */
290   dump_verbosity_onlyMethodTypes    = 0x000DF000,  /**< dump only method    types */
291   dump_verbosity_onlyPrimitiveTypes = 0x000BF000,  /**< dump only primitive types */
292   dump_verbosity_onlyEnumerationTypes=0x0007F000,  /**< dump only enumeration types */
293
294   dump_verbosity_max                = 0x48888887   /**< turn on all verbosity. */
295 } dump_verbosity;
296
297
298 /** Write the entity and all its attributes to the passed file.
299  *  */
300 void    dump_entity_to_file (FILE *F, entity *ent, unsigned verbosity);
301
302 /** Write the entity and all its attributes to the stdout.
303  *
304  *  Calls dump_entity_to_file().  */
305 void    dump_entity (entity *ent);
306
307 /** Write the type and all its attributes to the file passed.
308  * */
309 void    dump_type_to_file (FILE *f, type *tp, unsigned verbosity);
310
311 /** Write the type and all its attributes to stdout.
312  *  */
313 void    dump_type (type *tp);
314
315
316 /** Dump type information as text.
317  *
318  *  Often type graphs are unhandy in their vcg representation.  The text
319  *  dumper represents the information for a single type more compact, but
320  *  the relations between the types only implicitly.
321  *  Dumps only 'real' types, i.e., those in the type list.  Does not dump
322  *  the global type nor frame types or the like.
323  *
324  *  The file name is the program name (get_irp_name()), or 'TextTypes'
325  *  if the program name is not set appended by <suffix>-types.txt.
326  */
327 void dump_types_as_text(unsigned verbosity, const char *suffix);
328
329 /* **************************************************************************** */
330 /*                                    FLAGS                                     */
331 /* **************************************************************************** */
332
333 /** Output a selected graph.
334  *
335  *  All graph dumpers check this name.  If the name is != "" and
336  *  not a prefix of the graph to be dumped, the dumper does not
337  *  dump the graph.
338  *
339  *  @param name The prefix of the name (not the ld_name) of the method
340  *              entity to be dumped.
341  */
342 void only_dump_method_with_name(ident *name);
343
344 /**  Sets the vcg flag "display_edge_labels" to no.
345  *
346  *   This is necessary as xvcg and aisee both fail to display graphs
347  *   with self-edges if these edges have labes.
348  */
349 void turn_off_edge_labels(void);
350
351 /**
352  *  If set to true constants will be replicated for every use. In non
353  *  blocked view edges from constant to block are skipped.  Vcg then
354  *  layouts the graphs more compact, this makes them better readable.
355  *  The flag is automatically and temporarily set to false if other
356  *  edges are dumped, as outs, loop, ...
357  *  Default setting: false.
358  */
359 void dump_consts_local(bool b);
360
361 /**
362  * Returns false if dump_out_edge_flag or dump_loop_information_flag
363  * are set, else returns dump_const_local_flag.
364  */
365 bool get_opt_dump_const_local(void);
366
367 /**  Turns off dumping the values of constant entities. Makes type graphs
368  *   better readable.
369  */
370 void turn_off_constant_entity_values(void);
371
372 /**  Turns on dumping the edges from the End node to nodes to be kept
373  *   alive.
374  */
375 void dump_keepalive_edges(bool b);
376 bool get_opt_dump_keepalive_edges(void);
377
378 /** Turns on dumping the out edges starting from the Start block in
379  *  dump_ir_graph.
380  *
381  *  To test the consistency of the out datastructure.
382  */
383 void dump_out_edges(void);
384
385 /** If this flag is set the dumper dumps edges to immediate dominator in cfg.
386  */
387 void dump_dominator_information(void);
388
389 /** If this flag is set the dumper dumps loop nodes and edges from
390  *  these nodes to the contained ir nodes.
391  *
392  *  Can be turned off with dont_dump_loop_information().
393  *  If the loops are interprocedural nodes can be missing.
394  */
395 void dump_loop_information(void);
396
397 /**
398  * @see dump_loop_information()
399  */
400 void dont_dump_loop_information(void);
401
402 /** If set and backedge info is computed, backedges are dumped dashed
403  *  and as vcg 'backedge' construct.
404  *
405  *  Default: set.
406  */
407 void dump_backedge_information(bool b);
408
409 /** Dump the information of type field specified in ana/irtypeinfo.h.
410  *
411  *  If the flag is set, the type name is output in [] in the node label,
412  *  else it is output as info.
413  */
414 void dump_analysed_type_info(bool b);
415
416 /** Write the address of a node into the vcg info.
417  *
418  *  This is off per default for automatic comparisons of
419  *  vcg graphs -- these will differ in the pointer values!
420  */
421 void dump_pointer_values_to_info(bool b);
422
423
424 # endif /* _IRDUMP_H_ */