removed xprint stuff completely
[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  * @defgroup debug    The Firm interface to debugging support.
49  *
50  * @{
51  */
52
53 /**
54  * An abstract data type containing information for
55  * debugging support.
56  *
57  * This datatype is not defined anywere in the firm library, but pointers
58  * to this type can be stored in firm nodes.
59  */
60 typedef struct dbg_info dbg_info;
61
62 /**
63  * Sets the debug information of a node.
64  */
65 INLINE void set_irn_dbg_info(ir_node *n, dbg_info* db);
66
67 /**
68  * Returns the debug information of an node.
69  */
70 INLINE dbg_info *get_irn_dbg_info(ir_node *n);
71
72 /**
73  * Sets the debug information of an entity.
74  */
75 INLINE void set_entity_dbg_info(entity *ent, dbg_info* db);
76
77 /**
78  * Returns the debug information of an entity.
79  */
80 INLINE dbg_info *get_entity_dbg_info(entity *ent);
81
82 /**
83  * Sets the debug information of a type.
84  */
85 INLINE void set_type_dbg_info(type *tp, dbg_info* db);
86
87 /**
88  * Returns the debug information of a type.
89  */
90 INLINE dbg_info *get_type_dbg_info(type *tp);
91
92 /**
93  * An enumeration indicating the action performed by a transformation.
94  */
95 typedef enum {
96   dbg_error = 0,
97   dbg_opt_ssa,           /**< Optimization of the SSA representation, e.g., removal of superfluent phi nodes. */
98   dbg_opt_auxnode,       /**< Removal of unnecessary auxilliary nodes. */
99   dbg_const_eval,        /**< A Firm subgraph was evaluated to a single constant. */
100   dbg_straightening,     /**< A Firm subgraph was replaced by a single, existing block. */
101   dbg_if_simplification, /**< The control flow of an if is changed as either the
102                                                 else, the then or both blocks are empty. */
103   dbg_algebraic_simplification, /**< A Firm subgraph was replaced because of an algebraic
104                                      simplification. */
105   dbg_write_after_write,        /**< A Firm subgraph was replaced because of a write
106                                      after write optimization. */
107   dbg_write_after_read,         /**< A Firm subgraph was replaced because of a write
108                                      after read optimization. */
109   dbg_rem_poly_call,            /**< Remove polymorphic call. */
110   dbg_max                       /**< Maximum value. */
111
112 } dbg_action;
113
114
115 /**
116  * Converts enum values to strings.
117  */
118 inline static const char* dbg_action_2_str(dbg_action a) {
119   switch(a) {
120   case dbg_error: return "dbg_error"; break;
121   case dbg_opt_ssa: return "dbg_opt_ssa"; break;
122   case dbg_opt_auxnode: return "dbg_opt_auxnode"; break;
123   case dbg_const_eval: return "dbg_const_eval"; break;
124   case dbg_straightening: return "dbg_straightening"; break;
125   case dbg_if_simplification: return "dbg_if_simplification"; break;
126   case dbg_algebraic_simplification:
127     return "dbg_algebraic_simplification"; break;
128   case dbg_write_after_write: return "dbg_write_after_write"; break;
129   case dbg_write_after_read: return "dbg_write_after_read"; break;
130   case dbg_rem_poly_call: return "dbg_rem_poly_call"; break;
131   default:
132     if (a <= dbg_max)
133       return "string conversion not implemented";
134     else
135       assert(0);
136   }
137 }
138
139 /**
140  * The type of the debug info merge function.
141  *
142  * @param new_node    the new ir node
143  * @param old_node    the old ir node
144  * @param action      the action that triggers the merge
145  *
146  * @see dbg_init()
147  */
148 typedef void merge_pair_func(ir_node *new_node, ir_node *old_node, dbg_action action);
149
150 /**
151  * The type of the debug info merge sets function.
152  *
153  * @param new_node_array    array of new nodes
154  * @param new_num_entries   number of entries in new_node_array
155  * @param old_node_array    array of old nodes
156  * @param old_num_entries   number of entries in old_node_array
157  * @param action            the action that triggers the merge
158  *
159  * @see dbg_init()
160  */
161 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);
162
163 /**
164  *  Initializes the debug support.
165  *
166  *  @param dbg_info_merge_pair   see function description
167  *  @param dbg_info_merge_sets   see function description
168  *
169  *  This function takes Pointers to two functions that merge the
170  *  debug information when a
171  *  transformation of a firm graph is performed.
172  *  Firm transformations call one of these functions.
173  *
174  *   - dbg_info_merge_pair() is called in the following situation:
175  *     The optimization replaced the old node by the new one.  The new node
176  *     might be a recent allocated node not containing any debug information,
177  *     or just another node from somewhere in the graph with the same
178  *     semantics.
179  *   - dbg_info_merge_sets() is called in the following situation:
180  *     The optimization replaced a subgraph by another subgraph.  There is no
181  *     obviouse mapping between single nodes in both subgraphs.  The optimization
182  *     simply passes two lists to the debug module, one containing the nodes in
183  *     the old subgraph, the other containing the nodes in the new subgraph.
184  *     The same node can be in both lists.
185  *
186  *   Further both functions pass an enumeration indicating the action
187  *   performed by the transformation, e.g. the kind of optimization performed.
188  */
189 void dbg_init(merge_pair_func *dbg_info_merge_pair, merge_sets_func *dbg_info_merge_sets);
190
191 /** @} */
192
193 #endif /* _DBGINFO_H_ */