64ecc0476fb9e68f09f0bc17d139f18f9b9d59fc
[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  * Project:     libFIRM
22  * File name:   ir/debug/dbginfo.c
23  * Purpose:     Implements the Firm interface to debug information.
24  * Author:      Goetz Lindenmaier
25  * Modified by: Michael Beck
26  * Created:     2001
27  * CVS-ID:      $Id$
28  * Copyright:   (c) 2001-2006 Universität Karlsruhe
29  */
30
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
34
35 #include "dbginfo_t.h"
36 #include "irnode_t.h"
37 #include "type_t.h"
38 #include "entity_t.h"
39
40 merge_pair_func *__dbg_info_merge_pair = default_dbg_info_merge_pair;
41
42 merge_sets_func *__dbg_info_merge_sets = default_dbg_info_merge_sets;
43
44 snprint_dbg_func *__dbg_info_snprint   = (snprint_dbg_func *)0;
45
46 void dbg_init( merge_pair_func *mpf, merge_sets_func *msf, snprint_dbg_func *snprint_dbg )
47 {
48         __dbg_info_merge_pair = mpf ? mpf : default_dbg_info_merge_pair;
49         __dbg_info_merge_sets = msf ? msf : default_dbg_info_merge_sets;
50         __dbg_info_snprint    = snprint_dbg;
51 }  /* dbg_init */
52
53
54 void set_irn_dbg_info(ir_node *n, dbg_info *db) {
55         n->dbi = db;
56 }  /* set_irn_dbg_info */
57
58 struct dbg_info *get_irn_dbg_info(const ir_node *n) {
59         return n->dbi;
60 }  /* get_irn_dbg_info */
61
62
63 /* Routines to access the field of an entity containing the
64    debugging information. */
65 void set_entity_dbg_info(ir_entity *ent, dbg_info *db) {
66         ent->dbi = db;
67 }  /* set_entity_dbg_info */
68
69 dbg_info *get_entity_dbg_info(const ir_entity *ent) {
70         return ent->dbi;
71 }  /* get_entity_dbg_info */
72
73 /* Routines to access the field of a type containing the
74    debugging information. */
75 void set_type_dbg_info(ir_type *tp, dbg_info *db) {
76         tp->dbi = db;
77 }  /* set_type_dbg_info */
78
79 dbg_info *get_type_dbg_info(const ir_type *tp) {
80         return tp->dbi;
81 }  /* get_type_dbg_info */
82
83 /*
84  * Converts a debug_action into a string.
85  */
86 const char *dbg_action_2_str(dbg_action a) {
87 #define CASE(a) case a: return #a
88
89         switch (a) {
90         CASE(dbg_error);
91         CASE(dbg_opt_ssa);
92         CASE(dbg_opt_auxnode);
93         CASE(dbg_const_eval);
94         CASE(dbg_opt_cse);
95         CASE(dbg_straightening);
96         CASE(dbg_if_simplification);
97         CASE(dbg_algebraic_simplification);
98         CASE(dbg_write_after_write);
99         CASE(dbg_write_after_read);
100         CASE(dbg_read_after_write);
101         CASE(dbg_read_after_read);
102         CASE(dbg_read_a_const);
103         CASE(dbg_rem_poly_call);
104         CASE(dbg_dead_code);
105         CASE(dbg_opt_confirm);
106         CASE(dbg_backend);
107         default:
108                 if (a <= dbg_max)
109                         return "string conversion not implemented";
110                 else
111                         assert(!"Missing debug action in dbg_action_2_str()");
112                 return NULL;
113         }
114 #undef CASE
115 }  /* dbg_action_2_str */
116
117
118 void default_dbg_info_merge_pair(ir_node *nw, ir_node *old, dbg_action info) {
119         dbg_info *new_db = get_irn_dbg_info(nw);
120         if (new_db == NULL)
121                 set_irn_dbg_info(nw, get_irn_dbg_info(old));
122 }  /* default_dbg_info_merge_pair */
123
124 void default_dbg_info_merge_sets(ir_node **new_nodes, int n_new_nodes,
125                                  ir_node **old_nodes, int n_old_nodes,
126                                  dbg_action info) {
127         if (n_old_nodes == 1) {
128                 dbg_info *old_db = get_irn_dbg_info(old_nodes[0]);
129                 int i;
130
131                 for (i = 0; i < n_new_nodes; ++i)
132                         if (get_irn_dbg_info(new_nodes[i]) == NULL)
133                                 set_irn_dbg_info(new_nodes[i], old_db);
134         }
135 }  /* default_dbg_info_merge_sets */