* Licence: This file is protected by GPL - GNU GENERAL PUBLIC LICENSE.
*/
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+/* get prototype for alloca somehow */
+#ifdef HAVE_ALLOCA_H
+# include <alloca.h>
+#endif
+#ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
-#define _GNU_SOURCE
-#include <string.h>
+# include <string.h>
-# include "read.h"
+#include "read_t.h"
+#include "read.h"
#include "irprog.h"
#include "irgraph.h"
#include "ircons.h"
#include "type.h"
#include "tv.h"
-#if 0
+#define VERBOSE_PRINTING 1
+
+#if VERBOSE_PRINTING
# define VERBOSE_PRINT(s) fprintf s
#else
# define VERBOSE_PRINT(s)
/* @@@ HACK */
static module_t *current_module = NULL;
+#if VERBOSE_PRINTING
+/* this is only used inside a VERBOSE_PRINT() call */
static char *effect_string[] = {
"arg",
"valref",
"raise",
"ret"
};
+#endif /* defined VERBOSE_PRINTING */
-static const char*
-getNodeModule (xmlNodePtr node)
+static const ident*
+getNodeModuleIdent (xmlNodePtr node)
{
const char *mod_str = (const char*) xmlGetProp (node, BAD_CAST "module");
if (NULL == mod_str) {
return (NULL);
} else {
- const char *res = strdup (mod_str);
+ const ident *res = new_id_from_str (mod_str);
return (res);
}
}
{
const char *proc_str = (const char*) xmlGetProp (node, BAD_CAST "procname");
assert (proc_str);
- return (strdup (proc_str));
+ return (proc_str);
}
static char*
{
char *proc_str = (char*) xmlGetProp (node, BAD_CAST "class");
assert (proc_str);
- return (strdup (proc_str));
+ return ( (proc_str));
}
static const char*
{
const char *id_str = (const char*) xmlGetProp (node, BAD_CAST "id");
assert (id_str);
- return (strdup (id_str));
+ return (id_str);
}
-static firmid_t
+static const char *
getNodeRefId (xmlNodePtr node)
{
- firmid_t refid_str = (char*) xmlGetProp (node, BAD_CAST "refid");
+ const char *refid_str = (char*) xmlGetProp (node, BAD_CAST "refid");
assert (refid_str);
- return (strdup(refid_str));
+ return ((refid_str));
}
-static firmid_t
+static const char*
getNodeTypeId (xmlNodePtr node)
{
- firmid_t type_str = (char*) xmlGetProp (node, BAD_CAST "type");
+ const char *type_str = (char*) xmlGetProp (node, BAD_CAST "type");
assert (type_str);
- return (strdup(type_str));
+ return ((type_str));
}
static const char
{
const char *type_str = (char*) xmlGetProp (node, BAD_CAST "type");
assert (type_str);
-
return (type_str);
}
was Public Interface
*/
static
-type_t *getTypeByName (const char *name)
+type_t *getTypeByIdent (const ident *id)
{
- type_t *curr = types;
+ type_t *curr = types; // @@@ TODO module -> types
while (NULL != curr) {
- if (0 == strcmp (name, curr->name)) {
+ if (id == curr -> type_ident) {
return (curr);
}
curr = curr->prev;
}
static
-type_t *getTypeById (firmid_t id)
+type_t *getTypeById (const ident *id)
{
- type_t *curr = types;
+ type_t *curr = types; // which ones?
while (NULL != curr) {
- if (0 == strcmp(id, curr->id)) {
+ if (id == curr -> id) {
return (curr);
}
curr = curr->prev;
}
static
-entity_t *getEntityByNames (const char *name, const char *tp_name)
+entity_t *getEntityByIdents (const ident *name, const ident *tp_ident)
{
- entity_t *curr = entities;
+ entity_t *curr = entities; // TODO module -> entities
while (NULL != curr) {
- if ((0 == strcmp (name, curr->name))
- && (0 == strcmp (tp_name, curr->tp_name))) {
+ if ((name == curr -> ent_ident)
+ && (tp_ident == curr -> tp_ident)) {
return (curr);
}
curr = curr->prev;
}
static
-entity_t *getEntityById (firmid_t id)
+entity_t *getEntityById (const ident *id)
{
entity_t *curr = entities;
while (NULL != curr) {
- if (0 == strcmp(id, curr->id)) {
+ if (id == curr -> id) {
return (curr);
}
curr = curr->prev;
}
static
-proc_t *getEffectByName (const char *procname)
+proc_t *getEffectByName (const ident *proc_ident)
{
proc_t *curr_effs = procs;
while (NULL != curr_effs) {
- if (0 == strcmp (procname, curr_effs->procname)) {
+ if (proc_ident == curr_effs -> proc_ident) {
return (curr_effs);
}
curr_effs = curr_effs->next;
return (NULL);
}
+static
+xmlNodePtr get_any_valid_child(xmlNodePtr elem)
+{
+ xmlNodePtr child;
+
+ assert(elem && "no element");
+ child = elem -> xmlChildrenNode;
+ while(child && (NODE_NAME (child, comment))) {
+ child = child -> next;
+ }
+ return(child);
+}
+
+static
+xmlNodePtr get_valid_child(xmlNodePtr elem)
+{
+ xmlNodePtr child;
+
+ child = get_any_valid_child(elem);
+ assert(child && "lost child in deep black forest");
+ return(child);
+}
/*
* parse XML structure and construct an additional structure
arg = NEW (eff_t);
arg -> kind = eff_arg;
- arg -> id = id;
+ arg -> id = new_id_from_str(id);
arg -> effect.arg.num = num;
- arg -> effect.arg.type = typeid;
+ arg -> effect.arg.type_ident = new_id_from_str(typeid);
return (arg);
}
-static eff_t
-*parseValref (xmlDocPtr doc, xmlNodePtr valelm)
+static eff_t*
+parseValref (xmlDocPtr doc, xmlNodePtr valelm)
{
- firmid_t ref_id;
+ const char *ref_id;
eff_t *valref;
CHECK_NAME (valelm, valref);
valref = NEW (eff_t);
valref->kind = eff_valref;
- valref-> id = ref_id;
+ valref-> id = new_id_from_str(ref_id);
return (valref);
}
-static eff_t
-*parseSelect (xmlDocPtr doc, xmlNodePtr selelm)
+static eff_t*
+parseSelect (xmlDocPtr doc, xmlNodePtr selelm)
{
- firmid_t entity_id = getNodeEntityStr (selelm);
+ const ident *entity_id = new_id_from_str(getNodeEntityStr (selelm));
entity_t *ent;
xmlNodePtr child;
eff_t *valref = NULL;
ent = getEntityById (entity_id);
assert(ent && "entity not found");
- VERBOSE_PRINT ((stdout, "select entity %s\n", ent -> name));
+ VERBOSE_PRINT ((stdout, "select entity %s\n", get_id_str(ent -> ent_ident)));
child = selelm->xmlChildrenNode;
return (sel);
}
-static eff_t
-*parseLoad (xmlDocPtr doc, xmlNodePtr loadelm)
+static eff_t*
+parseLoad (xmlDocPtr doc, xmlNodePtr loadelm)
{
- firmid_t id;
+ const ident *id;
xmlNodePtr child;
eff_t *sel;
eff_t *load = NEW (eff_t);
CHECK_NAME (loadelm, load);
VERBOSE_PRINT ((stdout, "load node \t0x%08x\n", (int) loadelm));
- id = getNodeId (loadelm);
-
- child = loadelm->xmlChildrenNode;
-
- sel = parseSelect (doc, child);
+ id = new_id_from_str(getNodeId (loadelm));
+
+ child = get_valid_child(loadelm);
+ if(NODE_NAME (child, select)) {
+ sel = parseSelect (doc, child);
+ load-> effect.load.ent = sel-> effect.select.ent;
+ VERBOSE_PRINT ((stdout, "load entity \t%s\n",
+ get_id_str(load -> effect.load.ent -> ent_ident)));
+ }
+ else {
+ sel = parseValref (doc, child);
+ load-> effect.load.ent = NULL;
+ }
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 eff_t
-*parseStore (xmlDocPtr doc, xmlNodePtr storeelm)
+static eff_t*
+parseStore (xmlDocPtr doc, xmlNodePtr storeelm)
{
xmlNodePtr child;
eff_t *sel;
CHECK_NAME (storeelm, store);
VERBOSE_PRINT ((stdout, "store node \t0x%08x\n", (int) storeelm));
- child = storeelm->xmlChildrenNode;
- sel = parseSelect (doc, child);
+ child = get_valid_child(storeelm);
+ if(NODE_NAME (child, select)) {
+ sel = parseSelect (doc, child);
+ store-> effect.store.ent = sel-> effect.select.ent;
+ }
+ else {
+ sel = parseValref (doc, child);
+ store-> effect.store.ent = NULL;
+ }
+
child = child->next;
valref = parseValref (doc, child);
- store-> effect.store.ent = sel-> effect.select.ent;
store-> effect.store.ptrrefid = sel-> id;
store-> effect.store.valrefid = valref-> id;
return (store);
}
-static eff_t
-*parseAlloc (xmlDocPtr doc, xmlNodePtr allocelm)
+static eff_t*
+parseAlloc (xmlDocPtr doc, xmlNodePtr allocelm)
{
- firmid_t id;
- firmid_t type_id;
+ const ident *id;
+ const ident *type_id;
eff_t *alloc = NEW (eff_t); /* ...! */
alloc->kind = eff_alloc;
CHECK_NAME (allocelm, alloc);
VERBOSE_PRINT ((stdout, "alloc node \t0x%08x\n", (int) allocelm));
- id = getNodeId (allocelm);
- VERBOSE_PRINT ((stdout, "alloc->id = \"%s\"\n", id));
- type_id = getNodeTypeId (allocelm);
- VERBOSE_PRINT ((stdout, "alloc->type_id = \"%s\"\n", type_id));
+ id = new_id_from_str(getNodeId (allocelm));
+ VERBOSE_PRINT ((stdout, "alloc->id = \"%s\"\n", get_id_str(id)));
+ type_id = new_id_from_str(getNodeTypeId (allocelm));
+ VERBOSE_PRINT ((stdout, "alloc->type_id = \"%s\"\n", get_id_str(type_id)));
alloc-> id = id;
alloc-> effect.alloc.tp_id = type_id;
return (alloc);
}
-static eff_t
-*parseCall (xmlDocPtr doc, xmlNodePtr callelm)
+static eff_t*
+parseCall (xmlDocPtr doc, xmlNodePtr callelm)
{
- firmid_t id;
+ const ident *id;
xmlNodePtr child;
eff_t *sel;
xmlNodePtr arg;
CHECK_NAME (callelm, call);
VERBOSE_PRINT ((stdout, "call node \t0x%08x\n", (int) callelm));
- id = getNodeId (callelm);
- VERBOSE_PRINT ((stdout, "call->id = \"%s\"\n", id));
+ id = new_id_from_str(getNodeId (callelm));
+ VERBOSE_PRINT ((stdout, "call->id = \"%s\"\n", get_id_str(id)));
+
+ child = get_valid_child(callelm);
+ if(NODE_NAME (child, select)) {
+ sel = parseSelect (doc, child);
+ call-> effect.call.ent = sel-> effect.select.ent;
+ }
+ else {
+ sel = parseValref (doc, child);
+ call-> effect.call.ent = NULL;
+ }
- child = callelm->xmlChildrenNode;
- sel = parseSelect (doc, child);
arg = child = child->next;
n_args = 0;
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) {
- firmid_t *args = (firmid_t*) malloc (n_args * sizeof (firmid_t) );
+ const ident **args = (const ident**) malloc(n_args * sizeof(const ident*));
int i = 0;
while (NULL != arg) {
return (call);
}
-static eff_t
-*parseJoin (xmlDocPtr doc, xmlNodePtr joinelm)
+static eff_t*
+parseJoin (xmlDocPtr doc, xmlNodePtr joinelm)
{
- firmid_t id;
+ const ident *id;
int n_ins;
- firmid_t *ins;
+ const ident **ins;
int i;
xmlNodePtr child;
eff_t *join = NEW (eff_t);
CHECK_NAME (joinelm, join);
VERBOSE_PRINT ((stdout, "join node \t0x%08x\n", (int) joinelm));
- id = getNodeId (joinelm);
- VERBOSE_PRINT ((stdout, "join->id = \"%s\"\n", id));
+ id = new_id_from_str(getNodeId (joinelm));
+ VERBOSE_PRINT ((stdout, "join->id = \"%s\"\n", get_id_str(id)));
- child = joinelm->xmlChildrenNode;
+ child = get_valid_child(joinelm);
n_ins = 0;
while (NULL != child) {
child = child->next;
}
- ins = (firmid_t*) malloc (n_ins * sizeof (firmid_t) );
+ ins = (const ident **) malloc (n_ins * sizeof (const ident *) );
i = 0;
- child = joinelm->xmlChildrenNode;
+ child = get_valid_child(joinelm);
while (NULL != child) {
eff_t *valref = parseValref (doc, child);
return (join);
}
-static eff_t
-*parseUnknown (xmlDocPtr doc, xmlNodePtr unknownelm)
+static eff_t*
+parseUnknown (xmlDocPtr doc, xmlNodePtr unknownelm)
{
- firmid_t id;
+ const ident *id;
eff_t *unknown = NEW (eff_t);
unknown->kind = eff_unknown;
CHECK_NAME (unknownelm, unknown);
VERBOSE_PRINT ((stdout, "unknown node \t0x%08x\n", (int) unknownelm));
- id = getNodeId (unknownelm);
+ id = new_id_from_str(getNodeId (unknownelm));
unknown-> id = id;
return (unknown);
}
-static eff_t
-*parseReturn (xmlDocPtr doc, xmlNodePtr retelm)
+static eff_t*
+parseReturn (xmlDocPtr doc, xmlNodePtr retelm)
{
xmlNodePtr child;
eff_t *ret = NEW (eff_t);
CHECK_NAME (retelm, ret);
VERBOSE_PRINT ((stdout, "ret node \t0x%08x\n", (int) retelm));
- child = retelm->xmlChildrenNode;
+ child = get_any_valid_child(retelm);
if (child) {
eff_t *valref = parseValref (doc, child);
return (ret);
}
-static eff_t
-*parseRaise (xmlDocPtr doc, xmlNodePtr raiseelm)
+static eff_t*
+parseRaise (xmlDocPtr doc, xmlNodePtr raiseelm)
{
- firmid_t tp_id;
+ const char *tp_id;
eff_t *valref;
xmlNodePtr child;
eff_t *raise = NEW (eff_t);
VERBOSE_PRINT ((stdout, "raise node \t0x%08x\n", (int) raiseelm));
tp_id = getNodeTypeId (raiseelm);
VERBOSE_PRINT ((stdout, "raise->type = \"%s\"\n", tp_id));
- child = raiseelm->xmlChildrenNode;
+ child = get_valid_child(raiseelm);
assert (NULL != child);
valref = parseValref (doc, child);
raise-> effect.raise.valref = valref-> id;
- raise-> effect.raise.tp_id = tp_id;
+ raise-> effect.raise.tp_id = new_id_from_str(tp_id);
free (valref);
return (raise);
parseType (xmlDocPtr doc, xmlNodePtr typeelm)
{
type_t *type;
- firmid_t tp_id = getNodeId (typeelm);
+ const char *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 -> type_ident = new_id_from_str(getNodeTypeStr (typeelm));
+ type -> id = new_id_from_str(tp_id);
type->prev = types;
types = type;
entity_t *ent = NEW (entity_t);
/* parse it */
- firmid_t ent_id = getNodeId (entelm);
+ const char *ent_id = getNodeId (entelm);
/* fprintf (stdout, "entity node \t0x%08x (%d)\n", (int) entelm, ent_id); */
VERBOSE_PRINT ((stdout, "ent = \"%s.%s\"\n",
- getNodeTypeStr (entelm),
- getNodeEntityStr (entelm)));
+ 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 -> ent_ident = new_id_from_str (getNodeEntityStr (entelm));
+ ent -> tp_ident = new_id_from_str (getNodeTypeStr (entelm));
+ ent -> owner = new_id_from_str (getNodeOwnerStr (entelm));
+ ent -> id = new_id_from_str(ent_id);
ent->prev = entities;
entities = ent;
{
xmlNodePtr cur;
const char *procname = getNodeProcName (effelm);
- const char *typeid = getNodeTypeStr (effelm);
+ const char *ownerid = getNodeOwnerStr (effelm);
proc_t *curr_effs = NULL;
int i = 0;
int n_effs = 0;
VERBOSE_PRINT ((stdout, "has %d effects\n", n_effs));
curr_effs = NEW (proc_t);
- curr_effs->procname = procname;
- curr_effs->typeid = typeid;
+ curr_effs -> proc_ident = new_id_from_str(procname);
+ curr_effs -> ownerid = new_id_from_str(ownerid);
curr_effs->effs = (eff_t**) malloc (n_effs * sizeof (eff_t*));
cur = effelm -> xmlChildrenNode;
/* xmlNsPtr ns = NULL; */ /* no namespace for us */
xmlDocPtr doc; /* whole document */
xmlNodePtr cur; /* current node */
- const char *mod_str;
+ ident *mod_id;
module_t *module;
/* i've got no idea what the VERSION cast is all about. voodoo
exit (EXIT_FAILURE);
}
- mod_str = getNodeModule (cur);
- if (NULL != mod_str) {
- VERBOSE_PRINT ((stdout, "effects for \"%s\"\n", mod_str));
+ mod_id = getNodeModuleIdent (cur);
+ if (NULL != mod_id) {
+ VERBOSE_PRINT ((stdout, "effects for \"%s\"\n",
+ get_id_str(mod_id)));
}
else {
VERBOSE_PRINT ((stdout, "effects \t0x%08x\n", (int) cur));
}
module = NEW(module_t);
- module -> name = mod_str;
+ module -> id = mod_id;
module -> types = types;
module -> entities = entities;
module -> procs = procs;
int i;
int num;
- VERBOSE_PRINT ((stdout,
- "free effect for method \"%s\"\n", proc -> procname));
+ VERBOSE_PRINT ((stdout, "free effect for method \"%s\"\n",
+ get_id_str(proc -> proc_ident)));
+
num = proc -> n_effs;
for(i = 0; i < num; i++) {
switch(proc -> effs[i] -> kind) {
}
free(proc -> effs);
proc -> effs = NULL;
- free((void*)proc -> procname);
- proc -> procname = NULL;
}
static
{
proc_t *next_proc, *proc;
- VERBOSE_PRINT ((stdout,
- "free procs for module \"%s\"\n", module -> name));
+ VERBOSE_PRINT ((stdout, "free procs for module \"%s\"\n",
+ get_id_str(module -> id)));
+
proc = module -> procs;
while(proc) {
next_proc = proc -> next;
module = modules;
while(module) {
freeModuleProcs(module);
- free((char*)module -> name);
next_module = module -> next;
free(module);
module = next_module;
/********************************************************************/
static
-type_t *find_type_in_module(module_t *module, firmid_t typeid)
+type_t *find_type_in_module(module_t *module, const ident *typeid)
{
type_t *type;
for(type = module -> types; type; type = type -> prev) {
- VERBOSE_PRINT((stdout, "test typeid %s\n", type -> id));
- if(0 == strcmp(type -> id, typeid)) {
+ VERBOSE_PRINT((stdout, "test typeid %s\n", get_id_str(type -> id)));
+ if(type -> id == typeid) {
+ VERBOSE_PRINT((stdout, "found\n"));
return(type);
}
}
- VERBOSE_PRINT((stdout, "did not find type id %s\n", typeid));
+ VERBOSE_PRINT((stdout, "did not find type id %s\n", get_id_str(typeid)));
return(NULL);
}
}
-eff_t *find_valueid_in_proc_effects(firmid_t id, proc_t *proc)
+eff_t *find_valueid_in_proc_effects(const ident *id, proc_t *proc)
{
eff_t *val;
val = proc -> values;
while(val) {
- if(0 == strcmp(id, val -> id)) {
+ if(id == val -> id) {
return(val);
}
val = val -> next;
ir_node *x;
eff_t *eff_res;
- VERBOSE_PRINT((stdout, "create effect:return in %s\n", proc -> procname));
+ VERBOSE_PRINT((stdout, "create effect:return in %s\n",
+ get_id_str(proc -> proc_ident)));
if(NO_ID == eff -> effect.ret.ret_id) {
/* return void */
x = new_Return (get_store(), 0, NULL);
int num;
VERBOSE_PRINT((stdout, "create effect:arg %d in %s\n",
- eff -> effect.arg.num, proc -> procname));
+ eff -> effect.arg.num, get_id_str(proc -> proc_ident)));
ent = get_irg_entity(irg);
typ = get_entity_type(ent);
ir_mode *mode;
eff_t *addr;
- VERBOSE_PRINT((stdout, "create load in %s\n", proc -> procname));
+ VERBOSE_PRINT((stdout, "create load in %s\n",
+ get_id_str(proc -> proc_ident)));
- ent = eff -> effect.load.ent -> f_ent;
- VERBOSE_PRINT((stdout, "load from %s\n", get_entity_name(ent)));
+ if(eff -> effect.load.ent) {
+ ent = eff -> effect.load.ent -> f_ent;
+ VERBOSE_PRINT((stdout, "load from %s\n", get_entity_name(ent)));
+ }
+ else {
+ VERBOSE_PRINT((stdout, "store to memory\n"));
+ ent = NULL;
+ }
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 addr is Unknown, set proper mode */
if(iro_Unknown == get_irn_opcode(addr -> firmnode)) {
set_irn_mode(addr -> firmnode, mode_P);
}
- sel = new_simpleSel(get_store(), addr -> firmnode, ent);
- mode = get_type_mode(get_entity_type(ent));
+ if(ent) {
+ sel = new_simpleSel(get_store(), addr -> firmnode, ent);
+ mode = get_type_mode(get_entity_type(ent));
+ }
+ else {
+ sel = addr -> firmnode;
+ mode = mode_ANY;
+ }
load = new_Load(get_store(), sel, mode);
set_store(new_Proj(load, mode_M, 0));
eff -> firmnode = new_Proj(load, mode, 2);
entity *ent;
eff_t *addr, *val;
- VERBOSE_PRINT((stdout, "create store in %s\n", proc -> procname));
+ VERBOSE_PRINT((stdout, "create store in %s\n",
+ get_id_str(proc -> proc_ident)));
- ent = eff -> effect.store.ent -> f_ent;
- VERBOSE_PRINT((stdout, "store to %s\n", get_entity_name(ent)));
+ if(eff -> effect.store.ent) {
+ ent = eff -> effect.store.ent -> f_ent;
+ VERBOSE_PRINT((stdout, "store to entity %s\n", get_entity_name(ent)));
+ }
+ else {
+ VERBOSE_PRINT((stdout, "store to memory\n"));
+ ent = NULL;
+ }
addr = find_valueid_in_proc_effects(eff -> effect.store.ptrrefid, proc);
assert(addr && "no address for store");
set_irn_mode(val -> firmnode, get_type_mode(get_entity_type(ent)));
}
- sel = new_simpleSel(get_store(), addr -> firmnode, ent);
+ if(ent) {
+ sel = new_simpleSel(get_store(), addr -> firmnode, ent);
+ }
+ else {
+ sel = addr -> firmnode;
+ }
store = new_Store(get_store(), sel, val -> firmnode);
set_store(new_Proj(store, mode_M, 0));
eff -> firmnode = store;
type_t *xtype;
symconst_symbol sym;
- VERBOSE_PRINT((stdout, "create alloc in %s\n", proc -> procname));
+ VERBOSE_PRINT((stdout, "create alloc in %s\n",
+ get_id_str(proc -> proc_ident)));
xtype = find_type_in_module(current_module, eff -> effect.alloc.tp_id);
assert(xtype && "type not found");
sym.type_p = ftype;
alloc = new_Alloc(get_store(), new_SymConst(sym, symconst_size), ftype,
- heap_alloc);
+ heap_alloc);
set_store(new_Proj(alloc, mode_M, 0));
eff -> firmnode = new_Proj(alloc, mode_P, 2);
{
ir_node *unknown;
- VERBOSE_PRINT((stdout, "create unknown in %s\n", proc -> procname));
+ VERBOSE_PRINT((stdout, "create unknown in %s\n",
+ get_id_str(proc -> proc_ident)));
unknown = new_Unknown(mode_ANY);
eff -> firmnode = unknown;
ir_node **irns;
int i, num;
type *mtype;
+ int mik; /* is method somehow known? */
- VERBOSE_PRINT((stdout, "create call in %s\n", proc -> procname));
+ VERBOSE_PRINT((stdout, "create call in %s\n",
+ get_id_str(proc -> proc_ident)));
- ent = eff -> effect.call.ent -> f_ent;
- VERBOSE_PRINT((stdout, "call %s\n", get_entity_name(ent)));
+ if(eff -> effect.call.ent) {
+ ent = eff -> effect.call.ent -> f_ent;
+ VERBOSE_PRINT((stdout, "call %s\n", get_entity_name(ent)));
+ }
+ else {
+ ent = NULL;
+ VERBOSE_PRINT((stdout, "call something in memory\n"));
+ }
addr = find_valueid_in_proc_effects(eff -> effect.call.valrefid, proc);
assert(addr && "no address for load");
set_irn_mode(addr -> firmnode, mode_P);
}
- /* the address */
- sel = new_simpleSel(get_store(), addr -> firmnode, ent);
- /* mthod type */
- mtype = get_entity_type(ent);
+ if(ent) {
+ /* the address */
+ sel = new_simpleSel(get_store(), addr -> firmnode, ent);
+ /* mthod type */
+ mtype = get_entity_type(ent);
+ mik = true;
+ }
+ else {
+ /* the address */
+ sel = addr -> firmnode;
+ /* mthod type */
+ mtype = get_unknown_type();
+ mik = false;
+ }
+
/* 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)));
+ if(mik) {
+ 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)));
+ if(mik) {
+ set_irn_mode(irns[i], get_type_mode(get_method_param_type(mtype, i)));
+ }
+ else {
+ set_irn_mode(irns[i], mode_ANY);
+ }
}
}
- call = new_Call(get_store(), sel, num, irns, get_entity_type(ent));
+ call = new_Call(get_store(), sel, num, irns, mtype);
set_store(new_Proj(call, mode_M, 0));
- // eff -> firmnode = new_Proj(store, mode, 2);
- eff -> firmnode = call;
+ if(mik && (0 != get_method_n_ress(mtype))) {
+ eff -> firmnode = new_Proj(call,
+ get_type_mode(get_method_res_type(mtype, 0)),
+ 0);
+ add_value_to_proc(proc, eff); /* result can be accessed */
+ }
+ else {
+ eff -> firmnode = NULL; /* result can not be accessed */
+ }
+}
- add_value_to_proc(proc, eff);
+static void create_abstract_join2 (ir_graph *irg, proc_t *proc, eff_t *eff)
+{
+ ir_node *unknown = NULL;
+ ir_node *cond = NULL;
+ ir_node *phi = NULL;
+
+ ir_node *ins [2];
+ ir_node *block [2];
+ ir_node *projX [2];
+ ir_node *jmp [2];
+
+ eff_t *in_eff = NULL;
+ int n_ins = -1;
+
+ VERBOSE_PRINT((stdout, "create join2 in %s\n",
+ get_id_str(proc -> proc_ident)));
+
+ assert (eff_join == eff->kind);
+
+ n_ins = eff->effect.join.n_ins;
+ assert (2 == n_ins);
+
+ in_eff = find_valueid_in_proc_effects (eff->effect.join.ins [0], proc);
+ ins [0] = in_eff->firmnode;
+ in_eff = find_valueid_in_proc_effects (eff->effect.join.ins [1], proc);
+ ins [1] = in_eff->firmnode;
+
+ unknown = new_Unknown (mode_Iu);
+ cond = new_Cond (unknown);
+
+ projX [0] = new_Proj (cond, mode_X, 0);
+ projX [1] = new_Proj (cond, mode_X, 1);
+
+ mature_immBlock (get_cur_block ());
+
+ block [0] = new_immBlock ();
+ add_immBlock_pred (block [0], projX [0]);
+ jmp [0] = new_Jmp ();
+ mature_immBlock (block [0]);
+
+ block [1] = new_immBlock ();
+ add_immBlock_pred (block [1], projX [1]);
+ jmp [1] = new_Jmp ();
+ mature_immBlock (block [1]);
+
+ new_Block (2, jmp);
+
+ phi = new_Phi (2, ins, get_irn_mode (ins [0]));
+ VERBOSE_PRINT ((stdout, "%s: phi.nr = %li\n", __FUNCTION__, get_irn_node_nr (phi)));
+
+ eff->firmnode = phi;
+
+ add_value_to_proc (proc, eff);
+}
+
+static void create_abstract_join (ir_graph *irg, proc_t *proc, eff_t *eff)
+{
+ ir_node **ins = NULL;
+ ir_node *unknown = NULL;
+ ir_node *cond = NULL;
+ ir_node *block = NULL;
+ ir_node *phi = NULL;
+ ir_mode *join_md = mode_ANY;
+ int n_ins = -1;
+ int i;
+
+ VERBOSE_PRINT((stdout, "create join in %s\n",
+ get_id_str(proc -> proc_ident)));
+
+ assert (eff_join == eff->kind);
+
+ n_ins = eff->effect.join.n_ins;
+ /* hmm ... special-case n_ins==2? */
+ assert (2 == n_ins);
+
+ if (2 == n_ins) {
+ create_abstract_join2 (irg, proc, eff);
+ return;
+ }
+
+ unknown = new_Unknown (mode_Iu);
+ cond = new_Cond (unknown);
+ block = new_immBlock ();
+
+ ins = (ir_node**) malloc (n_ins * sizeof (ir_node*));
+ for (i = 0; i < n_ins; i ++) {
+ ir_node *s_block = new_immBlock ();
+ ir_node *projX = new_Proj (cond, mode_X, (long) i);
+ ir_node *jmp = NULL;
+ eff_t *in_eff;
+
+ add_immBlock_pred (s_block, projX);
+ mature_immBlock (s_block);
+
+ in_eff = find_valueid_in_proc_effects (eff->effect.join.ins [i], proc);
+
+ ins [i] = in_eff->firmnode;
+ if (mode_ANY != get_irn_mode (ins [i])) {
+ join_md = get_irn_mode (ins [i]);
+ }
+
+ jmp = new_Jmp ();
+ add_immBlock_pred (block, jmp);
+ }
+
+ mature_immBlock (block);
+ set_cur_block (block);
+ phi = new_Phi (n_ins, ins, join_md);
+ memset (ins, 0x00, n_ins * sizeof (ir_node*));
+ free (ins);
+
+ eff->firmnode = phi;
+
+ add_value_to_proc (proc, eff);
}
ir_graph *irg;
int i, num;
+ /* test entity */
+ assert(visibility_external_allocated == get_entity_visibility(fent)
+ && peculiarity_existent == get_entity_peculiarity(fent)
+ && "not an abstract entity");
/* create irg in entity */
irg = new_ir_graph(fent, 0);
+ set_irg_inline_property(irg, irg_inline_forbidden);
+
+ VERBOSE_PRINT((stdout, "create effects for %s\n",
+ get_id_str(proc -> proc_ident)));
- 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]));
+ "create effect \"%s\"\n", effect_string[(int)eff -> kind]));
switch(eff -> kind) {
case eff_ret:
create_abstract_return(irg, proc, eff);
case eff_call:
create_abstract_call(irg, proc, eff);
break;
+ case eff_join:
+ create_abstract_join(irg, proc, eff);
+ break;
default:
assert(0 && "effect not implemented");
break;
entity *ent;
VERBOSE_PRINT((stdout, "assign entity %s to typeid %s\n",
- xmlent -> name, xmlent -> owner));
+ get_id_str(xmlent -> ent_ident),
+ get_id_str(xmlent -> owner)));
+
typ = find_type_in_module(module, xmlent -> owner);
assert(typ && "class not found in module");
type = typ -> f_tp;
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)) {
+ get_id_str(xmlent -> ent_ident), get_entity_name(ent)));
+
+ if(get_entity_ident(ent) == xmlent -> ent_ident) {
break;
}
ent = NULL;
type *typ = NULL;
int num;
- VERBOSE_PRINT((stdout, "assign type %s\n", xmltype -> name));
+ VERBOSE_PRINT((stdout, "assign firm type to type %s\n",
+ get_id_str(xmltype -> type_ident)));
+
/* is it global type? */
typ = get_glob_type();
- if(0 == strcmp(xmltype -> name, get_type_name(typ))) {
+ if(xmltype -> type_ident == get_type_ident(typ)) {
/* yes */
xmltype -> f_tp = typ;
VERBOSE_PRINT((stdout, "is global type %s\n", get_type_name(typ)));
- }
- else {
+ } 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;
+ if(xmltype -> type_ident == get_type_ident(typ)) {
+ VERBOSE_PRINT((stdout, "found type %s\n", get_type_name(typ)));
+ xmltype -> f_tp = typ;
+ break;
}
typ = NULL;
}
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);
+ VERBOSE_PRINT((stdout, "do find owner id %s\n", get_id_str(proc -> ownerid)));
+ type = find_type_in_module(module, proc -> ownerid);
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))) {
+ if(type -> type_ident != get_type_ident(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;
+ && (type -> type_ident == get_type_ident(class_typ))) {
+ /* found class type */
+ VERBOSE_PRINT((stdout, "found type %s\n", get_type_name(class_typ)));
+ break;
}
class_typ = NULL;
}
type -> f_tp = class_typ;
/* find entity for procedure in class */
- VERBOSE_PRINT((stdout, "find method %s\n", proc -> procname));
+ VERBOSE_PRINT((stdout, "find method %s\n",
+ get_id_str(proc -> proc_ident)));
+
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));
+ if(proc -> proc_ident == get_entity_ident(fent)) {
+ VERBOSE_PRINT((stdout, "found proc %s\n",
+ get_id_str(proc -> proc_ident)));
/* @@@ TODO check args types - not in xml yet */
/* create Firm stuff */
create_abstract_firm(module, proc, fent);
type_t *type;
entity_t *ent;
- VERBOSE_PRINT((stdout,
- "create an abstraction for module %s\n", module -> name));
+ VERBOSE_PRINT((stdout, "create an abstraction for module %s\n",
+ get_id_str(module -> id)));
- VERBOSE_PRINT((stdout, "--handle types for module %s\n", module -> name));
+ VERBOSE_PRINT((stdout, "--handle types for module\n"));
for(type = module -> types; type; type = type -> prev) {
assign_firm_type(type);
}
- VERBOSE_PRINT((stdout, "--handle entities for module %s\n", module -> name));
+ VERBOSE_PRINT((stdout, "--handle entities for module\n"));
/* @@@ 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));
+ VERBOSE_PRINT((stdout, "--handle procs for module\n"));
for(proc = module -> procs; proc; proc = proc -> next) {
create_abstract_proc_effect(module, proc);
}
/* free data structures */
free_data();
+
+ types = NULL;
+ entities = NULL;
+ procs = NULL;
+ modules = NULL;
}
/********************************************************************/
\f
/*
* $Log$
+ * Revision 1.11 2004/10/29 18:51:53 liekweg
+ * Added Join
+ *
+ * Revision 1.10 2004/10/25 13:52:24 boesler
+ * seperated read.h (public interface) and read_t.h (types)
+ *
+ * Revision 1.9 2004/10/22 13:51:35 boesler
+ * prohibit inlining of pseudo ir_graphs
+ *
+ * Revision 1.8 2004/10/22 13:13:27 boesler
+ * replaced char* by idents, minor fix in Firm codegen for call
+ *
* Revision 1.7 2004/10/21 15:31:55 boesler
* added lots of stuff:
* - build abstract syntax trees