/* -*- 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"
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);
exit (EXIT_FAILURE);
}
- {
+ if (EXTERN_VERBOSE) {
const char *mod_str = getNodeModule (cur);
if (NULL != mod_str) {
}
}
+/** 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 */
}
-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
*
/* -*- 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))
{
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
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 */
typedef struct eff_str
{
eff_node_kind_t kind;
- /* struct eff_str *next; */
} eff_t;
typedef struct effs_str
typedef struct arg_str
{
eff_node_kind_t kind;
- /* struct eff_str *next; */
int id;
int num;
} arg_t;
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;
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;
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;
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 */
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;
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
{
/** 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