- kill Bad nodes from the keep-alive list: these arise from the new
[libfirm] / ir / debug / dbginfo.c
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  */
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
30
31 #include "dbginfo_t.h"
32 #include "irnode_t.h"
33 #include "type_t.h"
34 #include "entity_t.h"
35
36 merge_pair_func *__dbg_info_merge_pair = default_dbg_info_merge_pair;
37
38 merge_sets_func *__dbg_info_merge_sets = default_dbg_info_merge_sets;
39
40 snprint_dbg_func *__dbg_info_snprint   = (snprint_dbg_func *)0;
41
42 void dbg_init( merge_pair_func *mpf, merge_sets_func *msf, snprint_dbg_func *snprint_dbg )
43 {
44         __dbg_info_merge_pair = mpf ? mpf : default_dbg_info_merge_pair;
45         __dbg_info_merge_sets = msf ? msf : default_dbg_info_merge_sets;
46         __dbg_info_snprint    = snprint_dbg;
47 }  /* dbg_init */
48
49 /*
50  * Converts a debug_action into a string.
51  */
52 const char *dbg_action_2_str(dbg_action a) {
53 #define CASE(a) case a: return #a
54
55         switch (a) {
56         CASE(dbg_error);
57         CASE(dbg_opt_ssa);
58         CASE(dbg_opt_auxnode);
59         CASE(dbg_const_eval);
60         CASE(dbg_opt_cse);
61         CASE(dbg_straightening);
62         CASE(dbg_if_simplification);
63         CASE(dbg_algebraic_simplification);
64         CASE(dbg_write_after_write);
65         CASE(dbg_write_after_read);
66         CASE(dbg_read_after_write);
67         CASE(dbg_read_after_read);
68         CASE(dbg_read_a_const);
69         CASE(dbg_rem_poly_call);
70         CASE(dbg_dead_code);
71         CASE(dbg_opt_confirm);
72         CASE(dbg_gvn_pre);
73         CASE(dbg_combo);
74         CASE(dbg_backend);
75         default:
76                 if (a <= dbg_max)
77                         return "string conversion not implemented";
78                 else
79                         assert(!"Missing debug action in dbg_action_2_str()");
80                 return NULL;
81         }
82 #undef CASE
83 }  /* dbg_action_2_str */
84
85
86 void default_dbg_info_merge_pair(ir_node *nw, ir_node *old, dbg_action info) {
87         dbg_info *new_db = get_irn_dbg_info(nw);
88         (void) info;
89         if (new_db == NULL)
90                 set_irn_dbg_info(nw, get_irn_dbg_info(old));
91 }  /* default_dbg_info_merge_pair */
92
93 void default_dbg_info_merge_sets(ir_node **new_nodes, int n_new_nodes,
94                                  ir_node **old_nodes, int n_old_nodes,
95                                  dbg_action info) {
96         (void) info;
97         if (n_old_nodes == 1) {
98                 dbg_info *old_db = get_irn_dbg_info(old_nodes[0]);
99                 int i;
100
101                 for (i = 0; i < n_new_nodes; ++i)
102                         if (get_irn_dbg_info(new_nodes[i]) == NULL)
103                                 set_irn_dbg_info(new_nodes[i], old_db);
104         }
105 }  /* default_dbg_info_merge_sets */
106
107 /** The debug info retriever function. */
108 static retrieve_dbg_func retrieve_dbg = NULL;
109
110 /* Sets a debug info retriever. */
111 void ir_set_debug_retrieve(retrieve_dbg_func func) {
112         retrieve_dbg = func;
113 }
114
115 /* Retrieve the debug info. */
116 const char *ir_retrieve_dbg_info(const dbg_info *dbg, unsigned *line) {
117         if (retrieve_dbg)
118                 return retrieve_dbg(dbg, line);
119
120         *line = 0;
121         return NULL;
122 }