normalized various syntactic constructs for firm jni.
[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 /* to resolve recursion between entity.h and type.h */
31 #ifndef _ENTITY_TYPEDEF_
32 #define _ENTITY_TYPEDEF_
33 typedef struct entity entity;
34 #endif
35
36 #ifndef _TYPE_TYPEDEF_
37 #define _TYPE_TYPEDEF_
38 typedef struct type type;
39 #endif
40
41 /****s* dbginfo/dbg_info
42  *
43  * NAME
44  *   dbg_info - An abstract data type containing information for
45  *   debugging support.
46  * NOTE
47  *   This datatype is not defined in the firm library, but pointers
48  *   to this type can be stored in firm nodes.
49  * SEE ALSO
50  * SOURCE
51  */
52 typedef struct dbg_info dbg_info;
53 /* Routines to access the field of an ir node containing the
54    debugging information. */
55 INLINE void set_irn_dbg_info(ir_node *n, dbg_info* db);
56 INLINE dbg_info *get_irn_dbg_info(ir_node *n);
57 /* Routines to access the field of an entity containing the
58    debugging information. */
59 INLINE void set_entity_dbg_info(entity *ent, dbg_info* db);
60 INLINE dbg_info *get_entity_dbg_info(entity *ent);
61 /* Routines to access the field of a type containing the
62    debugging information. */
63 INLINE void set_type_dbg_info(type *tp, dbg_info* db);
64 INLINE dbg_info *get_type_dbg_info(type *tp);
65 /*****/
66
67 /****s* dbginfo/dbg_action
68  *
69  * NAME
70  *   dbg_action - An enumeration indicating the action performed by a
71  *   transformation.
72  * NOTE
73  * SOURCE
74  */
75 typedef enum {
76   dbg_error = 0,
77   dbg_opt_ssa,        /* Optimization of the SSA representation, e.g., removal
78                          of superfluent phi nodes. */
79   dbg_opt_auxnode,    /* Removal of unnecessary auxilliary nodes. */
80   dbg_const_eval,     /* A Firm subgraph was evaluated to a single constant. */
81   dbg_straightening,  /* A Firm subgraph was replaced by a single, existing
82                          block. */
83   dbg_if_simplification, /* The control flow of an if is changed as either the
84                             else, the then or both blocks are empty. */
85   dbg_algebraic_simplification,
86   dbg_write_after_write,
87   dbg_write_after_read,
88   dbg_max
89 } dbg_action;
90 /*****/
91
92
93 /****f* dbginfo/dbg_action_2_str
94  *
95  * NAME
96  *   dbg_action_2_str - converts enum to string
97  * SYNOPSIS
98  * INPUTS
99  * RESULT
100  ***
101  */
102 static const char* dbg_action_2_str(dbg_action a) {
103   switch(a) {
104   case dbg_error: return "dbg_error"; break;
105   case dbg_opt_ssa: return "dbg_opt_ssa"; break;
106   case dbg_opt_auxnode: return "dbg_opt_auxnode"; break;
107   case dbg_const_eval: return "dbg_const_eval"; break;
108   case dbg_straightening: return "dbg_straightening"; break;
109   case dbg_if_simplification: return "dbg_if_simplification"; break;
110   case dbg_algebraic_simplification:
111     return "dbg_algebraic_simplification"; break;
112   case dbg_write_after_write: return "dbg_write_after_write"; break;
113   case dbg_write_after_read: return "dbg_write_after_read"; break;
114   default:
115     if (a <= dbg_max)
116       return "string conversion not implemented";
117     else
118       assert(0);
119   }
120 }
121
122
123 /****f* dbginfo/dbg_init
124  *
125  * NAME
126  *   dbg_init - initializes the debug support.
127  * SYNOPSIS
128  *   void dbg_init( void (merge_pair)(ir_node *nw, ir_node *old, dbg_action info),
129  *                  void (merge_sets)(ir_node **new_nodes, int n_new_nodes,
130  *                                    ir_node **old_nodes, int n_old_nodes,
131  *                                    dbg_action info));
132  * INPUTS
133  *   Pointers to two functions that merge the debug information when a
134  *   transformation of a firm graph is performed.
135  *   Firm transformations call one of these functions.
136  *   - dbg_info_merge_pair() is called in the following situation:
137  *     The optimization replaced the old node by the new one.  The new node
138  *     might be a recent allocated node not containing any debug information,
139  *     or just another node from somewhere in the graph with the same
140  *     semantics.
141  *   - dbg_info_merge_sets() is called in the following situation:
142  *     The optimization replaced a subgraph by another subgraph.  There is no
143  *     obviouse mapping between single nodes in both subgraphs.  The optimization
144  *     simply passes two lists to the debug module, one containing the nodes in
145  *     the old subgraph, the other containing the nodes in the new subgraph.
146  *     The same node can be in both lists.
147  *   Further both functions pass an enumeration indicating the action
148  *   performed by the transformation, e.g. the kind of optimization performed.
149  * RESULT
150  *   No result.
151  ***
152  */
153
154
155 typedef void (merge_pair_func)(ir_node *, ir_node *, dbg_action);
156 typedef void (merge_sets_func)(ir_node **, int, ir_node **, int, dbg_action);
157
158 void dbg_init(merge_pair_func *mpf, merge_sets_func *msf);
159
160
161 #endif /* _DBGINFO_H_ */