6f60c6be5b1bba8ad9b9d422ce4a14f894090452
[libfirm] / include / libfirm / dbginfo.h
1 /*
2  * Copyright (C) 1995-2008 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief     Implements the Firm interface to debug information.
23  * @author    Goetz Lindenmaier, Michael Beck
24  * @date      2001
25  */
26 #ifndef FIRM_DEBUG_DBGINFO_H
27 #define FIRM_DEBUG_DBGINFO_H
28
29 #include <stdlib.h>
30 #include "firm_types.h"
31 #include "ident.h"
32 #include "begin.h"
33
34 /**
35  * @defgroup dbg_info    Source References
36  *  Firm requires a debugging module fulfilling this interface, else no
37  *  debugging information is passed to the backend.
38  *  The interface requires a datatype representing the debugging
39  *  information.  Firm supports administrating a reference to the debug
40  *  information in every Firm node.  Further Firm optimizations call
41  *  routines to propagate debug information from old nodes to new nodes
42  *  if the optimization replaces the old ones by the new ones.
43  * @{
44  */
45
46 /**
47  * @typedef dbg_info
48  *
49  * An abstract data type containing information for
50  * debugging support.
51  *
52  * This opaque data type is not defined anywhere in the Firm library,
53  * but pointers to this type can be stored in Firm nodes.
54  */
55
56 /**
57  * An enumeration indicating the action performed by a transformation.
58  */
59 typedef enum {
60         dbg_error = 0,
61         dbg_opt_ssa,           /**< Optimization of the SSA representation, e.g. removal of superfluent Phi nodes. */
62         dbg_opt_auxnode,       /**< Removal of unnecessary auxiliary nodes. */
63         dbg_const_eval,        /**< A Firm subgraph was evaluated to a single constant. */
64         dbg_opt_cse,           /**< A Firm node was replaced due to common subexpression elimination. */
65         dbg_straightening,     /**< A Firm subgraph was replaced by a single, existing block. */
66         dbg_if_simplification, /**< The control flow of an if is changed as either the
67                                           else, the then or both blocks are empty. */
68         dbg_algebraic_simplification, /**< A Firm subgraph was replaced because of an algebraic
69                                            simplification. */
70         dbg_write_after_write,        /**< A Firm subgraph was replaced because of a write
71                                            after write optimization. */
72         dbg_write_after_read,         /**< A Firm subgraph was replaced because of a write
73                                            after read optimization. */
74         dbg_read_after_write,         /**< A Firm subgraph was replaced because of a read
75                                            after write optimization. */
76         dbg_read_after_read,          /**< A Firm subgraph was replaced because of a read
77                                            after read optimization. */
78         dbg_read_a_const,             /**< A Firm subgraph was replaced because of a read
79                                            a constant optimization. */
80         dbg_rem_poly_call,            /**< Remove polymorphic call. */
81         dbg_dead_code,                /**< Removing unreachable code, i.e. blocks that are never executed. */
82         dbg_opt_confirm,              /**< A Firm subgraph was replace because of a Confirmation. */
83         dbg_gvn_pre,                  /**< A Firm node was replace because of the GVN-PRE algorithm. */
84         dbg_combo,                    /**< A Firm node was replace because of the combo algorithm. */
85         dbg_jumpthreading,            /**< A Firm node was replace because of the jumpthreading algorithm. */
86         dbg_backend,                  /**< A Firm subgraph was replaced because of a Backend transformation */
87         dbg_max                       /**< Maximum value. */
88 } dbg_action;
89
90 /**
91  * Converts a debug_action into a string.
92  *
93  * @param a  the debug action
94  */
95 FIRM_API const char *dbg_action_2_str(dbg_action a);
96
97 /**
98  * The type of the debug info merge function.
99  *
100  * @param new_node    the new ir node
101  * @param old_node    the old ir node
102  * @param action      the action that triggers the merge
103  *
104  * @see dbg_init()
105  */
106 typedef void merge_pair_func(ir_node *new_node, ir_node *old_node, dbg_action action);
107
108 /**
109  * The type of the debug info merge sets function.
110  *
111  * @param new_node_array    array of new nodes
112  * @param new_num_entries   number of entries in new_node_array
113  * @param old_node_array    array of old nodes
114  * @param old_num_entries   number of entries in old_node_array
115  * @param action            the action that triggers the merge
116  *
117  * @see dbg_init()
118  */
119 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);
120
121 /**
122  *  Initializes the debug support.
123  *
124  *  This function takes pointers to two functions that merge the
125  *  debug information when a
126  *  transformation of a Firm graph is performed.
127  *  Firm transformations call one of these functions.
128  *
129  *   - dbg_info_merge_pair() is called in the following situation:
130  *     The optimization replaced the old node by the new one.  The new node
131  *     might be a recent allocated node not containing any debug information,
132  *     or just another node from somewhere in the graph with the same
133  *     semantics.
134  *   - dbg_info_merge_sets() is called in the following situation:
135  *     The optimization replaced a subgraph by another subgraph.  There is no
136  *     obviously mapping between single nodes in both subgraphs.  The optimization
137  *     simply passes two lists to the debug module, one containing the nodes in
138  *     the old subgraph, the other containing the nodes in the new subgraph.
139  *     The same node can be in both lists.
140  *
141  *   Further both functions pass an enumeration indicating the action
142  *   performed by the transformation, e.g. the kind of optimization performed.
143  */
144 FIRM_API void dbg_init(merge_pair_func *dbg_info_merge_pair,
145                        merge_sets_func *dbg_info_merge_sets);
146
147 /**
148  * The type of the debug info retriever function.
149  *  When given a dbg_info returns the name (usually the filename) of the
150  *  compilation unit defining it. @p line is set to the line number of the
151  *  definition.
152  */
153 typedef const char *(*retrieve_dbg_func)(const dbg_info *dbg, unsigned *line);
154
155 /**
156  * Sets a debug info retriever.
157  *
158  * @param func   the debug retriever function.
159  */
160 FIRM_API void ir_set_debug_retrieve(retrieve_dbg_func func);
161
162 /**
163  * The type of the type debug info retrieve function.
164  * Prints a human readable source representation of a type to an obstack.
165  *  (Used for generating debug info like stabs or dwarf)
166  */
167 typedef void (*retrieve_type_dbg_func)(char *buffer, size_t buffer_size,
168                                        const type_dbg_info *tdbgi);
169
170 /**
171  * Set global print_type_dbg_info function in firm
172  */
173 FIRM_API void ir_set_type_debug_retrieve(retrieve_type_dbg_func func);
174
175 /**
176  * Retrieve the debug info.
177  */
178 FIRM_API const char *ir_retrieve_dbg_info(const dbg_info *dbg, unsigned *line);
179
180 /**
181  * Retrieve type debug info
182  */
183 FIRM_API void ir_retrieve_type_dbg_info(char *buffer, size_t buffer_size,
184                                         const type_dbg_info *tdbgi);
185
186 /** @} */
187
188 #include "end.h"
189
190 #endif