Cleanup, comments ...
[libfirm] / ir / external / read.h
1 /* -*- c -*- */
2
3 /*
4  * Project:     libFIRM
5  * File name:   ir/external/read.c
6  * Purpose:     Read descriptions of external effects
7  * Author:      Florian
8  * Modified by:
9  * Created:     11.10.2004
10  * CVS-ID:      $$
11  * Copyright:   (c) 1999-2004 Universität Karlsruhe
12  * Licence:     This file is protected by GPL -  GNU GENERAL PUBLIC LICENSE.
13  */
14
15 # ifndef _READ_H_
16 # define _READ_H_
17
18 # include <stdio.h>
19 # include <string.h>
20 # include <stdlib.h>
21 # include <assert.h>
22
23 # include <libxml/xmlmemory.h>
24 # include <libxml/parser.h>
25 # include <libxml/encoding.h>
26
27 # include "type.h"
28 # include "entity.h"
29
30 /* we need strdup */
31 # ifndef _BSD_SOURCE
32 #  define _BSD_SOURCE
33 # endif /* ! defined _BSD_SOURCE */
34
35 # define MY_ENCODING "ISO-8859-1"
36
37 /* quick hack until we get a cmd line flag or something: just add
38    '-DEXTERN_VERBOSE' to 'CFLAGS' */
39 # ifndef EXTERN_VERBOSE
40 #  define EXTERN_VERBOSE 1
41 # else
42 #  define EXTERN_VERBOSE 0
43 # endif /* defined EXTERN_VERBOSE */
44
45 # define CHECK(ptr,msg)     assert (ptr && msg)
46
47 # define NODE_NAME(n, m) (0 == xmlStrcmp (n->name, (const xmlChar*) #m))
48 # define CHECK_NAME(n, m) assert (0 == xmlStrcmp (n->name, (const xmlChar*) #m))
49
50 # define NEW(T)     (T*) malloc (sizeof (T))
51
52 /* first, the xml structures */
53
54 typedef struct type_str
55 {
56   const char *name;
57   int id;
58   entity *f_tp;                 /* firm type */
59   struct type_str *prev;        /* linked list */
60 } type_t;
61
62 typedef struct entity_str
63 {
64   const char *name;
65   const char *tp_name;
66   int id;
67   type *f_ent;                  /* firm entity */
68   struct entity_str *prev;      /* linked list */
69 } entity_t;
70
71 /* now the xml nodes */
72 typedef enum eff_node_kind {
73   eff_arg,
74   eff_valref,
75   eff_select,
76   eff_load,
77   eff_store,
78   eff_alloc,
79   eff_call,
80   eff_unknown,
81   eff_join,
82   eff_raise,
83   eff_ret
84 } eff_node_kind_t;
85
86 /* dummy type for all other effects */
87 typedef struct eff_str
88 {
89   eff_node_kind_t kind;
90 } eff_t;
91
92 typedef struct effs_str
93 {
94   char *procname;
95   int n_effs;
96   eff_t **effs;
97   struct effs_str *next;
98 } effs_t;
99
100 typedef struct arg_str
101 {
102   eff_node_kind_t kind;
103   int id;
104   int num;
105 } arg_t;
106
107 typedef struct valref_str
108 {
109   eff_node_kind_t kind;
110   int refid;
111 } valref_t;
112
113 typedef struct select_str
114 {
115   eff_node_kind_t kind;
116   int valrefid;                 /* id of enclosed valref node, or -1 */
117   entity_t *ent;
118 } select_t;
119
120 typedef struct load_str
121 {
122   eff_node_kind_t kind;
123   int id;
124   int ptrrefid;                 /* id of valref node enclosed in select, or -1 */
125   entity_t *ent;
126 } load_t;
127
128 typedef struct store_str
129 {
130   eff_node_kind_t kind;
131   int ptrrefid;                 /* id of ptr valref node enclosed in select, or -1 */
132   int valrefid;                 /* id of val valref node enclosed in select, or -1 */
133   entity_t *ent;
134 } store_t;
135
136 typedef struct alloc_str
137 {
138   eff_node_kind_t kind;
139   int id;
140   int tp_id;
141 } alloc_t;
142
143 typedef struct call_str
144 {
145   eff_node_kind_t kind;
146   int id;
147   int valrefid;                 /* id of enclosed valref node, or -1 */
148   entity_t *ent;                /* called entity */
149   int n_args;
150   int *args;
151 } call_t;
152
153 typedef struct unknown_str
154 {
155   eff_node_kind_t kind;
156   int id;
157 } unknown_t;
158
159 typedef struct join_str
160 {
161   eff_node_kind_t kind;
162   int id;
163   int n_ins;
164   int *ins;
165 } join_t;
166
167 typedef struct ret_str
168 {
169   eff_node_kind_t kind;
170   int ret_id;                   /* returned value, or -1 */
171 } ret_t;
172
173 typedef struct raise_str
174 {
175   eff_node_kind_t kind;
176   /* struct eff_str *next; */
177   int valref;                   /* what was that one for? */
178   int tp_id;
179 } raise_t;
180
181 /*
182   The public interface
183 */
184
185 /** get the type entry with the given name */
186 type_t *getTypeByName (const char*);
187
188 /** get the type entry with the given Id */
189 type_t *getTypeById (const int);
190
191 /** get the entity entry that has the given names */
192 entity_t *getEntityByNames (const char*, const char*);
193
194 /** get the entity entry that has the given Id */
195 entity_t *getEntityById (const int);
196
197 /** get the effect entry for the given name */
198 effs_t *getEffectByName (const char*);
199
200 /** initialise the data structures */
201 void extern_init (void);
202
203 /** read in the file of the given name */
204 void extern_read (const char*);
205
206 /** clean up our mess */
207 void extern_cleanup (void);
208
209 # endif /* defined _READ_H_ */
210
211 /*
212   $Log$
213   Revision 1.2  2004/10/11 15:56:09  liekweg
214   Cleanup, comments ...
215   Added init func --flo
216
217   Revision 1.1  2004/10/11 09:31:06  liekweg
218   First Import of XML reading procs --flo
219
220 */