dbginfo.h 7.08 KB
Newer Older
Christian Würdig's avatar
Christian Würdig committed
1
2
/*
 * This file is part of libFirm.
3
 * Copyright (C) 2012 University of Karlsruhe.
Christian Würdig's avatar
Christian Würdig committed
4
5
 */

Michael Beck's avatar
Michael Beck committed
6
/**
Matthias Braun's avatar
Matthias Braun committed
7
8
9
10
 * @file
 * @brief     Implements the Firm interface to debug information.
 * @author    Goetz Lindenmaier, Michael Beck
 * @date      2001
Michael Beck's avatar
Michael Beck committed
11
 */
Matthias Braun's avatar
Matthias Braun committed
12
13
#ifndef FIRM_DEBUG_DBGINFO_H
#define FIRM_DEBUG_DBGINFO_H
14

15
16
#include <stddef.h>

Michael Beck's avatar
Michael Beck committed
17
#include "firm_types.h"
18
#include "begin.h"
19

Sebastian Felis's avatar
Sebastian Felis committed
20
/**
Matthias Braun's avatar
Matthias Braun committed
21
22
23
24
25
26
27
28
 * @defgroup dbg_info    Source References
 *  Firm requires a debugging module fulfilling this interface, else no
 *  debugging information is passed to the backend.
 *  The interface requires a datatype representing the debugging
 *  information.  Firm supports administrating a reference to the debug
 *  information in every Firm node.  Further Firm optimizations call
 *  routines to propagate debug information from old nodes to new nodes
 *  if the optimization replaces the old ones by the new ones.
Michael Beck's avatar
Michael Beck committed
29
30
31
32
 * @{
 */

/**
33
34
 * @typedef dbg_info
 *
Michael Beck's avatar
Michael Beck committed
35
36
37
 * An abstract data type containing information for
 * debugging support.
 *
38
39
 * This opaque data type is not defined anywhere in the Firm library,
 * but pointers to this type can be stored in Firm nodes.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
40
 */
Michael Beck's avatar
Michael Beck committed
41

Sebastian Felis's avatar
Sebastian Felis committed
42
/**
43
 * An enumeration indicating the action performed by a transformation.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
44
45
 */
typedef enum {
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
	dbg_error = 0,
	dbg_opt_ssa,           /**< Optimization of the SSA representation, e.g. removal of superfluent Phi nodes. */
	dbg_opt_auxnode,       /**< Removal of unnecessary auxiliary nodes. */
	dbg_const_eval,        /**< A Firm subgraph was evaluated to a single constant. */
	dbg_opt_cse,           /**< A Firm node was replaced due to common subexpression elimination. */
	dbg_straightening,     /**< A Firm subgraph was replaced by a single, existing block. */
	dbg_if_simplification, /**< The control flow of an if is changed as either the
	                                  else, the then or both blocks are empty. */
	dbg_algebraic_simplification, /**< A Firm subgraph was replaced because of an algebraic
	                                   simplification. */
	dbg_write_after_write,        /**< A Firm subgraph was replaced because of a write
	                                   after write optimization. */
	dbg_write_after_read,         /**< A Firm subgraph was replaced because of a write
	                                   after read optimization. */
	dbg_read_after_write,         /**< A Firm subgraph was replaced because of a read
	                                   after write optimization. */
	dbg_read_after_read,          /**< A Firm subgraph was replaced because of a read
	                                   after read optimization. */
	dbg_read_a_const,             /**< A Firm subgraph was replaced because of a read
	                                   a constant optimization. */
yb9976's avatar
yb9976 committed
66
	dbg_dead_code,                /**< Removing unreachable code, i.e. blocks that are never executed. */
67
	dbg_opt_confirm,              /**< A Firm subgraph was replace because of a Confirmation. */
68
69
	dbg_gvn_pre,                  /**< A Firm node was replace because of the GVN-PRE algorithm. */
	dbg_combo,                    /**< A Firm node was replace because of the combo algorithm. */
yb9976's avatar
yb9976 committed
70
	dbg_jumpthreading,            /**< A Firm node was replace because of the jumpthreading algorithm. */
71
72
	dbg_backend,                  /**< A Firm subgraph was replaced because of a Backend transformation */
	dbg_max                       /**< Maximum value. */
Götz Lindenmaier's avatar
Götz Lindenmaier committed
73
} dbg_action;
Götz Lindenmaier's avatar
Götz Lindenmaier committed
74

Sebastian Felis's avatar
Sebastian Felis committed
75
/**
76
77
78
 * Converts a debug_action into a string.
 *
 * @param a  the debug action
Götz Lindenmaier's avatar
Götz Lindenmaier committed
79
 */
Michael Beck's avatar
Michael Beck committed
80
FIRM_API const char *dbg_action_2_str(dbg_action a);
81

82
83
84
/**
 * The type of the debug info merge function.
 *
Michael Beck's avatar
Michael Beck committed
85
86
87
88
 * @param new_node    the new ir node
 * @param old_node    the old ir node
 * @param action      the action that triggers the merge
 *
89
90
 * @see dbg_init()
 */
Michael Beck's avatar
Michael Beck committed
91
typedef void merge_pair_func(ir_node *new_node, ir_node *old_node, dbg_action action);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
92

Sebastian Felis's avatar
Sebastian Felis committed
93
/**
Michael Beck's avatar
Michael Beck committed
94
95
96
97
98
99
100
 * The type of the debug info merge sets function.
 *
 * @param new_node_array    array of new nodes
 * @param new_num_entries   number of entries in new_node_array
 * @param old_node_array    array of old nodes
 * @param old_num_entries   number of entries in old_node_array
 * @param action            the action that triggers the merge
101
102
103
 *
 * @see dbg_init()
 */
104
105
106
107
typedef void merge_sets_func(ir_node *const *new_node_array,
                             int new_num_entries,
                             ir_node *const *old_node_array,
                             int old_num_entries, dbg_action action);
108
109

/**
Michael Beck's avatar
Michael Beck committed
110
 *  Initializes the debug support.
111
 *
112
 *  This function takes pointers to two functions that merge the
Michael Beck's avatar
Michael Beck committed
113
 *  debug information when a
114
 *  transformation of a Firm graph is performed.
Michael Beck's avatar
Michael Beck committed
115
 *  Firm transformations call one of these functions.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
116
117
 *
 *   - dbg_info_merge_pair() is called in the following situation:
118
119
120
121
 *     The optimization replaced the old node by the new one.  The new node
 *     might be a recent allocated node not containing any debug information,
 *     or just another node from somewhere in the graph with the same
 *     semantics.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
122
 *   - dbg_info_merge_sets() is called in the following situation:
123
 *     The optimization replaced a subgraph by another subgraph.  There is no
Michael Beck's avatar
Michael Beck committed
124
 *     obviously mapping between single nodes in both subgraphs.  The optimization
125
126
127
128
129
130
 *     simply passes two lists to the debug module, one containing the nodes in
 *     the old subgraph, the other containing the nodes in the new subgraph.
 *     The same node can be in both lists.
 *
 *   Further both functions pass an enumeration indicating the action
 *   performed by the transformation, e.g. the kind of optimization performed.
Götz Lindenmaier's avatar
Götz Lindenmaier committed
131
 */
Michael Beck's avatar
Michael Beck committed
132
FIRM_API void dbg_init(merge_pair_func *dbg_info_merge_pair,
133
                       merge_sets_func *dbg_info_merge_sets);
Götz Lindenmaier's avatar
Götz Lindenmaier committed
134

Matthias Braun's avatar
Matthias Braun committed
135
/** A sourcecode location */
136
typedef struct src_loc_t {
Matthias Braun's avatar
Matthias Braun committed
137
138
139
	char const *file;    /**< the name of the source (usually a file) */
	unsigned    line;    /**< line number (starting at 1; 0 if unknown) */
	unsigned    column;  /**< column number (starting at 1; 0 if unknown) */
140
141
} src_loc_t;

142
/**
143
 * The type of the debug info retriever function.
144
145
146
147
 *  When given a dbg_info returns the name (usually the filename), line number
 *  and column number of the definition.
 *  Any part of the returned information may be NULL/0, which means it is not
 *  available.
148
 */
149
typedef src_loc_t (*retrieve_dbg_func)(dbg_info const *dbg);
150
151
152
153
154
155

/**
 * Sets a debug info retriever.
 *
 * @param func   the debug retriever function.
 */
Michael Beck's avatar
Michael Beck committed
156
FIRM_API void ir_set_debug_retrieve(retrieve_dbg_func func);
157

158
159
/**
 * The type of the type debug info retrieve function.
160
 * Prints a human readable source representation of a type to a buffer.
161
162
163
164
165
166
 *  (Used for generating debug info like stabs or dwarf)
 */
typedef void (*retrieve_type_dbg_func)(char *buffer, size_t buffer_size,
                                       const type_dbg_info *tdbgi);

/**
167
 * Sets global print_type_dbg_info function in firm
168
 */
Michael Beck's avatar
Michael Beck committed
169
FIRM_API void ir_set_type_debug_retrieve(retrieve_type_dbg_func func);
170

171
172
173
/**
 * Retrieve the debug info.
 */
174
FIRM_API src_loc_t ir_retrieve_dbg_info(dbg_info const *dbg);
175

176
177
178
/**
 * Retrieve type debug info
 */
Michael Beck's avatar
Michael Beck committed
179
FIRM_API void ir_retrieve_type_dbg_info(char *buffer, size_t buffer_size,
180
181
                                        const type_dbg_info *tdbgi);

Matthias Braun's avatar
Matthias Braun committed
182
183
/** @} */

184
#include "end.h"
185

Matthias Braun's avatar
Matthias Braun committed
186
#endif