initialisation; sanitize print levels, misc fixes
[libfirm] / ir / ana2 / pto_init.c
1 /* -*- c -*- */
2
3 /*
4  * Project:     libFIRM
5  * File name:   ir/ana2/pto_init.c
6  * Purpose:     Pto Initialization
7  * Author:      Florian
8  * Modified by:
9  * Created:     Wed  3 Nov 2004
10  * CVS-ID:      $Id$
11  * Copyright:   (c) 1999-2004 Universität Karlsruhe
12  * Licence:     This file is protected by GPL -  GNU GENERAL PUBLIC LICENSE.
13  */
14
15
16 # ifdef HAVE_CONFIG_H
17 #  include <config.h>
18 # endif
19
20 # include "pto.h"
21 # include "pto_util.h"
22
23 # include "entity.h"
24 # include "irnode.h"
25 # include "xmalloc.h"
26
27 # define DBGPRINT(lvl, msg) if (get_pto_verbose () > lvl) { fprintf msg; }
28
29 static void pto_init_proj_load (ir_node *proj, ir_node *load)
30 {
31   assert ((mode_P == get_irn_mode (proj)) && "wrong proj(load)");
32
33   pto_t *pto = pto_new_empty (proj);
34   pto_set_dummy (pto);
35
36   DBGPRINT (1, (stdout, "%s: pto (%s[%li]) = 0x%08x\n",
37                 __FUNCTION__,
38                 get_op_name (get_irn_op (proj)),
39                 get_irn_node_nr (proj),
40                 (int) pto));
41
42   set_pto (proj, pto);
43 }
44
45 static void pto_init_call (ir_node *call)
46 {
47   /* check return value: */
48   ir_node *ptr = get_Call_ptr (call);
49   entity *ent = get_ptr_ent (ptr);
50   type *meth_tp = get_entity_type (ent);
51
52   if (0 == get_method_n_ress (meth_tp)) {
53     /* no return value at all */
54     return;
55   }
56
57   type *ret_tp  = get_method_res_type (meth_tp, 0);
58
59   if (mode_P != get_type_mode (ret_tp)) {
60     /* no pointer-valued return value */
61     return;
62   }
63
64   pto_t *pto = pto_new_empty (call);
65   pto_set_dummy (pto);
66
67   DBGPRINT (1, (stdout, "%s: pto (%s[%li]) = 0x%08x\n",
68                 __FUNCTION__,
69                 get_op_name (get_irn_op (call)),
70                 get_irn_node_nr (call),
71                 (int) pto));
72
73   set_pto (call, pto);
74 }
75
76 static void pto_init_raise (ir_node *raise)
77 {
78   /* assert (0 && "initialise raise?"); */
79
80   /* right now, do nothing and hope that a raise can always be
81      analysed on-the-fly. */
82 }
83
84 static void pto_init_proj (ir_node *proj)
85 {
86   ir_node *in = get_Proj_pred (proj);
87   const opcode in_op = get_irn_opcode (in);
88
89   switch (in_op) {
90   case (iro_Proj): {
91     ir_node *in_in = get_Proj_pred (in);
92     const opcode in_in_op = get_irn_opcode (in_in);
93
94     switch (in_in_op) {
95     case (iro_Start): {
96       /* nothing (always initialised with actual values) */
97     } break;
98
99     case (iro_Call): {
100       /* nothing (must use call itself) */
101     } break;
102
103     default: {
104       fprintf (stderr, "%s: proj(proj(%s[%ld])) not handled\n",
105                __FUNCTION__,
106                get_op_name (get_irn_op (in_in)),
107                get_irn_node_nr (in_in));
108       assert (0);
109     }
110     } /* end switch(Proj.Proj.op) */
111   } break; /* iro_Proj */
112
113   case (iro_Start): {
114     /* ProjM (start) or ProjT (start) --- nothing */
115   } break;
116
117   case (iro_Call): {
118     /* ProjT (start) --- nothing */
119   } break;
120
121   case (iro_Load): {
122     if (mode_P == get_irn_mode (proj)) {
123     /* ProjV(load) */
124       pto_init_proj_load (proj, in);
125     } else {
126       /* ProjM(load) --- nothing to do */
127     }
128   } break;
129
130   case (iro_Store): {
131     /* ProjM (store) --- nothing */
132   } break;
133
134   case (iro_Alloc): {
135     /* nothing to do --- can always be computed on-the-fly */
136   } break;
137
138   case (iro_Raise): {
139     /* ProjX (raise) --- TODO */
140   } break;
141
142   case (iro_Cast): {
143     /* not needed */
144   } break;
145
146   default: {
147     fprintf (stderr, "%s: proj(%s[%ld]) not handled\n",
148              __FUNCTION__,
149              get_op_name (get_irn_op (in)),
150              get_irn_node_nr (in));
151     assert (0);
152   }
153   } /* end switch (Proj.op) */
154
155 }
156
157 void pto_init_node (ir_node *node)
158 {
159   const opcode op = get_irn_opcode (node);
160
161   DBGPRINT (1, (stdout, "%s (%s[%li])\n",
162                 __FUNCTION__,
163                 get_op_name (get_irn_op (node)),
164                 get_irn_node_nr (node)));
165
166   switch (op) {
167   case (iro_Start): {
168     /* nothing (not needed) */
169   } break;
170
171   case (iro_Load): {
172     /* nothing (not needed) */
173   } break;
174
175   case (iro_Store): {
176     /* nothing (not needed) */
177   } break;
178
179   case (iro_Alloc): {
180     /* nothing (can always be computed on-the-fly) */
181   } break;
182
183   case (iro_Raise): {
184     /* Todo: Check how a Raise works */
185     pto_init_raise (node);
186   } break;
187
188   case (iro_Call): {
189     /* pretend we have a return value */
190     pto_init_call (node);
191   } break;
192
193   case (iro_Proj): {
194     /* this actually does most of the work */
195     pto_init_proj (node);
196   } break;
197
198   case (iro_Cast): {
199     /* nothing (can always be computed on-the-fly) */
200   } break;
201
202   case (iro_SymConst): {
203     /* nothing (can always be computed on-the-fly) */
204   } break;
205
206   case (iro_Const): {
207     /* nothing (can always be computed on-the-fly) */
208   } break;
209
210   case (iro_Block): {
211     /* nothing (this is only interesting for the end block, and that
212        can always be computed on-the-fly) */
213   } break;
214
215   case (iro_Phi): {
216     /* nothing (This would need the predecessors to be initialized! Do this on-the-fly) */
217   } break;
218
219   /* now, enumerate everything else that is uninteresting */
220   case (iro_Return):
221   case (iro_Div):
222   case (iro_Quot):
223   case (iro_Mod):
224   case (iro_DivMod): {
225     /* nothing (not needed) */
226   } break;
227
228   default: {
229     fprintf (stderr, "%s: %s[%ld] not handled\n",
230              __FUNCTION__,
231              get_op_name (get_irn_op (node)),
232              get_irn_node_nr (node));
233     assert (0);
234   } break;
235
236   }
237 }
238
239
240 \f
241 /*
242  * $Log$
243  * Revision 1.2  2004/11/08 12:33:06  liekweg
244  * initialisation; sanitize print levels, misc fixes
245  *
246  * Revision 1.1  2004/11/04 14:58:59  liekweg
247  * added initialisation
248  *
249  *
250  */