2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief Implements the Firm interface to debug information.
9 * @author Goetz Lindenmaier, Michael Beck
12 #ifndef FIRM_DEBUG_DBGINFO_H
13 #define FIRM_DEBUG_DBGINFO_H
16 #include "firm_types.h"
21 * @defgroup dbg_info Source References
22 * Firm requires a debugging module fulfilling this interface, else no
23 * debugging information is passed to the backend.
24 * The interface requires a datatype representing the debugging
25 * information. Firm supports administrating a reference to the debug
26 * information in every Firm node. Further Firm optimizations call
27 * routines to propagate debug information from old nodes to new nodes
28 * if the optimization replaces the old ones by the new ones.
35 * An abstract data type containing information for
38 * This opaque data type is not defined anywhere in the Firm library,
39 * but pointers to this type can be stored in Firm nodes.
43 * An enumeration indicating the action performed by a transformation.
47 dbg_opt_ssa, /**< Optimization of the SSA representation, e.g. removal of superfluent Phi nodes. */
48 dbg_opt_auxnode, /**< Removal of unnecessary auxiliary nodes. */
49 dbg_const_eval, /**< A Firm subgraph was evaluated to a single constant. */
50 dbg_opt_cse, /**< A Firm node was replaced due to common subexpression elimination. */
51 dbg_straightening, /**< A Firm subgraph was replaced by a single, existing block. */
52 dbg_if_simplification, /**< The control flow of an if is changed as either the
53 else, the then or both blocks are empty. */
54 dbg_algebraic_simplification, /**< A Firm subgraph was replaced because of an algebraic
56 dbg_write_after_write, /**< A Firm subgraph was replaced because of a write
57 after write optimization. */
58 dbg_write_after_read, /**< A Firm subgraph was replaced because of a write
59 after read optimization. */
60 dbg_read_after_write, /**< A Firm subgraph was replaced because of a read
61 after write optimization. */
62 dbg_read_after_read, /**< A Firm subgraph was replaced because of a read
63 after read optimization. */
64 dbg_read_a_const, /**< A Firm subgraph was replaced because of a read
65 a constant optimization. */
66 dbg_rem_poly_call, /**< Remove polymorphic call. */
67 dbg_dead_code, /**< Removing unreachable code, i.e. blocks that are never executed. */
68 dbg_opt_confirm, /**< A Firm subgraph was replace because of a Confirmation. */
69 dbg_gvn_pre, /**< A Firm node was replace because of the GVN-PRE algorithm. */
70 dbg_combo, /**< A Firm node was replace because of the combo algorithm. */
71 dbg_jumpthreading, /**< A Firm node was replace because of the jumpthreading algorithm. */
72 dbg_backend, /**< A Firm subgraph was replaced because of a Backend transformation */
73 dbg_max /**< Maximum value. */
77 * Converts a debug_action into a string.
79 * @param a the debug action
81 FIRM_API const char *dbg_action_2_str(dbg_action a);
84 * The type of the debug info merge function.
86 * @param new_node the new ir node
87 * @param old_node the old ir node
88 * @param action the action that triggers the merge
92 typedef void merge_pair_func(ir_node *new_node, ir_node *old_node, dbg_action action);
95 * The type of the debug info merge sets function.
97 * @param new_node_array array of new nodes
98 * @param new_num_entries number of entries in new_node_array
99 * @param old_node_array array of old nodes
100 * @param old_num_entries number of entries in old_node_array
101 * @param action the action that triggers the merge
105 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);
108 * Initializes the debug support.
110 * This function takes pointers to two functions that merge the
111 * debug information when a
112 * transformation of a Firm graph is performed.
113 * Firm transformations call one of these functions.
115 * - dbg_info_merge_pair() is called in the following situation:
116 * The optimization replaced the old node by the new one. The new node
117 * might be a recent allocated node not containing any debug information,
118 * or just another node from somewhere in the graph with the same
120 * - dbg_info_merge_sets() is called in the following situation:
121 * The optimization replaced a subgraph by another subgraph. There is no
122 * obviously mapping between single nodes in both subgraphs. The optimization
123 * simply passes two lists to the debug module, one containing the nodes in
124 * the old subgraph, the other containing the nodes in the new subgraph.
125 * The same node can be in both lists.
127 * Further both functions pass an enumeration indicating the action
128 * performed by the transformation, e.g. the kind of optimization performed.
130 FIRM_API void dbg_init(merge_pair_func *dbg_info_merge_pair,
131 merge_sets_func *dbg_info_merge_sets);
133 /** A sourcecode location */
134 typedef struct src_loc_t {
135 char const *file; /**< the name of the source (usually a file) */
136 unsigned line; /**< line number (starting at 1; 0 if unknown) */
137 unsigned column; /**< column number (starting at 1; 0 if unknown) */
141 * The type of the debug info retriever function.
142 * When given a dbg_info returns the name (usually the filename), line number
143 * and column number of the definition.
144 * Any part of the returned information may be NULL/0, which means it is not
147 typedef src_loc_t (*retrieve_dbg_func)(dbg_info const *dbg);
150 * Sets a debug info retriever.
152 * @param func the debug retriever function.
154 FIRM_API void ir_set_debug_retrieve(retrieve_dbg_func func);
157 * The type of the type debug info retrieve function.
158 * Prints a human readable source representation of a type to an obstack.
159 * (Used for generating debug info like stabs or dwarf)
161 typedef void (*retrieve_type_dbg_func)(char *buffer, size_t buffer_size,
162 const type_dbg_info *tdbgi);
165 * Sets global print_type_dbg_info function in firm
167 FIRM_API void ir_set_type_debug_retrieve(retrieve_type_dbg_func func);
170 * Retrieve the debug info.
172 FIRM_API src_loc_t ir_retrieve_dbg_info(dbg_info const *dbg);
175 * Retrieve type debug info
177 FIRM_API void ir_retrieve_type_dbg_info(char *buffer, size_t buffer_size,
178 const type_dbg_info *tdbgi);