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