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.
30 # define VERBOSE_PRINT(s) fprintf s
32 # define VERBOSE_PRINT(s)
37 static type_t *types = NULL;
38 static entity_t *entities = NULL;
39 static proc_t *procs = NULL;
40 static module_t *modules = NULL;
43 static module_t *current_module = NULL;
45 static char *effect_string[] = {
60 getNodeModule (xmlNodePtr node)
62 const char *mod_str = (const char*) xmlGetProp (node, BAD_CAST "module");
64 if (NULL == mod_str) {
67 const char *res = strdup (mod_str);
73 getNodeProcName (xmlNodePtr node)
75 const char *proc_str = (const char*) xmlGetProp (node, BAD_CAST "procname");
77 return (strdup (proc_str));
81 getNodeClassName (xmlNodePtr node)
83 char *proc_str = (char*) xmlGetProp (node, BAD_CAST "class");
85 return (strdup (proc_str));
89 getNodeId (xmlNodePtr node)
91 const char *id_str = (const char*) xmlGetProp (node, BAD_CAST "id");
93 return (strdup (id_str));
97 getNodeRefId (xmlNodePtr node)
99 firmid_t refid_str = (char*) xmlGetProp (node, BAD_CAST "refid");
101 return (strdup(refid_str));
105 getNodeTypeId (xmlNodePtr node)
107 firmid_t type_str = (char*) xmlGetProp (node, BAD_CAST "type");
109 return (strdup(type_str));
113 *getNodeTypeStr (xmlNodePtr node)
115 const char *type_str = (char*) xmlGetProp (node, BAD_CAST "type");
122 getNodeOwnerStr (xmlNodePtr node)
124 const char *owner_str = (char*) xmlGetProp (node, BAD_CAST "owner");
130 *getNodeEntityStr (xmlNodePtr node)
132 const char *ent_str = (char*) xmlGetProp (node, BAD_CAST "entity");
143 type_t *getTypeByName (const char *name)
145 type_t *curr = types;
147 while (NULL != curr) {
148 if (0 == strcmp (name, curr->name)) {
158 type_t *getTypeById (firmid_t id)
160 type_t *curr = types;
162 while (NULL != curr) {
163 if (0 == strcmp(id, curr->id)) {
173 entity_t *getEntityByNames (const char *name, const char *tp_name)
175 entity_t *curr = entities;
177 while (NULL != curr) {
178 if ((0 == strcmp (name, curr->name))
179 && (0 == strcmp (tp_name, curr->tp_name))) {
189 entity_t *getEntityById (firmid_t id)
191 entity_t *curr = entities;
193 while (NULL != curr) {
194 if (0 == strcmp(id, curr->id)) {
204 proc_t *getEffectByName (const char *procname)
206 proc_t *curr_effs = procs;
208 while (NULL != curr_effs) {
209 if (0 == strcmp (procname, curr_effs->procname)) {
212 curr_effs = curr_effs->next;
220 * parse XML structure and construct an additional structure
223 parseArg (xmlDocPtr doc, xmlNodePtr argelm)
231 CHECK_NAME (argelm, arg);
232 VERBOSE_PRINT ((stdout, "arg node \t0x%08x\n", (int) argelm));
234 id = getNodeId (argelm);
235 VERBOSE_PRINT ((stdout, "arg->id = \"%s\"\n", id));
236 num_str = (char*) xmlGetProp (argelm, BAD_CAST "number");
237 num = atoi (num_str);
238 VERBOSE_PRINT ((stdout, "arg->no = \"%d\"\n", num));
240 typeid = getNodeTypeStr (argelm);
243 arg -> kind = eff_arg;
245 arg -> effect.arg.num = num;
246 arg -> effect.arg.type = typeid;
252 *parseValref (xmlDocPtr doc, xmlNodePtr valelm)
257 CHECK_NAME (valelm, valref);
258 VERBOSE_PRINT ((stdout, "valref node \t0x%08x\n", (int) valelm));
260 ref_id = getNodeRefId (valelm);
261 VERBOSE_PRINT ((stdout, "val->refid = \"%s\"\n", ref_id));
263 valref = NEW (eff_t);
264 valref->kind = eff_valref;
265 valref-> id = ref_id;
271 *parseSelect (xmlDocPtr doc, xmlNodePtr selelm)
273 firmid_t entity_id = getNodeEntityStr (selelm);
276 eff_t *valref = NULL;
277 eff_t *sel = NEW (eff_t);
278 sel->kind = eff_select;
280 CHECK_NAME (selelm, select);
281 VERBOSE_PRINT ((stdout, "select node \t0x%08x\n", (int) selelm));
283 ent = getEntityById (entity_id);
284 assert(ent && "entity not found");
285 VERBOSE_PRINT ((stdout, "select entity %s\n", ent -> name));
287 child = selelm->xmlChildrenNode;
290 valref = parseValref (doc, child);
293 sel-> id = valref ? valref-> id : NO_ID;
294 sel-> effect.select.ent = ent;
304 *parseLoad (xmlDocPtr doc, xmlNodePtr loadelm)
309 eff_t *load = NEW (eff_t);
310 load->kind = eff_load;
312 CHECK_NAME (loadelm, load);
313 VERBOSE_PRINT ((stdout, "load node \t0x%08x\n", (int) loadelm));
314 id = getNodeId (loadelm);
316 child = loadelm->xmlChildrenNode;
318 sel = parseSelect (doc, child);
321 load-> effect.load.ptrrefid = sel-> id;
322 load-> effect.load.ent = sel-> effect.select.ent;
323 VERBOSE_PRINT ((stdout,
324 "load entity \t%s\n", load -> effect.load.ent -> name));
332 *parseStore (xmlDocPtr doc, xmlNodePtr storeelm)
337 eff_t *store = NEW (eff_t);
338 store->kind = eff_store;
340 CHECK_NAME (storeelm, store);
341 VERBOSE_PRINT ((stdout, "store node \t0x%08x\n", (int) storeelm));
343 child = storeelm->xmlChildrenNode;
344 sel = parseSelect (doc, child);
346 valref = parseValref (doc, child);
348 store-> effect.store.ent = sel-> effect.select.ent;
349 store-> effect.store.ptrrefid = sel-> id;
350 store-> effect.store.valrefid = valref-> id;
359 *parseAlloc (xmlDocPtr doc, xmlNodePtr allocelm)
363 eff_t *alloc = NEW (eff_t); /* ...! */
364 alloc->kind = eff_alloc;
366 CHECK_NAME (allocelm, alloc);
367 VERBOSE_PRINT ((stdout, "alloc node \t0x%08x\n", (int) allocelm));
368 id = getNodeId (allocelm);
369 VERBOSE_PRINT ((stdout, "alloc->id = \"%s\"\n", id));
370 type_id = getNodeTypeId (allocelm);
371 VERBOSE_PRINT ((stdout, "alloc->type_id = \"%s\"\n", type_id));
374 alloc-> effect.alloc.tp_id = type_id;
380 *parseCall (xmlDocPtr doc, xmlNodePtr callelm)
387 eff_t *call = NEW (eff_t);
388 call->kind = eff_call;
390 CHECK_NAME (callelm, call);
391 VERBOSE_PRINT ((stdout, "call node \t0x%08x\n", (int) callelm));
392 id = getNodeId (callelm);
393 VERBOSE_PRINT ((stdout, "call->id = \"%s\"\n", id));
395 child = callelm->xmlChildrenNode;
396 sel = parseSelect (doc, child);
397 arg = child = child->next;
400 while (NULL != child) {
406 call-> effect.call.valrefid = sel-> id;
407 call-> effect.call.ent = sel-> effect.select.ent;
408 call-> effect.call.n_args = n_args;
409 call-> effect.call.args = NULL;
414 firmid_t *args = (firmid_t*) malloc (n_args * sizeof (firmid_t) );
417 while (NULL != arg) {
418 eff_t *valref = parseValref (doc, arg);
419 args [i ++] = valref-> id;
424 call-> effect.call.args = args;
431 *parseJoin (xmlDocPtr doc, xmlNodePtr joinelm)
438 eff_t *join = NEW (eff_t);
439 join->kind = eff_join;
441 CHECK_NAME (joinelm, join);
442 VERBOSE_PRINT ((stdout, "join node \t0x%08x\n", (int) joinelm));
443 id = getNodeId (joinelm);
444 VERBOSE_PRINT ((stdout, "join->id = \"%s\"\n", id));
446 child = joinelm->xmlChildrenNode;
449 while (NULL != child) {
454 ins = (firmid_t*) malloc (n_ins * sizeof (firmid_t) );
456 child = joinelm->xmlChildrenNode;
458 while (NULL != child) {
459 eff_t *valref = parseValref (doc, child);
460 ins [i ++] = valref-> id;
466 join-> effect.join.n_ins = n_ins;
467 join-> effect.join.ins = ins;
473 *parseUnknown (xmlDocPtr doc, xmlNodePtr unknownelm)
476 eff_t *unknown = NEW (eff_t);
477 unknown->kind = eff_unknown;
479 CHECK_NAME (unknownelm, unknown);
480 VERBOSE_PRINT ((stdout, "unknown node \t0x%08x\n", (int) unknownelm));
481 id = getNodeId (unknownelm);
488 *parseReturn (xmlDocPtr doc, xmlNodePtr retelm)
491 eff_t *ret = NEW (eff_t);
494 CHECK_NAME (retelm, ret);
495 VERBOSE_PRINT ((stdout, "ret node \t0x%08x\n", (int) retelm));
497 child = retelm->xmlChildrenNode;
500 eff_t *valref = parseValref (doc, child);
501 ret-> effect.ret.ret_id = valref-> id;
504 ret-> effect.ret.ret_id = NO_ID;
511 *parseRaise (xmlDocPtr doc, xmlNodePtr raiseelm)
516 eff_t *raise = NEW (eff_t);
517 raise->kind = eff_raise;
519 CHECK_NAME (raiseelm, raise);
520 VERBOSE_PRINT ((stdout, "raise node \t0x%08x\n", (int) raiseelm));
521 tp_id = getNodeTypeId (raiseelm);
522 VERBOSE_PRINT ((stdout, "raise->type = \"%s\"\n", tp_id));
523 child = raiseelm->xmlChildrenNode;
525 assert (NULL != child);
527 valref = parseValref (doc, child);
528 raise-> effect.raise.valref = valref-> id;
529 raise-> effect.raise.tp_id = tp_id;
540 /** parse a type node and insert it into the list */
542 parseType (xmlDocPtr doc, xmlNodePtr typeelm)
545 firmid_t tp_id = getNodeId (typeelm);
546 VERBOSE_PRINT ((stdout, "type node \t0x%08x (%s)\n", (int) typeelm, tp_id));
547 VERBOSE_PRINT ((stdout, "type = \"%s\"\n", getNodeTypeStr (typeelm)));
549 type = (type_t*) malloc (sizeof (type_t));
550 type->name = (char*) strdup (getNodeTypeStr (typeelm));
557 /** parse an entity node and insert it into the list */
559 parseEntity (xmlDocPtr doc, xmlNodePtr entelm)
561 entity_t *ent = NEW (entity_t);
564 firmid_t ent_id = getNodeId (entelm);
565 /* fprintf (stdout, "entity node \t0x%08x (%d)\n", (int) entelm, ent_id); */
566 VERBOSE_PRINT ((stdout, "ent = \"%s.%s\"\n",
567 getNodeTypeStr (entelm),
568 getNodeEntityStr (entelm)));
571 ent->name = (char*) strdup (getNodeEntityStr (entelm));
572 ent->tp_name = (char*) strdup (getNodeTypeStr (entelm));
573 ent -> owner = (char*) strdup (getNodeOwnerStr (entelm));
576 ent->prev = entities;
580 /** parse any effect, and turn it into an eff_t (TODO) */
582 parseEffect (xmlDocPtr doc, xmlNodePtr effelm)
585 const char *procname = getNodeProcName (effelm);
586 const char *typeid = getNodeTypeStr (effelm);
587 proc_t *curr_effs = NULL;
591 VERBOSE_PRINT ((stdout, "effect for method \"%s\"\n", procname));
593 cur = effelm -> xmlChildrenNode;
594 while (NULL != cur) {
598 VERBOSE_PRINT ((stdout, "has %d effects\n", n_effs));
600 curr_effs = NEW (proc_t);
601 curr_effs->procname = procname;
602 curr_effs->typeid = typeid;
603 curr_effs->effs = (eff_t**) malloc (n_effs * sizeof (eff_t*));
605 cur = effelm -> xmlChildrenNode;
606 while (NULL != cur) {
609 if (NODE_NAME (cur, arg)) {
610 eff = (eff_t*) parseArg (doc, cur);
611 } else if (NODE_NAME (cur, load)) {
612 eff = (eff_t*) parseLoad (doc, cur);
613 } else if (NODE_NAME (cur, store)) {
614 eff = (eff_t*) parseStore (doc, cur);
615 } else if (NODE_NAME (cur, alloc)) {
616 eff = (eff_t*) parseAlloc (doc, cur);
617 } else if (NODE_NAME (cur, call)) {
618 eff = (eff_t*) parseCall (doc, cur);
619 } else if (NODE_NAME (cur, join)) {
620 eff = (eff_t*) parseJoin (doc, cur);
621 } else if (NODE_NAME (cur, unknown)) {
622 eff = (eff_t*) parseUnknown (doc, cur);
623 } else if (NODE_NAME (cur, ret)) {
624 eff = (eff_t*) parseReturn (doc, cur);
625 } else if (NODE_NAME (cur, raise)) {
626 eff = (eff_t*) parseRaise (doc, cur);
627 } else if (NODE_NAME (cur, comment)) {
631 fprintf (stderr, "wrong element \"%s\"\n", BAD_CAST cur->name);
635 VERBOSE_PRINT ((stdout, "effect %p@%d\n", (void*)eff, i));
636 curr_effs -> effs[i++] = eff;
640 assert((i == n_effs) && "incorrect number of effects");
641 curr_effs -> n_effs = n_effs;
642 curr_effs -> next = procs;
648 void read_extern (const char *filename)
650 /* xmlNsPtr ns = NULL; */ /* no namespace for us */
651 xmlDocPtr doc; /* whole document */
652 xmlNodePtr cur; /* current node */
656 /* i've got no idea what the VERSION cast is all about. voodoo
657 programming at its finest. */
658 LIBXML_TEST_VERSION xmlKeepBlanksDefault (0);
659 VERBOSE_PRINT((stdout, "read file %s\n", filename));
660 doc = xmlParseFile (filename);
661 CHECK (doc, "xmlParseFile");
663 cur = xmlDocGetRootElement (doc);
664 CHECK (cur, "xmlDocGetRootElement");
666 if (! NODE_NAME (cur, effects)) {
667 fprintf (stderr,"root node \"%s\" != \"effects\"\n", BAD_CAST cur->name);
672 mod_str = getNodeModule (cur);
673 if (NULL != mod_str) {
674 VERBOSE_PRINT ((stdout, "effects for \"%s\"\n", mod_str));
677 VERBOSE_PRINT ((stdout, "effects \t0x%08x\n", (int) cur));
681 cur = cur->xmlChildrenNode;
682 while (cur != NULL) {
683 if (NODE_NAME (cur, type)) {
684 parseType (doc, cur);
685 } else if (NODE_NAME (cur, entity)) {
686 parseEntity (doc, cur);
687 } else if (NODE_NAME (cur, effect)) {
688 parseEffect (doc, cur);
689 } else if ((NODE_NAME (cur, comment))) {
692 fprintf (stderr, "wrong element \"%s\"\n", BAD_CAST cur->name);
698 module = NEW(module_t);
699 module -> name = mod_str;
700 module -> types = types;
701 module -> entities = entities;
702 module -> procs = procs;
708 module -> next = modules;
712 /********************************************************************/
715 * free additional structure
718 void freeArg (eff_t *arg)
720 VERBOSE_PRINT ((stdout, "free arg node \t0x%08x\n", (int) arg));
726 void freeValref (eff_t *valref)
728 VERBOSE_PRINT ((stdout, "free valref node \t0x%08x\n", (int) valref));
734 void freeSelect (eff_t *sel)
736 VERBOSE_PRINT ((stdout, "free select node \t0x%08x\n", (int) sel));
742 void freeLoad (eff_t *load)
744 VERBOSE_PRINT ((stdout, "free load node \t0x%08x\n", (int) load));
750 void freeStore (eff_t *store)
752 VERBOSE_PRINT ((stdout, "free store node \t0x%08x\n", (int) store));
758 void freeAlloc (eff_t *alloc)
760 VERBOSE_PRINT ((stdout, "free alloc node \t0x%08x\n", (int) alloc));
766 void freeCall (eff_t *call)
768 VERBOSE_PRINT ((stdout, "free call node \t0x%08x\n", (int) call));
769 free(call -> effect.call.args);
775 void freeJoin (eff_t *join)
777 VERBOSE_PRINT ((stdout, "free join node \t0x%08x\n", (int) join));
778 free(join -> effect.join.ins);
784 void freeUnknown (eff_t *unknown)
786 VERBOSE_PRINT ((stdout, "free unknown node \t0x%08x\n", (int) unknown));
792 void freeReturn (eff_t *ret)
794 VERBOSE_PRINT ((stdout, "free ret node \t0x%08x\n", (int) ret));
800 void freeRaise (eff_t *raise)
802 VERBOSE_PRINT ((stdout, "free raise node \t0x%08x\n", (int) raise));
809 void freeProcEffs(proc_t *proc)
814 VERBOSE_PRINT ((stdout,
815 "free effect for method \"%s\"\n", proc -> procname));
816 num = proc -> n_effs;
817 for(i = 0; i < num; i++) {
818 switch(proc -> effs[i] -> kind) {
820 freeArg(proc -> effs[i]);
823 freeValref(proc -> effs[i]);
826 freeSelect(proc -> effs[i]);
829 freeLoad(proc -> effs[i]);
832 freeStore(proc -> effs[i]);
835 freeAlloc(proc -> effs[i]);
838 freeCall(proc -> effs[i]);
841 freeUnknown(proc -> effs[i]);
844 freeJoin(proc -> effs[i]);
847 freeRaise(proc -> effs[i]);
850 freeReturn(proc -> effs[i]);
853 assert(0 && "try to free an unknown effect");
859 free((void*)proc -> procname);
860 proc -> procname = NULL;
864 void freeModuleProcs(module_t *module)
866 proc_t *next_proc, *proc;
868 VERBOSE_PRINT ((stdout,
869 "free procs for module \"%s\"\n", module -> name));
870 proc = module -> procs;
872 next_proc = proc -> next;
882 module_t *module, *next_module;
886 freeModuleProcs(module);
887 free((char*)module -> name);
888 next_module = module -> next;
890 module = next_module;
894 /********************************************************************/
897 type_t *find_type_in_module(module_t *module, firmid_t typeid)
901 for(type = module -> types; type; type = type -> prev) {
902 VERBOSE_PRINT((stdout, "test typeid %s\n", type -> id));
903 if(0 == strcmp(type -> id, typeid)) {
907 VERBOSE_PRINT((stdout, "did not find type id %s\n", typeid));
911 /********************************************************************/
913 static void add_value_to_proc(proc_t *proc, eff_t *eff)
915 eff -> next = proc -> values;
916 proc -> values = eff;
920 eff_t *find_valueid_in_proc_effects(firmid_t id, proc_t *proc)
924 val = proc -> values;
926 if(0 == strcmp(id, val -> id)) {
934 static void create_abstract_return(ir_graph *irg, proc_t *proc, eff_t *eff)
939 VERBOSE_PRINT((stdout, "create effect:return in %s\n", proc -> procname));
940 if(NO_ID == eff -> effect.ret.ret_id) {
942 x = new_Return (get_store(), 0, NULL);
947 /* return one value */
948 eff_res = find_valueid_in_proc_effects(eff -> effect.ret.ret_id, proc);
949 assert(eff_res -> firmnode && "firm in effect not set");
950 in[0] = eff_res -> firmnode;
951 x = new_Return (get_store(), 1, in);
955 /* Now we generated all instructions for this block and all its predecessor
956 * blocks so we can mature it. (There are not too much.) */
957 mature_immBlock (get_irg_current_block(irg));
959 /* This adds the in edge of the end block which originates at the return statement.
960 * The return node passes controlflow to the end block. */
961 add_immBlock_pred (get_irg_end_block(irg), x);
965 static void create_abstract_arg(ir_graph *irg, proc_t *proc, eff_t *eff)
973 VERBOSE_PRINT((stdout, "create effect:arg %d in %s\n",
974 eff -> effect.arg.num, proc -> procname));
975 ent = get_irg_entity(irg);
976 typ = get_entity_type(ent);
978 /* read argument eff -> effect.arg.num and place in values list */
979 num = get_method_n_params(typ);
980 assert((num >= eff -> effect.arg.num) && "number too big");
981 typ = get_method_param_type(typ, eff -> effect.arg.num);
982 mode = get_type_mode(typ);
984 arg = new_Proj(get_irg_args(irg), mode, eff -> effect.arg.num);
985 eff -> firmnode = arg;
987 add_value_to_proc(proc, eff);
991 static void create_abstract_load(ir_graph *irg, proc_t *proc, eff_t *eff)
998 VERBOSE_PRINT((stdout, "create load in %s\n", proc -> procname));
1000 ent = eff -> effect.load.ent -> f_ent;
1001 VERBOSE_PRINT((stdout, "load from %s\n", get_entity_name(ent)));
1003 addr = find_valueid_in_proc_effects(eff -> effect.load.ptrrefid, proc);
1004 assert(addr && "no address for load");
1005 /* if addr is Unknown, set propper mode */
1006 if(iro_Unknown == get_irn_opcode(addr -> firmnode)) {
1007 set_irn_mode(addr -> firmnode, mode_P);
1010 sel = new_simpleSel(get_store(), addr -> firmnode, ent);
1011 mode = get_type_mode(get_entity_type(ent));
1012 load = new_Load(get_store(), sel, mode);
1013 set_store(new_Proj(load, mode_M, 0));
1014 eff -> firmnode = new_Proj(load, mode, 2);
1016 add_value_to_proc(proc, eff);
1020 static void create_abstract_store(ir_graph *irg, proc_t *proc, eff_t *eff)
1022 ir_node *sel, *store;
1026 VERBOSE_PRINT((stdout, "create store in %s\n", proc -> procname));
1028 ent = eff -> effect.store.ent -> f_ent;
1029 VERBOSE_PRINT((stdout, "store to %s\n", get_entity_name(ent)));
1031 addr = find_valueid_in_proc_effects(eff -> effect.store.ptrrefid, proc);
1032 assert(addr && "no address for store");
1033 /* if addr is Unknown, set propper mode */
1034 if(iro_Unknown == get_irn_opcode(addr -> firmnode)) {
1035 set_irn_mode(addr -> firmnode, mode_P);
1038 val = find_valueid_in_proc_effects(eff -> effect.store.valrefid, proc);
1039 assert(val && "no address for store");
1040 /* if addr is Unknown, set propper mode */
1041 if(iro_Unknown == get_irn_opcode(val -> firmnode)) {
1042 set_irn_mode(val -> firmnode, get_type_mode(get_entity_type(ent)));
1045 sel = new_simpleSel(get_store(), addr -> firmnode, ent);
1046 store = new_Store(get_store(), sel, val -> firmnode);
1047 set_store(new_Proj(store, mode_M, 0));
1048 eff -> firmnode = store;
1052 static void create_abstract_alloc(ir_graph *irg, proc_t *proc, eff_t *eff)
1057 symconst_symbol sym;
1059 VERBOSE_PRINT((stdout, "create alloc in %s\n", proc -> procname));
1061 xtype = find_type_in_module(current_module, eff -> effect.alloc.tp_id);
1062 assert(xtype && "type not found");
1063 ftype = xtype -> f_tp;
1066 alloc = new_Alloc(get_store(), new_SymConst(sym, symconst_size), ftype,
1068 set_store(new_Proj(alloc, mode_M, 0));
1069 eff -> firmnode = new_Proj(alloc, mode_P, 2);
1071 add_value_to_proc(proc, eff);
1075 static void create_abstract_unknown(ir_graph *irg, proc_t *proc, eff_t *eff)
1079 VERBOSE_PRINT((stdout, "create unknown in %s\n", proc -> procname));
1081 unknown = new_Unknown(mode_ANY);
1082 eff -> firmnode = unknown;
1084 add_value_to_proc(proc, eff);
1088 static void create_abstract_call(ir_graph *irg, proc_t *proc, eff_t *eff)
1090 ir_node *sel, *call;
1097 VERBOSE_PRINT((stdout, "create call in %s\n", proc -> procname));
1099 ent = eff -> effect.call.ent -> f_ent;
1100 VERBOSE_PRINT((stdout, "call %s\n", get_entity_name(ent)));
1102 addr = find_valueid_in_proc_effects(eff -> effect.call.valrefid, proc);
1103 assert(addr && "no address for load");
1104 /* if addr is Unknown, set propper mode */
1105 if(iro_Unknown == get_irn_opcode(addr -> firmnode)) {
1106 set_irn_mode(addr -> firmnode, mode_P);
1110 sel = new_simpleSel(get_store(), addr -> firmnode, ent);
1112 mtype = get_entity_type(ent);
1114 num = eff -> effect.call.n_args;
1115 VERBOSE_PRINT((stdout, "number of args given: %d\n", num));
1116 VERBOSE_PRINT((stdout, "number of args expected: %d\n",
1117 get_method_n_params(mtype)));
1118 irns = alloca(num * sizeof(ir_node*));
1119 for(i = 0; i < num; i++) {
1120 irns[i] = find_valueid_in_proc_effects(eff -> effect.call.args[i], proc)
1122 if(iro_Unknown == get_irn_opcode(irns[i])) {
1123 set_irn_mode(irns[i], get_type_mode(get_method_param_type(mtype, i)));
1126 call = new_Call(get_store(), sel, num, irns, get_entity_type(ent));
1127 set_store(new_Proj(call, mode_M, 0));
1128 // eff -> firmnode = new_Proj(store, mode, 2);
1129 eff -> firmnode = call;
1131 add_value_to_proc(proc, eff);
1135 static void create_abstract_firm(module_t *module, proc_t *proc, entity *fent)
1141 /* create irg in entity */
1142 irg = new_ir_graph(fent, 0);
1144 VERBOSE_PRINT((stdout, "create effects for %s\n", proc -> procname));
1145 /* create effects in irg */
1146 num = proc -> n_effs;
1147 for(i = 0; i < num; i++) {
1148 eff = proc -> effs[i];
1149 VERBOSE_PRINT((stdout,
1150 "create effect \"%s\"\n", effect_string[(int)eff -> kind]));
1151 switch(eff -> kind) {
1153 create_abstract_return(irg, proc, eff);
1156 create_abstract_arg(irg, proc, eff);
1159 create_abstract_load(irg, proc, eff);
1162 create_abstract_store(irg, proc, eff);
1165 create_abstract_unknown(irg, proc, eff);
1168 create_abstract_alloc(irg, proc, eff);
1171 create_abstract_call(irg, proc, eff);
1174 assert(0 && "effect not implemented");
1179 /* close irg in entity */
1180 /* Now we can mature the end block as all it's predecessors are known. */
1181 mature_immBlock (get_irg_end_block(irg));
1183 /* Verify the graph. Finds some very bad errors in the graph. */
1184 VERBOSE_PRINT((stdout, "verify graph\n"));
1186 VERBOSE_PRINT((stdout, "finalize construction\n"));
1187 finalize_cons (irg);
1190 /********************************************************************/
1192 static void assign_firm_entity(module_t *module, entity_t *xmlent)
1199 VERBOSE_PRINT((stdout, "assign entity %s to typeid %s\n",
1200 xmlent -> name, xmlent -> owner));
1201 typ = find_type_in_module(module, xmlent -> owner);
1202 assert(typ && "class not found in module");
1204 assert(is_class_type(type));
1206 num = get_class_n_members(type);
1208 for(i = 0; i < num; i++) {
1209 ent = get_class_member(type, i);
1210 VERBOSE_PRINT((stdout, "compare entity %s and %s\n",
1211 xmlent -> name, get_entity_name(ent)));
1212 if(0 == strcmp(get_entity_name(ent), xmlent -> name)) {
1217 assert(ent && "did not find a entity");
1219 xmlent -> f_ent = ent;
1222 /********************************************************************/
1223 /* must be primitive type or class type */
1224 static void assign_firm_type(type_t *xmltype)
1230 VERBOSE_PRINT((stdout, "assign type %s\n", xmltype -> name));
1231 /* is it global type? */
1232 typ = get_glob_type();
1233 if(0 == strcmp(xmltype -> name, get_type_name(typ))) {
1235 xmltype -> f_tp = typ;
1236 VERBOSE_PRINT((stdout, "is global type %s\n", get_type_name(typ)));
1239 num = get_irp_n_types();
1240 for(i = 0; i < num; i++) {
1241 typ = get_irp_type(i);
1242 VERBOSE_PRINT((stdout, "test type %s\n", get_type_name(typ)));
1243 if(0 == strcmp(xmltype -> name, get_type_name(typ))) {
1244 VERBOSE_PRINT((stdout, "found type %s\n", get_type_name(typ)));
1245 xmltype -> f_tp = typ;
1251 assert(typ && "did not find a type");
1254 /********************************************************************/
1256 void create_abstract_proc_effect(module_t *module, proc_t *proc)
1259 type *class_typ = NULL;
1263 /* find the class of a procedure */
1264 VERBOSE_PRINT((stdout, "do find typeid %s\n", proc -> typeid));
1265 type = find_type_in_module(module, proc -> typeid);
1266 assert(type && "class not found in module");
1268 class_typ = get_glob_type();
1269 VERBOSE_PRINT((stdout, "test type %s\n", get_type_name(class_typ)));
1270 if(0 != strcmp(type -> name, get_type_name(class_typ))) {
1271 /* find module as class */
1272 num = get_irp_n_types();
1273 for(i = 0; i < num; i++) {
1274 class_typ = get_irp_type(i);
1275 VERBOSE_PRINT((stdout, "test type %s\n", get_type_name(class_typ)));
1276 if(is_class_type(class_typ)
1277 && (0 == strcmp(type -> name, get_type_name(class_typ)))) {
1278 /* found class type */
1279 VERBOSE_PRINT((stdout, "found type %s\n", get_type_name(class_typ)));
1286 VERBOSE_PRINT((stdout, "found global type %s\n", get_type_name(class_typ)));
1288 assert(class_typ && "type not found");
1289 assert(is_class_type(class_typ) && "is not a class type");
1290 type -> f_tp = class_typ;
1292 /* find entity for procedure in class */
1293 VERBOSE_PRINT((stdout, "find method %s\n", proc -> procname));
1294 num = get_class_n_members(class_typ);
1296 for(i = 0; i < num; i++) {
1297 fent = get_class_member(class_typ, i);
1298 VERBOSE_PRINT((stdout, "test proc %s\n", get_entity_name(fent)));
1299 if(0 == strcmp(proc -> procname, get_entity_name(fent))) {
1300 VERBOSE_PRINT((stdout, "found proc %s\n", proc -> procname));
1301 /* @@@ TODO check args types - not in xml yet */
1302 /* create Firm stuff */
1303 create_abstract_firm(module, proc, fent);
1310 assert(fent && "procedure not found in class");
1314 void create_abstract_module(module_t *module)
1320 VERBOSE_PRINT((stdout,
1321 "create an abstraction for module %s\n", module -> name));
1323 VERBOSE_PRINT((stdout, "--handle types for module %s\n", module -> name));
1324 for(type = module -> types; type; type = type -> prev) {
1325 assign_firm_type(type);
1328 VERBOSE_PRINT((stdout, "--handle entities for module %s\n", module -> name));
1330 for(ent = module -> entities; ent; ent = ent -> prev) {
1331 assign_firm_entity(module, ent);
1334 VERBOSE_PRINT((stdout, "--handle procs for module %s\n", module -> name));
1335 for(proc = module -> procs; proc; proc = proc -> next) {
1336 create_abstract_proc_effect(module, proc);
1341 void create_abstraction(const char *filename)
1345 /* read and parse XML file */
1346 read_extern(filename);
1348 /* finished reading and parsing here */
1349 /* build FIRM graphs */
1352 current_module = module;
1353 create_abstract_module(module);
1354 module = module -> next;
1356 current_module = NULL;
1358 /* free data structures */
1362 /********************************************************************/
1367 * Revision 1.7 2004/10/21 15:31:55 boesler
1368 * added lots of stuff:
1369 * - build abstract syntax trees
1370 * - build Firm graphs for many effects, still todos
1372 * Revision 1.5 2004/10/18 12:48:20 liekweg
1375 * Revision 1.4 2004/10/14 11:31:53 liekweg
1378 * Revision 1.3 2004/10/13 13:36:28 rubino
1381 * Revision 1.2 2004/10/11 15:56:09 liekweg
1382 * Cleanup, comments ...
1383 * Added init func --flo
1385 * Revision 1.1 2004/10/11 09:31:06 liekweg
1386 * First Import of XML reading procs --flo