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 */
37 #define VERBOSE_PRINTING 0
40 # define VERBOSE_PRINT(s) fprintf s
42 # define VERBOSE_PRINT(s)
47 static type_t *types = NULL;
48 static entity_t *entities = NULL;
49 static proc_t *procs = NULL;
50 static module_t *modules = NULL;
53 static module_t *current_module = NULL;
55 static char *effect_string[] = {
70 getNodeModuleIdent (xmlNodePtr node)
72 const char *mod_str = (const char*) xmlGetProp (node, BAD_CAST "module");
74 if (NULL == mod_str) {
77 const ident *res = new_id_from_str (mod_str);
83 getNodeProcName (xmlNodePtr node)
85 const char *proc_str = (const char*) xmlGetProp (node, BAD_CAST "procname");
91 getNodeClassName (xmlNodePtr node)
93 char *proc_str = (char*) xmlGetProp (node, BAD_CAST "class");
99 getNodeId (xmlNodePtr node)
101 const char *id_str = (const char*) xmlGetProp (node, BAD_CAST "id");
107 getNodeRefId (xmlNodePtr node)
109 const char *refid_str = (char*) xmlGetProp (node, BAD_CAST "refid");
111 return ((refid_str));
115 getNodeTypeId (xmlNodePtr node)
117 const char *type_str = (char*) xmlGetProp (node, BAD_CAST "type");
123 *getNodeTypeStr (xmlNodePtr node)
125 const char *type_str = (char*) xmlGetProp (node, BAD_CAST "type");
131 getNodeOwnerStr (xmlNodePtr node)
133 const char *owner_str = (char*) xmlGetProp (node, BAD_CAST "owner");
139 *getNodeEntityStr (xmlNodePtr node)
141 const char *ent_str = (char*) xmlGetProp (node, BAD_CAST "entity");
152 type_t *getTypeByIdent (const ident *id)
154 type_t *curr = types; // @@@ TODO module -> types
156 while (NULL != curr) {
157 if (id == curr -> type_ident) {
167 type_t *getTypeById (const ident *id)
169 type_t *curr = types; // which ones?
171 while (NULL != curr) {
172 if (id == curr -> id) {
182 entity_t *getEntityByIdents (const ident *name, const ident *tp_ident)
184 entity_t *curr = entities; // TODO module -> entities
186 while (NULL != curr) {
187 if ((name == curr -> ent_ident)
188 && (tp_ident == curr -> tp_ident)) {
198 entity_t *getEntityById (const ident *id)
200 entity_t *curr = entities;
202 while (NULL != curr) {
203 if (id == curr -> id) {
213 proc_t *getEffectByName (const ident *proc_ident)
215 proc_t *curr_effs = procs;
217 while (NULL != curr_effs) {
218 if (proc_ident == curr_effs -> proc_ident) {
221 curr_effs = curr_effs->next;
229 * parse XML structure and construct an additional structure
232 parseArg (xmlDocPtr doc, xmlNodePtr argelm)
240 CHECK_NAME (argelm, arg);
241 VERBOSE_PRINT ((stdout, "arg node \t0x%08x\n", (int) argelm));
243 id = getNodeId (argelm);
244 VERBOSE_PRINT ((stdout, "arg->id = \"%s\"\n", id));
245 num_str = (char*) xmlGetProp (argelm, BAD_CAST "number");
246 num = atoi (num_str);
247 VERBOSE_PRINT ((stdout, "arg->no = \"%d\"\n", num));
249 typeid = getNodeTypeStr (argelm);
252 arg -> kind = eff_arg;
253 arg -> id = new_id_from_str(id);
254 arg -> effect.arg.num = num;
255 arg -> effect.arg.type_ident = new_id_from_str(typeid);
261 *parseValref (xmlDocPtr doc, xmlNodePtr valelm)
266 CHECK_NAME (valelm, valref);
267 VERBOSE_PRINT ((stdout, "valref node \t0x%08x\n", (int) valelm));
269 ref_id = getNodeRefId (valelm);
270 VERBOSE_PRINT ((stdout, "val->refid = \"%s\"\n", ref_id));
272 valref = NEW (eff_t);
273 valref->kind = eff_valref;
274 valref-> id = new_id_from_str(ref_id);
280 *parseSelect (xmlDocPtr doc, xmlNodePtr selelm)
282 const ident *entity_id = new_id_from_str(getNodeEntityStr (selelm));
285 eff_t *valref = NULL;
286 eff_t *sel = NEW (eff_t);
287 sel->kind = eff_select;
289 CHECK_NAME (selelm, select);
290 VERBOSE_PRINT ((stdout, "select node \t0x%08x\n", (int) selelm));
292 ent = getEntityById (entity_id);
293 assert(ent && "entity not found");
294 VERBOSE_PRINT ((stdout, "select entity %s\n", get_id_str(ent -> ent_ident)));
296 child = selelm->xmlChildrenNode;
299 valref = parseValref (doc, child);
302 sel-> id = valref ? valref-> id : NO_ID;
303 sel-> effect.select.ent = ent;
313 *parseLoad (xmlDocPtr doc, xmlNodePtr loadelm)
318 eff_t *load = NEW (eff_t);
319 load->kind = eff_load;
321 CHECK_NAME (loadelm, load);
322 VERBOSE_PRINT ((stdout, "load node \t0x%08x\n", (int) loadelm));
323 id = new_id_from_str(getNodeId (loadelm));
325 child = loadelm->xmlChildrenNode;
326 sel = parseSelect (doc, child);
329 load-> effect.load.ptrrefid = sel-> id;
330 load-> effect.load.ent = sel-> effect.select.ent;
331 VERBOSE_PRINT ((stdout, "load entity \t%s\n",
332 get_id_str(load -> effect.load.ent -> ent_ident)));
340 *parseStore (xmlDocPtr doc, xmlNodePtr storeelm)
345 eff_t *store = NEW (eff_t);
346 store->kind = eff_store;
348 CHECK_NAME (storeelm, store);
349 VERBOSE_PRINT ((stdout, "store node \t0x%08x\n", (int) storeelm));
351 child = storeelm->xmlChildrenNode;
352 sel = parseSelect (doc, child);
354 valref = parseValref (doc, child);
356 store-> effect.store.ent = sel-> effect.select.ent;
357 store-> effect.store.ptrrefid = sel-> id;
358 store-> effect.store.valrefid = valref-> id;
367 *parseAlloc (xmlDocPtr doc, xmlNodePtr allocelm)
370 const ident *type_id;
371 eff_t *alloc = NEW (eff_t); /* ...! */
372 alloc->kind = eff_alloc;
374 CHECK_NAME (allocelm, alloc);
375 VERBOSE_PRINT ((stdout, "alloc node \t0x%08x\n", (int) allocelm));
376 id = new_id_from_str(getNodeId (allocelm));
377 VERBOSE_PRINT ((stdout, "alloc->id = \"%s\"\n", get_id_str(id)));
378 type_id = new_id_from_str(getNodeTypeId (allocelm));
379 VERBOSE_PRINT ((stdout, "alloc->type_id = \"%s\"\n", get_id_str(type_id)));
382 alloc-> effect.alloc.tp_id = type_id;
388 *parseCall (xmlDocPtr doc, xmlNodePtr callelm)
395 eff_t *call = NEW (eff_t);
396 call->kind = eff_call;
398 CHECK_NAME (callelm, call);
399 VERBOSE_PRINT ((stdout, "call node \t0x%08x\n", (int) callelm));
400 id = new_id_from_str(getNodeId (callelm));
401 VERBOSE_PRINT ((stdout, "call->id = \"%s\"\n", get_id_str(id)));
403 child = callelm->xmlChildrenNode;
404 sel = parseSelect (doc, child);
405 arg = child = child->next;
408 while (NULL != child) {
414 call-> effect.call.valrefid = sel-> id;
415 call-> effect.call.ent = sel-> effect.select.ent;
416 call-> effect.call.n_args = n_args;
417 call-> effect.call.args = NULL;
422 const ident **args = (const ident**) malloc(n_args * sizeof(const ident*));
425 while (NULL != arg) {
426 eff_t *valref = parseValref (doc, arg);
427 args [i ++] = valref-> id;
432 call-> effect.call.args = args;
439 *parseJoin (xmlDocPtr doc, xmlNodePtr joinelm)
446 eff_t *join = NEW (eff_t);
447 join->kind = eff_join;
449 CHECK_NAME (joinelm, join);
450 VERBOSE_PRINT ((stdout, "join node \t0x%08x\n", (int) joinelm));
451 id = new_id_from_str(getNodeId (joinelm));
452 VERBOSE_PRINT ((stdout, "join->id = \"%s\"\n", get_id_str(id)));
454 child = joinelm->xmlChildrenNode;
457 while (NULL != child) {
462 ins = (const ident **) malloc (n_ins * sizeof (const ident *) );
464 child = joinelm->xmlChildrenNode;
466 while (NULL != child) {
467 eff_t *valref = parseValref (doc, child);
468 ins [i ++] = valref-> id;
474 join-> effect.join.n_ins = n_ins;
475 join-> effect.join.ins = ins;
481 *parseUnknown (xmlDocPtr doc, xmlNodePtr unknownelm)
484 eff_t *unknown = NEW (eff_t);
485 unknown->kind = eff_unknown;
487 CHECK_NAME (unknownelm, unknown);
488 VERBOSE_PRINT ((stdout, "unknown node \t0x%08x\n", (int) unknownelm));
489 id = new_id_from_str(getNodeId (unknownelm));
496 *parseReturn (xmlDocPtr doc, xmlNodePtr retelm)
499 eff_t *ret = NEW (eff_t);
502 CHECK_NAME (retelm, ret);
503 VERBOSE_PRINT ((stdout, "ret node \t0x%08x\n", (int) retelm));
505 child = retelm->xmlChildrenNode;
508 eff_t *valref = parseValref (doc, child);
509 ret-> effect.ret.ret_id = valref-> id;
512 ret-> effect.ret.ret_id = NO_ID;
519 *parseRaise (xmlDocPtr doc, xmlNodePtr raiseelm)
524 eff_t *raise = NEW (eff_t);
525 raise->kind = eff_raise;
527 CHECK_NAME (raiseelm, raise);
528 VERBOSE_PRINT ((stdout, "raise node \t0x%08x\n", (int) raiseelm));
529 tp_id = getNodeTypeId (raiseelm);
530 VERBOSE_PRINT ((stdout, "raise->type = \"%s\"\n", tp_id));
531 child = raiseelm->xmlChildrenNode;
533 assert (NULL != child);
535 valref = parseValref (doc, child);
536 raise-> effect.raise.valref = valref-> id;
537 raise-> effect.raise.tp_id = new_id_from_str(tp_id);
548 /** parse a type node and insert it into the list */
550 parseType (xmlDocPtr doc, xmlNodePtr typeelm)
553 const char *tp_id = getNodeId (typeelm);
554 VERBOSE_PRINT ((stdout, "type node \t0x%08x (%s)\n", (int) typeelm, tp_id));
555 VERBOSE_PRINT ((stdout, "type = \"%s\"\n", getNodeTypeStr (typeelm)));
557 type = (type_t*) malloc (sizeof (type_t));
558 type -> type_ident = new_id_from_str(getNodeTypeStr (typeelm));
559 type -> id = new_id_from_str(tp_id);
565 /** parse an entity node and insert it into the list */
567 parseEntity (xmlDocPtr doc, xmlNodePtr entelm)
569 entity_t *ent = NEW (entity_t);
572 const char *ent_id = getNodeId (entelm);
573 /* fprintf (stdout, "entity node \t0x%08x (%d)\n", (int) entelm, ent_id); */
574 VERBOSE_PRINT ((stdout, "ent = \"%s.%s\"\n",
575 getNodeTypeStr (entelm),
576 getNodeEntityStr (entelm)));
579 ent -> ent_ident = new_id_from_str (getNodeEntityStr (entelm));
580 ent -> tp_ident = new_id_from_str (getNodeTypeStr (entelm));
581 ent -> owner = new_id_from_str (getNodeOwnerStr (entelm));
582 ent -> id = new_id_from_str(ent_id);
584 ent->prev = entities;
588 /** parse any effect, and turn it into an eff_t (TODO) */
590 parseEffect (xmlDocPtr doc, xmlNodePtr effelm)
593 const char *procname = getNodeProcName (effelm);
594 const char *typeid = getNodeTypeStr (effelm);
595 proc_t *curr_effs = NULL;
599 VERBOSE_PRINT ((stdout, "effect for method \"%s\"\n", procname));
601 cur = effelm -> xmlChildrenNode;
602 while (NULL != cur) {
606 VERBOSE_PRINT ((stdout, "has %d effects\n", n_effs));
608 curr_effs = NEW (proc_t);
609 curr_effs -> proc_ident = new_id_from_str(procname);
610 curr_effs -> typeid = new_id_from_str(typeid);
611 curr_effs->effs = (eff_t**) malloc (n_effs * sizeof (eff_t*));
613 cur = effelm -> xmlChildrenNode;
614 while (NULL != cur) {
617 if (NODE_NAME (cur, arg)) {
618 eff = (eff_t*) parseArg (doc, cur);
619 } else if (NODE_NAME (cur, load)) {
620 eff = (eff_t*) parseLoad (doc, cur);
621 } else if (NODE_NAME (cur, store)) {
622 eff = (eff_t*) parseStore (doc, cur);
623 } else if (NODE_NAME (cur, alloc)) {
624 eff = (eff_t*) parseAlloc (doc, cur);
625 } else if (NODE_NAME (cur, call)) {
626 eff = (eff_t*) parseCall (doc, cur);
627 } else if (NODE_NAME (cur, join)) {
628 eff = (eff_t*) parseJoin (doc, cur);
629 } else if (NODE_NAME (cur, unknown)) {
630 eff = (eff_t*) parseUnknown (doc, cur);
631 } else if (NODE_NAME (cur, ret)) {
632 eff = (eff_t*) parseReturn (doc, cur);
633 } else if (NODE_NAME (cur, raise)) {
634 eff = (eff_t*) parseRaise (doc, cur);
635 } else if (NODE_NAME (cur, comment)) {
639 fprintf (stderr, "wrong element \"%s\"\n", BAD_CAST cur->name);
643 VERBOSE_PRINT ((stdout, "effect %p@%d\n", (void*)eff, i));
644 curr_effs -> effs[i++] = eff;
648 assert((i == n_effs) && "incorrect number of effects");
649 curr_effs -> n_effs = n_effs;
650 curr_effs -> next = procs;
656 void read_extern (const char *filename)
658 /* xmlNsPtr ns = NULL; */ /* no namespace for us */
659 xmlDocPtr doc; /* whole document */
660 xmlNodePtr cur; /* current node */
664 /* i've got no idea what the VERSION cast is all about. voodoo
665 programming at its finest. */
666 LIBXML_TEST_VERSION xmlKeepBlanksDefault (0);
667 VERBOSE_PRINT((stdout, "read file %s\n", filename));
668 doc = xmlParseFile (filename);
669 CHECK (doc, "xmlParseFile");
671 cur = xmlDocGetRootElement (doc);
672 CHECK (cur, "xmlDocGetRootElement");
674 if (! NODE_NAME (cur, effects)) {
675 fprintf (stderr,"root node \"%s\" != \"effects\"\n", BAD_CAST cur->name);
680 mod_id = getNodeModuleIdent (cur);
681 if (NULL != mod_id) {
682 VERBOSE_PRINT ((stdout, "effects for \"%s\"\n",
683 get_id_str(mod_id)));
686 VERBOSE_PRINT ((stdout, "effects \t0x%08x\n", (int) cur));
690 cur = cur->xmlChildrenNode;
691 while (cur != NULL) {
692 if (NODE_NAME (cur, type)) {
693 parseType (doc, cur);
694 } else if (NODE_NAME (cur, entity)) {
695 parseEntity (doc, cur);
696 } else if (NODE_NAME (cur, effect)) {
697 parseEffect (doc, cur);
698 } else if ((NODE_NAME (cur, comment))) {
701 fprintf (stderr, "wrong element \"%s\"\n", BAD_CAST cur->name);
707 module = NEW(module_t);
708 module -> id = mod_id;
709 module -> types = types;
710 module -> entities = entities;
711 module -> procs = procs;
717 module -> next = modules;
721 /********************************************************************/
724 * free additional structure
727 void freeArg (eff_t *arg)
729 VERBOSE_PRINT ((stdout, "free arg node \t0x%08x\n", (int) arg));
735 void freeValref (eff_t *valref)
737 VERBOSE_PRINT ((stdout, "free valref node \t0x%08x\n", (int) valref));
743 void freeSelect (eff_t *sel)
745 VERBOSE_PRINT ((stdout, "free select node \t0x%08x\n", (int) sel));
751 void freeLoad (eff_t *load)
753 VERBOSE_PRINT ((stdout, "free load node \t0x%08x\n", (int) load));
759 void freeStore (eff_t *store)
761 VERBOSE_PRINT ((stdout, "free store node \t0x%08x\n", (int) store));
767 void freeAlloc (eff_t *alloc)
769 VERBOSE_PRINT ((stdout, "free alloc node \t0x%08x\n", (int) alloc));
775 void freeCall (eff_t *call)
777 VERBOSE_PRINT ((stdout, "free call node \t0x%08x\n", (int) call));
778 free(call -> effect.call.args);
784 void freeJoin (eff_t *join)
786 VERBOSE_PRINT ((stdout, "free join node \t0x%08x\n", (int) join));
787 free(join -> effect.join.ins);
793 void freeUnknown (eff_t *unknown)
795 VERBOSE_PRINT ((stdout, "free unknown node \t0x%08x\n", (int) unknown));
801 void freeReturn (eff_t *ret)
803 VERBOSE_PRINT ((stdout, "free ret node \t0x%08x\n", (int) ret));
809 void freeRaise (eff_t *raise)
811 VERBOSE_PRINT ((stdout, "free raise node \t0x%08x\n", (int) raise));
818 void freeProcEffs(proc_t *proc)
823 VERBOSE_PRINT ((stdout, "free effect for method \"%s\"\n",
824 get_id_str(proc -> proc_ident)));
826 num = proc -> n_effs;
827 for(i = 0; i < num; i++) {
828 switch(proc -> effs[i] -> kind) {
830 freeArg(proc -> effs[i]);
833 freeValref(proc -> effs[i]);
836 freeSelect(proc -> effs[i]);
839 freeLoad(proc -> effs[i]);
842 freeStore(proc -> effs[i]);
845 freeAlloc(proc -> effs[i]);
848 freeCall(proc -> effs[i]);
851 freeUnknown(proc -> effs[i]);
854 freeJoin(proc -> effs[i]);
857 freeRaise(proc -> effs[i]);
860 freeReturn(proc -> effs[i]);
863 assert(0 && "try to free an unknown effect");
872 void freeModuleProcs(module_t *module)
874 proc_t *next_proc, *proc;
876 VERBOSE_PRINT ((stdout, "free procs for module \"%s\"\n",
877 get_id_str(module -> id)));
879 proc = module -> procs;
881 next_proc = proc -> next;
891 module_t *module, *next_module;
895 freeModuleProcs(module);
896 next_module = module -> next;
898 module = next_module;
902 /********************************************************************/
905 type_t *find_type_in_module(module_t *module, const ident *typeid)
909 for(type = module -> types; type; type = type -> prev) {
910 VERBOSE_PRINT((stdout, "test typeid %s\n", get_id_str(type -> id)));
911 if(type -> id == typeid) {
912 VERBOSE_PRINT((stdout, "found\n"));
916 VERBOSE_PRINT((stdout, "did not find type id %s\n", get_id_str(typeid)));
920 /********************************************************************/
922 static void add_value_to_proc(proc_t *proc, eff_t *eff)
924 eff -> next = proc -> values;
925 proc -> values = eff;
929 eff_t *find_valueid_in_proc_effects(const ident *id, proc_t *proc)
933 val = proc -> values;
935 if(id == val -> id) {
943 static void create_abstract_return(ir_graph *irg, proc_t *proc, eff_t *eff)
948 VERBOSE_PRINT((stdout, "create effect:return in %s\n",
949 get_id_str(proc -> proc_ident)));
950 if(NO_ID == eff -> effect.ret.ret_id) {
952 x = new_Return (get_store(), 0, NULL);
957 /* return one value */
958 eff_res = find_valueid_in_proc_effects(eff -> effect.ret.ret_id, proc);
959 assert(eff_res -> firmnode && "firm in effect not set");
960 in[0] = eff_res -> firmnode;
961 x = new_Return (get_store(), 1, in);
965 /* Now we generated all instructions for this block and all its predecessor
966 * blocks so we can mature it. (There are not too much.) */
967 mature_immBlock (get_irg_current_block(irg));
969 /* This adds the in edge of the end block which originates at the return statement.
970 * The return node passes controlflow to the end block. */
971 add_immBlock_pred (get_irg_end_block(irg), x);
975 static void create_abstract_arg(ir_graph *irg, proc_t *proc, eff_t *eff)
983 VERBOSE_PRINT((stdout, "create effect:arg %d in %s\n",
984 eff -> effect.arg.num, get_id_str(proc -> proc_ident)));
985 ent = get_irg_entity(irg);
986 typ = get_entity_type(ent);
988 /* read argument eff -> effect.arg.num and place in values list */
989 num = get_method_n_params(typ);
990 assert((num >= eff -> effect.arg.num) && "number too big");
991 typ = get_method_param_type(typ, eff -> effect.arg.num);
992 mode = get_type_mode(typ);
994 arg = new_Proj(get_irg_args(irg), mode, eff -> effect.arg.num);
995 eff -> firmnode = arg;
997 add_value_to_proc(proc, eff);
1001 static void create_abstract_load(ir_graph *irg, proc_t *proc, eff_t *eff)
1003 ir_node *sel, *load;
1008 VERBOSE_PRINT((stdout, "create load in %s\n",
1009 get_id_str(proc -> proc_ident)));
1011 ent = eff -> effect.load.ent -> f_ent;
1012 VERBOSE_PRINT((stdout, "load from %s\n", get_entity_name(ent)));
1014 addr = find_valueid_in_proc_effects(eff -> effect.load.ptrrefid, proc);
1015 assert(addr && "no address for load");
1016 /* if addr is Unknown, set propper mode */
1017 if(iro_Unknown == get_irn_opcode(addr -> firmnode)) {
1018 set_irn_mode(addr -> firmnode, mode_P);
1021 sel = new_simpleSel(get_store(), addr -> firmnode, ent);
1022 mode = get_type_mode(get_entity_type(ent));
1023 load = new_Load(get_store(), sel, mode);
1024 set_store(new_Proj(load, mode_M, 0));
1025 eff -> firmnode = new_Proj(load, mode, 2);
1027 add_value_to_proc(proc, eff);
1031 static void create_abstract_store(ir_graph *irg, proc_t *proc, eff_t *eff)
1033 ir_node *sel, *store;
1037 VERBOSE_PRINT((stdout, "create store in %s\n",
1038 get_id_str(proc -> proc_ident)));
1040 ent = eff -> effect.store.ent -> f_ent;
1041 VERBOSE_PRINT((stdout, "store to %s\n", get_entity_name(ent)));
1043 addr = find_valueid_in_proc_effects(eff -> effect.store.ptrrefid, proc);
1044 assert(addr && "no address for store");
1045 /* if addr is Unknown, set propper mode */
1046 if(iro_Unknown == get_irn_opcode(addr -> firmnode)) {
1047 set_irn_mode(addr -> firmnode, mode_P);
1050 val = find_valueid_in_proc_effects(eff -> effect.store.valrefid, proc);
1051 assert(val && "no address for store");
1052 /* if addr is Unknown, set propper mode */
1053 if(iro_Unknown == get_irn_opcode(val -> firmnode)) {
1054 set_irn_mode(val -> firmnode, get_type_mode(get_entity_type(ent)));
1057 sel = new_simpleSel(get_store(), addr -> firmnode, ent);
1058 store = new_Store(get_store(), sel, val -> firmnode);
1059 set_store(new_Proj(store, mode_M, 0));
1060 eff -> firmnode = store;
1064 static void create_abstract_alloc(ir_graph *irg, proc_t *proc, eff_t *eff)
1069 symconst_symbol sym;
1071 VERBOSE_PRINT((stdout, "create alloc in %s\n",
1072 get_id_str(proc -> proc_ident)));
1074 xtype = find_type_in_module(current_module, eff -> effect.alloc.tp_id);
1075 assert(xtype && "type not found");
1076 ftype = xtype -> f_tp;
1079 alloc = new_Alloc(get_store(), new_SymConst(sym, symconst_size), ftype,
1081 set_store(new_Proj(alloc, mode_M, 0));
1082 eff -> firmnode = new_Proj(alloc, mode_P, 2);
1084 add_value_to_proc(proc, eff);
1088 static void create_abstract_unknown(ir_graph *irg, proc_t *proc, eff_t *eff)
1092 VERBOSE_PRINT((stdout, "create unknown in %s\n",
1093 get_id_str(proc -> proc_ident)));
1095 unknown = new_Unknown(mode_ANY);
1096 eff -> firmnode = unknown;
1098 add_value_to_proc(proc, eff);
1102 static void create_abstract_call(ir_graph *irg, proc_t *proc, eff_t *eff)
1104 ir_node *sel, *call;
1111 VERBOSE_PRINT((stdout, "create call in %s\n",
1112 get_id_str(proc -> proc_ident)));
1114 ent = eff -> effect.call.ent -> f_ent;
1115 VERBOSE_PRINT((stdout, "call %s\n", get_entity_name(ent)));
1117 addr = find_valueid_in_proc_effects(eff -> effect.call.valrefid, proc);
1118 assert(addr && "no address for load");
1119 /* if addr is Unknown, set propper mode */
1120 if(iro_Unknown == get_irn_opcode(addr -> firmnode)) {
1121 set_irn_mode(addr -> firmnode, mode_P);
1125 sel = new_simpleSel(get_store(), addr -> firmnode, ent);
1127 mtype = get_entity_type(ent);
1129 num = eff -> effect.call.n_args;
1130 VERBOSE_PRINT((stdout, "number of args given: %d\n", num));
1131 VERBOSE_PRINT((stdout, "number of args expected: %d\n",
1132 get_method_n_params(mtype)));
1133 irns = alloca(num * sizeof(ir_node*));
1134 for(i = 0; i < num; i++) {
1135 irns[i] = find_valueid_in_proc_effects(eff -> effect.call.args[i], proc)
1137 if(iro_Unknown == get_irn_opcode(irns[i])) {
1138 set_irn_mode(irns[i], get_type_mode(get_method_param_type(mtype, i)));
1141 call = new_Call(get_store(), sel, num, irns, get_entity_type(ent));
1142 set_store(new_Proj(call, mode_M, 0));
1143 if(0 != get_method_n_ress(mtype)) {
1144 eff -> firmnode = new_Proj(call,
1145 get_type_mode(get_method_res_type(mtype, 0)),
1147 add_value_to_proc(proc, eff); /* result can be accessed */
1150 eff -> firmnode = NULL; /* result can not be accessed */
1155 static void create_abstract_firm(module_t *module, proc_t *proc, entity *fent)
1162 assert(visibility_external_allocated == get_entity_visibility(fent)
1163 && peculiarity_existent == get_entity_peculiarity(fent)
1164 && "not an abstract entity");
1165 /* create irg in entity */
1166 irg = new_ir_graph(fent, 0);
1168 VERBOSE_PRINT((stdout, "create effects for %s\n",
1169 get_id_str(proc -> proc_ident)));
1171 /* create effects in irg */
1172 num = proc -> n_effs;
1173 for(i = 0; i < num; i++) {
1174 eff = proc -> effs[i];
1175 VERBOSE_PRINT((stdout,
1176 "create effect \"%s\"\n", effect_string[(int)eff -> kind]));
1177 switch(eff -> kind) {
1179 create_abstract_return(irg, proc, eff);
1182 create_abstract_arg(irg, proc, eff);
1185 create_abstract_load(irg, proc, eff);
1188 create_abstract_store(irg, proc, eff);
1191 create_abstract_unknown(irg, proc, eff);
1194 create_abstract_alloc(irg, proc, eff);
1197 create_abstract_call(irg, proc, eff);
1200 assert(0 && "effect not implemented");
1205 /* close irg in entity */
1206 /* Now we can mature the end block as all it's predecessors are known. */
1207 mature_immBlock (get_irg_end_block(irg));
1209 /* Verify the graph. Finds some very bad errors in the graph. */
1210 VERBOSE_PRINT((stdout, "verify graph\n"));
1212 VERBOSE_PRINT((stdout, "finalize construction\n"));
1213 finalize_cons (irg);
1216 /********************************************************************/
1218 static void assign_firm_entity(module_t *module, entity_t *xmlent)
1225 VERBOSE_PRINT((stdout, "assign entity %s to typeid %s\n",
1226 get_id_str(xmlent -> ent_ident),
1227 get_id_str(xmlent -> owner)));
1229 typ = find_type_in_module(module, xmlent -> owner);
1230 assert(typ && "class not found in module");
1232 assert(is_class_type(type));
1234 num = get_class_n_members(type);
1236 for(i = 0; i < num; i++) {
1237 ent = get_class_member(type, i);
1238 VERBOSE_PRINT((stdout, "compare entity %s and %s\n",
1239 get_id_str(xmlent -> ent_ident), get_entity_name(ent)));
1241 if(get_entity_ident(ent) == xmlent -> ent_ident) {
1246 assert(ent && "did not find a entity");
1248 xmlent -> f_ent = ent;
1251 /********************************************************************/
1252 /* must be primitive type or class type */
1253 static void assign_firm_type(type_t *xmltype)
1259 VERBOSE_PRINT((stdout, "assign firm type to type %s\n",
1260 get_id_str(xmltype -> type_ident)));
1262 /* is it global type? */
1263 typ = get_glob_type();
1264 if(xmltype -> type_ident == get_type_ident(typ)) {
1266 xmltype -> f_tp = typ;
1267 VERBOSE_PRINT((stdout, "is global type %s\n", get_type_name(typ)));
1270 num = get_irp_n_types();
1271 for(i = 0; i < num; i++) {
1272 typ = get_irp_type(i);
1273 VERBOSE_PRINT((stdout, "test type %s\n", get_type_name(typ)));
1274 if(xmltype -> type_ident == get_type_ident(typ)) {
1275 VERBOSE_PRINT((stdout, "found type %s\n", get_type_name(typ)));
1276 xmltype -> f_tp = typ;
1282 assert(typ && "did not find a type");
1285 /********************************************************************/
1287 void create_abstract_proc_effect(module_t *module, proc_t *proc)
1290 type *class_typ = NULL;
1294 /* find the class of a procedure */
1295 VERBOSE_PRINT((stdout, "do find typeid %s\n", get_id_str(proc -> typeid)));
1296 type = find_type_in_module(module, proc -> typeid);
1297 assert(type && "class not found in module");
1299 class_typ = get_glob_type();
1300 VERBOSE_PRINT((stdout, "test type %s\n", get_type_name(class_typ)));
1301 if(type -> type_ident != get_type_ident(class_typ)) {
1302 /* find module as class */
1303 num = get_irp_n_types();
1304 for(i = 0; i < num; i++) {
1305 class_typ = get_irp_type(i);
1306 VERBOSE_PRINT((stdout, "test type %s\n", get_type_name(class_typ)));
1307 if(is_class_type(class_typ)
1308 && (type -> type_ident == get_type_ident(class_typ))) {
1309 /* found class type */
1310 VERBOSE_PRINT((stdout, "found type %s\n", get_type_name(class_typ)));
1317 VERBOSE_PRINT((stdout, "found global type %s\n", get_type_name(class_typ)));
1319 assert(class_typ && "type not found");
1320 assert(is_class_type(class_typ) && "is not a class type");
1321 type -> f_tp = class_typ;
1323 /* find entity for procedure in class */
1324 VERBOSE_PRINT((stdout, "find method %s\n",
1325 get_id_str(proc -> proc_ident)));
1327 num = get_class_n_members(class_typ);
1329 for(i = 0; i < num; i++) {
1330 fent = get_class_member(class_typ, i);
1331 VERBOSE_PRINT((stdout, "test proc %s\n", get_entity_name(fent)));
1332 if(proc -> proc_ident == get_entity_ident(fent)) {
1333 VERBOSE_PRINT((stdout, "found proc %s\n",
1334 get_id_str(proc -> proc_ident)));
1335 /* @@@ TODO check args types - not in xml yet */
1336 /* create Firm stuff */
1337 create_abstract_firm(module, proc, fent);
1344 assert(fent && "procedure not found in class");
1348 void create_abstract_module(module_t *module)
1354 VERBOSE_PRINT((stdout, "create an abstraction for module %s\n",
1355 get_id_str(module -> id)));
1357 VERBOSE_PRINT((stdout, "--handle types for module\n"));
1358 for(type = module -> types; type; type = type -> prev) {
1359 assign_firm_type(type);
1362 VERBOSE_PRINT((stdout, "--handle entities for module\n"));
1364 for(ent = module -> entities; ent; ent = ent -> prev) {
1365 assign_firm_entity(module, ent);
1368 VERBOSE_PRINT((stdout, "--handle procs for module\n"));
1369 for(proc = module -> procs; proc; proc = proc -> next) {
1370 create_abstract_proc_effect(module, proc);
1375 void create_abstraction(const char *filename)
1379 /* read and parse XML file */
1380 read_extern(filename);
1382 /* finished reading and parsing here */
1383 /* build FIRM graphs */
1386 current_module = module;
1387 create_abstract_module(module);
1388 module = module -> next;
1390 current_module = NULL;
1392 /* free data structures */
1396 /********************************************************************/
1401 * Revision 1.8 2004/10/22 13:13:27 boesler
1402 * replaced char* by idents, minor fix in Firm codegen for call
1404 * Revision 1.7 2004/10/21 15:31:55 boesler
1405 * added lots of stuff:
1406 * - build abstract syntax trees
1407 * - build Firm graphs for many effects, still todos
1409 * Revision 1.5 2004/10/18 12:48:20 liekweg
1412 * Revision 1.4 2004/10/14 11:31:53 liekweg
1415 * Revision 1.3 2004/10/13 13:36:28 rubino
1418 * Revision 1.2 2004/10/11 15:56:09 liekweg
1419 * Cleanup, comments ...
1420 * Added init func --flo
1422 * Revision 1.1 2004/10/11 09:31:06 liekweg
1423 * First Import of XML reading procs --flo