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
28 #include "dbginfo_t.h"
34 merge_pair_func *__dbg_info_merge_pair = default_dbg_info_merge_pair;
35 merge_sets_func *__dbg_info_merge_sets = default_dbg_info_merge_sets;
37 void dbg_init(merge_pair_func *mpf, merge_sets_func *msf)
39 __dbg_info_merge_pair = mpf ? mpf : default_dbg_info_merge_pair;
40 __dbg_info_merge_sets = msf ? msf : default_dbg_info_merge_sets;
44 * Converts a debug_action into a string.
46 const char *dbg_action_2_str(dbg_action a)
48 #define CASE(a) case a: return #a
53 CASE(dbg_opt_auxnode);
56 CASE(dbg_straightening);
57 CASE(dbg_if_simplification);
58 CASE(dbg_algebraic_simplification);
59 CASE(dbg_write_after_write);
60 CASE(dbg_write_after_read);
61 CASE(dbg_read_after_write);
62 CASE(dbg_read_after_read);
63 CASE(dbg_read_a_const);
64 CASE(dbg_rem_poly_call);
66 CASE(dbg_opt_confirm);
69 CASE(dbg_jumpthreading);
73 return "string conversion not implemented";
75 panic("Missing debug action");
80 void default_dbg_info_merge_pair(ir_node *nw, ir_node *old, dbg_action info)
82 dbg_info *new_db = get_irn_dbg_info(nw);
85 set_irn_dbg_info(nw, get_irn_dbg_info(old));
88 void default_dbg_info_merge_sets(ir_node **new_nodes, int n_new_nodes,
89 ir_node **old_nodes, int n_old_nodes,
93 if (n_old_nodes == 1) {
94 dbg_info *old_db = get_irn_dbg_info(old_nodes[0]);
97 for (i = 0; i < n_new_nodes; ++i)
98 if (get_irn_dbg_info(new_nodes[i]) == NULL)
99 set_irn_dbg_info(new_nodes[i], old_db);
103 static src_loc_t default_retrieve_dbg(dbg_info const *const dbg)
106 src_loc_t const loc = { NULL, 0, 0 };
110 /** The debug info retriever function. */
111 static retrieve_dbg_func retrieve_dbg = default_retrieve_dbg;
112 static retrieve_type_dbg_func retrieve_type_dbg = NULL;
114 void ir_set_debug_retrieve(retrieve_dbg_func func)
116 retrieve_dbg = func ? func : default_retrieve_dbg;
119 src_loc_t ir_retrieve_dbg_info(dbg_info const *const dbg)
121 return retrieve_dbg(dbg);
124 void ir_set_type_debug_retrieve(retrieve_type_dbg_func func)
126 retrieve_type_dbg = func;
129 void ir_retrieve_type_dbg_info(char *buffer, size_t buffer_size,
130 const type_dbg_info *tdbgi)
133 if (retrieve_type_dbg)
134 retrieve_type_dbg(buffer, buffer_size, tdbgi);
135 assert(buffer_size > 0);
136 buffer[buffer_size-1] = '\0';
139 void ir_dbg_info_snprint(char *buf, size_t bufsize, const dbg_info *dbg)
141 src_loc_t const loc = ir_retrieve_dbg_info(dbg);
148 if (loc.column == 0) {
149 snprintf(buf, bufsize, "%s:%u", loc.file, loc.line);
151 snprintf(buf, bufsize, "%s:%u:%u", loc.file, loc.line, loc.column);