5 * File name: ir/external/read.c
6 * Purpose: Read descriptions of external effects
8 * Modified by: Boris Boesler
11 * Copyright: (c) 1999-2004 Universität Karlsruhe
12 * Licence: This file is protected by GPL - GNU GENERAL PUBLIC LICENSE.
19 /* get prototype for alloca somehow */
38 #define VERBOSE_PRINTING 0
41 # define VERBOSE_PRINT(s) fprintf s
43 # define VERBOSE_PRINT(s)
48 static type_t *types = NULL;
49 static entity_t *entities = NULL;
50 static proc_t *procs = NULL;
51 static module_t *modules = NULL;
54 static module_t *current_module = NULL;
56 static char *effect_string[] = {
71 getNodeModuleIdent (xmlNodePtr node)
73 const char *mod_str = (const char*) xmlGetProp (node, BAD_CAST "module");
75 if (NULL == mod_str) {
78 const ident *res = new_id_from_str (mod_str);
84 getNodeProcName (xmlNodePtr node)
86 const char *proc_str = (const char*) xmlGetProp (node, BAD_CAST "procname");
92 getNodeClassName (xmlNodePtr node)
94 char *proc_str = (char*) xmlGetProp (node, BAD_CAST "class");
100 getNodeId (xmlNodePtr node)
102 const char *id_str = (const char*) xmlGetProp (node, BAD_CAST "id");
108 getNodeRefId (xmlNodePtr node)
110 const char *refid_str = (char*) xmlGetProp (node, BAD_CAST "refid");
112 return ((refid_str));
116 getNodeTypeId (xmlNodePtr node)
118 const char *type_str = (char*) xmlGetProp (node, BAD_CAST "type");
124 *getNodeTypeStr (xmlNodePtr node)
126 const char *type_str = (char*) xmlGetProp (node, BAD_CAST "type");
132 getNodeOwnerStr (xmlNodePtr node)
134 const char *owner_str = (char*) xmlGetProp (node, BAD_CAST "owner");
140 *getNodeEntityStr (xmlNodePtr node)
142 const char *ent_str = (char*) xmlGetProp (node, BAD_CAST "entity");
153 type_t *getTypeByIdent (const ident *id)
155 type_t *curr = types; // @@@ TODO module -> types
157 while (NULL != curr) {
158 if (id == curr -> type_ident) {
168 type_t *getTypeById (const ident *id)
170 type_t *curr = types; // which ones?
172 while (NULL != curr) {
173 if (id == curr -> id) {
183 entity_t *getEntityByIdents (const ident *name, const ident *tp_ident)
185 entity_t *curr = entities; // TODO module -> entities
187 while (NULL != curr) {
188 if ((name == curr -> ent_ident)
189 && (tp_ident == curr -> tp_ident)) {
199 entity_t *getEntityById (const ident *id)
201 entity_t *curr = entities;
203 while (NULL != curr) {
204 if (id == curr -> id) {
214 proc_t *getEffectByName (const ident *proc_ident)
216 proc_t *curr_effs = procs;
218 while (NULL != curr_effs) {
219 if (proc_ident == curr_effs -> proc_ident) {
222 curr_effs = curr_effs->next;
229 xmlNodePtr get_any_valid_child(xmlNodePtr elem)
233 assert(elem && "no element");
234 child = elem -> xmlChildrenNode;
235 while(child && (NODE_NAME (child, comment))) {
236 child = child -> next;
242 xmlNodePtr get_valid_child(xmlNodePtr elem)
246 child = get_any_valid_child(elem);
247 assert(child && "lost child in deep black forest");
252 * parse XML structure and construct an additional structure
255 parseArg (xmlDocPtr doc, xmlNodePtr argelm)
263 CHECK_NAME (argelm, arg);
264 VERBOSE_PRINT ((stdout, "arg node \t0x%08x\n", (int) argelm));
266 id = getNodeId (argelm);
267 VERBOSE_PRINT ((stdout, "arg->id = \"%s\"\n", id));
268 num_str = (char*) xmlGetProp (argelm, BAD_CAST "number");
269 num = atoi (num_str);
270 VERBOSE_PRINT ((stdout, "arg->no = \"%d\"\n", num));
272 typeid = getNodeTypeStr (argelm);
275 arg -> kind = eff_arg;
276 arg -> id = new_id_from_str(id);
277 arg -> effect.arg.num = num;
278 arg -> effect.arg.type_ident = new_id_from_str(typeid);
284 *parseValref (xmlDocPtr doc, xmlNodePtr valelm)
289 CHECK_NAME (valelm, valref);
290 VERBOSE_PRINT ((stdout, "valref node \t0x%08x\n", (int) valelm));
292 ref_id = getNodeRefId (valelm);
293 VERBOSE_PRINT ((stdout, "val->refid = \"%s\"\n", ref_id));
295 valref = NEW (eff_t);
296 valref->kind = eff_valref;
297 valref-> id = new_id_from_str(ref_id);
303 *parseSelect (xmlDocPtr doc, xmlNodePtr selelm)
305 const ident *entity_id = new_id_from_str(getNodeEntityStr (selelm));
308 eff_t *valref = NULL;
309 eff_t *sel = NEW (eff_t);
310 sel->kind = eff_select;
312 CHECK_NAME (selelm, select);
313 VERBOSE_PRINT ((stdout, "select node \t0x%08x\n", (int) selelm));
315 ent = getEntityById (entity_id);
316 assert(ent && "entity not found");
317 VERBOSE_PRINT ((stdout, "select entity %s\n", get_id_str(ent -> ent_ident)));
319 child = selelm->xmlChildrenNode;
322 valref = parseValref (doc, child);
325 sel-> id = valref ? valref-> id : NO_ID;
326 sel-> effect.select.ent = ent;
336 *parseLoad (xmlDocPtr doc, xmlNodePtr loadelm)
341 eff_t *load = NEW (eff_t);
342 load->kind = eff_load;
344 CHECK_NAME (loadelm, load);
345 VERBOSE_PRINT ((stdout, "load node \t0x%08x\n", (int) loadelm));
346 id = new_id_from_str(getNodeId (loadelm));
348 child = get_valid_child(loadelm);
349 if(NODE_NAME (child, select)) {
350 sel = parseSelect (doc, child);
351 load-> effect.load.ent = sel-> effect.select.ent;
352 VERBOSE_PRINT ((stdout, "load entity \t%s\n",
353 get_id_str(load -> effect.load.ent -> ent_ident)));
356 sel = parseValref (doc, child);
357 load-> effect.load.ent = NULL;
361 load-> effect.load.ptrrefid = sel-> id;
369 *parseStore (xmlDocPtr doc, xmlNodePtr storeelm)
374 eff_t *store = NEW (eff_t);
375 store->kind = eff_store;
377 CHECK_NAME (storeelm, store);
378 VERBOSE_PRINT ((stdout, "store node \t0x%08x\n", (int) storeelm));
380 child = get_valid_child(storeelm);
381 if(NODE_NAME (child, select)) {
382 sel = parseSelect (doc, child);
383 store-> effect.store.ent = sel-> effect.select.ent;
386 sel = parseValref (doc, child);
387 store-> effect.store.ent = NULL;
391 valref = parseValref (doc, child);
393 store-> effect.store.ptrrefid = sel-> id;
394 store-> effect.store.valrefid = valref-> id;
403 *parseAlloc (xmlDocPtr doc, xmlNodePtr allocelm)
406 const ident *type_id;
407 eff_t *alloc = NEW (eff_t); /* ...! */
408 alloc->kind = eff_alloc;
410 CHECK_NAME (allocelm, alloc);
411 VERBOSE_PRINT ((stdout, "alloc node \t0x%08x\n", (int) allocelm));
412 id = new_id_from_str(getNodeId (allocelm));
413 VERBOSE_PRINT ((stdout, "alloc->id = \"%s\"\n", get_id_str(id)));
414 type_id = new_id_from_str(getNodeTypeId (allocelm));
415 VERBOSE_PRINT ((stdout, "alloc->type_id = \"%s\"\n", get_id_str(type_id)));
418 alloc-> effect.alloc.tp_id = type_id;
424 *parseCall (xmlDocPtr doc, xmlNodePtr callelm)
431 eff_t *call = NEW (eff_t);
432 call->kind = eff_call;
434 CHECK_NAME (callelm, call);
435 VERBOSE_PRINT ((stdout, "call node \t0x%08x\n", (int) callelm));
436 id = new_id_from_str(getNodeId (callelm));
437 VERBOSE_PRINT ((stdout, "call->id = \"%s\"\n", get_id_str(id)));
439 child = get_valid_child(callelm);
440 if(NODE_NAME (child, select)) {
441 sel = parseSelect (doc, child);
442 call-> effect.call.ent = sel-> effect.select.ent;
445 sel = parseValref (doc, child);
446 call-> effect.call.ent = NULL;
449 arg = child = child->next;
452 while (NULL != child) {
458 call-> effect.call.valrefid = sel-> id;
459 call-> effect.call.n_args = n_args;
460 call-> effect.call.args = NULL;
465 const ident **args = (const ident**) malloc(n_args * sizeof(const ident*));
468 while (NULL != arg) {
469 eff_t *valref = parseValref (doc, arg);
470 args [i ++] = valref-> id;
475 call-> effect.call.args = args;
482 *parseJoin (xmlDocPtr doc, xmlNodePtr joinelm)
489 eff_t *join = NEW (eff_t);
490 join->kind = eff_join;
492 CHECK_NAME (joinelm, join);
493 VERBOSE_PRINT ((stdout, "join node \t0x%08x\n", (int) joinelm));
494 id = new_id_from_str(getNodeId (joinelm));
495 VERBOSE_PRINT ((stdout, "join->id = \"%s\"\n", get_id_str(id)));
497 child = get_valid_child(joinelm);
500 while (NULL != child) {
505 ins = (const ident **) malloc (n_ins * sizeof (const ident *) );
507 child = get_valid_child(joinelm);
509 while (NULL != child) {
510 eff_t *valref = parseValref (doc, child);
511 ins [i ++] = valref-> id;
517 join-> effect.join.n_ins = n_ins;
518 join-> effect.join.ins = ins;
524 *parseUnknown (xmlDocPtr doc, xmlNodePtr unknownelm)
527 eff_t *unknown = NEW (eff_t);
528 unknown->kind = eff_unknown;
530 CHECK_NAME (unknownelm, unknown);
531 VERBOSE_PRINT ((stdout, "unknown node \t0x%08x\n", (int) unknownelm));
532 id = new_id_from_str(getNodeId (unknownelm));
539 *parseReturn (xmlDocPtr doc, xmlNodePtr retelm)
542 eff_t *ret = NEW (eff_t);
545 CHECK_NAME (retelm, ret);
546 VERBOSE_PRINT ((stdout, "ret node \t0x%08x\n", (int) retelm));
548 child = get_any_valid_child(retelm);
551 eff_t *valref = parseValref (doc, child);
552 ret-> effect.ret.ret_id = valref-> id;
555 ret-> effect.ret.ret_id = NO_ID;
562 *parseRaise (xmlDocPtr doc, xmlNodePtr raiseelm)
567 eff_t *raise = NEW (eff_t);
568 raise->kind = eff_raise;
570 CHECK_NAME (raiseelm, raise);
571 VERBOSE_PRINT ((stdout, "raise node \t0x%08x\n", (int) raiseelm));
572 tp_id = getNodeTypeId (raiseelm);
573 VERBOSE_PRINT ((stdout, "raise->type = \"%s\"\n", tp_id));
574 child = get_valid_child(raiseelm);
576 assert (NULL != child);
578 valref = parseValref (doc, child);
579 raise-> effect.raise.valref = valref-> id;
580 raise-> effect.raise.tp_id = new_id_from_str(tp_id);
591 /** parse a type node and insert it into the list */
593 parseType (xmlDocPtr doc, xmlNodePtr typeelm)
596 const char *tp_id = getNodeId (typeelm);
597 VERBOSE_PRINT ((stdout, "type node \t0x%08x (%s)\n", (int) typeelm, tp_id));
598 VERBOSE_PRINT ((stdout, "type = \"%s\"\n", getNodeTypeStr (typeelm)));
600 type = (type_t*) malloc (sizeof (type_t));
601 type -> type_ident = new_id_from_str(getNodeTypeStr (typeelm));
602 type -> id = new_id_from_str(tp_id);
608 /** parse an entity node and insert it into the list */
610 parseEntity (xmlDocPtr doc, xmlNodePtr entelm)
612 entity_t *ent = NEW (entity_t);
615 const char *ent_id = getNodeId (entelm);
616 /* fprintf (stdout, "entity node \t0x%08x (%d)\n", (int) entelm, ent_id); */
617 VERBOSE_PRINT ((stdout, "ent = \"%s.%s\"\n",
618 getNodeTypeStr (entelm),
619 getNodeEntityStr (entelm)));
622 ent -> ent_ident = new_id_from_str (getNodeEntityStr (entelm));
623 ent -> tp_ident = new_id_from_str (getNodeTypeStr (entelm));
624 ent -> owner = new_id_from_str (getNodeOwnerStr (entelm));
625 ent -> id = new_id_from_str(ent_id);
627 ent->prev = entities;
631 /** parse any effect, and turn it into an eff_t (TODO) */
633 parseEffect (xmlDocPtr doc, xmlNodePtr effelm)
636 const char *procname = getNodeProcName (effelm);
637 const char *ownerid = getNodeOwnerStr (effelm);
638 proc_t *curr_effs = NULL;
642 VERBOSE_PRINT ((stdout, "effect for method \"%s\"\n", procname));
644 cur = effelm -> xmlChildrenNode;
645 while (NULL != cur) {
649 VERBOSE_PRINT ((stdout, "has %d effects\n", n_effs));
651 curr_effs = NEW (proc_t);
652 curr_effs -> proc_ident = new_id_from_str(procname);
653 curr_effs -> ownerid = new_id_from_str(ownerid);
654 curr_effs->effs = (eff_t**) malloc (n_effs * sizeof (eff_t*));
656 cur = effelm -> xmlChildrenNode;
657 while (NULL != cur) {
660 if (NODE_NAME (cur, arg)) {
661 eff = (eff_t*) parseArg (doc, cur);
662 } else if (NODE_NAME (cur, load)) {
663 eff = (eff_t*) parseLoad (doc, cur);
664 } else if (NODE_NAME (cur, store)) {
665 eff = (eff_t*) parseStore (doc, cur);
666 } else if (NODE_NAME (cur, alloc)) {
667 eff = (eff_t*) parseAlloc (doc, cur);
668 } else if (NODE_NAME (cur, call)) {
669 eff = (eff_t*) parseCall (doc, cur);
670 } else if (NODE_NAME (cur, join)) {
671 eff = (eff_t*) parseJoin (doc, cur);
672 } else if (NODE_NAME (cur, unknown)) {
673 eff = (eff_t*) parseUnknown (doc, cur);
674 } else if (NODE_NAME (cur, ret)) {
675 eff = (eff_t*) parseReturn (doc, cur);
676 } else if (NODE_NAME (cur, raise)) {
677 eff = (eff_t*) parseRaise (doc, cur);
678 } else if (NODE_NAME (cur, comment)) {
682 fprintf (stderr, "wrong element \"%s\"\n", BAD_CAST cur->name);
686 VERBOSE_PRINT ((stdout, "effect %p@%d\n", (void*)eff, i));
687 curr_effs -> effs[i++] = eff;
691 assert((i == n_effs) && "incorrect number of effects");
692 curr_effs -> n_effs = n_effs;
693 curr_effs -> next = procs;
699 void read_extern (const char *filename)
701 /* xmlNsPtr ns = NULL; */ /* no namespace for us */
702 xmlDocPtr doc; /* whole document */
703 xmlNodePtr cur; /* current node */
707 /* i've got no idea what the VERSION cast is all about. voodoo
708 programming at its finest. */
709 LIBXML_TEST_VERSION xmlKeepBlanksDefault (0);
710 VERBOSE_PRINT((stdout, "read file %s\n", filename));
711 doc = xmlParseFile (filename);
712 CHECK (doc, "xmlParseFile");
714 cur = xmlDocGetRootElement (doc);
715 CHECK (cur, "xmlDocGetRootElement");
717 if (! NODE_NAME (cur, effects)) {
718 fprintf (stderr,"root node \"%s\" != \"effects\"\n", BAD_CAST cur->name);
723 mod_id = getNodeModuleIdent (cur);
724 if (NULL != mod_id) {
725 VERBOSE_PRINT ((stdout, "effects for \"%s\"\n",
726 get_id_str(mod_id)));
729 VERBOSE_PRINT ((stdout, "effects \t0x%08x\n", (int) cur));
733 cur = cur->xmlChildrenNode;
734 while (cur != NULL) {
735 if (NODE_NAME (cur, type)) {
736 parseType (doc, cur);
737 } else if (NODE_NAME (cur, entity)) {
738 parseEntity (doc, cur);
739 } else if (NODE_NAME (cur, effect)) {
740 parseEffect (doc, cur);
741 } else if ((NODE_NAME (cur, comment))) {
744 fprintf (stderr, "wrong element \"%s\"\n", BAD_CAST cur->name);
750 module = NEW(module_t);
751 module -> id = mod_id;
752 module -> types = types;
753 module -> entities = entities;
754 module -> procs = procs;
760 module -> next = modules;
764 /********************************************************************/
767 * free additional structure
770 void freeArg (eff_t *arg)
772 VERBOSE_PRINT ((stdout, "free arg node \t0x%08x\n", (int) arg));
778 void freeValref (eff_t *valref)
780 VERBOSE_PRINT ((stdout, "free valref node \t0x%08x\n", (int) valref));
786 void freeSelect (eff_t *sel)
788 VERBOSE_PRINT ((stdout, "free select node \t0x%08x\n", (int) sel));
794 void freeLoad (eff_t *load)
796 VERBOSE_PRINT ((stdout, "free load node \t0x%08x\n", (int) load));
802 void freeStore (eff_t *store)
804 VERBOSE_PRINT ((stdout, "free store node \t0x%08x\n", (int) store));
810 void freeAlloc (eff_t *alloc)
812 VERBOSE_PRINT ((stdout, "free alloc node \t0x%08x\n", (int) alloc));
818 void freeCall (eff_t *call)
820 VERBOSE_PRINT ((stdout, "free call node \t0x%08x\n", (int) call));
821 free(call -> effect.call.args);
827 void freeJoin (eff_t *join)
829 VERBOSE_PRINT ((stdout, "free join node \t0x%08x\n", (int) join));
830 free(join -> effect.join.ins);
836 void freeUnknown (eff_t *unknown)
838 VERBOSE_PRINT ((stdout, "free unknown node \t0x%08x\n", (int) unknown));
844 void freeReturn (eff_t *ret)
846 VERBOSE_PRINT ((stdout, "free ret node \t0x%08x\n", (int) ret));
852 void freeRaise (eff_t *raise)
854 VERBOSE_PRINT ((stdout, "free raise node \t0x%08x\n", (int) raise));
861 void freeProcEffs(proc_t *proc)
866 VERBOSE_PRINT ((stdout, "free effect for method \"%s\"\n",
867 get_id_str(proc -> proc_ident)));
869 num = proc -> n_effs;
870 for(i = 0; i < num; i++) {
871 switch(proc -> effs[i] -> kind) {
873 freeArg(proc -> effs[i]);
876 freeValref(proc -> effs[i]);
879 freeSelect(proc -> effs[i]);
882 freeLoad(proc -> effs[i]);
885 freeStore(proc -> effs[i]);
888 freeAlloc(proc -> effs[i]);
891 freeCall(proc -> effs[i]);
894 freeUnknown(proc -> effs[i]);
897 freeJoin(proc -> effs[i]);
900 freeRaise(proc -> effs[i]);
903 freeReturn(proc -> effs[i]);
906 assert(0 && "try to free an unknown effect");
915 void freeModuleProcs(module_t *module)
917 proc_t *next_proc, *proc;
919 VERBOSE_PRINT ((stdout, "free procs for module \"%s\"\n",
920 get_id_str(module -> id)));
922 proc = module -> procs;
924 next_proc = proc -> next;
934 module_t *module, *next_module;
938 freeModuleProcs(module);
939 next_module = module -> next;
941 module = next_module;
945 /********************************************************************/
948 type_t *find_type_in_module(module_t *module, const ident *typeid)
952 for(type = module -> types; type; type = type -> prev) {
953 VERBOSE_PRINT((stdout, "test typeid %s\n", get_id_str(type -> id)));
954 if(type -> id == typeid) {
955 VERBOSE_PRINT((stdout, "found\n"));
959 VERBOSE_PRINT((stdout, "did not find type id %s\n", get_id_str(typeid)));
963 /********************************************************************/
965 static void add_value_to_proc(proc_t *proc, eff_t *eff)
967 eff -> next = proc -> values;
968 proc -> values = eff;
972 eff_t *find_valueid_in_proc_effects(const ident *id, proc_t *proc)
976 val = proc -> values;
978 if(id == val -> id) {
986 static void create_abstract_return(ir_graph *irg, proc_t *proc, eff_t *eff)
991 VERBOSE_PRINT((stdout, "create effect:return in %s\n",
992 get_id_str(proc -> proc_ident)));
993 if(NO_ID == eff -> effect.ret.ret_id) {
995 x = new_Return (get_store(), 0, NULL);
1000 /* return one value */
1001 eff_res = find_valueid_in_proc_effects(eff -> effect.ret.ret_id, proc);
1002 assert(eff_res -> firmnode && "firm in effect not set");
1003 in[0] = eff_res -> firmnode;
1004 x = new_Return (get_store(), 1, in);
1006 eff -> firmnode = x;
1008 /* Now we generated all instructions for this block and all its predecessor
1009 * blocks so we can mature it. (There are not too much.) */
1010 mature_immBlock (get_irg_current_block(irg));
1012 /* This adds the in edge of the end block which originates at the return statement.
1013 * The return node passes controlflow to the end block. */
1014 add_immBlock_pred (get_irg_end_block(irg), x);
1018 static void create_abstract_arg(ir_graph *irg, proc_t *proc, eff_t *eff)
1026 VERBOSE_PRINT((stdout, "create effect:arg %d in %s\n",
1027 eff -> effect.arg.num, get_id_str(proc -> proc_ident)));
1028 ent = get_irg_entity(irg);
1029 typ = get_entity_type(ent);
1031 /* read argument eff -> effect.arg.num and place in values list */
1032 num = get_method_n_params(typ);
1033 assert((num >= eff -> effect.arg.num) && "number too big");
1034 typ = get_method_param_type(typ, eff -> effect.arg.num);
1035 mode = get_type_mode(typ);
1037 arg = new_Proj(get_irg_args(irg), mode, eff -> effect.arg.num);
1038 eff -> firmnode = arg;
1040 add_value_to_proc(proc, eff);
1044 static void create_abstract_load(ir_graph *irg, proc_t *proc, eff_t *eff)
1046 ir_node *sel, *load;
1051 VERBOSE_PRINT((stdout, "create load in %s\n",
1052 get_id_str(proc -> proc_ident)));
1054 if(eff -> effect.load.ent) {
1055 ent = eff -> effect.load.ent -> f_ent;
1056 VERBOSE_PRINT((stdout, "load from %s\n", get_entity_name(ent)));
1059 VERBOSE_PRINT((stdout, "store to memory\n"));
1063 addr = find_valueid_in_proc_effects(eff -> effect.load.ptrrefid, proc);
1064 assert(addr && "no address for load");
1065 /* if addr is Unknown, set propper mode */
1066 if(iro_Unknown == get_irn_opcode(addr -> firmnode)) {
1067 set_irn_mode(addr -> firmnode, mode_P);
1071 sel = new_simpleSel(get_store(), addr -> firmnode, ent);
1072 mode = get_type_mode(get_entity_type(ent));
1075 sel = addr -> firmnode;
1078 load = new_Load(get_store(), sel, mode);
1079 set_store(new_Proj(load, mode_M, 0));
1080 eff -> firmnode = new_Proj(load, mode, 2);
1082 add_value_to_proc(proc, eff);
1086 static void create_abstract_store(ir_graph *irg, proc_t *proc, eff_t *eff)
1088 ir_node *sel, *store;
1092 VERBOSE_PRINT((stdout, "create store in %s\n",
1093 get_id_str(proc -> proc_ident)));
1095 if(eff -> effect.store.ent) {
1096 ent = eff -> effect.store.ent -> f_ent;
1097 VERBOSE_PRINT((stdout, "store to entity %s\n", get_entity_name(ent)));
1100 VERBOSE_PRINT((stdout, "store to memory\n"));
1104 addr = find_valueid_in_proc_effects(eff -> effect.store.ptrrefid, proc);
1105 assert(addr && "no address for store");
1106 /* if addr is Unknown, set propper mode */
1107 if(iro_Unknown == get_irn_opcode(addr -> firmnode)) {
1108 set_irn_mode(addr -> firmnode, mode_P);
1111 val = find_valueid_in_proc_effects(eff -> effect.store.valrefid, proc);
1112 assert(val && "no address for store");
1113 /* if addr is Unknown, set propper mode */
1114 if(iro_Unknown == get_irn_opcode(val -> firmnode)) {
1115 set_irn_mode(val -> firmnode, get_type_mode(get_entity_type(ent)));
1119 sel = new_simpleSel(get_store(), addr -> firmnode, ent);
1122 sel = addr -> firmnode;
1124 store = new_Store(get_store(), sel, val -> firmnode);
1125 set_store(new_Proj(store, mode_M, 0));
1126 eff -> firmnode = store;
1130 static void create_abstract_alloc(ir_graph *irg, proc_t *proc, eff_t *eff)
1135 symconst_symbol sym;
1137 VERBOSE_PRINT((stdout, "create alloc in %s\n",
1138 get_id_str(proc -> proc_ident)));
1140 xtype = find_type_in_module(current_module, eff -> effect.alloc.tp_id);
1141 assert(xtype && "type not found");
1142 ftype = xtype -> f_tp;
1145 alloc = new_Alloc(get_store(), new_SymConst(sym, symconst_size), ftype,
1147 set_store(new_Proj(alloc, mode_M, 0));
1148 eff -> firmnode = new_Proj(alloc, mode_P, 2);
1150 add_value_to_proc(proc, eff);
1154 static void create_abstract_unknown(ir_graph *irg, proc_t *proc, eff_t *eff)
1158 VERBOSE_PRINT((stdout, "create unknown in %s\n",
1159 get_id_str(proc -> proc_ident)));
1161 unknown = new_Unknown(mode_ANY);
1162 eff -> firmnode = unknown;
1164 add_value_to_proc(proc, eff);
1168 static void create_abstract_call(ir_graph *irg, proc_t *proc, eff_t *eff)
1170 ir_node *sel, *call;
1176 int mik; /* is method somehow known? */
1178 VERBOSE_PRINT((stdout, "create call in %s\n",
1179 get_id_str(proc -> proc_ident)));
1181 if(eff -> effect.call.ent) {
1182 ent = eff -> effect.call.ent -> f_ent;
1183 VERBOSE_PRINT((stdout, "call %s\n", get_entity_name(ent)));
1187 VERBOSE_PRINT((stdout, "call something in memory\n"));
1190 addr = find_valueid_in_proc_effects(eff -> effect.call.valrefid, proc);
1191 assert(addr && "no address for load");
1192 /* if addr is Unknown, set propper mode */
1193 if(iro_Unknown == get_irn_opcode(addr -> firmnode)) {
1194 set_irn_mode(addr -> firmnode, mode_P);
1199 sel = new_simpleSel(get_store(), addr -> firmnode, ent);
1201 mtype = get_entity_type(ent);
1206 sel = addr -> firmnode;
1208 mtype = get_unknown_type();
1213 num = eff -> effect.call.n_args;
1214 VERBOSE_PRINT((stdout, "number of args given: %d\n", num));
1216 VERBOSE_PRINT((stdout, "number of args expected: %d\n",
1217 get_method_n_params(mtype)));
1219 irns = alloca(num * sizeof(ir_node*));
1220 for(i = 0; i < num; i++) {
1221 irns[i] = find_valueid_in_proc_effects(eff -> effect.call.args[i], proc)
1223 if(iro_Unknown == get_irn_opcode(irns[i])) {
1225 set_irn_mode(irns[i], get_type_mode(get_method_param_type(mtype, i)));
1228 set_irn_mode(irns[i], mode_ANY);
1232 call = new_Call(get_store(), sel, num, irns, mtype);
1233 set_store(new_Proj(call, mode_M, 0));
1234 if(mik && (0 != get_method_n_ress(mtype))) {
1235 eff -> firmnode = new_Proj(call,
1236 get_type_mode(get_method_res_type(mtype, 0)),
1238 add_value_to_proc(proc, eff); /* result can be accessed */
1241 eff -> firmnode = NULL; /* result can not be accessed */
1246 static void create_abstract_firm(module_t *module, proc_t *proc, entity *fent)
1253 assert(visibility_external_allocated == get_entity_visibility(fent)
1254 && peculiarity_existent == get_entity_peculiarity(fent)
1255 && "not an abstract entity");
1256 /* create irg in entity */
1257 irg = new_ir_graph(fent, 0);
1258 set_irg_inline_property(irg, irg_inline_forbidden);
1260 VERBOSE_PRINT((stdout, "create effects for %s\n",
1261 get_id_str(proc -> proc_ident)));
1263 /* create effects in irg */
1264 num = proc -> n_effs;
1265 for(i = 0; i < num; i++) {
1266 eff = proc -> effs[i];
1267 VERBOSE_PRINT((stdout,
1268 "create effect \"%s\"\n", effect_string[(int)eff -> kind]));
1269 switch(eff -> kind) {
1271 create_abstract_return(irg, proc, eff);
1274 create_abstract_arg(irg, proc, eff);
1277 create_abstract_load(irg, proc, eff);
1280 create_abstract_store(irg, proc, eff);
1283 create_abstract_unknown(irg, proc, eff);
1286 create_abstract_alloc(irg, proc, eff);
1289 create_abstract_call(irg, proc, eff);
1292 assert(0 && "effect not implemented");
1297 /* close irg in entity */
1298 /* Now we can mature the end block as all it's predecessors are known. */
1299 mature_immBlock (get_irg_end_block(irg));
1301 /* Verify the graph. Finds some very bad errors in the graph. */
1302 VERBOSE_PRINT((stdout, "verify graph\n"));
1304 VERBOSE_PRINT((stdout, "finalize construction\n"));
1305 finalize_cons (irg);
1308 /********************************************************************/
1310 static void assign_firm_entity(module_t *module, entity_t *xmlent)
1317 VERBOSE_PRINT((stdout, "assign entity %s to typeid %s\n",
1318 get_id_str(xmlent -> ent_ident),
1319 get_id_str(xmlent -> owner)));
1321 typ = find_type_in_module(module, xmlent -> owner);
1322 assert(typ && "class not found in module");
1324 assert(is_class_type(type));
1326 num = get_class_n_members(type);
1328 for(i = 0; i < num; i++) {
1329 ent = get_class_member(type, i);
1330 VERBOSE_PRINT((stdout, "compare entity %s and %s\n",
1331 get_id_str(xmlent -> ent_ident), get_entity_name(ent)));
1333 if(get_entity_ident(ent) == xmlent -> ent_ident) {
1338 assert(ent && "did not find a entity");
1340 xmlent -> f_ent = ent;
1343 /********************************************************************/
1344 /* must be primitive type or class type */
1345 static void assign_firm_type(type_t *xmltype)
1351 VERBOSE_PRINT((stdout, "assign firm type to type %s\n",
1352 get_id_str(xmltype -> type_ident)));
1354 /* is it global type? */
1355 typ = get_glob_type();
1356 if(xmltype -> type_ident == get_type_ident(typ)) {
1358 xmltype -> f_tp = typ;
1359 VERBOSE_PRINT((stdout, "is global type %s\n", get_type_name(typ)));
1362 num = get_irp_n_types();
1363 for(i = 0; i < num; i++) {
1364 typ = get_irp_type(i);
1365 VERBOSE_PRINT((stdout, "test type %s\n", get_type_name(typ)));
1366 if(xmltype -> type_ident == get_type_ident(typ)) {
1367 VERBOSE_PRINT((stdout, "found type %s\n", get_type_name(typ)));
1368 xmltype -> f_tp = typ;
1374 assert(typ && "did not find a type");
1377 /********************************************************************/
1379 void create_abstract_proc_effect(module_t *module, proc_t *proc)
1382 type *class_typ = NULL;
1386 /* find the class of a procedure */
1387 VERBOSE_PRINT((stdout, "do find owner id %s\n", get_id_str(proc -> ownerid)));
1388 type = find_type_in_module(module, proc -> ownerid);
1389 assert(type && "class not found in module");
1391 class_typ = get_glob_type();
1392 VERBOSE_PRINT((stdout, "test type %s\n", get_type_name(class_typ)));
1393 if(type -> type_ident != get_type_ident(class_typ)) {
1394 /* find module as class */
1395 num = get_irp_n_types();
1396 for(i = 0; i < num; i++) {
1397 class_typ = get_irp_type(i);
1398 VERBOSE_PRINT((stdout, "test type %s\n", get_type_name(class_typ)));
1399 if(is_class_type(class_typ)
1400 && (type -> type_ident == get_type_ident(class_typ))) {
1401 /* found class type */
1402 VERBOSE_PRINT((stdout, "found type %s\n", get_type_name(class_typ)));
1409 VERBOSE_PRINT((stdout, "found global type %s\n", get_type_name(class_typ)));
1411 assert(class_typ && "type not found");
1412 assert(is_class_type(class_typ) && "is not a class type");
1413 type -> f_tp = class_typ;
1415 /* find entity for procedure in class */
1416 VERBOSE_PRINT((stdout, "find method %s\n",
1417 get_id_str(proc -> proc_ident)));
1419 num = get_class_n_members(class_typ);
1421 for(i = 0; i < num; i++) {
1422 fent = get_class_member(class_typ, i);
1423 VERBOSE_PRINT((stdout, "test proc %s\n", get_entity_name(fent)));
1424 if(proc -> proc_ident == get_entity_ident(fent)) {
1425 VERBOSE_PRINT((stdout, "found proc %s\n",
1426 get_id_str(proc -> proc_ident)));
1427 /* @@@ TODO check args types - not in xml yet */
1428 /* create Firm stuff */
1429 create_abstract_firm(module, proc, fent);
1436 assert(fent && "procedure not found in class");
1440 void create_abstract_module(module_t *module)
1446 VERBOSE_PRINT((stdout, "create an abstraction for module %s\n",
1447 get_id_str(module -> id)));
1449 VERBOSE_PRINT((stdout, "--handle types for module\n"));
1450 for(type = module -> types; type; type = type -> prev) {
1451 assign_firm_type(type);
1454 VERBOSE_PRINT((stdout, "--handle entities for module\n"));
1456 for(ent = module -> entities; ent; ent = ent -> prev) {
1457 assign_firm_entity(module, ent);
1460 VERBOSE_PRINT((stdout, "--handle procs for module\n"));
1461 for(proc = module -> procs; proc; proc = proc -> next) {
1462 create_abstract_proc_effect(module, proc);
1467 void create_abstraction(const char *filename)
1471 /* read and parse XML file */
1472 read_extern(filename);
1474 /* finished reading and parsing here */
1475 /* build FIRM graphs */
1478 current_module = module;
1479 create_abstract_module(module);
1480 module = module -> next;
1482 current_module = NULL;
1484 /* free data structures */
1493 /********************************************************************/
1498 * Revision 1.10 2004/10/25 13:52:24 boesler
1499 * seperated read.h (public interface) and read_t.h (types)
1501 * Revision 1.9 2004/10/22 13:51:35 boesler
1502 * prohibit inlining of pseudo ir_graphs
1504 * Revision 1.8 2004/10/22 13:13:27 boesler
1505 * replaced char* by idents, minor fix in Firm codegen for call
1507 * Revision 1.7 2004/10/21 15:31:55 boesler
1508 * added lots of stuff:
1509 * - build abstract syntax trees
1510 * - build Firm graphs for many effects, still todos
1512 * Revision 1.5 2004/10/18 12:48:20 liekweg
1515 * Revision 1.4 2004/10/14 11:31:53 liekweg
1518 * Revision 1.3 2004/10/13 13:36:28 rubino
1521 * Revision 1.2 2004/10/11 15:56:09 liekweg
1522 * Cleanup, comments ...
1523 * Added init func --flo
1525 * Revision 1.1 2004/10/11 09:31:06 liekweg
1526 * First Import of XML reading procs --flo