renamed firm_break() to firm_debug()
[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: Michael Beck
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 "firm_types.h"
34 #include "ident.h"
35
36 /**
37  * @defgroup debug    The Firm interface to debugging support.
38  *
39  * @{
40  */
41
42 /**
43  * An abstract data type containing information for
44  * debugging support.
45  *
46  * This opaque data type is not defined anywhere in the firm library,
47  * but pointers to this type can be stored in firm nodes.
48  */
49 typedef struct dbg_info dbg_info;
50
51 /**
52  * Sets the debug information of a node.
53  */
54 void set_irn_dbg_info(ir_node *n, dbg_info *db);
55
56 /**
57  * Returns the debug information of an node.
58  */
59 dbg_info *get_irn_dbg_info(ir_node *n);
60
61 /**
62  * Sets the debug information of an entity.
63  */
64 void set_entity_dbg_info(entity *ent, dbg_info *db);
65
66 /**
67  * Returns the debug information of an entity.
68  */
69 dbg_info *get_entity_dbg_info(entity *ent);
70
71 /**
72  * Sets the debug information of a type.
73  */
74 void set_type_dbg_info(type *tp, dbg_info *db);
75
76 /**
77  * Returns the debug information of a type.
78  */
79 dbg_info *get_type_dbg_info(type *tp);
80
81 /**
82  * An enumeration indicating the action performed by a transformation.
83  */
84 typedef enum {
85   dbg_error = 0,
86   dbg_opt_ssa,           /**< Optimization of the SSA representation, e.g., removal of superfluent phi nodes. */
87   dbg_opt_auxnode,       /**< Removal of unnecessary auxiliary nodes. */
88   dbg_const_eval,        /**< A Firm subgraph was evaluated to a single constant. */
89   dbg_opt_cse,           /**< A Firm node was replaced due to common subexpression elimination. */
90   dbg_straightening,     /**< A Firm subgraph was replaced by a single, existing block. */
91   dbg_if_simplification, /**< The control flow of an if is changed as either the
92                                     else, the then or both blocks are empty. */
93   dbg_algebraic_simplification, /**< A Firm subgraph was replaced because of an algebraic
94                                      simplification. */
95   dbg_write_after_write,        /**< A Firm subgraph was replaced because of a write
96                                      after write optimization. */
97   dbg_write_after_read,         /**< A Firm subgraph was replaced because of a write
98                                      after read optimization. */
99   dbg_read_after_write,         /**< A Firm subgraph was replaced because of a read
100                                      after write optimization. */
101   dbg_read_after_read,          /**< A Firm subgraph was replaced because of a read
102                                      after read optimization. */
103   dbg_read_a_const,             /**< A Firm subgraph was replaced because of a read
104                                      a constant optimization. */
105   dbg_rem_poly_call,            /**< Remove polymorphic call. */
106   dbg_dead_code,                /**< Removing unreachable code, I.e. blocks that are never executed. */
107   dbg_opt_confirm,              /**< A Firm subgraph was replace because of a Confirmation */
108   dbg_max                       /**< Maximum value. */
109 } dbg_action;
110
111 /**
112  * Converts a debug_action into a string.
113  *
114  * @param a  the debug action
115  */
116 const char *dbg_action_2_str(dbg_action a);
117
118 /**
119  * The type of the debug info merge function.
120  *
121  * @param new_node    the new ir node
122  * @param old_node    the old ir node
123  * @param action      the action that triggers the merge
124  *
125  * @see dbg_init()
126  */
127 typedef void merge_pair_func(ir_node *new_node, ir_node *old_node, dbg_action action);
128
129 /**
130  * The type of the debug info merge sets function.
131  *
132  * @param new_node_array    array of new nodes
133  * @param new_num_entries   number of entries in new_node_array
134  * @param old_node_array    array of old nodes
135  * @param old_num_entries   number of entries in old_node_array
136  * @param action            the action that triggers the merge
137  *
138  * @see dbg_init()
139  */
140 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);
141
142 /**
143  * The type of the debug info to human readable string function.
144  *
145  * @param buf    pointer to a buffer that will hold the info
146  * @param len    length of the buffer
147  * @param dbg    the debug info
148  *
149  * @return  Number of written characters to the buffer.
150  *
151  * @see dbg_init()
152  */
153 typedef unsigned snprint_dbg_func(char *buf, unsigned len, const dbg_info *dbg);
154
155 /**
156  *  Initializes the debug support.
157  *
158  *  @param dbg_info_merge_pair   see function description
159  *  @param dbg_info_merge_sets   see function description
160  *  @param snprint_dbg           see function description
161  *
162  *  This function takes Pointers to two functions that merge the
163  *  debug information when a
164  *  transformation of a firm graph is performed.
165  *  Firm transformations call one of these functions.
166  *
167  *   - dbg_info_merge_pair() is called in the following situation:
168  *     The optimization replaced the old node by the new one.  The new node
169  *     might be a recent allocated node not containing any debug information,
170  *     or just another node from somewhere in the graph with the same
171  *     semantics.
172  *   - dbg_info_merge_sets() is called in the following situation:
173  *     The optimization replaced a subgraph by another subgraph.  There is no
174  *     obviously mapping between single nodes in both subgraphs.  The optimization
175  *     simply passes two lists to the debug module, one containing the nodes in
176  *     the old subgraph, the other containing the nodes in the new subgraph.
177  *     The same node can be in both lists.
178  *
179  *   Further both functions pass an enumeration indicating the action
180  *   performed by the transformation, e.g. the kind of optimization performed.
181  *
182  * The third argument snprint_dbg is called to convert a debug info into a human readable string.
183  * This string is the dumped in the dumper functions.
184  *
185  * Note that if NULL is passed for dbg_info_merge_pair or dbg_info_merge_sets, the default
186  * implementations default_dbg_info_merge_pair() and default_dbg_info_merge_sets() are used.
187  * NULL passed for snprint_dbg means no output.
188  */
189 void dbg_init(merge_pair_func *dbg_info_merge_pair, merge_sets_func *dbg_info_merge_sets, snprint_dbg_func *snprint_dbg);
190
191 /** @} */
192
193 /**
194  * The default merge_pair_func implementation, simply copies the debug info
195  * from old to new.
196  */
197 void default_dbg_info_merge_pair(ir_node *nw, ir_node *old, dbg_action info);
198
199 /**
200  * The default merge_sets_func implementation, does nothing
201  */
202 void default_dbg_info_merge_sets(ir_node **new_nodes, int n_new_nodes,
203                             ir_node **old_nodes, int n_old_nodes,
204                             dbg_action info);
205
206 #endif /* _DBGINFO_H_ */