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