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