moved be_retrieve_dbg_info() into middleend and rename it to ir_retrieve_dbg_info()
[libfirm] / ir / debug / dbginfo.c
1 /*
2  * Copyright (C) 1995-2007 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_backend);
73         default:
74                 if (a <= dbg_max)
75                         return "string conversion not implemented";
76                 else
77                         assert(!"Missing debug action in dbg_action_2_str()");
78                 return NULL;
79         }
80 #undef CASE
81 }  /* dbg_action_2_str */
82
83
84 void default_dbg_info_merge_pair(ir_node *nw, ir_node *old, dbg_action info) {
85         dbg_info *new_db = get_irn_dbg_info(nw);
86         (void) info;
87         if (new_db == NULL)
88                 set_irn_dbg_info(nw, get_irn_dbg_info(old));
89 }  /* default_dbg_info_merge_pair */
90
91 void default_dbg_info_merge_sets(ir_node **new_nodes, int n_new_nodes,
92                                  ir_node **old_nodes, int n_old_nodes,
93                                  dbg_action info) {
94         (void) info;
95         if (n_old_nodes == 1) {
96                 dbg_info *old_db = get_irn_dbg_info(old_nodes[0]);
97                 int i;
98
99                 for (i = 0; i < n_new_nodes; ++i)
100                         if (get_irn_dbg_info(new_nodes[i]) == NULL)
101                                 set_irn_dbg_info(new_nodes[i], old_db);
102         }
103 }  /* default_dbg_info_merge_sets */
104
105 /** The debug info retriever function. */
106 static retrieve_dbg_func retrieve_dbg = NULL;
107
108 /* Sets a debug info retriever. */
109 void ir_set_debug_retrieve(retrieve_dbg_func func) {
110         retrieve_dbg = func;
111 }
112
113 /* Retrieve the debug info. */
114 const char *ir_retrieve_dbg_info(const dbg_info *dbg, unsigned *line) {
115         if (retrieve_dbg)
116                 return retrieve_dbg(dbg, line);
117
118         *line = 0;
119         return NULL;
120 }