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