added Load/Store addres counter
[libfirm] / ir / external / read.c
index 652bebc..388b570 100644 (file)
@@ -1,5 +1,6 @@
 /* -*- c -*- */
 
+
 /*
  * Project:     libFIRM
  * File name:   ir/external/read.c
 #ifdef HAVE_STDLIB_H
 # include <stdlib.h>
 #endif
-
+#ifdef HAVE_STRING_H
 # include <string.h>
+#endif
+
+#include <assert.h>
+
+#include <libxml/xmlmemory.h>
+#include <libxml/parser.h>
+#include <libxml/encoding.h>
 
 #include "read_t.h"
 #include "read.h"
 #include "irvrfy.h"
 #include "type.h"
 #include "tv.h"
+#include "xmalloc.h"
+
+# define MY_ENCODING "ISO-8859-1"
+
+# define CHECK(ptr,msg)     assert (ptr && msg)
+
+# define NODE_NAME(n, m) (0 == xmlStrcmp (n->name, (const xmlChar*) #m))
+# define CHECK_NAME(n, m) assert (0 == xmlStrcmp (n->name, (const xmlChar*) #m))
+
+# define NEW(T)     (T*)xmalloc(sizeof (T))
+
 
 #define VERBOSE_PRINTING 0
 
@@ -58,7 +77,7 @@ static module_t *current_module = NULL;
 
 #if VERBOSE_PRINTING
 /* this is only used inside a VERBOSE_PRINT() call */
-static char *effect_string[] = {
+static const char *effect_string[] = {
   "arg",
   "valref",
   "select",
@@ -73,7 +92,7 @@ static char *effect_string[] = {
 };
 #endif /* defined VERBOSE_PRINTING */
 
-static const ident*
+static ident*
 getNodeModuleIdent (xmlNodePtr node)
 {
   const char *mod_str = (const char*) xmlGetProp (node, BAD_CAST "module");
@@ -81,7 +100,7 @@ getNodeModuleIdent (xmlNodePtr node)
   if (NULL == mod_str) {
     return (NULL);
   } else {
-    const ident *res = new_id_from_str (mod_str);
+    ident *res = new_id_from_str (mod_str);
     return (res);
   }
 }
@@ -94,6 +113,7 @@ getNodeProcName (xmlNodePtr node)
   return (proc_str);
 }
 
+# ifdef NEEDED
 static char*
 getNodeClassName (xmlNodePtr node)
 {
@@ -101,6 +121,7 @@ getNodeClassName (xmlNodePtr node)
   assert (proc_str);
   return ( (proc_str));
 }
+# endif /* defined NEEDED */
 
 static const char*
 getNodeId (xmlNodePtr node)
@@ -155,8 +176,9 @@ static const char
 /*
   was Public Interface
 */
+# ifdef NEEDED
 static
-type_t *getTypeByIdent (const ident *id)
+type_t *getTypeByIdent (ident *id)
 {
   type_t *curr = types; // @@@ TODO module -> types
 
@@ -169,9 +191,11 @@ type_t *getTypeByIdent (const ident *id)
 
   return (NULL);
 }
+# endif /* defined NEEDED */
 
+# ifdef NEEDED
 static
-type_t *getTypeById (const ident *id)
+type_t *getTypeById (ident *id)
 {
   type_t *curr = types; // which ones?
 
@@ -184,9 +208,11 @@ type_t *getTypeById (const ident *id)
 
   return (NULL);
 }
+# endif /* defined NEEDED */
 
+# ifdef NEEDED
 static
-entity_t *getEntityByIdents (const ident *name, const ident *tp_ident)
+entity_t *getEntityByIdents (ident *name, ident *tp_ident)
 {
   entity_t *curr = entities; // TODO module -> entities
 
@@ -200,9 +226,10 @@ entity_t *getEntityByIdents (const ident *name, const ident *tp_ident)
 
   return (NULL);
 }
+# endif /* defined NEEDED */
 
 static
-entity_t *getEntityById (const ident *id)
+entity_t *getEntityById (ident *id)
 {
   entity_t *curr = entities;
 
@@ -216,8 +243,9 @@ entity_t *getEntityById (const ident *id)
   return (NULL);
 }
 
+# ifdef NEEDED
 static
-proc_t *getEffectByName (const ident *proc_ident)
+proc_t *getEffectByName (ident *proc_ident)
 {
   proc_t *curr_effs = procs;
 
@@ -230,6 +258,7 @@ proc_t *getEffectByName (const ident *proc_ident)
 
   return (NULL);
 }
+# endif /* defined NEEDED */
 
 static
 xmlNodePtr get_any_valid_child(xmlNodePtr elem)
@@ -308,7 +337,7 @@ parseValref (xmlDocPtr doc, xmlNodePtr valelm)
 static eff_t*
 parseSelect (xmlDocPtr doc, xmlNodePtr selelm)
 {
-  const ident *entity_id = new_id_from_str(getNodeEntityStr (selelm));
+  ident *entity_id = new_id_from_str(getNodeEntityStr (selelm));
   entity_t *ent;
   xmlNodePtr child;
   eff_t *valref = NULL;
@@ -341,7 +370,7 @@ parseSelect (xmlDocPtr doc, xmlNodePtr selelm)
 static eff_t*
 parseLoad (xmlDocPtr doc, xmlNodePtr loadelm)
 {
-  const ident *id;
+  ident *id;
   xmlNodePtr child;
   eff_t *sel;
   eff_t *load = NEW (eff_t);
@@ -408,8 +437,8 @@ parseStore (xmlDocPtr doc, xmlNodePtr storeelm)
 static eff_t*
 parseAlloc (xmlDocPtr doc, xmlNodePtr allocelm)
 {
-  const ident *id;
-  const ident *type_id;
+  ident *id;
+  ident *type_id;
   eff_t *alloc = NEW (eff_t); /* ...! */
   alloc->kind = eff_alloc;
 
@@ -429,7 +458,7 @@ parseAlloc (xmlDocPtr doc, xmlNodePtr allocelm)
 static eff_t*
 parseCall (xmlDocPtr doc, xmlNodePtr callelm)
 {
-  const ident *id;
+  ident *id;
   xmlNodePtr child;
   eff_t *sel;
   xmlNodePtr arg;
@@ -468,7 +497,7 @@ parseCall (xmlDocPtr doc, xmlNodePtr callelm)
   free (sel);
 
   if (0 != n_args) {
-    const ident **args = (const ident**) malloc(n_args * sizeof(const ident*));
+    ident **args = (ident**) xmalloc(n_args * sizeof(ident*));
     int i = 0;
 
     while (NULL != arg) {
@@ -487,9 +516,9 @@ parseCall (xmlDocPtr doc, xmlNodePtr callelm)
 static eff_t*
 parseJoin (xmlDocPtr doc, xmlNodePtr joinelm)
 {
-  const ident *id;
+  ident *id;
   int n_ins;
-  const ident **ins;
+  ident **ins;
   int i;
   xmlNodePtr child;
   eff_t *join = NEW (eff_t);
@@ -508,7 +537,7 @@ parseJoin (xmlDocPtr doc, xmlNodePtr joinelm)
     child = child->next;
   }
 
-  ins = (const ident **) malloc (n_ins * sizeof (const ident *) );
+  ins = (ident **) xmalloc (n_ins * sizeof (ident *) );
   i = 0;
   child = get_valid_child(joinelm);
 
@@ -529,7 +558,7 @@ parseJoin (xmlDocPtr doc, xmlNodePtr joinelm)
 static eff_t*
 parseUnknown (xmlDocPtr doc, xmlNodePtr unknownelm)
 {
-  const ident *id;
+  ident *id;
   eff_t *unknown = NEW (eff_t);
   unknown->kind = eff_unknown;
 
@@ -603,7 +632,7 @@ parseType (xmlDocPtr doc, xmlNodePtr 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 = (type_t*) xmalloc (sizeof (type_t));
   type -> type_ident = new_id_from_str(getNodeTypeStr (typeelm));
   type -> id         = new_id_from_str(tp_id);
 
@@ -657,7 +686,7 @@ parseEffect (xmlDocPtr doc, xmlNodePtr effelm)
   curr_effs = NEW (proc_t);
   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*));
+  curr_effs->effs = (eff_t**) xmalloc (n_effs * sizeof (eff_t*));
 
   cur = effelm -> xmlChildrenNode;
   while (NULL != cur) {
@@ -702,7 +731,7 @@ parseEffect (xmlDocPtr doc, xmlNodePtr effelm)
 
 
 static
-void read_extern (const char *filename)
+int read_extern (const char *filename)
 {
   /* xmlNsPtr ns = NULL; */           /* no namespace for us */
   xmlDocPtr doc;                /* whole document */
@@ -715,7 +744,8 @@ void read_extern (const char *filename)
   LIBXML_TEST_VERSION xmlKeepBlanksDefault (0);
   VERBOSE_PRINT((stdout, "read file %s\n", filename));
   doc = xmlParseFile (filename);
-  CHECK (doc, "xmlParseFile");
+  if (! doc)
+    return 0;
 
   cur = xmlDocGetRootElement (doc);
   CHECK (cur, "xmlDocGetRootElement");
@@ -765,6 +795,8 @@ void read_extern (const char *filename)
 
   module -> next = modules;
   modules = module;
+
+  return 1;
 }
 
 /********************************************************************/
@@ -951,7 +983,7 @@ void free_data(void)
 /********************************************************************/
 
 static
-type_t *find_type_in_module(module_t *module, const ident *typeid)
+type_t *find_type_in_module(module_t *module, ident *typeid)
 {
   type_t *type;
 
@@ -975,7 +1007,7 @@ static void add_value_to_proc(proc_t *proc, eff_t *eff)
 }
 
 
-eff_t *find_valueid_in_proc_effects(const ident *id, proc_t *proc)
+eff_t *find_valueid_in_proc_effects(ident *id, proc_t *proc)
 {
   eff_t *val;
 
@@ -1026,7 +1058,7 @@ static void create_abstract_arg(ir_graph *irg, proc_t *proc, eff_t *eff)
   ir_node *arg;
   entity *ent;
   ir_mode *mode;
-  type *typ;
+  ir_type *typ;
   int num;
 
   VERBOSE_PRINT((stdout, "create effect:arg %d in %s\n",
@@ -1135,7 +1167,7 @@ static void create_abstract_store(ir_graph *irg, proc_t *proc, eff_t *eff)
 
 static void create_abstract_alloc(ir_graph *irg, proc_t *proc, eff_t *eff)
 {
-  type *ftype;
+  ir_type *ftype;
   ir_node *alloc;
   type_t *xtype;
   symconst_symbol sym;
@@ -1148,7 +1180,7 @@ static void create_abstract_alloc(ir_graph *irg, proc_t *proc, eff_t *eff)
   ftype = xtype -> f_tp;
 
   sym.type_p = ftype;
-  alloc = new_Alloc(get_store(), new_SymConst(sym, symconst_size), ftype,
+  alloc = new_Alloc(get_store(), new_SymConst(sym, symconst_type_size), ftype,
             heap_alloc);
   set_store(new_Proj(alloc, mode_M, 0));
   eff -> firmnode = new_Proj(alloc, mode_P, 2);
@@ -1178,7 +1210,7 @@ static void create_abstract_call(ir_graph *irg, proc_t *proc, eff_t *eff)
   eff_t *addr;
   ir_node **irns;
   int i, num;
-  type *mtype;
+  ir_type *mtype;
   int mik; /* is method somehow known? */
 
   VERBOSE_PRINT((stdout, "create call in %s\n",
@@ -1195,7 +1227,7 @@ static void create_abstract_call(ir_graph *irg, proc_t *proc, eff_t *eff)
 
   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 addr is Unknown, set proper mode */
   if(iro_Unknown == get_irn_opcode(addr -> firmnode)) {
     set_irn_mode(addr -> firmnode, mode_P);
   }
@@ -1203,16 +1235,16 @@ static void create_abstract_call(ir_graph *irg, proc_t *proc, eff_t *eff)
   if(ent) {
     /* the address */
     sel = new_simpleSel(get_store(), addr -> firmnode, ent);
-    /* mthod type */
+    /* method type */
     mtype = get_entity_type(ent);
-    mik = true;
+    mik = 1;
   }
   else {
     /* the address */
     sel = addr -> firmnode;
-    /* mthod type */
+    /* method type */
     mtype = get_unknown_type();
-    mik = false;
+    mik = 0;
   }
 
   /* the args */
@@ -1278,7 +1310,7 @@ static void create_abstract_join (ir_graph *irg, proc_t *proc, eff_t *eff)
 
   c_block   = new_immBlock ();  /* for the Phi after the branch(es) */
 
-  ins = (ir_node**) malloc (n_ins * sizeof (ir_node*));
+  ins = (ir_node**) xmalloc (n_ins * sizeof (ir_node*));
   for (i = 0; i < n_ins; i ++) {
     ir_node *projX   = NULL;
     ir_node *s_block = NULL;
@@ -1383,7 +1415,7 @@ static void create_abstract_firm(module_t *module, proc_t *proc, entity *fent)
   irg = new_pseudo_ir_graph(fent, 0);
   set_irg_inline_property(irg, irg_inline_forbidden);
 
-  /* If the spec says so: */
+  /* @@@ If the spec says so: */
   set_entity_visibility(fent, visibility_local);
 
   VERBOSE_PRINT((stdout, "create effects for %s\n",
@@ -1437,7 +1469,7 @@ static void create_abstract_firm(module_t *module, proc_t *proc, entity *fent)
   VERBOSE_PRINT((stdout, "verify graph\n"));
   irg_vrfy(irg);
   VERBOSE_PRINT((stdout, "finalize construction\n"));
-  finalize_cons (irg);
+  irg_finalize_cons (irg);
 }
 
 /********************************************************************/
@@ -1446,7 +1478,7 @@ static void assign_firm_entity(module_t *module, entity_t *xmlent)
 {
   int i, num;
   type_t *typ;
-  type *type;
+  ir_type *type;
   entity *ent;
 
   VERBOSE_PRINT((stdout, "assign entity %s to typeid %s\n",
@@ -1456,7 +1488,7 @@ static void assign_firm_entity(module_t *module, entity_t *xmlent)
   typ = find_type_in_module(module, xmlent -> owner);
   assert(typ && "class not found in module");
   type = typ -> f_tp;
-  assert(is_class_type(type));
+  assert(is_Class_type(type));
 
   num = get_class_n_members(type);
   ent = NULL;
@@ -1480,7 +1512,7 @@ static void assign_firm_entity(module_t *module, entity_t *xmlent)
 static void assign_firm_type(type_t *xmltype)
 {
   int i;
-  type *typ = NULL;
+  ir_type *typ = NULL;
   int num;
 
   VERBOSE_PRINT((stdout, "assign firm type to type %s\n",
@@ -1513,7 +1545,7 @@ static
 void create_abstract_proc_effect(module_t *module, proc_t *proc)
 {
   int i, num;
-  type *class_typ = NULL;
+  ir_type *class_typ = NULL;
   type_t *type;
   entity *fent;
 
@@ -1530,11 +1562,11 @@ void create_abstract_proc_effect(module_t *module, proc_t *proc)
     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)
-     && (type -> type_ident == get_type_ident(class_typ))) {
-    /* found class type */
-    VERBOSE_PRINT((stdout, "found type %s\n", get_type_name(class_typ)));
-    break;
+      if (is_Class_type(class_typ)
+         && (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;
     }
@@ -1543,7 +1575,7 @@ void create_abstract_proc_effect(module_t *module, proc_t *proc)
     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");
+  assert(is_Class_type(class_typ) && "is not a class type");
   type -> f_tp = class_typ;
 
   /* find entity for procedure in class */
@@ -1570,8 +1602,8 @@ void create_abstract_proc_effect(module_t *module, proc_t *proc)
 
   /* fail */
   fprintf(stderr,
-         "method %s not found\nNo effects generated\nCandidates are:\n",
-         get_id_str(proc -> proc_ident));
+      "method %s not found\nNo effects generated\nCandidates are:\n",
+      get_id_str(proc -> proc_ident));
   for(i = 0; i < num; i++) {
     fent = get_class_member(class_typ, i);
     fprintf(stderr, "%s\n", get_entity_name(fent));
@@ -1607,12 +1639,13 @@ void create_abstract_module(module_t *module)
 }
 
 
-void create_abstraction(const char *filename)
+int create_abstraction(const char *filename)
 {
   module_t *module;
 
   /* read and parse XML file */
-  read_extern(filename);
+  if (! read_extern(filename))
+    return 0;
 
   /* finished reading and parsing here */
   /* build FIRM graphs */
@@ -1631,6 +1664,8 @@ void create_abstraction(const char *filename)
   entities = NULL;
   procs = NULL;
   modules = NULL;
+
+  return 1;
 }
 
 
@@ -1649,6 +1684,37 @@ void free_abstraction(void) {
 \f
 /*
  * $Log$
+ * Revision 1.26  2006/12/15 12:37:40  matze
+ * fix warnings
+ *
+ * Revision 1.25  2006/06/09 11:26:35  firm
+ * renamed type to ir_type
+ *
+ * Revision 1.24  2006/05/29 13:34:49  beck
+ * renamed symconst_size to symconst_type_size
+ *
+ * Revision 1.22  2005/08/16 10:18:35  beck
+ * create_abstraction() now returns an error code if the file could not
+ * be opened.
+ *
+ * Revision 1.21  2005/03/10 10:05:38  goetz
+ * chanmged method name
+ *
+ * Revision 1.20  2005/01/05 14:28:35  beck
+ * renames all is_x*_type() functions to is_X*_type() to prevent name clash with EDG frontend
+ *
+ * Revision 1.19  2004/12/10 15:14:34  beck
+ * used xmalloc instead of malloc
+ *
+ * Revision 1.18  2004/12/02 16:21:42  beck
+ * fixed config.h include
+ *
+ * Revision 1.17  2004/11/23 14:17:31  liekweg
+ * fenced out currently unneeded static functions
+ *
+ * Revision 1.16  2004/11/11 12:24:52  goetz
+ * fixes
+ *
  * Revision 1.15  2004/11/11 09:28:32  goetz
  * treat pseudo irgs special
  * parse 'local' from xml files