From: Boris Boesler Date: Thu, 21 Oct 2004 15:31:55 +0000 (+0000) Subject: added lots of stuff: X-Git-Url: http://nsz.repo.hu/git/?a=commitdiff_plain;h=c2833257101eb926edbfc67e52dd207d3ae73714;p=libfirm added lots of stuff: - build abstract syntax trees - build Firm graphs for many effects, still todos [r4178] --- diff --git a/ir/external/Makefile.in b/ir/external/Makefile.in index e6e384e83..f6670146c 100644 --- a/ir/external/Makefile.in +++ b/ir/external/Makefile.in @@ -28,10 +28,10 @@ SOURCES += Makefile.in \ include $(topdir)/MakeRules -CPPFLAGS += -I$(top_srcdir)/ir/tr -I$(top_srcdir)/ir/ident \ - -I$(top_srcdir)/ir/common -I$(top_srcdir)/ir/ir \ - -I$(top_srcdir)/ir/debug \ - -I$(LIBXML2)/include/libxml2 +CPPFLAGS += -I$(top_srcdir)/ir/adt -I$(top_srcdir)/ir/ir -I$(top_srcdir)/ir/common \ + -I$(top_srcdir)/ir/ident -I$(top_srcdir)/ir/tr -I$(top_srcdir)/ir/tv \ + -I$(top_srcdir)/ir/debug -I$(top_srcdir)/ir/ana -I$(top_srcdir)/ir/st \ + -I$(top_srcdir)/ir/stat -I$(LIBXML2)/include/libxml2 include $(top_srcdir)/MakeTargets diff --git a/ir/external/read.c b/ir/external/read.c index 4cdcfca7d..44595fe60 100644 --- a/ir/external/read.c +++ b/ir/external/read.c @@ -5,22 +5,56 @@ * File name: ir/external/read.c * Purpose: Read descriptions of external effects * Author: Florian - * Modified by: + * Modified by: Boris Boesler * Created: 11.10.2004 - * CVS-ID: $$ + * CVS-ID: $Id$ * Copyright: (c) 1999-2004 Universität Karlsruhe * Licence: This file is protected by GPL - GNU GENERAL PUBLIC LICENSE. */ -# define _GNU_SOURCE + +#define _GNU_SOURCE +#include + # include "read.h" +#include "irprog.h" +#include "irgraph.h" +#include "ircons.h" +#include "irmode.h" +#include "irdump.h" +#include "irvrfy.h" +#include "type.h" +#include "tv.h" + +#if 0 +# define VERBOSE_PRINT(s) fprintf s +#else +# define VERBOSE_PRINT(s) +#endif + +#define NO_ID NULL static type_t *types = NULL; static entity_t *entities = NULL; -static effs_t *effs = NULL; - -static int _ent_id = 0; -/* static int _node_id = 0; */ +static proc_t *procs = NULL; +static module_t *modules = NULL; + +/* @@@ HACK */ +static module_t *current_module = NULL; + +static char *effect_string[] = { + "arg", + "valref", + "select", + "load", + "store", + "alloc", + "call", + "unknown", + "join", + "raise", + "ret" +}; static const char* getNodeModule (xmlNodePtr node) @@ -31,52 +65,48 @@ getNodeModule (xmlNodePtr node) return (NULL); } else { const char *res = strdup (mod_str); - return (res); } } -static char* +static const char* getNodeProcName (xmlNodePtr node) { - char *proc_str = (char*) xmlGetProp (node, BAD_CAST "procname"); - + const char *proc_str = (const char*) xmlGetProp (node, BAD_CAST "procname"); assert (proc_str); + return (strdup (proc_str)); +} +static char* +getNodeClassName (xmlNodePtr node) +{ + char *proc_str = (char*) xmlGetProp (node, BAD_CAST "class"); + assert (proc_str); return (strdup (proc_str)); } -static const int +static const char* getNodeId (xmlNodePtr node) { - char *id_str = (char*) xmlGetProp (node, BAD_CAST "id"); - int id; + const char *id_str = (const char*) xmlGetProp (node, BAD_CAST "id"); assert (id_str); - id = atoi (id_str+1); - - return (id); + return (strdup (id_str)); } -static const int +static firmid_t getNodeRefId (xmlNodePtr node) { - char *refid_str = (char*) xmlGetProp (node, BAD_CAST "refid"); - int refid; + firmid_t refid_str = (char*) xmlGetProp (node, BAD_CAST "refid"); assert (refid_str); - refid = atoi (refid_str+1); - - return (refid); + return (strdup(refid_str)); } -static const int +static firmid_t getNodeTypeId (xmlNodePtr node) { - char *type_str = (char*) xmlGetProp (node, BAD_CAST "type"); - int type_id; + firmid_t type_str = (char*) xmlGetProp (node, BAD_CAST "type"); assert (type_str); - type_id = atoi (type_str+1); - - return (type_id); + return (strdup(type_str)); } static const char @@ -88,6 +118,14 @@ static const char return (type_str); } +static const char* +getNodeOwnerStr (xmlNodePtr node) +{ + const char *owner_str = (char*) xmlGetProp (node, BAD_CAST "owner"); + assert (owner_str); + return (owner_str); +} + static const char *getNodeEntityStr (xmlNodePtr node) { @@ -97,64 +135,154 @@ static const char return (ent_str); } -static arg_t * + +/* + was Public Interface +*/ +static +type_t *getTypeByName (const char *name) +{ + type_t *curr = types; + + while (NULL != curr) { + if (0 == strcmp (name, curr->name)) { + return (curr); + } + curr = curr->prev; + } + + return (NULL); +} + +static +type_t *getTypeById (firmid_t id) +{ + type_t *curr = types; + + while (NULL != curr) { + if (0 == strcmp(id, curr->id)) { + return (curr); + } + curr = curr->prev; + } + + return (NULL); +} + +static +entity_t *getEntityByNames (const char *name, const char *tp_name) +{ + entity_t *curr = entities; + + while (NULL != curr) { + if ((0 == strcmp (name, curr->name)) + && (0 == strcmp (tp_name, curr->tp_name))) { + return (curr); + } + curr = curr->prev; + } + + return (NULL); +} + +static +entity_t *getEntityById (firmid_t id) +{ + entity_t *curr = entities; + + while (NULL != curr) { + if (0 == strcmp(id, curr->id)) { + return (curr); + } + curr = curr->prev; + } + + return (NULL); +} + +static +proc_t *getEffectByName (const char *procname) +{ + proc_t *curr_effs = procs; + + while (NULL != curr_effs) { + if (0 == strcmp (procname, curr_effs->procname)) { + return (curr_effs); + } + curr_effs = curr_effs->next; + } + + return (NULL); +} + + +/* + * parse XML structure and construct an additional structure + */ +static eff_t * parseArg (xmlDocPtr doc, xmlNodePtr argelm) { - int id; + const char *id; + const char *typeid; int num; char *num_str; - arg_t *arg; + eff_t *arg; CHECK_NAME (argelm, arg); - /* fprintf (stdout, "arg node \t0x%08x\n", (int) argelm); */ + VERBOSE_PRINT ((stdout, "arg node \t0x%08x\n", (int) argelm)); id = getNodeId (argelm); - /* fprintf (stdout, "arg->id = \"%d\"\n", id); */ + VERBOSE_PRINT ((stdout, "arg->id = \"%s\"\n", id)); num_str = (char*) xmlGetProp (argelm, BAD_CAST "number"); num = atoi (num_str); - /* fprintf (stdout, "arg->no = \"%d\"\n", no); */ + VERBOSE_PRINT ((stdout, "arg->no = \"%d\"\n", num)); - arg = NEW (arg_t); - arg->kind = eff_arg; - arg->id = id; - arg->num = num; + typeid = getNodeTypeStr (argelm); + + arg = NEW (eff_t); + arg -> kind = eff_arg; + arg -> id = id; + arg -> effect.arg.num = num; + arg -> effect.arg.type = typeid; return (arg); } -static valref_t +static eff_t *parseValref (xmlDocPtr doc, xmlNodePtr valelm) { - int ref_id; - valref_t *valref; + firmid_t ref_id; + eff_t *valref; + CHECK_NAME (valelm, valref); - /* fprintf (stdout, "valref node \t0x%08x\n", (int) valelm); */ + VERBOSE_PRINT ((stdout, "valref node \t0x%08x\n", (int) valelm)); ref_id = getNodeRefId (valelm); - /* fprintf (stdout, "val->refid = \"%d\"\n", ref_id); */ + VERBOSE_PRINT ((stdout, "val->refid = \"%s\"\n", ref_id)); - valref = NEW (valref_t); + valref = NEW (eff_t); valref->kind = eff_valref; - valref->refid = ref_id; + valref-> id = ref_id; return (valref); } -static select_t +static eff_t *parseSelect (xmlDocPtr doc, xmlNodePtr selelm) { - char *entity_str = (char*) xmlGetProp (selelm, BAD_CAST "entity"); - const int entity_id = atoi (entity_str+1); + firmid_t entity_id = getNodeEntityStr (selelm); entity_t *ent; xmlNodePtr child; - valref_t *valref = NULL; - select_t *sel = NEW (select_t); + eff_t *valref = NULL; + eff_t *sel = NEW (eff_t); sel->kind = eff_select; CHECK_NAME (selelm, select); - /* fprintf (stdout, "select node \t0x%08x\n", (int) selelm); */ + VERBOSE_PRINT ((stdout, "select node \t0x%08x\n", (int) selelm)); ent = getEntityById (entity_id); + assert(ent && "entity not found"); + VERBOSE_PRINT ((stdout, "select entity %s\n", ent -> name)); child = selelm->xmlChildrenNode; @@ -162,8 +290,8 @@ static select_t valref = parseValref (doc, child); } - sel->valrefid = valref ? valref->refid : -1; - sel->ent = ent; + sel-> id = valref ? valref-> id : NO_ID; + sel-> effect.select.ent = ent; if (valref) { free (valref); @@ -172,55 +300,54 @@ static select_t return (sel); } -static load_t +static eff_t *parseLoad (xmlDocPtr doc, xmlNodePtr loadelm) { - int id; + firmid_t id; xmlNodePtr child; - select_t *sel; - load_t *load = NEW (load_t); + eff_t *sel; + eff_t *load = NEW (eff_t); load->kind = eff_load; CHECK_NAME (loadelm, load); - /* fprintf (stdout, "load node \t0x%08x\n", (int) loadelm); */ + VERBOSE_PRINT ((stdout, "load node \t0x%08x\n", (int) loadelm)); id = getNodeId (loadelm); child = loadelm->xmlChildrenNode; sel = parseSelect (doc, child); - load->id = id; - load->ptrrefid = sel->valrefid; - load->ent = sel->ent; + load-> id = id; + load-> effect.load.ptrrefid = sel-> id; + load-> effect.load.ent = sel-> effect.select.ent; + VERBOSE_PRINT ((stdout, + "load entity \t%s\n", load -> effect.load.ent -> name)); free (sel); return (load); } -static store_t +static eff_t *parseStore (xmlDocPtr doc, xmlNodePtr storeelm) { xmlNodePtr child; - select_t *sel; - valref_t *valref; - store_t *store = NEW (store_t); + eff_t *sel; + eff_t *valref; + eff_t *store = NEW (eff_t); store->kind = eff_store; CHECK_NAME (storeelm, store); - /* fprintf (stdout, "store node \t0x%08x\n", (int) storeelm); */ + VERBOSE_PRINT ((stdout, "store node \t0x%08x\n", (int) storeelm)); child = storeelm->xmlChildrenNode; - sel = parseSelect (doc, child); - child = child->next; - valref = parseValref (doc, child); - store->ent = sel->ent; - store->ptrrefid = sel->valrefid; - store->valrefid = valref->refid; + store-> effect.store.ent = sel-> effect.select.ent; + store-> effect.store.ptrrefid = sel-> id; + store-> effect.store.valrefid = valref-> id; free (sel); free (valref); @@ -228,101 +355,95 @@ static store_t return (store); } -static alloc_t +static eff_t *parseAlloc (xmlDocPtr doc, xmlNodePtr allocelm) { - int id; - int type_id; - alloc_t *alloc = NEW (alloc_t); /* ...! */ + firmid_t id; + firmid_t type_id; + eff_t *alloc = NEW (eff_t); /* ...! */ alloc->kind = eff_alloc; CHECK_NAME (allocelm, alloc); - /* fprintf (stdout, "alloc node \t0x%08x\n", (int) allocelm); */ + VERBOSE_PRINT ((stdout, "alloc node \t0x%08x\n", (int) allocelm)); id = getNodeId (allocelm); - /* fprintf (stdout, "alloc->id = \"%d\"\n", id); */ + VERBOSE_PRINT ((stdout, "alloc->id = \"%s\"\n", id)); type_id = getNodeTypeId (allocelm); - /* fprintf (stdout, "alloc->type_id = \"%d\"\n", type_id); */ + VERBOSE_PRINT ((stdout, "alloc->type_id = \"%s\"\n", type_id)); - alloc->id = id; - alloc->tp_id = type_id; + alloc-> id = id; + alloc-> effect.alloc.tp_id = type_id; return (alloc); } -static call_t +static eff_t *parseCall (xmlDocPtr doc, xmlNodePtr callelm) { - int id; + firmid_t id; xmlNodePtr child; - select_t *sel; + eff_t *sel; xmlNodePtr arg; int n_args; - call_t *call = NEW (call_t); + eff_t *call = NEW (eff_t); call->kind = eff_call; CHECK_NAME (callelm, call); - /* fprintf (stdout, "call node \t0x%08x\n", (int) callelm); */ + VERBOSE_PRINT ((stdout, "call node \t0x%08x\n", (int) callelm)); id = getNodeId (callelm); - /* fprintf (stdout, "call->id = \"%d\"\n", id); */ + VERBOSE_PRINT ((stdout, "call->id = \"%s\"\n", id)); child = callelm->xmlChildrenNode; - sel = parseSelect (doc, child); - arg = child = child->next; - n_args = 0; while (NULL != child) { n_args ++; - child = child->next; } - call->id = id; - call->valrefid = sel->valrefid; - call->ent = sel->ent; - call->n_args = n_args; - call->args = NULL; + call-> id = id; + call-> effect.call.valrefid = sel-> id; + call-> effect.call.ent = sel-> effect.select.ent; + call-> effect.call.n_args = n_args; + call-> effect.call.args = NULL; free (sel); if (0 != n_args) { - int *args = (int*) malloc (n_args * sizeof (int) ); + firmid_t *args = (firmid_t*) malloc (n_args * sizeof (firmid_t) ); int i = 0; while (NULL != arg) { - valref_t *valref = parseValref (doc, arg); - args [i ++] = valref->refid; + eff_t *valref = parseValref (doc, arg); + args [i ++] = valref-> id; free (valref); - arg = arg->next; } - call->args = args; + call-> effect.call.args = args; } return (call); } -static join_t +static eff_t *parseJoin (xmlDocPtr doc, xmlNodePtr joinelm) { - int id; + firmid_t id; int n_ins; - int *ins; + firmid_t *ins; int i; xmlNodePtr child; - join_t *join = NEW (join_t); + eff_t *join = NEW (eff_t); join->kind = eff_join; CHECK_NAME (joinelm, join); - /* fprintf (stdout, "join node \t0x%08x\n", (int) joinelm); */ + VERBOSE_PRINT ((stdout, "join node \t0x%08x\n", (int) joinelm)); id = getNodeId (joinelm); - /* fprintf (stdout, "join->id = \"%d\"\n", id); */ + VERBOSE_PRINT ((stdout, "join->id = \"%s\"\n", id)); child = joinelm->xmlChildrenNode; - n_ins = 0; while (NULL != child) { @@ -330,93 +451,88 @@ static join_t child = child->next; } - ins = (int*) malloc (n_ins * sizeof (int) ); + ins = (firmid_t*) malloc (n_ins * sizeof (firmid_t) ); i = 0; - child = joinelm->xmlChildrenNode; while (NULL != child) { - valref_t *valref = parseValref (doc, child); - ins [i ++] = valref->refid; - + eff_t *valref = parseValref (doc, child); + ins [i ++] = valref-> id; + free(valref); child = child->next; } - join->id = id; - join->n_ins = n_ins; - join->ins = ins; + join-> id = id; + join-> effect.join.n_ins = n_ins; + join-> effect.join.ins = ins; return (join); } -static unknown_t +static eff_t *parseUnknown (xmlDocPtr doc, xmlNodePtr unknownelm) { - int id; - unknown_t *unknown = NEW (unknown_t); + firmid_t id; + eff_t *unknown = NEW (eff_t); unknown->kind = eff_unknown; CHECK_NAME (unknownelm, unknown); - /* fprintf (stdout, "unknown node \t0x%08x\n", (int) unknownelm); */ + VERBOSE_PRINT ((stdout, "unknown node \t0x%08x\n", (int) unknownelm)); id = getNodeId (unknownelm); - - unknown->id = id; + unknown-> id = id; return (unknown); } -static ret_t +static eff_t *parseReturn (xmlDocPtr doc, xmlNodePtr retelm) { xmlNodePtr child; - ret_t *ret = NEW (ret_t); + eff_t *ret = NEW (eff_t); ret->kind = eff_ret; CHECK_NAME (retelm, ret); - /* fprintf (stdout, "ret node \t0x%08x\n", (int) retelm); */ + VERBOSE_PRINT ((stdout, "ret node \t0x%08x\n", (int) retelm)); child = retelm->xmlChildrenNode; if (child) { - valref_t *valref = parseValref (doc, child); - ret->ret_id = valref->refid; + eff_t *valref = parseValref (doc, child); + ret-> effect.ret.ret_id = valref-> id; free (valref); } else { - ret->ret_id = -1; + ret-> effect.ret.ret_id = NO_ID; } return (ret); } -static raise_t +static eff_t *parseRaise (xmlDocPtr doc, xmlNodePtr raiseelm) { - int tp_id; - valref_t *valref; + firmid_t tp_id; + eff_t *valref; xmlNodePtr child; - raise_t *raise = NEW (raise_t); + eff_t *raise = NEW (eff_t); raise->kind = eff_raise; CHECK_NAME (raiseelm, raise); - /* fprintf (stdout, "raise node \t0x%08x\n", (int) raiseelm); */ - + VERBOSE_PRINT ((stdout, "raise node \t0x%08x\n", (int) raiseelm)); tp_id = getNodeTypeId (raiseelm); - /* fprintf (stdout, "raise->type = \"%d\"\n", tp_id); */ - + VERBOSE_PRINT ((stdout, "raise->type = \"%s\"\n", tp_id)); child = raiseelm->xmlChildrenNode; assert (NULL != child); valref = parseValref (doc, child); - - raise->valref = valref->refid; - raise->tp_id = tp_id; - + raise-> effect.raise.valref = valref-> id; + raise-> effect.raise.tp_id = tp_id; free (valref); return (raise); } + /* Types and Entities */ @@ -426,21 +542,16 @@ static void parseType (xmlDocPtr doc, xmlNodePtr typeelm) { type_t *type; - const int tp_id = getNodeId (typeelm); - /* fprintf (stdout, "type node \t0x%08x (%d)\n", (int) typeelm, tp_id); */ - fprintf (stdout, "type = \"%s\"\n", getNodeTypeStr (typeelm)); + firmid_t tp_id = getNodeId (typeelm); + VERBOSE_PRINT ((stdout, "type node \t0x%08x (%s)\n", (int) typeelm, tp_id)); + VERBOSE_PRINT ((stdout, "type = \"%s\"\n", getNodeTypeStr (typeelm))); type = (type_t*) malloc (sizeof (type_t)); - type->name = (char*) strdup (getNodeTypeStr (typeelm)); type->id = tp_id; type->prev = types; types = type; - - if (_ent_id <= tp_id) { - _ent_id = tp_id+1; - } } /** parse an entity node and insert it into the list */ @@ -450,47 +561,48 @@ parseEntity (xmlDocPtr doc, xmlNodePtr entelm) entity_t *ent = NEW (entity_t); /* parse it */ - const int ent_id = getNodeId (entelm); + firmid_t ent_id = getNodeId (entelm); /* fprintf (stdout, "entity node \t0x%08x (%d)\n", (int) entelm, ent_id); */ - fprintf (stdout, "ent = \"%s.%s\"\n", - getNodeTypeStr (entelm), - getNodeEntityStr (entelm)); + VERBOSE_PRINT ((stdout, "ent = \"%s.%s\"\n", + getNodeTypeStr (entelm), + getNodeEntityStr (entelm))); ent->name = (char*) strdup (getNodeEntityStr (entelm)); ent->tp_name = (char*) strdup (getNodeTypeStr (entelm)); + ent -> owner = (char*) strdup (getNodeOwnerStr (entelm)); ent->id = ent_id; ent->prev = entities; entities = ent; - - if (_ent_id <= ent_id) { - _ent_id = ent_id+1; - } } /** parse any effect, and turn it into an eff_t (TODO) */ static void parseEffect (xmlDocPtr doc, xmlNodePtr effelm) { - xmlNodePtr cur = effelm->xmlChildrenNode; - char *procname = getNodeProcName (effelm); - effs_t *curr_effs = NULL; + xmlNodePtr cur; + const char *procname = getNodeProcName (effelm); + const char *typeid = getNodeTypeStr (effelm); + proc_t *curr_effs = NULL; int i = 0; int n_effs = 0; - fprintf (stdout, "effect for \"%s\"\n", procname); + VERBOSE_PRINT ((stdout, "effect for method \"%s\"\n", procname)); + cur = effelm -> xmlChildrenNode; while (NULL != cur) { n_effs ++; cur = cur->next; } + VERBOSE_PRINT ((stdout, "has %d effects\n", n_effs)); - curr_effs = NEW (effs_t); + curr_effs = NEW (proc_t); curr_effs->procname = procname; - curr_effs->n_effs = n_effs; + curr_effs->typeid = typeid; curr_effs->effs = (eff_t**) malloc (n_effs * sizeof (eff_t*)); + cur = effelm -> xmlChildrenNode; while (NULL != cur) { eff_t *eff = NULL; @@ -514,252 +626,748 @@ parseEffect (xmlDocPtr doc, xmlNodePtr effelm) eff = (eff_t*) parseRaise (doc, cur); } else if (NODE_NAME (cur, comment)) { /* comment */ + --n_effs; } else { fprintf (stderr, "wrong element \"%s\"\n", BAD_CAST cur->name); exit (EXIT_FAILURE); } + if(eff) { + VERBOSE_PRINT ((stdout, "effect %p@%d\n", (void*)eff, i)); + curr_effs -> effs[i++] = eff; + } + cur = cur -> next; + } + assert((i == n_effs) && "incorrect number of effects"); + curr_effs -> n_effs = n_effs; + curr_effs -> next = procs; + procs = curr_effs; +} - cur = cur->next; - curr_effs->effs [i ++] = eff; +static +void read_extern (const char *filename) +{ + /* xmlNsPtr ns = NULL; */ /* no namespace for us */ + xmlDocPtr doc; /* whole document */ + xmlNodePtr cur; /* current node */ + const char *mod_str; + module_t *module; + + /* i've got no idea what the VERSION cast is all about. voodoo + programming at its finest. */ + LIBXML_TEST_VERSION xmlKeepBlanksDefault (0); + VERBOSE_PRINT((stdout, "read file %s\n", filename)); + doc = xmlParseFile (filename); + CHECK (doc, "xmlParseFile"); + + cur = xmlDocGetRootElement (doc); + CHECK (cur, "xmlDocGetRootElement"); + + if (! NODE_NAME (cur, effects)) { + fprintf (stderr,"root node \"%s\" != \"effects\"\n", BAD_CAST cur->name); + xmlFreeDoc (doc); + exit (EXIT_FAILURE); + } + + mod_str = getNodeModule (cur); + if (NULL != mod_str) { + VERBOSE_PRINT ((stdout, "effects for \"%s\"\n", mod_str)); + } + else { + VERBOSE_PRINT ((stdout, "effects \t0x%08x\n", (int) cur)); + } + + /* parse entities */ + cur = cur->xmlChildrenNode; + while (cur != NULL) { + if (NODE_NAME (cur, type)) { + parseType (doc, cur); + } else if (NODE_NAME (cur, entity)) { + parseEntity (doc, cur); + } else if (NODE_NAME (cur, effect)) { + parseEffect (doc, cur); + } else if ((NODE_NAME (cur, comment))) { + /* comment */ + } else { + fprintf (stderr, "wrong element \"%s\"\n", BAD_CAST cur->name); + exit (EXIT_FAILURE); + } + cur = cur->next; } - curr_effs->next = effs; - effs = curr_effs; + module = NEW(module_t); + module -> name = mod_str; + module -> types = types; + module -> entities = entities; + module -> procs = procs; + + types = NULL; + entities = NULL; + procs = NULL; + + module -> next = modules; + modules = module; } +/********************************************************************/ + /* - Public Interface -*/ -type_t *getTypeByName (const char *name) + * free additional structure + */ +static +void freeArg (eff_t *arg) { - type_t *curr = types; + VERBOSE_PRINT ((stdout, "free arg node \t0x%08x\n", (int) arg)); + free(arg); + return; +} - while (NULL != curr) { - if (0 == strcmp (name, curr->name)) { - return (curr); - } +static +void freeValref (eff_t *valref) +{ + VERBOSE_PRINT ((stdout, "free valref node \t0x%08x\n", (int) valref)); + free(valref); + return; +} - curr = curr->prev; - } +static +void freeSelect (eff_t *sel) +{ + VERBOSE_PRINT ((stdout, "free select node \t0x%08x\n", (int) sel)); + free(sel); + return; +} - return (NULL); +static +void freeLoad (eff_t *load) +{ + VERBOSE_PRINT ((stdout, "free load node \t0x%08x\n", (int) load)); + free (load); + return; } -type_t *getTypeById (const int id) +static +void freeStore (eff_t *store) { - type_t *curr = types; + VERBOSE_PRINT ((stdout, "free store node \t0x%08x\n", (int) store)); + free (store); + return; +} - while (NULL != curr) { - if (id == curr->id) { - return (curr); - } +static +void freeAlloc (eff_t *alloc) +{ + VERBOSE_PRINT ((stdout, "free alloc node \t0x%08x\n", (int) alloc)); + free(alloc); + return; +} - curr = curr->prev; - } +static +void freeCall (eff_t *call) +{ + VERBOSE_PRINT ((stdout, "free call node \t0x%08x\n", (int) call)); + free(call -> effect.call.args); + free(call); + return; +} - return (NULL); +static +void freeJoin (eff_t *join) +{ + VERBOSE_PRINT ((stdout, "free join node \t0x%08x\n", (int) join)); + free(join -> effect.join.ins); + free(join); + return; } -entity_t *getEntityByNames (const char *name, const char *tp_name) +static +void freeUnknown (eff_t *unknown) { - entity_t *curr = entities; + VERBOSE_PRINT ((stdout, "free unknown node \t0x%08x\n", (int) unknown)); + free(unknown); + return; +} - while (NULL != curr) { - if ((0 == strcmp (name, curr->name)) && (0 == strcmp (tp_name, curr->tp_name))) { - return (curr); +static +void freeReturn (eff_t *ret) +{ + VERBOSE_PRINT ((stdout, "free ret node \t0x%08x\n", (int) ret)); + free(ret); + return; +} + +static +void freeRaise (eff_t *raise) +{ + VERBOSE_PRINT ((stdout, "free raise node \t0x%08x\n", (int) raise)); + free (raise); + return; +} + + +static +void freeProcEffs(proc_t *proc) +{ + int i; + int num; + + VERBOSE_PRINT ((stdout, + "free effect for method \"%s\"\n", proc -> procname)); + num = proc -> n_effs; + for(i = 0; i < num; i++) { + switch(proc -> effs[i] -> kind) { + case eff_arg: + freeArg(proc -> effs[i]); + break; + case eff_valref: + freeValref(proc -> effs[i]); + break; + case eff_select: + freeSelect(proc -> effs[i]); + break; + case eff_load: + freeLoad(proc -> effs[i]); + break; + case eff_store: + freeStore(proc -> effs[i]); + break; + case eff_alloc: + freeAlloc(proc -> effs[i]); + break; + case eff_call: + freeCall(proc -> effs[i]); + break; + case eff_unknown: + freeUnknown(proc -> effs[i]); + break; + case eff_join: + freeJoin(proc -> effs[i]); + break; + case eff_raise: + freeRaise(proc -> effs[i]); + break; + case eff_ret: + freeReturn(proc -> effs[i]); + break; + default: + assert(0 && "try to free an unknown effect"); + break; } + } + free(proc -> effs); + proc -> effs = NULL; + free((void*)proc -> procname); + proc -> procname = NULL; +} - curr = curr->prev; +static +void freeModuleProcs(module_t *module) +{ + proc_t *next_proc, *proc; + + VERBOSE_PRINT ((stdout, + "free procs for module \"%s\"\n", module -> name)); + proc = module -> procs; + while(proc) { + next_proc = proc -> next; + freeProcEffs(proc); + free(proc); + proc = next_proc; } +} - return (NULL); +static +void free_data(void) +{ + module_t *module, *next_module; + + module = modules; + while(module) { + freeModuleProcs(module); + free((char*)module -> name); + next_module = module -> next; + free(module); + module = next_module; + } } -entity_t *getEntityById (const int id) +/********************************************************************/ + +static +type_t *find_type_in_module(module_t *module, firmid_t typeid) { - entity_t *curr = entities; + type_t *type; - while (NULL != curr) { - if (id == curr->id) { - return (curr); + for(type = module -> types; type; type = type -> prev) { + VERBOSE_PRINT((stdout, "test typeid %s\n", type -> id)); + if(0 == strcmp(type -> id, typeid)) { + return(type); } - - curr = curr->prev; } + VERBOSE_PRINT((stdout, "did not find type id %s\n", typeid)); + return(NULL); +} - return (NULL); +/********************************************************************/ + +static void add_value_to_proc(proc_t *proc, eff_t *eff) +{ + eff -> next = proc -> values; + proc -> values = eff; } -effs_t *getEffectByName (const char *procname) + +eff_t *find_valueid_in_proc_effects(firmid_t id, proc_t *proc) { - effs_t *curr_effs = effs; + eff_t *val; - while (NULL != curr_effs) { - if (0 == strcmp (procname, curr_effs->procname)) { - return (curr_effs); + val = proc -> values; + while(val) { + if(0 == strcmp(id, val -> id)) { + return(val); } + val = val -> next; + } + return(NULL); +} - curr_effs = curr_effs->next; +static void create_abstract_return(ir_graph *irg, proc_t *proc, eff_t *eff) +{ + ir_node *x; + eff_t *eff_res; + + VERBOSE_PRINT((stdout, "create effect:return in %s\n", proc -> procname)); + if(NO_ID == eff -> effect.ret.ret_id) { + /* return void */ + x = new_Return (get_store(), 0, NULL); } + else { + ir_node *in[1]; + + /* return one value */ + eff_res = find_valueid_in_proc_effects(eff -> effect.ret.ret_id, proc); + assert(eff_res -> firmnode && "firm in effect not set"); + in[0] = eff_res -> firmnode; + x = new_Return (get_store(), 1, in); + } + eff -> firmnode = x; - return (NULL); + /* Now we generated all instructions for this block and all its predecessor + * blocks so we can mature it. (There are not too much.) */ + mature_immBlock (get_irg_current_block(irg)); + + /* This adds the in edge of the end block which originates at the return statement. + * The return node passes controlflow to the end block. */ + add_immBlock_pred (get_irg_end_block(irg), x); } -void extern_init () + +static void create_abstract_arg(ir_graph *irg, proc_t *proc, eff_t *eff) { - /* nothing to do */ + ir_node *arg; + entity *ent; + ir_mode *mode; + type *typ; + int num; + + VERBOSE_PRINT((stdout, "create effect:arg %d in %s\n", + eff -> effect.arg.num, proc -> procname)); + ent = get_irg_entity(irg); + typ = get_entity_type(ent); + + /* read argument eff -> effect.arg.num and place in values list */ + num = get_method_n_params(typ); + assert((num >= eff -> effect.arg.num) && "number too big"); + typ = get_method_param_type(typ, eff -> effect.arg.num); + mode = get_type_mode(typ); + + arg = new_Proj(get_irg_args(irg), mode, eff -> effect.arg.num); + eff -> firmnode = arg; + + add_value_to_proc(proc, eff); } -void extern_read (const char *filename) -{ - /* xmlNsPtr ns = NULL; */ /* no namespace for us */ - xmlDocPtr doc; /* whole document */ - xmlNodePtr cur; /* current node */ - /* i've got no idea what the VERSION cast is all about. voodoo - programming at its finest. */ - LIBXML_TEST_VERSION xmlKeepBlanksDefault (0); - doc = xmlParseFile (filename); - CHECK (doc, "xmlParseFile"); +static void create_abstract_load(ir_graph *irg, proc_t *proc, eff_t *eff) +{ + ir_node *sel, *load; + entity *ent; + ir_mode *mode; + eff_t *addr; - cur = xmlDocGetRootElement (doc); - CHECK (cur, "xmlDocGetRootElement"); + VERBOSE_PRINT((stdout, "create load in %s\n", proc -> procname)); - if (! NODE_NAME (cur, effects)) { - fprintf (stderr,"root node \"%s\" != \"effects\"\n", BAD_CAST cur->name); - xmlFreeDoc (doc); + ent = eff -> effect.load.ent -> f_ent; + VERBOSE_PRINT((stdout, "load from %s\n", get_entity_name(ent))); - exit (EXIT_FAILURE); + addr = find_valueid_in_proc_effects(eff -> effect.load.ptrrefid, proc); + assert(addr && "no address for load"); + /* if addr is Unknown, set propper mode */ + if(iro_Unknown == get_irn_opcode(addr -> firmnode)) { + set_irn_mode(addr -> firmnode, mode_P); } - if (EXTERN_VERBOSE) { - const char *mod_str = getNodeModule (cur); + sel = new_simpleSel(get_store(), addr -> firmnode, ent); + mode = get_type_mode(get_entity_type(ent)); + load = new_Load(get_store(), sel, mode); + set_store(new_Proj(load, mode_M, 0)); + eff -> firmnode = new_Proj(load, mode, 2); - if (NULL != mod_str) { - fprintf (stdout, "effects for \"%s\"\n", mod_str); - free ((char*) mod_str); - } else { - fprintf (stdout, "effects \t0x%08x\n", (int) cur); - } - } + add_value_to_proc(proc, eff); +} - /* parse entities */ - cur = cur->xmlChildrenNode; - while (cur != NULL) { - if (NODE_NAME (cur, type)) { - parseType (doc, cur); - } else if (NODE_NAME (cur, entity)) { - parseEntity (doc, cur); - } else if (NODE_NAME (cur, effect)) { - parseEffect (doc, cur); - } else if ((NODE_NAME (cur, comment))) { - /* comment */ - } else { - fprintf (stderr, "wrong element \"%s\"\n", BAD_CAST cur->name); - exit (EXIT_FAILURE); - } - cur = cur->next; +static void create_abstract_store(ir_graph *irg, proc_t *proc, eff_t *eff) +{ + ir_node *sel, *store; + entity *ent; + eff_t *addr, *val; + + VERBOSE_PRINT((stdout, "create store in %s\n", proc -> procname)); + + ent = eff -> effect.store.ent -> f_ent; + VERBOSE_PRINT((stdout, "store to %s\n", get_entity_name(ent))); + + addr = find_valueid_in_proc_effects(eff -> effect.store.ptrrefid, proc); + assert(addr && "no address for store"); + /* if addr is Unknown, set propper mode */ + if(iro_Unknown == get_irn_opcode(addr -> firmnode)) { + set_irn_mode(addr -> firmnode, mode_P); + } + + val = find_valueid_in_proc_effects(eff -> effect.store.valrefid, proc); + assert(val && "no address for store"); + /* if addr is Unknown, set propper mode */ + if(iro_Unknown == get_irn_opcode(val -> firmnode)) { + set_irn_mode(val -> firmnode, get_type_mode(get_entity_type(ent))); } + + sel = new_simpleSel(get_store(), addr -> firmnode, ent); + store = new_Store(get_store(), sel, val -> firmnode); + set_store(new_Proj(store, mode_M, 0)); + eff -> firmnode = store; } -/** clean up our mess */ -void extern_cleanup () + +static void create_abstract_alloc(ir_graph *irg, proc_t *proc, eff_t *eff) { - /* the types */ - { - type_t *tp = types; + type *ftype; + ir_node *alloc; + type_t *xtype; + symconst_symbol sym; - while (NULL != tp) { - type_t *curr = tp; - tp = tp->prev; + VERBOSE_PRINT((stdout, "create alloc in %s\n", proc -> procname)); - free ((char*) curr->name); - memset (curr, 0x00, sizeof (type_t)); - free (curr); - } + xtype = find_type_in_module(current_module, eff -> effect.alloc.tp_id); + assert(xtype && "type not found"); + ftype = xtype -> f_tp; - types = NULL; - } + sym.type_p = ftype; + alloc = new_Alloc(get_store(), new_SymConst(sym, symconst_size), ftype, + heap_alloc); + set_store(new_Proj(alloc, mode_M, 0)); + eff -> firmnode = new_Proj(alloc, mode_P, 2); - /* the ennities */ - { - entity_t *ent = entities; + add_value_to_proc(proc, eff); +} - while (NULL != ent) { - entity_t *curr = ent; - ent = ent->prev; - free ((char*) curr->name); - free ((char*) curr->tp_name); - memset (curr, 0x00, sizeof (entity_t)); - free (curr); - } +static void create_abstract_unknown(ir_graph *irg, proc_t *proc, eff_t *eff) +{ + ir_node *unknown; + + VERBOSE_PRINT((stdout, "create unknown in %s\n", proc -> procname)); + + unknown = new_Unknown(mode_ANY); + eff -> firmnode = unknown; + + add_value_to_proc(proc, eff); +} + - entities = NULL; +static void create_abstract_call(ir_graph *irg, proc_t *proc, eff_t *eff) +{ + ir_node *sel, *call; + entity *ent; + eff_t *addr; + ir_node **irns; + int i, num; + type *mtype; + + VERBOSE_PRINT((stdout, "create call in %s\n", proc -> procname)); + + ent = eff -> effect.call.ent -> f_ent; + VERBOSE_PRINT((stdout, "call %s\n", get_entity_name(ent))); + + addr = find_valueid_in_proc_effects(eff -> effect.call.valrefid, proc); + assert(addr && "no address for load"); + /* if addr is Unknown, set propper mode */ + if(iro_Unknown == get_irn_opcode(addr -> firmnode)) { + set_irn_mode(addr -> firmnode, mode_P); } - /* the effs */ - { - effs_t *eff = effs; + /* the address */ + sel = new_simpleSel(get_store(), addr -> firmnode, ent); + /* mthod type */ + mtype = get_entity_type(ent); + /* the args */ + num = eff -> effect.call.n_args; + VERBOSE_PRINT((stdout, "number of args given: %d\n", num)); + VERBOSE_PRINT((stdout, "number of args expected: %d\n", + get_method_n_params(mtype))); + irns = alloca(num * sizeof(ir_node*)); + for(i = 0; i < num; i++) { + irns[i] = find_valueid_in_proc_effects(eff -> effect.call.args[i], proc) + -> firmnode; + if(iro_Unknown == get_irn_opcode(irns[i])) { + set_irn_mode(irns[i], get_type_mode(get_method_param_type(mtype, i))); + } + } + call = new_Call(get_store(), sel, num, irns, get_entity_type(ent)); + set_store(new_Proj(call, mode_M, 0)); + // eff -> firmnode = new_Proj(store, mode, 2); + eff -> firmnode = call; - while (NULL != eff) { - int i; - effs_t *curr = eff; - eff = eff->next; + add_value_to_proc(proc, eff); +} - for (i = 0; i < curr->n_effs; i ++) { - free (curr->effs [i]); - } - free (curr); +static void create_abstract_firm(module_t *module, proc_t *proc, entity *fent) +{ + eff_t *eff; + ir_graph *irg; + int i, num; + + /* create irg in entity */ + irg = new_ir_graph(fent, 0); + + VERBOSE_PRINT((stdout, "create effects for %s\n", proc -> procname)); + /* create effects in irg */ + num = proc -> n_effs; + for(i = 0; i < num; i++) { + eff = proc -> effs[i]; + VERBOSE_PRINT((stdout, + "create effect \"%s\"\n", effect_string[(int)eff -> kind])); + switch(eff -> kind) { + case eff_ret: + create_abstract_return(irg, proc, eff); + break; + case eff_arg: + create_abstract_arg(irg, proc, eff); + break; + case eff_load: + create_abstract_load(irg, proc, eff); + break; + case eff_store: + create_abstract_store(irg, proc, eff); + break; + case eff_unknown: + create_abstract_unknown(irg, proc, eff); + break; + case eff_alloc: + create_abstract_alloc(irg, proc, eff); + break; + case eff_call: + create_abstract_call(irg, proc, eff); + break; + default: + assert(0 && "effect not implemented"); + break; } } - effs = NULL; + /* close irg in entity */ + /* Now we can mature the end block as all it's predecessors are known. */ + mature_immBlock (get_irg_end_block(irg)); + + /* Verify the graph. Finds some very bad errors in the graph. */ + VERBOSE_PRINT((stdout, "verify graph\n")); + irg_vrfy(irg); + VERBOSE_PRINT((stdout, "finalize construction\n")); + finalize_cons (irg); } +/********************************************************************/ -void test_getEffectByName (void) +static void assign_firm_entity(module_t *module, entity_t *xmlent) { - /* test getEffectByName */ - char *names [] = { - "store_unknown_proc", - "rise_something", - "other_fake_proc", - "ret_alloc", - "mash_args", - "ret_arg", - "empty_external", - "no_this_doesn't_really_exist", - "my_fake_proc", - NULL - }; + int i, num; + type_t *typ; + type *type; + entity *ent; + + VERBOSE_PRINT((stdout, "assign entity %s to typeid %s\n", + xmlent -> name, xmlent -> owner)); + typ = find_type_in_module(module, xmlent -> owner); + assert(typ && "class not found in module"); + type = typ -> f_tp; + assert(is_class_type(type)); + + num = get_class_n_members(type); + ent = NULL; + for(i = 0; i < num; i++) { + ent = get_class_member(type, i); + VERBOSE_PRINT((stdout, "compare entity %s and %s\n", + xmlent -> name, get_entity_name(ent))); + if(0 == strcmp(get_entity_name(ent), xmlent -> name)) { + break; + } + ent = NULL; + } + assert(ent && "did not find a entity"); - int i = 0; + xmlent -> f_ent = ent; +} - while (NULL != names [i]) { - effs_t *the_eff = getEffectByName (names [i]); +/********************************************************************/ +/* must be primitive type or class type */ +static void assign_firm_type(type_t *xmltype) +{ + int i; + type *typ = NULL; + int num; - if (the_eff) { - fprintf (stdout, "Effect for \"%s\" is at 0x%08x\n", - names [i], (int) the_eff); - } else { - fprintf (stdout, "Effect for \"%s\" not found\n", - names [i]); + VERBOSE_PRINT((stdout, "assign type %s\n", xmltype -> name)); + /* is it global type? */ + typ = get_glob_type(); + if(0 == strcmp(xmltype -> name, get_type_name(typ))) { + /* yes */ + xmltype -> f_tp = typ; + VERBOSE_PRINT((stdout, "is global type %s\n", get_type_name(typ))); + } + else { + num = get_irp_n_types(); + for(i = 0; i < num; i++) { + typ = get_irp_type(i); + VERBOSE_PRINT((stdout, "test type %s\n", get_type_name(typ))); + if(0 == strcmp(xmltype -> name, get_type_name(typ))) { + VERBOSE_PRINT((stdout, "found type %s\n", get_type_name(typ))); + xmltype -> f_tp = typ; + break; + } + typ = NULL; + } + } + assert(typ && "did not find a type"); +} + +/********************************************************************/ +static +void create_abstract_proc_effect(module_t *module, proc_t *proc) +{ + int i, num; + type *class_typ = NULL; + type_t *type; + entity *fent; + + /* find the class of a procedure */ + VERBOSE_PRINT((stdout, "do find typeid %s\n", proc -> typeid)); + type = find_type_in_module(module, proc -> typeid); + assert(type && "class not found in module"); + + class_typ = get_glob_type(); + VERBOSE_PRINT((stdout, "test type %s\n", get_type_name(class_typ))); + if(0 != strcmp(type -> name, get_type_name(class_typ))) { + /* find module as class */ + num = get_irp_n_types(); + for(i = 0; i < num; i++) { + class_typ = get_irp_type(i); + VERBOSE_PRINT((stdout, "test type %s\n", get_type_name(class_typ))); + if(is_class_type(class_typ) + && (0 == strcmp(type -> name, get_type_name(class_typ)))) { + /* found class type */ + VERBOSE_PRINT((stdout, "found type %s\n", get_type_name(class_typ))); + break; + } + class_typ = NULL; } - i ++; } + else { + VERBOSE_PRINT((stdout, "found global type %s\n", get_type_name(class_typ))); + } + assert(class_typ && "type not found"); + assert(is_class_type(class_typ) && "is not a class type"); + type -> f_tp = class_typ; + + /* find entity for procedure in class */ + VERBOSE_PRINT((stdout, "find method %s\n", proc -> procname)); + num = get_class_n_members(class_typ); + fent = NULL; + for(i = 0; i < num; i++) { + fent = get_class_member(class_typ, i); + VERBOSE_PRINT((stdout, "test proc %s\n", get_entity_name(fent))); + if(0 == strcmp(proc -> procname, get_entity_name(fent))) { + VERBOSE_PRINT((stdout, "found proc %s\n", proc -> procname)); + /* @@@ TODO check args types - not in xml yet */ + /* create Firm stuff */ + create_abstract_firm(module, proc, fent); + break; + } + else { + fent = NULL; + } + } + assert(fent && "procedure not found in class"); } +static +void create_abstract_module(module_t *module) +{ + proc_t *proc; + type_t *type; + entity_t *ent; + + VERBOSE_PRINT((stdout, + "create an abstraction for module %s\n", module -> name)); + + VERBOSE_PRINT((stdout, "--handle types for module %s\n", module -> name)); + for(type = module -> types; type; type = type -> prev) { + assign_firm_type(type); + } + + VERBOSE_PRINT((stdout, "--handle entities for module %s\n", module -> name)); + /* @@@ TODO */ + for(ent = module -> entities; ent; ent = ent -> prev) { + assign_firm_entity(module, ent); + } + + VERBOSE_PRINT((stdout, "--handle procs for module %s\n", module -> name)); + for(proc = module -> procs; proc; proc = proc -> next) { + create_abstract_proc_effect(module, proc); + } +} + + +void create_abstraction(const char *filename) +{ + module_t *module; + + /* read and parse XML file */ + read_extern(filename); + + /* finished reading and parsing here */ + /* build FIRM graphs */ + module = modules; + while(module) { + current_module = module; + create_abstract_module(module); + module = module -> next; + } + current_module = NULL; + + /* free data structures */ + free_data(); +} +/********************************************************************/ /* * $Log$ - * Revision 1.6 2004/10/21 11:12:11 liekweg - * strdup fix + * Revision 1.7 2004/10/21 15:31:55 boesler + * added lots of stuff: + * - build abstract syntax trees + * - build Firm graphs for many effects, still todos * * Revision 1.5 2004/10/18 12:48:20 liekweg * avoid warning diff --git a/ir/external/read.h b/ir/external/read.h index e7e452473..71e400122 100644 --- a/ir/external/read.h +++ b/ir/external/read.h @@ -1,50 +1,37 @@ /* -*- c -*- */ - /* * Project: libFIRM * File name: ir/external/read.c * Purpose: Read descriptions of external effects * Author: Florian - * Modified by: + * Modified by: Boris Boesler * Created: 11.10.2004 - * CVS-ID: $$ + * CVS-ID: $Id$ * Copyright: (c) 1999-2004 Universität Karlsruhe * Licence: This file is protected by GPL - GNU GENERAL PUBLIC LICENSE. */ -# ifndef _READ_H_ -# define _READ_H_ - -# if 0 -/* we need strdup */ -# ifndef _GNU_SOURCE -# define _GNU_SOURCE -# endif /* ! defined _GNU_SOURCE */ -# endif /* 0 */ +#ifndef _READ_H_ +#define _READ_H_ -# include -# include -# include -# include +#include +#include +#include +#include -# include -# include -# include +#include +#include +#include -# include "type.h" -# include "entity.h" +#include "type.h" +#include "entity.h" +# ifndef _BSD_SOURCE +# define _BSD_SOURCE /* need strdup */ +# endif /* ! defined _BSD_SOURCE */ # define MY_ENCODING "ISO-8859-1" -/* quick hack until we get a cmd line flag or something: just add - '-DEXTERN_VERBOSE' to 'CFLAGS' */ -# ifndef EXTERN_VERBOSE -# define EXTERN_VERBOSE 1 -# else -# define EXTERN_VERBOSE 0 -# endif /* defined EXTERN_VERBOSE */ - # define CHECK(ptr,msg) assert (ptr && msg) # define NODE_NAME(n, m) (0 == xmlStrcmp (n->name, (const xmlChar*) #m)) @@ -52,176 +39,166 @@ # define NEW(T) (T*) malloc (sizeof (T)) +typedef const char* firmid_t; + /* first, the xml structures */ typedef struct type_str { const char *name; - int id; - entity *f_tp; /* firm type */ - struct type_str *prev; /* linked list */ + firmid_t id; + type *f_tp; /* firm type */ + struct type_str *prev; } type_t; typedef struct entity_str { - const char *name; - const char *tp_name; - int id; - type *f_ent; /* firm entity */ - struct entity_str *prev; /* linked list */ + const char *name; /* name of entity */ + const char *tp_name; /* name of type/class */ + firmid_t id; /* id for references */ + firmid_t owner; /* id of owner */ + entity *f_ent; /* firm entity */ + struct entity_str *prev; } entity_t; /* now the xml nodes */ typedef enum eff_node_kind { - eff_arg, - eff_valref, - eff_select, - eff_load, - eff_store, - eff_alloc, - eff_call, - eff_unknown, - eff_join, - eff_raise, - eff_ret + eff_arg, // done + eff_valref, // eliminated + eff_select, // eliminated + eff_load, // done + eff_store, // done + eff_alloc, // done + eff_call, // TODO + eff_unknown, // done + eff_join, // TODO + eff_raise, // TODO + eff_ret // done } eff_node_kind_t; -/* dummy type for all other effects */ -typedef struct eff_str -{ - eff_node_kind_t kind; -} eff_t; - -typedef struct effs_str -{ - char *procname; - int n_effs; - eff_t **effs; - struct effs_str *next; -} effs_t; typedef struct arg_str { - eff_node_kind_t kind; - int id; + firmid_t type; int num; } arg_t; typedef struct valref_str { - eff_node_kind_t kind; - int refid; + int dummy; } valref_t; typedef struct select_str { - eff_node_kind_t kind; - int valrefid; /* id of enclosed valref node, or -1 */ entity_t *ent; } select_t; typedef struct load_str { - eff_node_kind_t kind; - int id; - int ptrrefid; /* id of valref node enclosed in select, or -1 */ + firmid_t ptrrefid; /* id of valref node enclosed in select, or -1 */ entity_t *ent; } load_t; typedef struct store_str { - eff_node_kind_t kind; - int ptrrefid; /* id of ptr valref node enclosed in select, or -1 */ - int valrefid; /* id of val valref node enclosed in select, or -1 */ + firmid_t ptrrefid; /* id of ptr valref node enclosed in select, or -1 */ + firmid_t valrefid; /* id of val valref node enclosed in select, or -1 */ entity_t *ent; } store_t; typedef struct alloc_str { - eff_node_kind_t kind; - int id; - int tp_id; + firmid_t tp_id; } alloc_t; typedef struct call_str { - eff_node_kind_t kind; - int id; - int valrefid; /* id of enclosed valref node, or -1 */ + firmid_t valrefid; /* id of enclosed valref node, or -1 */ entity_t *ent; /* called entity */ int n_args; - int *args; + firmid_t *args; } call_t; typedef struct unknown_str { - eff_node_kind_t kind; - int id; + int dummy; } unknown_t; typedef struct join_str { - eff_node_kind_t kind; - int id; int n_ins; - int *ins; + firmid_t *ins; } join_t; typedef struct ret_str { - eff_node_kind_t kind; - int ret_id; /* returned value, or -1 */ -} ret_t; + firmid_t ret_id; +} ret_t; /* returned value, or NO_ID */ typedef struct raise_str { - eff_node_kind_t kind; - /* struct eff_str *next; */ - int valref; /* what was that one for? */ - int tp_id; + firmid_t valref; /* what was that one for? */ + firmid_t tp_id; } raise_t; -/* - The public interface -*/ - -/** get the type entry with the given name */ -type_t *getTypeByName (const char*); - -/** get the type entry with the given Id */ -type_t *getTypeById (const int); +/* dummy type for all other effects */ +typedef struct eff_str +{ + eff_node_kind_t kind; + firmid_t id; /* identifier to access this node */ + union { + arg_t arg; + valref_t valref; + select_t select; + load_t load; + store_t store; + alloc_t alloc; + call_t call; + unknown_t unknown; + join_t join; + ret_t ret; + raise_t raise; + } effect; + ir_node *firmnode; + struct eff_str *next; /* effects with values are stored in proc.values */ +} eff_t; -/** get the entity entry that has the given names */ -entity_t *getEntityByNames (const char*, const char*); +typedef struct proc_str +{ + const char *procname; + firmid_t typeid; + int n_effs; + eff_t **effs; + struct proc_str *next; + eff_t *values; +} proc_t; -/** get the entity entry that has the given Id */ -entity_t *getEntityById (const int); -/** get the effect entry for the given name */ -effs_t *getEffectByName (const char*); +typedef struct mod_str +{ + const char *name; /* name of module */ + type_t *types; /* types in module */ + entity_t *entities; /* entities in module */ + proc_t *procs; /* methods with effects */ + struct mod_str *next; /* unused - only one module possible */ +} module_t; -/** initialise the data structures */ -void extern_init (void); -/** read in the file of the given name */ -void extern_read (const char*); +/* + The public intyerface +*/ +/** read the file and build the graphs */ +void create_abstraction(const char *filename); -/** clean up our mess */ -void extern_cleanup (void); -# endif /* defined _READ_H_ */ +#endif /* defined _READ_H_ */ /* $Log$ - Revision 1.4 2004/10/13 11:56:16 liekweg - need strdup, don't need _GNU_SOURCE (wtf?) - - Revision 1.3 2004/10/13 08:39:59 liekweg - need strdup - - Revision 1.2 2004/10/11 15:56:09 liekweg - Cleanup, comments ... - Added init func --flo + Revision 1.5 2004/10/21 15:31:55 boesler + added lots of stuff: + - build abstract syntax trees + - build Firm graphs for many effects, still todos Revision 1.1 2004/10/11 09:31:06 liekweg First Import of XML reading procs --flo