2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief Implements the Firm interface to debug information.
23 * @author Goetz Lindenmaier, Michael Beck
29 #include "dbginfo_t.h"
35 merge_pair_func *__dbg_info_merge_pair = default_dbg_info_merge_pair;
36 merge_sets_func *__dbg_info_merge_sets = default_dbg_info_merge_sets;
38 void dbg_init(merge_pair_func *mpf, merge_sets_func *msf)
40 __dbg_info_merge_pair = mpf ? mpf : default_dbg_info_merge_pair;
41 __dbg_info_merge_sets = msf ? msf : default_dbg_info_merge_sets;
45 * Converts a debug_action into a string.
47 const char *dbg_action_2_str(dbg_action a)
49 #define CASE(a) case a: return #a
54 CASE(dbg_opt_auxnode);
57 CASE(dbg_straightening);
58 CASE(dbg_if_simplification);
59 CASE(dbg_algebraic_simplification);
60 CASE(dbg_write_after_write);
61 CASE(dbg_write_after_read);
62 CASE(dbg_read_after_write);
63 CASE(dbg_read_after_read);
64 CASE(dbg_read_a_const);
65 CASE(dbg_rem_poly_call);
67 CASE(dbg_opt_confirm);
70 CASE(dbg_jumpthreading);
74 return "string conversion not implemented";
76 panic("Missing debug action in dbg_action_2_str()");
81 void default_dbg_info_merge_pair(ir_node *nw, ir_node *old, dbg_action info)
83 dbg_info *new_db = get_irn_dbg_info(nw);
86 set_irn_dbg_info(nw, get_irn_dbg_info(old));
89 void default_dbg_info_merge_sets(ir_node **new_nodes, int n_new_nodes,
90 ir_node **old_nodes, int n_old_nodes,
94 if (n_old_nodes == 1) {
95 dbg_info *old_db = get_irn_dbg_info(old_nodes[0]);
98 for (i = 0; i < n_new_nodes; ++i)
99 if (get_irn_dbg_info(new_nodes[i]) == NULL)
100 set_irn_dbg_info(new_nodes[i], old_db);
104 /** The debug info retriever function. */
105 static retrieve_dbg_func retrieve_dbg = NULL;
106 static retrieve_type_dbg_func retrieve_type_dbg = NULL;
108 void ir_set_debug_retrieve(retrieve_dbg_func func)
113 const char *ir_retrieve_dbg_info(const dbg_info *dbg, unsigned *line)
116 return retrieve_dbg(dbg, line);
122 void ir_set_type_debug_retrieve(retrieve_type_dbg_func func)
124 retrieve_type_dbg = func;
127 void ir_retrieve_type_dbg_info(char *buffer, size_t buffer_size,
128 const type_dbg_info *tdbgi)
130 if (retrieve_type_dbg)
131 retrieve_type_dbg(buffer, buffer_size, tdbgi);
132 assert(buffer_size > 0);
133 buffer[buffer_size-1] = 0;
136 void ir_dbg_info_snprint(char *buf, size_t bufsize, const dbg_info *dbg)
139 const char *source = ir_retrieve_dbg_info(dbg, &line);
141 if (source == NULL) {
146 snprintf(buf, bufsize, "%s:%u", source, line);