More doxygen comments
[libfirm] / ir / debug / dbginfo.h
1 /*
2 *  Copyright (C) 2001 by Universitaet Karlsruhe
3 *  All rights reserved.
4 */
5
6 /**
7 * @file  dbginfo.h
8 *
9 *  This is the Firm interface to debugging support.
10 *
11 *  @author Goetz Lindenmaier
12 *
13 *  Firm requires
14 *  a debugging module fulfilling this interface, else no debugging information
15 *  is passed to the backend.
16 *  The interface requires a datatype representing the debugging information.
17 *  Firm supports administrating a reference to the debug information
18 *  in every firm node.  Further Firm optimizations call routines to
19 *  propagate debug information from old nodes to new nodes if the optimization
20 *  replaces the old ones by the new ones.
21 *
22 */
23
24 /* $Id$ */
25
26 # ifndef _DBGINFO_H_
27 # define _DBGINFO_H_
28
29 #include "ident.h"
30
31 #ifndef _IR_NODE_TYPEDEF_
32 #define _IR_NODE_TYPEDEF_
33 typedef struct ir_node ir_node;
34 #endif
35
36 /* to resolve recursion between entity.h and type.h */
37 #ifndef _ENTITY_TYPEDEF_
38 #define _ENTITY_TYPEDEF_
39 typedef struct entity entity;
40 #endif
41
42 #ifndef _TYPE_TYPEDEF_
43 #define _TYPE_TYPEDEF_
44 typedef struct type type;
45 #endif
46
47 /**
48  *
49  *   An abstract data type containing information for
50  *   debugging support.
51  *   This datatype is not defined in the firm library, but pointers
52  *   to this type can be stored in firm nodes.
53  */
54 typedef struct dbg_info dbg_info;
55 /* Routines to access the field of an ir node containing the
56    debugging information. */
57 INLINE void set_irn_dbg_info(ir_node *n, dbg_info* db);
58 INLINE dbg_info *get_irn_dbg_info(ir_node *n);
59 /* Routines to access the field of an entity containing the
60    debugging information. */
61 INLINE void set_entity_dbg_info(entity *ent, dbg_info* db);
62 INLINE dbg_info *get_entity_dbg_info(entity *ent);
63 /* Routines to access the field of a type containing the
64    debugging information. */
65 INLINE void set_type_dbg_info(type *tp, dbg_info* db);
66 INLINE dbg_info *get_type_dbg_info(type *tp);
67
68 /**
69  * An enumeration indicating the action performed by a transformation.
70  */
71 typedef enum {
72   dbg_error = 0,
73   dbg_opt_ssa,           /**< Optimization of the SSA representation, e.g., removal of superfluent phi nodes. */
74   dbg_opt_auxnode,       /**< Removal of unnecessary auxilliary nodes. */
75   dbg_const_eval,        /**< A Firm subgraph was evaluated to a single constant. */
76   dbg_straightening,     /**< A Firm subgraph was replaced by a single, existing block. */
77   dbg_if_simplification, /**< The control flow of an if is changed as either the
78                                                 else, the then or both blocks are empty. */
79   dbg_algebraic_simplification,
80   dbg_write_after_write,
81   dbg_write_after_read,
82   dbg_max
83 } dbg_action;
84
85
86 /**
87  *   converts enum values to strings
88  */
89 static const char* dbg_action_2_str(dbg_action a) {
90   switch(a) {
91   case dbg_error: return "dbg_error"; break;
92   case dbg_opt_ssa: return "dbg_opt_ssa"; break;
93   case dbg_opt_auxnode: return "dbg_opt_auxnode"; break;
94   case dbg_const_eval: return "dbg_const_eval"; break;
95   case dbg_straightening: return "dbg_straightening"; break;
96   case dbg_if_simplification: return "dbg_if_simplification"; break;
97   case dbg_algebraic_simplification:
98     return "dbg_algebraic_simplification"; break;
99   case dbg_write_after_write: return "dbg_write_after_write"; break;
100   case dbg_write_after_read: return "dbg_write_after_read"; break;
101   default:
102     if (a <= dbg_max)
103       return "string conversion not implemented";
104     else
105       assert(0);
106   }
107 }
108
109 /**
110  * The type of the debug info merge function.
111  *
112  * @see dbg_init()
113  */
114 typedef void merge_pair_func(ir_node *, ir_node *, dbg_action);
115
116 /**
117  * The type of the debug info merge function.
118  *
119  * @see dbg_init()
120  */
121 typedef void merge_sets_func(ir_node **, int, ir_node **, int, dbg_action);
122
123 /**
124  *   Initializes the debug support.
125  *
126  *   @param dbg_info_merge_pair   see function description
127  *   @param dbg_info_merge_sets   see function description
128  *
129  *   This function takes Pointers to two functions that merge the debug information when a
130  *   transformation of a firm graph is performed.
131  *   Firm transformations call one of these functions.
132  *
133  *   - dbg_info_merge_pair() is called in the following situation:
134  *     The optimization replaced the old node by the new one.  The new node
135  *     might be a recent allocated node not containing any debug information,
136  *     or just another node from somewhere in the graph with the same
137  *     semantics.
138  *   - dbg_info_merge_sets() is called in the following situation:
139  *     The optimization replaced a subgraph by another subgraph.  There is no
140  *     obviouse mapping between single nodes in both subgraphs.  The optimization
141  *     simply passes two lists to the debug module, one containing the nodes in
142  *     the old subgraph, the other containing the nodes in the new subgraph.
143  *     The same node can be in both lists.
144  *
145  *   Further both functions pass an enumeration indicating the action
146  *   performed by the transformation, e.g. the kind of optimization performed.
147  *
148  *   @return No result.
149  *
150  */
151 void dbg_init(merge_pair_func *dbg_info_merge_pair, merge_sets_func *dbg_info_merge_sets);
152
153
154 #endif /* _DBGINFO_H_ */