fixed some depencies between irdump.c and irdumptxt.c
[libfirm] / ir / external / read.c
1 /* -*- c -*- */
2
3 /*
4  * Project:     libFIRM
5  * File name:   ir/external/read.c
6  * Purpose:     Read descriptions of external effects
7  * Author:      Florian
8  * Modified by: Boris Boesler
9  * Created:     11.10.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 #ifdef HAVE_CONFIG_H
16 # include "config.h"
17 #endif
18
19 /* get prototype for alloca somehow */
20 #ifdef HAVE_ALLOCA_H
21 # include <alloca.h>
22 #endif
23 #ifdef HAVE_STDLIB_H
24 # include <stdlib.h>
25 #endif
26
27 # include <string.h>
28
29 #include "read_t.h"
30 #include "read.h"
31 #include "irprog.h"
32 #include "irgraph.h"
33 #include "pseudo_irg.h"
34 #include "ircons.h"
35 #include "irmode.h"
36 #include "irdump.h"
37 #include "irvrfy.h"
38 #include "type.h"
39 #include "tv.h"
40
41 #define VERBOSE_PRINTING 0
42
43 #if VERBOSE_PRINTING
44 # define VERBOSE_PRINT(s) fprintf s
45 #else
46 # define VERBOSE_PRINT(s)
47 #endif
48
49 #define NO_ID NULL
50
51 static type_t *types = NULL;
52 static entity_t *entities = NULL;
53 static proc_t *procs = NULL;
54 static module_t *modules = NULL;
55
56 /* @@@ HACK */
57 static module_t *current_module = NULL;
58
59 #if VERBOSE_PRINTING
60 /* this is only used inside a VERBOSE_PRINT() call */
61 static char *effect_string[] = {
62   "arg",
63   "valref",
64   "select",
65   "load",
66   "store",
67   "alloc",
68   "call",
69   "unknown",
70   "join",
71   "raise",
72   "ret"
73 };
74 #endif /* defined VERBOSE_PRINTING */
75
76 static const ident*
77 getNodeModuleIdent (xmlNodePtr node)
78 {
79   const char *mod_str = (const char*) xmlGetProp (node, BAD_CAST "module");
80
81   if (NULL == mod_str) {
82     return (NULL);
83   } else {
84     const ident *res = new_id_from_str (mod_str);
85     return (res);
86   }
87 }
88
89 static const char*
90 getNodeProcName (xmlNodePtr node)
91 {
92   const char *proc_str = (const char*) xmlGetProp (node, BAD_CAST "procname");
93   assert (proc_str);
94   return (proc_str);
95 }
96
97 static char*
98 getNodeClassName (xmlNodePtr node)
99 {
100   char *proc_str = (char*) xmlGetProp (node, BAD_CAST "class");
101   assert (proc_str);
102   return ( (proc_str));
103 }
104
105 static const char*
106 getNodeId (xmlNodePtr node)
107 {
108   const char *id_str = (const char*) xmlGetProp (node, BAD_CAST "id");
109   assert (id_str);
110   return (id_str);
111 }
112
113 static const char *
114 getNodeRefId (xmlNodePtr node)
115 {
116   const char *refid_str = (char*) xmlGetProp (node, BAD_CAST "refid");
117   assert (refid_str);
118   return ((refid_str));
119 }
120
121 static const char*
122 getNodeTypeId (xmlNodePtr node)
123 {
124   const char *type_str = (char*) xmlGetProp (node, BAD_CAST "type");
125   assert (type_str);
126   return ((type_str));
127 }
128
129 static const char
130 *getNodeTypeStr (xmlNodePtr node)
131 {
132   const char *type_str = (char*) xmlGetProp (node, BAD_CAST "type");
133   assert (type_str);
134   return (type_str);
135 }
136
137 static const char*
138 getNodeOwnerStr (xmlNodePtr node)
139 {
140   const char *owner_str = (char*) xmlGetProp (node, BAD_CAST "owner");
141   assert (owner_str);
142   return (owner_str);
143 }
144
145 static const char
146 *getNodeEntityStr (xmlNodePtr node)
147 {
148   const char *ent_str = (char*) xmlGetProp (node, BAD_CAST "entity");
149   assert (ent_str);
150
151   return (ent_str);
152 }
153
154
155 /*
156   was Public Interface
157 */
158 static
159 type_t *getTypeByIdent (const ident *id)
160 {
161   type_t *curr = types; // @@@ TODO module -> types
162
163   while (NULL != curr) {
164     if (id == curr -> type_ident) {
165       return (curr);
166     }
167     curr = curr->prev;
168   }
169
170   return (NULL);
171 }
172
173 static
174 type_t *getTypeById (const ident *id)
175 {
176   type_t *curr = types; // which ones?
177
178   while (NULL != curr) {
179     if (id == curr -> id) {
180       return (curr);
181     }
182     curr = curr->prev;
183   }
184
185   return (NULL);
186 }
187
188 static
189 entity_t *getEntityByIdents (const ident *name, const ident *tp_ident)
190 {
191   entity_t *curr = entities; // TODO module -> entities
192
193   while (NULL != curr) {
194     if ((name == curr -> ent_ident)
195     && (tp_ident == curr -> tp_ident)) {
196       return (curr);
197     }
198     curr = curr->prev;
199   }
200
201   return (NULL);
202 }
203
204 static
205 entity_t *getEntityById (const ident *id)
206 {
207   entity_t *curr = entities;
208
209   while (NULL != curr) {
210     if (id == curr -> id) {
211       return (curr);
212     }
213     curr = curr->prev;
214   }
215
216   return (NULL);
217 }
218
219 static
220 proc_t *getEffectByName (const ident *proc_ident)
221 {
222   proc_t *curr_effs = procs;
223
224   while (NULL != curr_effs) {
225     if (proc_ident == curr_effs -> proc_ident) {
226       return (curr_effs);
227     }
228     curr_effs = curr_effs->next;
229   }
230
231   return (NULL);
232 }
233
234 static
235 xmlNodePtr get_any_valid_child(xmlNodePtr elem)
236 {
237   xmlNodePtr child;
238
239   assert(elem && "no element");
240   child = elem -> xmlChildrenNode;
241   while(child && (NODE_NAME (child, comment))) {
242     child = child -> next;
243   }
244   return(child);
245 }
246
247 static
248 xmlNodePtr get_valid_child(xmlNodePtr elem)
249 {
250   xmlNodePtr child;
251
252   child = get_any_valid_child(elem);
253   assert(child && "lost child in deep black forest");
254   return(child);
255 }
256
257 /*
258  * parse XML structure and construct an additional structure
259  */
260 static eff_t *
261 parseArg (xmlDocPtr doc, xmlNodePtr argelm)
262 {
263   const char *id;
264   const char *typeid;
265   int num;
266   char *num_str;
267   eff_t *arg;
268
269   CHECK_NAME (argelm, arg);
270   VERBOSE_PRINT ((stdout, "arg node \t0x%08x\n", (int) argelm));
271
272   id = getNodeId (argelm);
273   VERBOSE_PRINT ((stdout, "arg->id = \"%s\"\n", id));
274   num_str = (char*) xmlGetProp (argelm, BAD_CAST "number");
275   num = atoi (num_str);
276   VERBOSE_PRINT ((stdout, "arg->no = \"%d\"\n", num));
277
278   typeid = getNodeTypeStr (argelm);
279
280   arg = NEW (eff_t);
281   arg -> kind = eff_arg;
282   arg -> id = new_id_from_str(id);
283   arg -> effect.arg.num = num;
284   arg -> effect.arg.type_ident = new_id_from_str(typeid);
285
286   return (arg);
287 }
288
289 static eff_t*
290 parseValref (xmlDocPtr doc, xmlNodePtr valelm)
291 {
292   const char *ref_id;
293   eff_t *valref;
294
295   CHECK_NAME (valelm, valref);
296   VERBOSE_PRINT ((stdout, "valref node \t0x%08x\n", (int) valelm));
297
298   ref_id = getNodeRefId (valelm);
299   VERBOSE_PRINT ((stdout, "val->refid = \"%s\"\n", ref_id));
300
301   valref = NEW (eff_t);
302   valref->kind = eff_valref;
303   valref-> id = new_id_from_str(ref_id);
304
305   return (valref);
306 }
307
308 static eff_t*
309 parseSelect (xmlDocPtr doc, xmlNodePtr selelm)
310 {
311   const ident *entity_id = new_id_from_str(getNodeEntityStr (selelm));
312   entity_t *ent;
313   xmlNodePtr child;
314   eff_t *valref = NULL;
315   eff_t *sel = NEW (eff_t);
316   sel->kind = eff_select;
317
318   CHECK_NAME (selelm, select);
319   VERBOSE_PRINT ((stdout, "select node \t0x%08x\n", (int) selelm));
320
321   ent = getEntityById (entity_id);
322   assert(ent && "entity not found");
323   VERBOSE_PRINT ((stdout, "select entity %s\n", get_id_str(ent -> ent_ident)));
324
325   child = selelm->xmlChildrenNode;
326
327   if (child) {
328     valref = parseValref (doc, child);
329   }
330
331   sel-> id = valref ? valref-> id : NO_ID;
332   sel-> effect.select.ent = ent;
333
334   if (valref) {
335     free (valref);
336   }
337
338   return (sel);
339 }
340
341 static eff_t*
342 parseLoad (xmlDocPtr doc, xmlNodePtr loadelm)
343 {
344   const ident *id;
345   xmlNodePtr child;
346   eff_t *sel;
347   eff_t *load = NEW (eff_t);
348   load->kind = eff_load;
349
350   CHECK_NAME (loadelm, load);
351   VERBOSE_PRINT ((stdout, "load node \t0x%08x\n", (int) loadelm));
352   id = new_id_from_str(getNodeId (loadelm));
353
354   child = get_valid_child(loadelm);
355   if(NODE_NAME (child, select)) {
356     sel = parseSelect (doc, child);
357     load-> effect.load.ent = sel-> effect.select.ent;
358     VERBOSE_PRINT ((stdout, "load entity \t%s\n",
359             get_id_str(load -> effect.load.ent -> ent_ident)));
360   }
361   else {
362     sel = parseValref (doc, child);
363     load-> effect.load.ent = NULL;
364   }
365
366   load-> id = id;
367   load-> effect.load.ptrrefid = sel-> id;
368
369   free (sel);
370
371   return (load);
372 }
373
374 static eff_t*
375 parseStore (xmlDocPtr doc, xmlNodePtr storeelm)
376 {
377   xmlNodePtr child;
378   eff_t *sel;
379   eff_t *valref;
380   eff_t *store = NEW (eff_t);
381   store->kind = eff_store;
382
383   CHECK_NAME (storeelm, store);
384   VERBOSE_PRINT ((stdout, "store node \t0x%08x\n", (int) storeelm));
385
386   child = get_valid_child(storeelm);
387   if(NODE_NAME (child, select)) {
388     sel = parseSelect (doc, child);
389     store-> effect.store.ent = sel-> effect.select.ent;
390   }
391   else {
392     sel = parseValref (doc, child);
393     store-> effect.store.ent = NULL;
394   }
395
396   child = child->next;
397   valref = parseValref (doc, child);
398
399   store-> effect.store.ptrrefid = sel-> id;
400   store-> effect.store.valrefid = valref-> id;
401
402   free (sel);
403   free (valref);
404
405   return (store);
406 }
407
408 static eff_t*
409 parseAlloc (xmlDocPtr doc, xmlNodePtr allocelm)
410 {
411   const ident *id;
412   const ident *type_id;
413   eff_t *alloc = NEW (eff_t); /* ...! */
414   alloc->kind = eff_alloc;
415
416   CHECK_NAME (allocelm, alloc);
417   VERBOSE_PRINT ((stdout, "alloc node \t0x%08x\n", (int) allocelm));
418   id = new_id_from_str(getNodeId (allocelm));
419   VERBOSE_PRINT ((stdout, "alloc->id = \"%s\"\n", get_id_str(id)));
420   type_id = new_id_from_str(getNodeTypeId (allocelm));
421   VERBOSE_PRINT ((stdout, "alloc->type_id = \"%s\"\n", get_id_str(type_id)));
422
423   alloc-> id = id;
424   alloc-> effect.alloc.tp_id = type_id;
425
426   return (alloc);
427 }
428
429 static eff_t*
430 parseCall (xmlDocPtr doc, xmlNodePtr callelm)
431 {
432   const ident *id;
433   xmlNodePtr child;
434   eff_t *sel;
435   xmlNodePtr arg;
436   int n_args;
437   eff_t *call = NEW (eff_t);
438   call->kind = eff_call;
439
440   CHECK_NAME (callelm, call);
441   VERBOSE_PRINT ((stdout, "call node \t0x%08x\n", (int) callelm));
442   id = new_id_from_str(getNodeId (callelm));
443   VERBOSE_PRINT ((stdout, "call->id = \"%s\"\n", get_id_str(id)));
444
445   child = get_valid_child(callelm);
446   if(NODE_NAME (child, select)) {
447     sel = parseSelect (doc, child);
448     call-> effect.call.ent = sel-> effect.select.ent;
449   }
450   else {
451     sel = parseValref (doc, child);
452     call-> effect.call.ent = NULL;
453   }
454
455   arg = child = child->next;
456   n_args = 0;
457
458   while (NULL != child) {
459     n_args ++;
460     child = child->next;
461   }
462
463   call-> id = id;
464   call-> effect.call.valrefid = sel-> id;
465   call-> effect.call.n_args = n_args;
466   call-> effect.call.args = NULL;
467
468   free (sel);
469
470   if (0 != n_args) {
471     const ident **args = (const ident**) malloc(n_args * sizeof(const ident*));
472     int i = 0;
473
474     while (NULL != arg) {
475       eff_t *valref = parseValref (doc, arg);
476       args [i ++] = valref-> id;
477       free (valref);
478       arg = arg->next;
479     }
480
481     call-> effect.call.args = args;
482   }
483
484   return (call);
485 }
486
487 static eff_t*
488 parseJoin (xmlDocPtr doc, xmlNodePtr joinelm)
489 {
490   const ident *id;
491   int n_ins;
492   const ident **ins;
493   int i;
494   xmlNodePtr child;
495   eff_t *join = NEW (eff_t);
496   join->kind = eff_join;
497
498   CHECK_NAME (joinelm, join);
499   VERBOSE_PRINT ((stdout, "join node \t0x%08x\n", (int) joinelm));
500   id = new_id_from_str(getNodeId (joinelm));
501   VERBOSE_PRINT ((stdout, "join->id = \"%s\"\n", get_id_str(id)));
502
503   child = get_valid_child(joinelm);
504   n_ins = 0;
505
506   while (NULL != child) {
507     n_ins ++;
508     child = child->next;
509   }
510
511   ins = (const ident **) malloc (n_ins * sizeof (const ident *) );
512   i = 0;
513   child = get_valid_child(joinelm);
514
515   while (NULL != child) {
516     eff_t *valref = parseValref (doc, child);
517     ins [i ++] = valref-> id;
518     free(valref);
519     child = child->next;
520   }
521
522   join-> id = id;
523   join-> effect.join.n_ins = n_ins;
524   join-> effect.join.ins = ins;
525
526   return (join);
527 }
528
529 static eff_t*
530 parseUnknown (xmlDocPtr doc, xmlNodePtr unknownelm)
531 {
532   const ident *id;
533   eff_t *unknown = NEW (eff_t);
534   unknown->kind = eff_unknown;
535
536   CHECK_NAME (unknownelm, unknown);
537   VERBOSE_PRINT ((stdout, "unknown node \t0x%08x\n", (int) unknownelm));
538   id = new_id_from_str(getNodeId (unknownelm));
539   unknown-> id = id;
540
541   return (unknown);
542 }
543
544 static eff_t*
545 parseReturn (xmlDocPtr doc, xmlNodePtr retelm)
546 {
547   xmlNodePtr child;
548   eff_t *ret = NEW (eff_t);
549   ret->kind = eff_ret;
550
551   CHECK_NAME (retelm, ret);
552   VERBOSE_PRINT ((stdout, "ret node \t0x%08x\n", (int) retelm));
553
554   child = get_any_valid_child(retelm);
555
556   if (child) {
557     eff_t *valref = parseValref (doc, child);
558     ret-> effect.ret.ret_id = valref-> id;
559     free (valref);
560   } else {
561     ret-> effect.ret.ret_id = NO_ID;
562   }
563
564   return (ret);
565 }
566
567 static eff_t*
568 parseRaise (xmlDocPtr doc, xmlNodePtr raiseelm)
569 {
570   const char *tp_id;
571   eff_t *valref;
572   xmlNodePtr child;
573   eff_t *raise = NEW (eff_t);
574   raise->kind = eff_raise;
575
576   CHECK_NAME (raiseelm, raise);
577   VERBOSE_PRINT ((stdout, "raise node \t0x%08x\n", (int) raiseelm));
578   tp_id = getNodeTypeId (raiseelm);
579   VERBOSE_PRINT ((stdout, "raise->type = \"%s\"\n", tp_id));
580   child = get_valid_child(raiseelm);
581
582   assert (NULL != child);
583
584   valref = parseValref (doc, child);
585   raise-> effect.raise.valref = valref-> id;
586   raise-> effect.raise.tp_id = new_id_from_str(tp_id);
587   free (valref);
588
589   return (raise);
590 }
591
592
593 /*
594   Types and Entities
595 */
596
597 /** parse a type node and insert it into the list */
598 static void
599 parseType (xmlDocPtr doc, xmlNodePtr typeelm)
600 {
601   type_t *type;
602   const char *tp_id = getNodeId (typeelm);
603   VERBOSE_PRINT ((stdout, "type node \t0x%08x (%s)\n", (int) typeelm, tp_id));
604   VERBOSE_PRINT ((stdout, "type = \"%s\"\n", getNodeTypeStr (typeelm)));
605
606   type = (type_t*) malloc (sizeof (type_t));
607   type -> type_ident = new_id_from_str(getNodeTypeStr (typeelm));
608   type -> id         = new_id_from_str(tp_id);
609
610   type->prev = types;
611   types = type;
612 }
613
614 /** parse an entity node and insert it into the list */
615 static void
616 parseEntity (xmlDocPtr doc, xmlNodePtr entelm)
617 {
618   entity_t *ent = NEW (entity_t);
619
620   /* parse it */
621   const char *ent_id = getNodeId (entelm);
622   /* fprintf (stdout, "entity node \t0x%08x (%d)\n", (int) entelm, ent_id); */
623   VERBOSE_PRINT ((stdout, "ent  = \"%s.%s\"\n",
624           getNodeTypeStr (entelm),
625           getNodeEntityStr (entelm)));
626
627
628   ent -> ent_ident = new_id_from_str (getNodeEntityStr (entelm));
629   ent -> tp_ident  = new_id_from_str (getNodeTypeStr   (entelm));
630   ent -> owner     = new_id_from_str (getNodeOwnerStr  (entelm));
631   ent -> id = new_id_from_str(ent_id);
632
633   ent->prev = entities;
634   entities = ent;
635 }
636
637 /** parse any effect, and turn it into an eff_t (TODO) */
638 static void
639 parseEffect (xmlDocPtr doc, xmlNodePtr effelm)
640 {
641   xmlNodePtr cur;
642   const char *procname = getNodeProcName (effelm);
643   const char *ownerid = getNodeOwnerStr (effelm);
644   proc_t *curr_effs = NULL;
645   int i = 0;
646   int n_effs = 0;
647
648   VERBOSE_PRINT ((stdout, "effect for method \"%s\"\n", procname));
649
650   cur = effelm -> xmlChildrenNode;
651   while (NULL != cur) {
652     n_effs ++;
653     cur = cur->next;
654   }
655   VERBOSE_PRINT ((stdout, "has %d effects\n", n_effs));
656
657   curr_effs = NEW (proc_t);
658   curr_effs -> proc_ident = new_id_from_str(procname);
659   curr_effs -> ownerid = new_id_from_str(ownerid);
660   curr_effs->effs = (eff_t**) malloc (n_effs * sizeof (eff_t*));
661
662   cur = effelm -> xmlChildrenNode;
663   while (NULL != cur) {
664     eff_t *eff = NULL;
665
666     if (NODE_NAME (cur, arg)) {
667       eff = (eff_t*) parseArg (doc, cur);
668     } else if (NODE_NAME (cur, load)) {
669       eff = (eff_t*) parseLoad (doc, cur);
670     } else if (NODE_NAME (cur, store)) {
671       eff = (eff_t*) parseStore (doc, cur);
672     } else if (NODE_NAME (cur, alloc)) {
673       eff = (eff_t*) parseAlloc (doc, cur);
674     } else if (NODE_NAME (cur, call)) {
675       eff = (eff_t*) parseCall (doc, cur);
676     } else if (NODE_NAME (cur, join)) {
677       eff = (eff_t*) parseJoin (doc, cur);
678     } else if (NODE_NAME (cur, unknown)) {
679       eff = (eff_t*) parseUnknown (doc, cur);
680     } else if (NODE_NAME (cur, ret)) {
681       eff = (eff_t*) parseReturn (doc, cur);
682     } else if (NODE_NAME (cur, raise)) {
683       eff = (eff_t*) parseRaise (doc, cur);
684     } else if (NODE_NAME (cur, comment)) {
685       /* comment */
686       --n_effs;
687     } else {
688       fprintf (stderr, "wrong element \"%s\"\n", BAD_CAST cur->name);
689       exit (EXIT_FAILURE);
690     }
691     if(eff) {
692       VERBOSE_PRINT ((stdout, "effect %p@%d\n", (void*)eff, i));
693       curr_effs -> effs[i++] = eff;
694     }
695     cur = cur -> next;
696   }
697   assert((i == n_effs) && "incorrect number of effects");
698   curr_effs -> n_effs = n_effs;
699   curr_effs -> next = procs;
700   procs = curr_effs;
701 }
702
703
704 static
705 void read_extern (const char *filename)
706 {
707   /* xmlNsPtr ns = NULL; */           /* no namespace for us */
708   xmlDocPtr doc;                /* whole document */
709   xmlNodePtr cur;               /* current node */
710   ident *mod_id;
711   module_t *module;
712
713   /* i've got no idea what the VERSION cast is all about. voodoo
714      programming at its finest. */
715   LIBXML_TEST_VERSION xmlKeepBlanksDefault (0);
716   VERBOSE_PRINT((stdout, "read file %s\n", filename));
717   doc = xmlParseFile (filename);
718   CHECK (doc, "xmlParseFile");
719
720   cur = xmlDocGetRootElement (doc);
721   CHECK (cur, "xmlDocGetRootElement");
722
723   if (! NODE_NAME (cur, effects)) {
724     fprintf (stderr,"root node \"%s\" != \"effects\"\n", BAD_CAST cur->name);
725     xmlFreeDoc (doc);
726     exit (EXIT_FAILURE);
727   }
728
729   mod_id = getNodeModuleIdent (cur);
730   if (NULL != mod_id) {
731     VERBOSE_PRINT ((stdout, "effects for \"%s\"\n",
732             get_id_str(mod_id)));
733   }
734   else {
735     VERBOSE_PRINT ((stdout, "effects \t0x%08x\n", (int) cur));
736   }
737
738   /* parse entities */
739   cur = cur->xmlChildrenNode;
740   while (cur != NULL) {
741     if (NODE_NAME (cur, type)) {
742       parseType (doc, cur);
743     } else if (NODE_NAME (cur, entity)) {
744       parseEntity (doc, cur);
745     } else if (NODE_NAME (cur, effect)) {
746       parseEffect (doc, cur);
747     } else if ((NODE_NAME (cur, comment))) {
748       /* comment */
749     } else {
750       fprintf (stderr, "wrong element \"%s\"\n", BAD_CAST cur->name);
751       exit (EXIT_FAILURE);
752     }
753     cur = cur->next;
754   }
755
756   module = NEW(module_t);
757   module -> id = mod_id;
758   module -> types = types;
759   module -> entities = entities;
760   module -> procs = procs;
761
762   types = NULL;
763   entities = NULL;
764   procs = NULL;
765
766   module -> next = modules;
767   modules = module;
768 }
769
770 /********************************************************************/
771
772 /*
773  * free additional structure
774  */
775 static
776 void freeArg (eff_t *arg)
777 {
778   VERBOSE_PRINT ((stdout, "free arg node \t0x%08x\n", (int) arg));
779   free(arg);
780   return;
781 }
782
783 static
784 void freeValref (eff_t *valref)
785 {
786   VERBOSE_PRINT ((stdout, "free valref node \t0x%08x\n", (int) valref));
787   free(valref);
788   return;
789 }
790
791 static
792 void freeSelect (eff_t *sel)
793 {
794   VERBOSE_PRINT ((stdout, "free select node \t0x%08x\n", (int) sel));
795   free(sel);
796   return;
797 }
798
799 static
800 void freeLoad (eff_t *load)
801 {
802   VERBOSE_PRINT ((stdout, "free load node \t0x%08x\n", (int) load));
803   free (load);
804   return;
805 }
806
807 static
808 void freeStore (eff_t *store)
809 {
810   VERBOSE_PRINT ((stdout, "free store node \t0x%08x\n", (int) store));
811   free (store);
812   return;
813 }
814
815 static
816 void freeAlloc (eff_t *alloc)
817 {
818   VERBOSE_PRINT ((stdout, "free alloc node \t0x%08x\n", (int) alloc));
819   free(alloc);
820   return;
821 }
822
823 static
824 void freeCall (eff_t *call)
825 {
826   VERBOSE_PRINT ((stdout, "free call node \t0x%08x\n", (int) call));
827   free(call -> effect.call.args);
828   free(call);
829   return;
830 }
831
832 static
833 void freeJoin (eff_t *join)
834 {
835   VERBOSE_PRINT ((stdout, "free join node \t0x%08x\n", (int) join));
836   free(join -> effect.join.ins);
837   free(join);
838   return;
839 }
840
841 static
842 void freeUnknown (eff_t *unknown)
843 {
844   VERBOSE_PRINT ((stdout, "free unknown node \t0x%08x\n", (int) unknown));
845   free(unknown);
846   return;
847 }
848
849 static
850 void freeReturn (eff_t *ret)
851 {
852   VERBOSE_PRINT ((stdout, "free ret node \t0x%08x\n", (int) ret));
853   free(ret);
854   return;
855 }
856
857 static
858 void freeRaise (eff_t *raise)
859 {
860   VERBOSE_PRINT ((stdout, "free raise node \t0x%08x\n", (int) raise));
861   free (raise);
862   return;
863 }
864
865
866 static
867 void freeProcEffs(proc_t *proc)
868 {
869   int i;
870   int num;
871
872   VERBOSE_PRINT ((stdout, "free effect for method \"%s\"\n",
873           get_id_str(proc -> proc_ident)));
874
875   num = proc -> n_effs;
876   for(i = 0; i < num; i++) {
877     switch(proc -> effs[i] -> kind) {
878     case eff_arg:
879       freeArg(proc -> effs[i]);
880       break;
881     case eff_valref:
882       freeValref(proc -> effs[i]);
883       break;
884     case eff_select:
885       freeSelect(proc -> effs[i]);
886       break;
887     case eff_load:
888       freeLoad(proc -> effs[i]);
889       break;
890     case eff_store:
891       freeStore(proc -> effs[i]);
892       break;
893     case eff_alloc:
894       freeAlloc(proc -> effs[i]);
895       break;
896     case eff_call:
897       freeCall(proc -> effs[i]);
898       break;
899     case eff_unknown:
900       freeUnknown(proc -> effs[i]);
901       break;
902     case eff_join:
903       freeJoin(proc -> effs[i]);
904       break;
905     case eff_raise:
906       freeRaise(proc -> effs[i]);
907       break;
908     case eff_ret:
909       freeReturn(proc -> effs[i]);
910       break;
911     default:
912       assert(0 && "try to free an unknown effect");
913       break;
914     }
915   }
916   free(proc -> effs);
917   proc -> effs = NULL;
918 }
919
920 static
921 void freeModuleProcs(module_t *module)
922 {
923   proc_t *next_proc, *proc;
924
925   VERBOSE_PRINT ((stdout, "free procs for module \"%s\"\n",
926           get_id_str(module -> id)));
927
928   proc = module -> procs;
929   while(proc) {
930     next_proc = proc -> next;
931     freeProcEffs(proc);
932     free(proc);
933     proc = next_proc;
934   }
935 }
936
937 static
938 void free_data(void)
939 {
940   module_t *module, *next_module;
941
942   module = modules;
943   while(module) {
944     freeModuleProcs(module);
945     next_module = module -> next;
946     free(module);
947     module = next_module;
948   }
949 }
950
951 /********************************************************************/
952
953 static
954 type_t *find_type_in_module(module_t *module, const ident *typeid)
955 {
956   type_t *type;
957
958   for(type = module -> types; type; type = type -> prev) {
959     VERBOSE_PRINT((stdout, "test typeid %s\n", get_id_str(type -> id)));
960     if(type -> id == typeid) {
961       VERBOSE_PRINT((stdout, "found\n"));
962       return(type);
963     }
964   }
965   VERBOSE_PRINT((stdout, "did not find type id %s\n", get_id_str(typeid)));
966   return(NULL);
967 }
968
969 /********************************************************************/
970
971 static void add_value_to_proc(proc_t *proc, eff_t *eff)
972 {
973   eff -> next = proc -> values;
974   proc -> values = eff;
975 }
976
977
978 eff_t *find_valueid_in_proc_effects(const ident *id, proc_t *proc)
979 {
980   eff_t *val;
981
982   val = proc -> values;
983   while(val) {
984     if(id == val -> id) {
985       return(val);
986     }
987     val = val -> next;
988   }
989   return(NULL);
990 }
991
992 static void create_abstract_return(ir_graph *irg, proc_t *proc, eff_t *eff)
993 {
994   ir_node *x;
995   eff_t *eff_res;
996
997   VERBOSE_PRINT((stdout, "create effect:return in %s\n",
998          get_id_str(proc -> proc_ident)));
999   if(NO_ID == eff -> effect.ret.ret_id) {
1000     /* return void */
1001     x = new_Return (get_store(), 0, NULL);
1002   }
1003   else {
1004     ir_node *in[1];
1005
1006     /* return one value */
1007     eff_res = find_valueid_in_proc_effects(eff -> effect.ret.ret_id, proc);
1008     assert(eff_res -> firmnode && "firm in effect not set");
1009     in[0] = eff_res -> firmnode;
1010     x = new_Return (get_store(), 1, in);
1011   }
1012   eff -> firmnode = x;
1013
1014   /* Now we generated all instructions for this block and all its predecessor
1015    * blocks so we can mature it.  (There are not too much.) */
1016   mature_immBlock (get_irg_current_block(irg));
1017
1018   /* This adds the in edge of the end block which originates at the return statement.
1019    * The return node passes controlflow to the end block.  */
1020   add_immBlock_pred (get_irg_end_block(irg), x);
1021 }
1022
1023
1024 static void create_abstract_arg(ir_graph *irg, proc_t *proc, eff_t *eff)
1025 {
1026   ir_node *arg;
1027   entity *ent;
1028   ir_mode *mode;
1029   type *typ;
1030   int num;
1031
1032   VERBOSE_PRINT((stdout, "create effect:arg %d in %s\n",
1033          eff -> effect.arg.num, get_id_str(proc -> proc_ident)));
1034   ent = get_irg_entity(irg);
1035   typ = get_entity_type(ent);
1036
1037   /* read argument eff -> effect.arg.num and place in values list */
1038   num = get_method_n_params(typ);
1039   assert((num >= eff -> effect.arg.num) && "number too big");
1040   typ = get_method_param_type(typ, eff -> effect.arg.num);
1041   mode = get_type_mode(typ);
1042
1043   arg = new_Proj(get_irg_args(irg), mode, eff -> effect.arg.num);
1044   eff -> firmnode = arg;
1045
1046   add_value_to_proc(proc, eff);
1047 }
1048
1049
1050 static void create_abstract_load(ir_graph *irg, proc_t *proc, eff_t *eff)
1051 {
1052   ir_node *sel, *load;
1053   entity *ent;
1054   ir_mode *mode;
1055   eff_t *addr;
1056
1057   VERBOSE_PRINT((stdout, "create load in %s\n",
1058          get_id_str(proc -> proc_ident)));
1059
1060   if(eff -> effect.load.ent) {
1061     ent = eff -> effect.load.ent -> f_ent;
1062     VERBOSE_PRINT((stdout, "load from %s\n", get_entity_name(ent)));
1063   }
1064   else {
1065     VERBOSE_PRINT((stdout, "store to memory\n"));
1066     ent = NULL;
1067   }
1068
1069   addr = find_valueid_in_proc_effects(eff -> effect.load.ptrrefid, proc);
1070   assert(addr && "no address for load");
1071   /* if addr is Unknown, set proper mode */
1072   if(iro_Unknown == get_irn_opcode(addr -> firmnode)) {
1073     set_irn_mode(addr -> firmnode, mode_P);
1074   }
1075
1076   if(ent) {
1077     sel = new_simpleSel(get_store(), addr -> firmnode, ent);
1078     mode = get_type_mode(get_entity_type(ent));
1079   }
1080   else {
1081     sel = addr -> firmnode;
1082     mode = mode_ANY;
1083   }
1084   load = new_Load(get_store(), sel, mode);
1085   set_store(new_Proj(load, mode_M, 0));
1086   eff -> firmnode = new_Proj(load, mode, 2);
1087
1088   add_value_to_proc(proc, eff);
1089 }
1090
1091
1092 static void create_abstract_store(ir_graph *irg, proc_t *proc, eff_t *eff)
1093 {
1094   ir_node *sel, *store;
1095   entity *ent;
1096   eff_t *addr, *val;
1097
1098   VERBOSE_PRINT((stdout, "create store in %s\n",
1099          get_id_str(proc -> proc_ident)));
1100
1101   if(eff -> effect.store.ent) {
1102     ent = eff -> effect.store.ent -> f_ent;
1103     VERBOSE_PRINT((stdout, "store to entity %s\n", get_entity_name(ent)));
1104   }
1105   else {
1106     VERBOSE_PRINT((stdout, "store to memory\n"));
1107     ent = NULL;
1108   }
1109
1110   addr = find_valueid_in_proc_effects(eff -> effect.store.ptrrefid, proc);
1111   assert(addr && "no address for store");
1112   /* if addr is Unknown, set propper mode */
1113   if(iro_Unknown == get_irn_opcode(addr -> firmnode)) {
1114     set_irn_mode(addr -> firmnode, mode_P);
1115   }
1116
1117   val = find_valueid_in_proc_effects(eff -> effect.store.valrefid, proc);
1118   assert(val && "no address for store");
1119   /* if addr is Unknown, set propper mode */
1120   if(iro_Unknown == get_irn_opcode(val -> firmnode)) {
1121     set_irn_mode(val -> firmnode, get_type_mode(get_entity_type(ent)));
1122   }
1123
1124   if(ent) {
1125     sel = new_simpleSel(get_store(), addr -> firmnode, ent);
1126   }
1127   else {
1128     sel = addr -> firmnode;
1129   }
1130   store = new_Store(get_store(), sel, val -> firmnode);
1131   set_store(new_Proj(store, mode_M, 0));
1132   eff -> firmnode = store;
1133 }
1134
1135
1136 static void create_abstract_alloc(ir_graph *irg, proc_t *proc, eff_t *eff)
1137 {
1138   type *ftype;
1139   ir_node *alloc;
1140   type_t *xtype;
1141   symconst_symbol sym;
1142
1143   VERBOSE_PRINT((stdout, "create alloc in %s\n",
1144          get_id_str(proc -> proc_ident)));
1145
1146   xtype = find_type_in_module(current_module, eff -> effect.alloc.tp_id);
1147   assert(xtype && "type not found");
1148   ftype = xtype -> f_tp;
1149
1150   sym.type_p = ftype;
1151   alloc = new_Alloc(get_store(), new_SymConst(sym, symconst_size), ftype,
1152             heap_alloc);
1153   set_store(new_Proj(alloc, mode_M, 0));
1154   eff -> firmnode = new_Proj(alloc, mode_P, 2);
1155
1156   add_value_to_proc(proc, eff);
1157 }
1158
1159
1160 static void create_abstract_unknown(ir_graph *irg, proc_t *proc, eff_t *eff)
1161 {
1162   ir_node *unknown;
1163
1164   VERBOSE_PRINT((stdout, "create unknown in %s\n",
1165          get_id_str(proc -> proc_ident)));
1166
1167   unknown = new_Unknown(mode_ANY);
1168   eff -> firmnode = unknown;
1169
1170   add_value_to_proc(proc, eff);
1171 }
1172
1173
1174 static void create_abstract_call(ir_graph *irg, proc_t *proc, eff_t *eff)
1175 {
1176   ir_node *sel, *call;
1177   entity *ent;
1178   eff_t *addr;
1179   ir_node **irns;
1180   int i, num;
1181   type *mtype;
1182   int mik; /* is method somehow known? */
1183
1184   VERBOSE_PRINT((stdout, "create call in %s\n",
1185          get_id_str(proc -> proc_ident)));
1186
1187   if(eff -> effect.call.ent) {
1188     ent = eff -> effect.call.ent -> f_ent;
1189     VERBOSE_PRINT((stdout, "call %s\n", get_entity_name(ent)));
1190   }
1191   else {
1192     ent = NULL;
1193     VERBOSE_PRINT((stdout, "call something in memory\n"));
1194   }
1195
1196   addr = find_valueid_in_proc_effects(eff -> effect.call.valrefid, proc);
1197   assert(addr && "no address for load");
1198   /* if addr is Unknown, set propper mode */
1199   if(iro_Unknown == get_irn_opcode(addr -> firmnode)) {
1200     set_irn_mode(addr -> firmnode, mode_P);
1201   }
1202
1203   if(ent) {
1204     /* the address */
1205     sel = new_simpleSel(get_store(), addr -> firmnode, ent);
1206     /* mthod type */
1207     mtype = get_entity_type(ent);
1208     mik = true;
1209   }
1210   else {
1211     /* the address */
1212     sel = addr -> firmnode;
1213     /* mthod type */
1214     mtype = get_unknown_type();
1215     mik = false;
1216   }
1217
1218   /* the args */
1219   num = eff -> effect.call.n_args;
1220   VERBOSE_PRINT((stdout, "number of args given: %d\n", num));
1221   if(mik) {
1222     VERBOSE_PRINT((stdout, "number of args expected: %d\n",
1223            get_method_n_params(mtype)));
1224   }
1225   irns = alloca(num * sizeof(ir_node*));
1226   for(i = 0; i < num; i++) {
1227     irns[i] = find_valueid_in_proc_effects(eff -> effect.call.args[i], proc)
1228       -> firmnode;
1229     if(iro_Unknown == get_irn_opcode(irns[i])) {
1230       if(mik) {
1231     set_irn_mode(irns[i], get_type_mode(get_method_param_type(mtype, i)));
1232       }
1233       else {
1234     set_irn_mode(irns[i], mode_ANY);
1235       }
1236     }
1237   }
1238   call = new_Call(get_store(), sel, num, irns, mtype);
1239   set_store(new_Proj(call, mode_M, 0));
1240   if(mik && (0 != get_method_n_ress(mtype))) {
1241     eff -> firmnode = new_Proj(call,
1242                    get_type_mode(get_method_res_type(mtype, 0)),
1243                    0);
1244     add_value_to_proc(proc, eff); /* result can be accessed */
1245   }
1246   else {
1247     eff -> firmnode = NULL; /* result can not be accessed */
1248   }
1249 }
1250
1251 static void create_abstract_join (ir_graph *irg, proc_t *proc, eff_t *eff)
1252 {
1253   ir_node **ins    = NULL;
1254   ir_node *unknown = NULL;
1255   ir_node *cond    = NULL;
1256   ir_node *block   = NULL;
1257   ir_node *c_block = NULL;
1258   ir_node *phi     = NULL;
1259   ir_mode *join_md = mode_ANY;
1260   int n_ins = -1;
1261   int i;
1262
1263   VERBOSE_PRINT((stdout, "create join in %s\n",
1264          get_id_str(proc -> proc_ident)));
1265
1266   assert (eff_join == eff->kind);
1267
1268   n_ins = eff->effect.join.n_ins;
1269
1270   /* seems like current_block is not always mature at this point */
1271   mature_immBlock (get_cur_block ());
1272
1273   block = get_cur_block ();     /* remember this so we can put the ProjXs into it */
1274
1275   /* jump based on an unknown condition so all values are possible */
1276   unknown = new_Unknown (mode_Iu);
1277   cond    = new_Cond (unknown);
1278
1279   c_block   = new_immBlock ();  /* for the Phi after the branch(es) */
1280
1281   ins = (ir_node**) malloc (n_ins * sizeof (ir_node*));
1282   for (i = 0; i < n_ins; i ++) {
1283     ir_node *projX   = NULL;
1284     ir_node *s_block = NULL;
1285     ir_node *jmp     = NULL;
1286     eff_t *in_eff;
1287
1288     /* make sure the projX is in the 'switch' block */
1289     set_cur_block (block);
1290     projX   = new_Proj (cond, mode_X, (long) i);
1291
1292     /* this also sets current_block, so the rest of the code ends up there: */
1293     s_block = new_immBlock ();
1294
1295     add_immBlock_pred (s_block, projX);
1296     mature_immBlock (s_block);
1297
1298     in_eff = find_valueid_in_proc_effects (eff->effect.join.ins [i], proc);
1299
1300     ins [i] = in_eff->firmnode;
1301
1302     /* need to find a suitable mode for the Phi node */
1303     if (mode_ANY != get_irn_mode (ins [i])) {
1304       join_md = get_irn_mode (ins [i]);
1305     }
1306
1307     jmp = new_Jmp ();
1308     add_immBlock_pred (c_block, jmp);
1309   }
1310
1311   set_cur_block (c_block);
1312
1313   phi = new_Phi (n_ins, ins, join_md);
1314
1315   mature_immBlock (c_block);
1316   memset (ins, 0x00, n_ins * sizeof (ir_node*));
1317   free (ins);
1318
1319   eff->firmnode = phi;
1320
1321   add_value_to_proc (proc, eff);
1322 }
1323
1324 static void create_abstract_raise (ir_graph *irg, proc_t *proc, eff_t *eff)
1325 {
1326   ir_node *block   = NULL;
1327   ir_node *unknown = NULL;
1328   ir_node *cond    = NULL;
1329
1330   /* seems like current_block is not always mature at this point */
1331   mature_immBlock (get_cur_block ());
1332   block = get_cur_block ();     /* remember this so we can put the ProjXs into it */
1333
1334   /* jump based on an unknown condition so both values are possible */
1335   unknown = new_Unknown (mode_Iu);
1336   cond    = new_Cond (unknown);
1337
1338   /* one branch for 'throw-exception' case */
1339   {
1340     ir_node *projX = new_Proj (cond, mode_X, 1L);
1341     ir_node *b_exc = new_immBlock ();
1342     ir_node *obj   = NULL;
1343     ir_node *thrw  = NULL;
1344     eff_t *thrw_eff = NULL;
1345
1346     add_immBlock_pred (b_exc, projX);
1347
1348     thrw_eff = find_valueid_in_proc_effects (eff->effect.raise.valref, proc);
1349     obj = thrw_eff->firmnode;
1350
1351     thrw = new_Raise (get_store (), obj);
1352     /* exc-jump to end block */
1353     thrw = new_Proj (thrw, mode_X, 0L);
1354
1355     add_immBlock_pred (get_irg_end_block (irg), thrw);
1356     mature_immBlock (get_cur_block ());
1357   }
1358
1359   set_cur_block (block);     /* back to the first block */
1360
1361   /* one branch for 'non-exception' case */
1362   {
1363     ir_node *projX = new_Proj (cond, mode_X, 0);
1364     new_immBlock ();            /* also sets current_block */
1365     add_immBlock_pred (get_cur_block (), projX);
1366     mature_immBlock (get_cur_block ());
1367     /* continue building in current_block */
1368   }
1369
1370 }
1371
1372 static void create_abstract_firm(module_t *module, proc_t *proc, entity *fent)
1373 {
1374   eff_t *eff;
1375   ir_graph *irg;
1376   int i, num;
1377
1378   /* test entity */
1379   assert(visibility_external_allocated == get_entity_visibility(fent)
1380      && peculiarity_existent == get_entity_peculiarity(fent)
1381      && "not an abstract entity");
1382   /* create irg in entity */
1383   irg = new_pseudo_ir_graph(fent, 0);
1384   set_irg_inline_property(irg, irg_inline_forbidden);
1385
1386   /* @@@ If the spec says so: */
1387   set_entity_visibility(fent, visibility_local);
1388
1389   VERBOSE_PRINT((stdout, "create effects for %s\n",
1390          get_id_str(proc -> proc_ident)));
1391
1392   /* create effects in irg */
1393   num = proc -> n_effs;
1394   for(i = 0; i < num; i++) {
1395     eff = proc -> effs[i];
1396     VERBOSE_PRINT((stdout,
1397            "create effect \"%s\"\n", effect_string[(int)eff -> kind]));
1398     switch(eff -> kind) {
1399     case eff_ret:
1400       create_abstract_return(irg, proc, eff);
1401       break;
1402     case eff_arg:
1403       create_abstract_arg(irg, proc, eff);
1404       break;
1405     case eff_load:
1406       create_abstract_load(irg, proc, eff);
1407       break;
1408     case eff_store:
1409       create_abstract_store(irg, proc, eff);
1410       break;
1411     case eff_unknown:
1412       create_abstract_unknown(irg, proc, eff);
1413       break;
1414     case eff_alloc:
1415       create_abstract_alloc(irg, proc, eff);
1416       break;
1417     case eff_call:
1418       create_abstract_call(irg, proc, eff);
1419       break;
1420     case eff_join:
1421       create_abstract_join(irg, proc, eff);
1422       break;
1423     case eff_raise:
1424       create_abstract_raise(irg, proc, eff);
1425       break;
1426     default:
1427       assert(0 && "effect not implemented");
1428       break;
1429     }
1430   }
1431
1432   /* close irg in entity */
1433   /* Now we can mature the end block as all it's predecessors are known. */
1434   mature_immBlock (get_irg_end_block(irg));
1435
1436   /* Verify the graph.  Finds some very bad errors in the graph. */
1437   VERBOSE_PRINT((stdout, "verify graph\n"));
1438   irg_vrfy(irg);
1439   VERBOSE_PRINT((stdout, "finalize construction\n"));
1440   finalize_cons (irg);
1441 }
1442
1443 /********************************************************************/
1444
1445 static void assign_firm_entity(module_t *module, entity_t *xmlent)
1446 {
1447   int i, num;
1448   type_t *typ;
1449   type *type;
1450   entity *ent;
1451
1452   VERBOSE_PRINT((stdout, "assign entity %s to typeid %s\n",
1453          get_id_str(xmlent -> ent_ident),
1454          get_id_str(xmlent -> owner)));
1455
1456   typ = find_type_in_module(module, xmlent -> owner);
1457   assert(typ && "class not found in module");
1458   type = typ -> f_tp;
1459   assert(is_class_type(type));
1460
1461   num = get_class_n_members(type);
1462   ent = NULL;
1463   for(i = 0; i < num; i++) {
1464     ent = get_class_member(type, i);
1465     VERBOSE_PRINT((stdout, "compare entity %s and %s\n",
1466            get_id_str(xmlent -> ent_ident), get_entity_name(ent)));
1467
1468     if(get_entity_ident(ent) == xmlent -> ent_ident) {
1469       break;
1470     }
1471     ent = NULL;
1472   }
1473   assert(ent && "did not find a entity");
1474
1475   xmlent -> f_ent = ent;
1476 }
1477
1478 /********************************************************************/
1479 /* must be primitive type or class type */
1480 static void assign_firm_type(type_t *xmltype)
1481 {
1482   int i;
1483   type *typ = NULL;
1484   int num;
1485
1486   VERBOSE_PRINT((stdout, "assign firm type to type %s\n",
1487                  get_id_str(xmltype -> type_ident)));
1488
1489   /* is it global type? */
1490   typ = get_glob_type();
1491   if(xmltype -> type_ident == get_type_ident(typ)) {
1492     /* yes */
1493     xmltype -> f_tp = typ;
1494     VERBOSE_PRINT((stdout, "is global type %s\n", get_type_name(typ)));
1495   } else {
1496     num = get_irp_n_types();
1497     for(i = 0; i < num; i++) {
1498       typ = get_irp_type(i);
1499       VERBOSE_PRINT((stdout, "test type %s\n", get_type_name(typ)));
1500       if(xmltype -> type_ident == get_type_ident(typ)) {
1501         VERBOSE_PRINT((stdout, "found type %s\n", get_type_name(typ)));
1502         xmltype -> f_tp = typ;
1503         break;
1504       }
1505       typ = NULL;
1506     }
1507   }
1508   assert(typ && "did not find a type");
1509 }
1510
1511 /********************************************************************/
1512 static
1513 void create_abstract_proc_effect(module_t *module, proc_t *proc)
1514 {
1515   int i, num;
1516   type *class_typ = NULL;
1517   type_t *type;
1518   entity *fent;
1519
1520   /* find the class of a procedure */
1521   VERBOSE_PRINT((stdout, "do find owner id %s\n", get_id_str(proc -> ownerid)));
1522   type = find_type_in_module(module, proc -> ownerid);
1523   assert(type && "class not found in module");
1524
1525   class_typ = get_glob_type();
1526   VERBOSE_PRINT((stdout, "test type %s\n", get_type_name(class_typ)));
1527   if(type -> type_ident != get_type_ident(class_typ)) {
1528     /* find module as class */
1529     num = get_irp_n_types();
1530     for(i = 0; i < num; i++) {
1531       class_typ = get_irp_type(i);
1532       VERBOSE_PRINT((stdout, "test type %s\n", get_type_name(class_typ)));
1533       if(is_class_type(class_typ)
1534      && (type -> type_ident == get_type_ident(class_typ))) {
1535     /* found class type */
1536     VERBOSE_PRINT((stdout, "found type %s\n", get_type_name(class_typ)));
1537     break;
1538       }
1539       class_typ = NULL;
1540     }
1541   }
1542   else {
1543     VERBOSE_PRINT((stdout, "found global type %s\n", get_type_name(class_typ)));
1544   }
1545   assert(class_typ && "type not found");
1546   assert(is_class_type(class_typ) && "is not a class type");
1547   type -> f_tp = class_typ;
1548
1549   /* find entity for procedure in class */
1550   VERBOSE_PRINT((stdout, "find method %s\n",
1551          get_id_str(proc -> proc_ident)));
1552
1553   num = get_class_n_members(class_typ);
1554   fent = NULL;
1555   for(i = 0; i < num; i++) {
1556     fent = get_class_member(class_typ, i);
1557     VERBOSE_PRINT((stdout, "test proc %s\n", get_entity_name(fent)));
1558     if(proc -> proc_ident == get_entity_ident(fent)) {
1559       VERBOSE_PRINT((stdout, "found proc %s\n",
1560              get_id_str(proc -> proc_ident)));
1561       /* @@@ TODO check args types - not in xml yet */
1562       /* create Firm stuff */
1563       create_abstract_firm(module, proc, fent);
1564       return;
1565     }
1566     else {
1567       fent = NULL;
1568     }
1569   }
1570
1571   /* fail */
1572   fprintf(stderr,
1573           "method %s not found\nNo effects generated\nCandidates are:\n",
1574           get_id_str(proc -> proc_ident));
1575   for(i = 0; i < num; i++) {
1576     fent = get_class_member(class_typ, i);
1577     fprintf(stderr, "%s\n", get_entity_name(fent));
1578   }
1579   //assert(fent && "procedure not found in class");
1580 }
1581
1582 static
1583 void create_abstract_module(module_t *module)
1584 {
1585   proc_t *proc;
1586   type_t *type;
1587   entity_t *ent;
1588
1589   VERBOSE_PRINT((stdout, "create an abstraction for module %s\n",
1590          get_id_str(module -> id)));
1591
1592   VERBOSE_PRINT((stdout, "--handle types for module\n"));
1593   for(type = module -> types; type; type = type -> prev) {
1594     assign_firm_type(type);
1595   }
1596
1597   VERBOSE_PRINT((stdout, "--handle entities for module\n"));
1598   /* @@@ TODO */
1599   for(ent = module -> entities; ent; ent = ent -> prev) {
1600     assign_firm_entity(module, ent);
1601   }
1602
1603   VERBOSE_PRINT((stdout, "--handle procs for module\n"));
1604   for(proc = module -> procs; proc; proc = proc -> next) {
1605     create_abstract_proc_effect(module, proc);
1606   }
1607 }
1608
1609
1610 void create_abstraction(const char *filename)
1611 {
1612   module_t *module;
1613
1614   /* read and parse XML file */
1615   read_extern(filename);
1616
1617   /* finished reading and parsing here */
1618   /* build FIRM graphs */
1619   module = modules;
1620   while(module) {
1621     current_module = module;
1622     create_abstract_module(module);
1623     module = module -> next;
1624   }
1625   current_module = NULL;
1626
1627   /* free data structures */
1628   free_data();
1629
1630   types = NULL;
1631   entities = NULL;
1632   procs = NULL;
1633   modules = NULL;
1634 }
1635
1636
1637 void free_abstraction(void) {
1638   int i, n_pseudo_irgs = get_irp_n_pseudo_irgs();
1639   for (i = 0; i < n_pseudo_irgs; ++i) {
1640     ir_graph *p_irg = get_irp_pseudo_irg(i);
1641     set_entity_visibility(get_irg_entity(p_irg), visibility_external_allocated);
1642     // @@@ free_pseudo_ir_graph(p_irg);
1643   }
1644 }
1645
1646
1647 /********************************************************************/
1648
1649 \f
1650 /*
1651  * $Log$
1652  * Revision 1.16  2004/11/11 12:24:52  goetz
1653  * fixes
1654  *
1655  * Revision 1.15  2004/11/11 09:28:32  goetz
1656  * treat pseudo irgs special
1657  * parse 'local' from xml files
1658  *
1659  * Revision 1.14  2004/11/10 14:42:00  boesler
1660  * be more helpful if a method does not exist
1661  *
1662  * Revision 1.13  2004/11/05 14:00:53  liekweg
1663  * added raise
1664  *
1665  * Revision 1.12  2004/11/02 14:30:31  liekweg
1666  * fixed multi-input join (thx, Boris) --flo
1667  *
1668  * Revision 1.11  2004/10/29 18:51:53  liekweg
1669  * Added Join
1670  *
1671  * Revision 1.10  2004/10/25 13:52:24  boesler
1672  * seperated read.h (public interface) and read_t.h (types)
1673  *
1674  * Revision 1.9  2004/10/22 13:51:35  boesler
1675  * prohibit inlining of pseudo ir_graphs
1676  *
1677  * Revision 1.8  2004/10/22 13:13:27  boesler
1678  * replaced char* by idents, minor fix in Firm codegen for call
1679  *
1680  * Revision 1.7  2004/10/21 15:31:55  boesler
1681  * added lots of stuff:
1682  * - build abstract syntax trees
1683  * - build Firm graphs for many effects, still todos
1684  *
1685  * Revision 1.5  2004/10/18 12:48:20  liekweg
1686  * avoid warning
1687  *
1688  * Revision 1.4  2004/10/14 11:31:53  liekweg
1689  * ...
1690  *
1691  * Revision 1.3  2004/10/13 13:36:28  rubino
1692  * fix for strdup
1693  *
1694  * Revision 1.2  2004/10/11 15:56:09  liekweg
1695  * Cleanup, comments ...
1696  * Added init func --flo
1697  *
1698  * Revision 1.1  2004/10/11 09:31:06  liekweg
1699  * First Import of XML reading procs --flo
1700  *
1701  */