Cleanup, comments ...
authorFlorian Liekweg <liekweg@ipd.info.uni-karlsruhe.de>
Mon, 11 Oct 2004 15:56:09 +0000 (15:56 +0000)
committerFlorian Liekweg <liekweg@ipd.info.uni-karlsruhe.de>
Mon, 11 Oct 2004 15:56:09 +0000 (15:56 +0000)
Added init func --flo

[r4098]

ir/external/read.c
ir/external/read.h

index cca73ac..7b01c32 100644 (file)
@@ -1,14 +1,16 @@
 /* -*- c -*- */
 
 /*
-  configure libxml2 (default Linux libxml2.rpm doesn't cut it)
-
-  ./configure --prefix=/afs/info.uni-karlsruhe.de/user/<home>/src/C/xml --with-gnu-ld --with-pic --with-output --with-tree --with-reader --with-pattern --with-writer --with-push --with-valid --with-catalog --with-xpath--with-xptr --with-c14n --with-xinclude --with-schemas --with-regexps --with-debug --with-mem-debug
-
-
-  gcc -g read.c -I../include/libxml2 -L../lib -lxml2 -o read
-  ./read <file>.xml
-*/
+ * Project:     libFIRM
+ * File name:   ir/external/read.c
+ * Purpose:     Read descriptions of external effects
+ * Author:      Florian
+ * Modified by:
+ * Created:     11.10.2004
+ * CVS-ID:      $$
+ * Copyright:   (c) 1999-2004 Universität Karlsruhe
+ * Licence:     This file is protected by GPL -  GNU GENERAL PUBLIC LICENSE.
+ */
 
 # include "read.h"
 
@@ -603,11 +605,17 @@ effs_t *getEffectByName (const char *procname)
   return (NULL);
 }
 
-void read_extern (const char *filename)
+void extern_init ()
+{
+  /* nothing to do */
+}
+
+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);
@@ -624,7 +632,7 @@ void read_extern (const char *filename)
     exit (EXIT_FAILURE);
   }
 
-  {
+  if (EXTERN_VERBOSE) {
     const char *mod_str = getNodeModule (cur);
 
     if (NULL != mod_str) {
@@ -654,6 +662,63 @@ void read_extern (const char *filename)
   }
 }
 
+/** clean up our mess */
+void extern_cleanup ()
+{
+  /* the types */
+  {
+    type_t *tp = types;
+
+    while (NULL != tp) {
+      type_t *curr = tp;
+      tp = tp->prev;
+
+      free ((char*) curr->name);
+      memset (curr, 0x00, sizeof (type_t));
+      free (curr);
+    }
+
+    types = NULL;
+  }
+
+  /* the ennities */
+  {
+    entity_t *ent = entities;
+
+    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);
+    }
+
+    entities = NULL;
+  }
+
+  /* the effs */
+  {
+    effs_t *eff = effs;
+
+    while (NULL != eff) {
+      int i;
+      effs_t *curr = eff;
+      eff = eff->next;
+
+      for (i = 0; i < curr->n_effs; i ++) {
+        free (curr->effs [i]);
+      }
+
+      free (curr);
+    }
+  }
+
+  effs = NULL;
+}
+
+
 void test_getEffectByName ()
 {
   /* test getEffectByName */
@@ -687,103 +752,14 @@ void test_getEffectByName ()
 }
 
 
-int
-main (int argc, char **argv)
-{
-  /* xmlNsPtr ns = NULL; */           /* no namespace for us */
-  xmlDocPtr doc;                /* whole document */
-  xmlNodePtr cur;               /* current node */
-  char *name;
-
-  if (2 != argc) {
-    fprintf (stderr, "no filename\n");
-    exit (EXIT_FAILURE);
-  }
-
-  /* i've got no idea what the VERSION cast is all about. voodoo
-     programming at its finest. */
-  LIBXML_TEST_VERSION xmlKeepBlanksDefault (0);
-  name = argv [1];
-  doc = xmlParseFile (name);
-
-  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);
-  }
-
-  {
-    const char *mod_str = getNodeModule (cur);
-
-    if (NULL != mod_str) {
-      fprintf (stdout, "effects for \"%s\"\n", mod_str);
-    } else {
-      fprintf (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;
-  }
-
-  /* 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 = 0;
-
-    while (NULL != names [i]) {
-      effs_t *the_eff = getEffectByName (names [i]);
-
-      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]);
-      }
-      i ++;
-    }
-  }
-
-  exit (EXIT_SUCCESS);
-}
 
 \f
 /*
  * $Log$
+ * Revision 1.2  2004/10/11 15:56:09  liekweg
+ * Cleanup, comments ...
+ * Added init func --flo
+ *
  * Revision 1.1  2004/10/11 09:31:06  liekweg
  * First Import of XML reading procs --flo
  *
index 042f8c7..d623979 100644 (file)
@@ -1,23 +1,47 @@
 /* -*- c -*- */
 
-#ifndef _READ_H_
-#define _READ_H_
-
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <assert.h>
-
-#include <libxml/xmlmemory.h>
-#include <libxml/parser.h>
-#include <libxml/encoding.h>
-
+/*
+ * Project:     libFIRM
+ * File name:   ir/external/read.c
+ * Purpose:     Read descriptions of external effects
+ * Author:      Florian
+ * Modified by:
+ * Created:     11.10.2004
+ * CVS-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_
+
+# include <stdio.h>
+# include <string.h>
+# include <stdlib.h>
+# include <assert.h>
+
+# include <libxml/xmlmemory.h>
+# include <libxml/parser.h>
+# include <libxml/encoding.h>
+
+# include "type.h"
+# include "entity.h"
+
+/* we need strdup */
 # ifndef _BSD_SOURCE
-#  define _BSD_SOURCE            /* need strdup */
+#  define _BSD_SOURCE
 # 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))
@@ -31,8 +55,8 @@ typedef struct type_str
 {
   const char *name;
   int id;
-  void *f_tp;                   /* firm type */
-  struct type_str *prev;
+  entity *f_tp;                 /* firm type */
+  struct type_str *prev;        /* linked list */
 } type_t;
 
 typedef struct entity_str
@@ -40,8 +64,8 @@ typedef struct entity_str
   const char *name;
   const char *tp_name;
   int id;
-  void *f_ent;                  /* firm entity */
-  struct entity_str *prev;
+  type *f_ent;                  /* firm entity */
+  struct entity_str *prev;      /* linked list */
 } entity_t;
 
 /* now the xml nodes */
@@ -63,7 +87,6 @@ typedef enum eff_node_kind {
 typedef struct eff_str
 {
   eff_node_kind_t kind;
-  /* struct eff_str *next; */
 } eff_t;
 
 typedef struct effs_str
@@ -77,7 +100,6 @@ typedef struct effs_str
 typedef struct arg_str
 {
   eff_node_kind_t kind;
-  /* struct eff_str *next; */
   int id;
   int num;
 } arg_t;
@@ -85,14 +107,12 @@ typedef struct arg_str
 typedef struct valref_str
 {
   eff_node_kind_t kind;
-  /* struct eff_str *next; */
   int refid;
 } valref_t;
 
 typedef struct select_str
 {
   eff_node_kind_t kind;
-  /* struct eff_str *next; */
   int valrefid;                 /* id of enclosed valref node, or -1 */
   entity_t *ent;
 } select_t;
@@ -100,7 +120,6 @@ typedef struct select_str
 typedef struct load_str
 {
   eff_node_kind_t kind;
-  /* struct eff_str *next; */
   int id;
   int ptrrefid;                 /* id of valref node enclosed in select, or -1 */
   entity_t *ent;
@@ -109,7 +128,6 @@ typedef struct load_str
 typedef struct store_str
 {
   eff_node_kind_t kind;
-  /* struct eff_str *next; */
   int ptrrefid;                 /* id of ptr valref node enclosed in select, or -1 */
   int valrefid;                 /* id of val valref node enclosed in select, or -1 */
   entity_t *ent;
@@ -125,7 +143,6 @@ typedef struct alloc_str
 typedef struct call_str
 {
   eff_node_kind_t kind;
-  /* struct eff_str *next; */
   int id;
   int valrefid;                 /* id of enclosed valref node, or -1 */
   entity_t *ent;                /* called entity */
@@ -136,14 +153,12 @@ typedef struct call_str
 typedef struct unknown_str
 {
   eff_node_kind_t kind;
-  /* struct eff_str *next; */
   int id;
 } unknown_t;
 
 typedef struct join_str
 {
   eff_node_kind_t kind;
-  /* struct eff_str *next; */
   int id;
   int n_ins;
   int *ins;
@@ -152,9 +167,8 @@ typedef struct join_str
 typedef struct ret_str
 {
   eff_node_kind_t kind;
-  /* struct eff_str *next; */
-  int ret_id;
-} ret_t;                     /* returned value, or -1 */
+  int ret_id;                   /* returned value, or -1 */
+} ret_t;
 
 typedef struct raise_str
 {
@@ -183,14 +197,23 @@ entity_t *getEntityById (const int);
 /** get the effect entry for the given name */
 effs_t *getEffectByName (const char*);
 
+/** initialise the data structures */
+void extern_init (void);
+
 /** read in the file of the given name */
-void read_extern (const char*);
+void extern_read (const char*);
 
+/** clean up our mess */
+void extern_cleanup (void);
 
-#endif /* defined _READ_H_ */
+# endif /* defined _READ_H_ */
 
 /*
   $Log$
+  Revision 1.2  2004/10/11 15:56:09  liekweg
+  Cleanup, comments ...
+  Added init func --flo
+
   Revision 1.1  2004/10/11 09:31:06  liekweg
   First Import of XML reading procs --flo