properties updated
[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 void set_irn_dbg_info(ir_node *n, dbg_info *db) {
51         n->dbi = db;
52 }  /* set_irn_dbg_info */
53
54 struct dbg_info *get_irn_dbg_info(const ir_node *n) {
55         return n->dbi;
56 }  /* get_irn_dbg_info */
57
58
59 /* Routines to access the field of an entity containing the
60    debugging information. */
61 void set_entity_dbg_info(ir_entity *ent, dbg_info *db) {
62         ent->dbi = db;
63 }  /* set_entity_dbg_info */
64
65 dbg_info *get_entity_dbg_info(const ir_entity *ent) {
66         return ent->dbi;
67 }  /* get_entity_dbg_info */
68
69 /* Routines to access the field of a type containing the
70    debugging information. */
71 void set_type_dbg_info(ir_type *tp, dbg_info *db) {
72         tp->dbi = db;
73 }  /* set_type_dbg_info */
74
75 dbg_info *get_type_dbg_info(const ir_type *tp) {
76         return tp->dbi;
77 }  /* get_type_dbg_info */
78
79 /*
80  * Converts a debug_action into a string.
81  */
82 const char *dbg_action_2_str(dbg_action a) {
83 #define CASE(a) case a: return #a
84
85         switch (a) {
86         CASE(dbg_error);
87         CASE(dbg_opt_ssa);
88         CASE(dbg_opt_auxnode);
89         CASE(dbg_const_eval);
90         CASE(dbg_opt_cse);
91         CASE(dbg_straightening);
92         CASE(dbg_if_simplification);
93         CASE(dbg_algebraic_simplification);
94         CASE(dbg_write_after_write);
95         CASE(dbg_write_after_read);
96         CASE(dbg_read_after_write);
97         CASE(dbg_read_after_read);
98         CASE(dbg_read_a_const);
99         CASE(dbg_rem_poly_call);
100         CASE(dbg_dead_code);
101         CASE(dbg_opt_confirm);
102         CASE(dbg_backend);
103         default:
104                 if (a <= dbg_max)
105                         return "string conversion not implemented";
106                 else
107                         assert(!"Missing debug action in dbg_action_2_str()");
108                 return NULL;
109         }
110 #undef CASE
111 }  /* dbg_action_2_str */
112
113
114 void default_dbg_info_merge_pair(ir_node *nw, ir_node *old, dbg_action info) {
115         dbg_info *new_db = get_irn_dbg_info(nw);
116         if (new_db == NULL)
117                 set_irn_dbg_info(nw, get_irn_dbg_info(old));
118 }  /* default_dbg_info_merge_pair */
119
120 void default_dbg_info_merge_sets(ir_node **new_nodes, int n_new_nodes,
121                                  ir_node **old_nodes, int n_old_nodes,
122                                  dbg_action info) {
123         if (n_old_nodes == 1) {
124                 dbg_info *old_db = get_irn_dbg_info(old_nodes[0]);
125                 int i;
126
127                 for (i = 0; i < n_new_nodes; ++i)
128                         if (get_irn_dbg_info(new_nodes[i]) == NULL)
129                                 set_irn_dbg_info(new_nodes[i], old_db);
130         }
131 }  /* default_dbg_info_merge_sets */