Added comment
[libfirm] / ir / debug / dbginfo.h
1 /*
2  * Project:     libFIRM
3  * File name:   ir/debug/dbginfo.h
4  * Purpose:     Implements the Firm interface to debug information.
5  * Author:      Goetz Lindenmaier
6  * Modified by:
7  * Created:     2001
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 2001-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 /**
14 * @file  dbginfo.h
15 *
16 *  This is the Firm interface to debugging support.
17 *
18 *  @author Goetz Lindenmaier
19 *
20 *  Firm requires a debugging module fulfilling this interface, else no
21 *  debugging information is passed to the backend.
22 *  The interface requires a datatype representing the debugging
23 *  information.  Firm supports administrating a reference to the debug
24 *  information in every firm node.  Further Firm optimizations call
25 *  routines to propagate debug information from old nodes to new nodes
26 *  if the optimization replaces the old ones by the new ones.
27 *
28 */
29
30 # ifndef _DBGINFO_H_
31 # define _DBGINFO_H_
32
33 #include "ident.h"
34
35 #ifndef _IR_NODE_TYPEDEF_
36 #define _IR_NODE_TYPEDEF_
37 typedef struct ir_node ir_node;
38 #endif
39
40 /* to resolve recursion between entity.h and type.h */
41 #ifndef _ENTITY_TYPEDEF_
42 #define _ENTITY_TYPEDEF_
43 typedef struct entity entity;
44 #endif
45
46 #ifndef _TYPE_TYPEDEF_
47 #define _TYPE_TYPEDEF_
48 typedef struct type type;
49 #endif
50
51 /**
52  * @defgroup debug    The Firm interface to debugging support.
53  *
54  * @{
55  */
56
57 /**
58  * An abstract data type containing information for
59  * debugging support.
60  *
61  * This datatype is not defined anywere in the firm library, but pointers
62  * to this type can be stored in firm nodes.
63  */
64 typedef struct dbg_info dbg_info;
65
66 /**
67  * Sets the debug information of a node.
68  */
69 void set_irn_dbg_info(ir_node *n, dbg_info* db);
70
71 /**
72  * Returns the debug information of an node.
73  */
74 dbg_info *get_irn_dbg_info(ir_node *n);
75
76 /**
77  * Sets the debug information of an entity.
78  */
79 void set_entity_dbg_info(entity *ent, dbg_info* db);
80
81 /**
82  * Returns the debug information of an entity.
83  */
84 dbg_info *get_entity_dbg_info(entity *ent);
85
86 /**
87  * Sets the debug information of a type.
88  */
89 void set_type_dbg_info(type *tp, dbg_info* db);
90
91 /**
92  * Returns the debug information of a type.
93  */
94 dbg_info *get_type_dbg_info(type *tp);
95
96 /**
97  * An enumeration indicating the action performed by a transformation.
98  */
99 typedef enum {
100   dbg_error = 0,
101   dbg_opt_ssa,           /**< Optimization of the SSA representation, e.g., removal of superfluent phi nodes. */
102   dbg_opt_auxnode,       /**< Removal of unnecessary auxilliary nodes. */
103   dbg_const_eval,        /**< A Firm subgraph was evaluated to a single constant. */
104   dbg_straightening,     /**< A Firm subgraph was replaced by a single, existing block. */
105   dbg_if_simplification, /**< The control flow of an if is changed as either the
106                                                 else, the then or both blocks are empty. */
107   dbg_algebraic_simplification, /**< A Firm subgraph was replaced because of an algebraic
108                                      simplification. */
109   dbg_write_after_write,        /**< A Firm subgraph was replaced because of a write
110                                      after write optimization. */
111   dbg_write_after_read,         /**< A Firm subgraph was replaced because of a write
112                                      after read optimization. */
113   dbg_rem_poly_call,            /**< Remove polymorphic call. */
114   dbg_dead_code,                /**< Removing unreachable code, I.e. blocks that are never executed. */
115   dbg_max                       /**< Maximum value. */
116
117 } dbg_action;
118
119
120 /**
121  * Converts enum values to strings.
122  */
123 #ifdef __GNUC__
124 static const char* dbg_action_2_str(dbg_action) __attribute__ ((unused));
125 #endif
126
127 static const char* dbg_action_2_str(dbg_action a) {
128   switch(a) {
129   case dbg_error: return "dbg_error"; break;
130   case dbg_opt_ssa: return "dbg_opt_ssa"; break;
131   case dbg_opt_auxnode: return "dbg_opt_auxnode"; break;
132   case dbg_const_eval: return "dbg_const_eval"; break;
133   case dbg_straightening: return "dbg_straightening"; break;
134   case dbg_if_simplification: return "dbg_if_simplification"; break;
135   case dbg_algebraic_simplification:
136     return "dbg_algebraic_simplification"; break;
137   case dbg_write_after_write: return "dbg_write_after_write"; break;
138   case dbg_write_after_read: return "dbg_write_after_read"; break;
139   case dbg_rem_poly_call: return "dbg_rem_poly_call"; break;
140   default:
141     if (a <= dbg_max)
142       return "string conversion not implemented";
143     else
144       assert(0);
145     return NULL;
146   }
147 }
148
149 /**
150  * The type of the debug info merge function.
151  *
152  * @param new_node    the new ir node
153  * @param old_node    the old ir node
154  * @param action      the action that triggers the merge
155  *
156  * @see dbg_init()
157  */
158 typedef void merge_pair_func(ir_node *new_node, ir_node *old_node, dbg_action action);
159
160 /**
161  * The type of the debug info merge sets function.
162  *
163  * @param new_node_array    array of new nodes
164  * @param new_num_entries   number of entries in new_node_array
165  * @param old_node_array    array of old nodes
166  * @param old_num_entries   number of entries in old_node_array
167  * @param action            the action that triggers the merge
168  *
169  * @see dbg_init()
170  */
171 typedef void merge_sets_func(ir_node **new_node_array, int new_num_entries, ir_node **old_node_array, int old_num_entries, dbg_action action);
172
173 /**
174  *  Initializes the debug support.
175  *
176  *  @param dbg_info_merge_pair   see function description
177  *  @param dbg_info_merge_sets   see function description
178  *
179  *  This function takes Pointers to two functions that merge the
180  *  debug information when a
181  *  transformation of a firm graph is performed.
182  *  Firm transformations call one of these functions.
183  *
184  *   - dbg_info_merge_pair() is called in the following situation:
185  *     The optimization replaced the old node by the new one.  The new node
186  *     might be a recent allocated node not containing any debug information,
187  *     or just another node from somewhere in the graph with the same
188  *     semantics.
189  *   - dbg_info_merge_sets() is called in the following situation:
190  *     The optimization replaced a subgraph by another subgraph.  There is no
191  *     obviouse mapping between single nodes in both subgraphs.  The optimization
192  *     simply passes two lists to the debug module, one containing the nodes in
193  *     the old subgraph, the other containing the nodes in the new subgraph.
194  *     The same node can be in both lists.
195  *
196  *   Further both functions pass an enumeration indicating the action
197  *   performed by the transformation, e.g. the kind of optimization performed.
198  */
199 void dbg_init(merge_pair_func *dbg_info_merge_pair, merge_sets_func *dbg_info_merge_sets);
200
201 /** @} */
202
203 #endif /* _DBGINFO_H_ */