6164a07c00ac7141f4050cc5ddbc3a247744683b
[libfirm] / ir / debug / dbginfo.h
1 /*
2 **  Copyright (C) 2001 by Universitaet Karlsruhe
3 **  All rights reserved.
4 **
5 **  Authors: Goetz Lindenmaier
6 **
7 **  dbginfo: This is the Firm interface to debugging support.  Firm requires
8 **  a debugging module fulfilling this interface, else no debugging information
9 **  is passed to the backend.
10 **  The interface requires a datatype representing the debugging information.
11 **  Firm supports administrating a reference to the debug information
12 **  in every firm node.  Further Firm optimizations call routines to
13 **  propagate debug information from old nodes to new nodes if the optimization
14 **  replaces the old ones by the new ones.
15 **
16 */
17
18 /* $Id$ */
19
20 # ifndef _DBGINFO_H_
21 # define _DBGINFO_H_
22
23 #include "ident.h"
24
25 #ifndef _IR_NODE_TYPEDEF_
26 #define _IR_NODE_TYPEDEF_
27 typedef struct ir_node ir_node;
28 #endif
29
30
31 /****s* dbginfo/dbg_info
32  *
33  * NAME
34  *   dbg_info - An abstract data type containing information for
35  *   debugging support.
36  * NOTE
37  *   This datatype is not defined in the firm library, but pointers
38  *   to this type can be stored in firm nodes.
39  * SEE ALSO
40  * SOURCE
41  */
42 typedef struct dbg_info dbg_info;
43 /* Routines to access the field of an ir node containing the
44    debugging information. */
45 inline void set_irn_dbg_info(ir_node *n, dbg_info* db);
46 inline dbg_info *get_irn_dbg_info(ir_node *n);
47 /*****/
48
49 /****s* dbginfo/dbg_action
50  *
51  * NAME
52  *   dbg_action - An enumeration indicating the action performed by a
53  *   transformation.
54  * NOTE
55  * SOURCE
56  */
57 typedef enum {
58   dbg_error = 0,
59   dbg_opt_ssa,        /* Optimization of the SSA representation, e.g., removal
60                          of superfluent phi nodes. */
61   dbg_opt_auxnode,    /* Removal of unnecessary auxilliary nodes. */
62   dbg_const_eval,     /* A Firm subgraph was evaluated to a single constant. */
63   dbg_straightening,  /* A Firm subgraph was replaced by a single, existing
64                          block. */
65   dbg_if_simplification, /* The control flow of an if is changed as either the
66                             else, the then or both blocks are empty. */
67   dbg_algebraic_simplification,
68   dbg_write_after_write,
69   dbg_write_after_read,
70   dbg_max
71 } dbg_action;
72 /*****/
73
74
75 /****f* dbginfo/dbg_action_2_str
76  *
77  * NAME
78  *   dbg_action_2_str - converts enum to string
79  * SYNOPSIS
80  * INPUTS
81  * RESULT
82  ***
83  */
84 static const char* dbg_action_2_str(dbg_action a) {
85   switch(a) {
86   case dbg_error: return "dbg_error"; break;
87   case dbg_opt_ssa: return "dbg_opt_ssa"; break;
88   case dbg_opt_auxnode: return "dbg_opt_auxnode"; break;
89   case dbg_const_eval: return "dbg_const_eval"; break;
90   case dbg_straightening: return "dbg_straightening"; break;
91   case dbg_if_simplification: return "dbg_if_simplification"; break;
92   case dbg_algebraic_simplification:
93     return "dbg_algebraic_simplification"; break;
94   case dbg_write_after_write: return "dbg_write_after_write"; break;
95   case dbg_write_after_read: return "dbg_write_after_read"; break;
96 //case dbg_: return "dbg_"; break;
97   default:
98     if (a <= dbg_max)
99       return "string conversion not implemented";
100     else
101       assert(0);
102   }
103 }
104
105
106 /****f* dbginfo/dbg_init
107  *
108  * NAME
109  *   dbg_init - initializes the debug support.
110  * SYNOPSIS
111  *   void dbg_init( void (merge_pair)(ir_node *nw, ir_node *old, dbg_action info),
112  *                  void (merge_sets)(ir_node **new_nodes, int n_new_nodes,
113  *                                    ir_node **old_nodes, int n_old_nodes,
114  *                                    dbg_action info));
115  * INPUTS
116  *   Pointers to two functions that merge the debug information when a
117  *   transformation of a firm graph is performed.
118  *   Firm transformations call one of these functions.
119  *   - dbg_info_merge_pair() is called in the following situation:
120  *     The optimization replaced the old node by the new one.  The new node
121  *     might be a recent allocated node not containing any debug information,
122  *     or just another node from somewhere in the graph with the same
123  *     semantics.
124  *   - dbg_info_merge_sets() is called in the following situation:
125  *     The optimization replaced a subgraph by another subgraph.  There is no
126  *     obviouse mapping between single nodes in both subgraphs.  The optimization
127  *     simply passes two lists to the debug module, one containing the nodes in
128  *     the old subgraph, the other containing the nodes in the new subgraph.
129  *     The same node can be in both lists.
130  *   Further both functions pass an enumeration indicating the action
131  *   performed by the transformation, e.g. the kind of optimization performed.
132  * RESULT
133  *   No result.
134  ***
135  */
136 void dbg_init( void (merge_pair)(ir_node *nw, ir_node *old, dbg_action info),
137                void (merge_sets)(ir_node **new_nodes, int n_new_nodes,
138                                  ir_node **old_nodes, int n_old_nodes,
139                                  dbg_action info)
140                );
141
142
143 #endif /* _DBGINFO_H_ */