Debian Codegraph @

mip/manifest.h

raw symbols SCIP
1 /* $Id: manifest.h,v 1.114 2018/10/21 17:42:14 ragge Exp $ */
2 /*
3 * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * Redistributions of source code and documentation must retain the above
10 * copyright notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditionsand the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed or owned by Caldera
17 * International, Inc.
18 * Neither the name of Caldera International, Inc. nor the names of other
19 * contributors may be used to endorse or promote products derived from
20 * this software without specific prior written permission.
21 *
22 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
23 * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
27 * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36 #ifndef MANIFEST
37 #define MANIFEST
38
39 #include <stdio.h>
40 #include <string.h>
41 #include "config.h"
42 #include "macdefs.h"
43 #include "node.h"
44 #include "compat.h"
45
46 /*
47 * Node types
48 */
49 #define LTYPE 02 /* leaf */
50 #define UTYPE 04 /* unary */
51 #define BITYPE 010 /* binary */
52
53 /*
54 * DSIZE is the size of the dope array
55 */
56 #define DSIZE (MAXOP+1)
57
58 /*
59 * Type names, used in symbol table building.
60 * The order of the integer types are important.
61 * Signed types must have bit 0 unset, unsigned types set (used below).
62 */
63 #define UNDEF 0 /* free symbol table entry */
64 #define BOOL 1 /* function argument */
65 #define CHAR 2
66 #define UCHAR 3
67 #define SHORT 4
68 #define USHORT 5
69 #define INT 6
70 #define UNSIGNED 7
71 #define LONG 8
72 #define ULONG 9
73 #define LONGLONG 10
74 #define ULONGLONG 11
75 #define FLOAT 12
76 #define DOUBLE 13
77 #define LDOUBLE 14
78 #define STRTY 15
79 #define UNIONTY 16
80 #define XTYPE 17 /* Extended target-specific type */
81 /* #define MOETY 18 */ /* member of enum */
82 #define VOID 19
83
84 #define MAXTYPES 19 /* highest type+1 to be used by lang code */
85 /*
86 * Various flags
87 */
88 #define NOLAB (-1)
89
90 /*
91 * Type modifiers.
92 */
93 #define PTR 0x20
94 #define FTN 0x40
95 #define ARY 0x60
96 #define CON 0x20
97 #define VOL 0x40
98
99 /*
100 * Type packing constants
101 */
102 #define TMASK 0x060
103 #define TMASK1 0x180
104 #define TMASK2 0x1e0
105 #define BTMASK 0x1f
106 #define BTSHIFT 5
107 #define TSHIFT 2
108
109 /*
110 * Macros
111 */
112 #define MODTYPE(x,y) x = ((x)&(~BTMASK))|(y) /* set basic type of x to y */
113 #define BTYPE(x) ((x)&BTMASK) /* basic type of x */
114 #define ISLONGLONG(x) ((x) == LONGLONG || (x) == ULONGLONG)
115 #define ISUNSIGNED(x) (((x) <= ULONGLONG) && (((x) & 1) == (UNSIGNED & 1)))
116 #define UNSIGNABLE(x) (((x)<=ULONGLONG&&(x)>=CHAR) && !ISUNSIGNED(x))
117 #define ENUNSIGN(x) enunsign(x)
118 #define DEUNSIGN(x) deunsign(x)
119 #define ISINTEGER(x) ((x) >= BOOL && (x) <= ULONGLONG)
120 #define ISPTR(x) (((x)&TMASK)==PTR)
121 #define ISFTN(x) (((x)&TMASK)==FTN) /* is x a function type? */
122 #define ISARY(x) (((x)&TMASK)==ARY) /* is x an array type? */
123 #define ISCON(x) (((x)&CON)==CON) /* is x const? */
124 #define ISVOL(x) (((x)&VOL)==VOL) /* is x volatile? */
125 #define INCREF(x) ((((x)&~BTMASK)<<TSHIFT)|PTR|((x)&BTMASK))
126 #define INCQAL(x) ((((x)&~BTMASK)<<TSHIFT)|((x)&BTMASK))
127 #define DECREF(x) ((((x)>>TSHIFT)&~BTMASK)|((x)&BTMASK))
128 #define DECQAL(x) ((((x)>>TSHIFT)&~BTMASK)|((x)&BTMASK))
129 #define SETOFF(x,y) { if ((x)%(y) != 0) (x) = (((x)/(y) + 1) * (y)); }
130 /* advance x to a multiple of y */
131 #define NOFIT(x,y,z) (((x)%(z) + (y)) > (z))
132 /* can y bits be added to x without overflowing z */
133
134 /* Endianness. Target is expected to TARGET_ENDIAN to one of these */
135 #define TARGET_LE 1
136 #define TARGET_BE 2
137 #define TARGET_PDP 3
138 #define TARGET_ANY 4
139
140 #ifndef SPECIAL_INTEGERS
141 #define ASGLVAL(lval, val)
142 #endif
143
144 /*
145 * Pack and unpack field descriptors (size and offset)
146 */
147 #define PKFIELD(s,o) (((o)<<7)| (s))
148 #define UPKFSZ(v) ((v)&0177)
149 #define UPKFOFF(v) ((v)>>7)
150
151 /*
152 * Operator information
153 */
154 #define TYFLG 016
155 #define ASGFLG 01
156 #define LOGFLG 020
157
158 #define SIMPFLG 040
159 #define COMMFLG 0100
160 #define DIVFLG 0200
161 #define FLOFLG 0400
162 #define LTYFLG 01000
163 #define CALLFLG 02000
164 #define MULFLG 04000
165 #define SHFFLG 010000
166 #define ASGOPFLG 020000
167
168 #define SPFLG 040000
169
170 #define regno(p) ((p)->n_rval) /* register number */
171
172 /*
173 *
174 */
175 extern int gflag, kflag, pflag;
176 extern int sspflag;
177 extern int xscp, xssa, xtailcall, xtemps, xdeljumps, xdce;
178 extern int xuchar;
179
180 int yyparse(void);
181 void yyaccpt(void);
182
183 /*
184 * List handling macros, similar to those in 4.4BSD.
185 * The double-linked list is insque-style.
186 */
187 /* Double-linked list macros */
188 #define DLIST_INIT(h,f) { (h)->f.q_forw = (h); (h)->f.q_back = (h); }
189 #define DLIST_ENTRY(t) struct { struct t *q_forw, *q_back; }
190 #define DLIST_NEXT(h,f) (h)->f.q_forw
191 #define DLIST_PREV(h,f) (h)->f.q_back
192 #define DLIST_ISEMPTY(h,f) ((h)->f.q_forw == (h))
193 #define DLIST_ENDMARK(h) (h)
194 #define DLIST_FOREACH(v,h,f) \
195 for ((v) = (h)->f.q_forw; (v) != (h); (v) = (v)->f.q_forw)
196 #define DLIST_FOREACH_REVERSE(v,h,f) \
197 for ((v) = (h)->f.q_back; (v) != (h); (v) = (v)->f.q_back)
198 #define DLIST_INSERT_BEFORE(h,e,f) { \
199 (e)->f.q_forw = (h); \
200 (e)->f.q_back = (h)->f.q_back; \
201 (e)->f.q_back->f.q_forw = (e); \
202 (h)->f.q_back = (e); \
203 }
204 #define DLIST_INSERT_AFTER(h,e,f) { \
205 (e)->f.q_forw = (h)->f.q_forw; \
206 (e)->f.q_back = (h); \
207 (e)->f.q_forw->f.q_back = (e); \
208 (h)->f.q_forw = (e); \
209 }
210 #define DLIST_REMOVE(e,f) { \
211 (e)->f.q_forw->f.q_back = (e)->f.q_back; \
212 (e)->f.q_back->f.q_forw = (e)->f.q_forw; \
213 }
214
215 /* Single-linked list */
216 #define SLIST_INIT(h) \
217 { (h)->q_forw = NULL; (h)->q_last = &(h)->q_forw; }
218 #define SLIST_SETUP(h) { NULL, &(h)->q_forw }
219 #define SLIST_ENTRY(t) struct { struct t *q_forw; }
220 #define SLIST_HEAD(n,t) struct n { struct t *q_forw, **q_last; }
221 #define SLIST_ISEMPTY(h) ((h)->q_last == &(h)->q_forw)
222 #define SLIST_FIRST(h) ((h)->q_forw)
223 #define SLIST_FOREACH(v,h,f) \
224 for ((v) = (h)->q_forw; (v) != NULL; (v) = (v)->f.q_forw)
225 #define SLIST_INSERT_FIRST(h,e,f) { \
226 if ((h)->q_last == &(h)->q_forw) \
227 (h)->q_last = &(e)->f.q_forw; \
228 (e)->f.q_forw = (h)->q_forw; \
229 (h)->q_forw = (e); \
230 }
231 #define SLIST_INSERT_LAST(h,e,f) { \
232 (e)->f.q_forw = NULL; \
233 *(h)->q_last = (e); \
234 (h)->q_last = &(e)->f.q_forw; \
235 }
236
237 #ifndef MKEXT
238 /*
239 * Functions for inter-pass communication.
240 *
241 */
242 struct interpass {
243 DLIST_ENTRY(interpass) qelem;
244 int type;
245 int lineno;
246 union {
247 NODE *_p;
248 int _locctr;
249 int _label;
250 int _curoff;
251 char *_name;
252 } _un;
253 };
254
255 /*
256 * Special struct for prologue/epilogue.
257 * - ip_lblnum contains the lowest/highest+1 label used
258 * - ip_lbl is set before/after all code and after/before the prolog/epilog.
259 */
260 struct interpass_prolog {
261 struct interpass ipp_ip;
262 char *ipp_name; /* Function name */
263 int ipp_vis; /* Function visibility */
264 TWORD ipp_type; /* Function type */
265 int ipp_autos; /* Size on stack needed */
266 int ip_tmpnum; /* # allocated temp nodes so far */
267 int ip_lblnum; /* # used labels so far */
268 int *ip_labels; /* labels used in computed goto */
269 #ifdef TARGET_IPP_MEMBERS
270 TARGET_IPP_MEMBERS
271 #endif
272 };
273 #else
274 struct interpass { int dummy; };
275 struct interpass_prolog;
276 #endif /* !MKEXT */
277
278 /*
279 * Epilog/prolog takes following arguments (in order):
280 * - type
281 * - regs
282 * - autos
283 * - name
284 * - type
285 * - retlab
286 */
287
288 #define ip_node _un._p
289 #define ip_locc _un._locctr
290 #define ip_lbl _un._label
291 #define ip_name _un._name
292 #define ip_asm _un._name
293 #define ip_off _un._curoff
294
295 /* Types of inter-pass structs */
296 #define IP_NODE 1
297 #define IP_PROLOG 2
298 #define IP_EPILOG 4
299 #define IP_DEFLAB 5
300 #define IP_DEFNAM 6
301 #define IP_ASM 7
302 #define MAXIP 7
303
304 void send_passt(int type, ...);
305
306
307 /*
308 * Attributes common to all passes.
309 */
310 enum {
311 ATTR_NONE,
312 ATTR_FP_SWAPPED,
313 #ifdef GCC_COMPAT
314 GCC_ATYP_STDCALL,
315 GCC_ATYP_CDECL,
316 #endif
317 #ifdef ATTR_MI_TARGET
318 ATTR_MI_TARGET,
319 #endif
320 ATTR_MI_MAX
321 };
322
323 struct attr *attr_add(struct attr *orig, struct attr *new);
324 struct attr *attr_new(int, int);
325 struct attr *attr_find(struct attr *, int);
326 struct attr *attr_copy(struct attr *src, struct attr *dst, int nelem);
327 struct attr *attr_dup(struct attr *ap);
328
329 /*
330 * External declarations, typedefs and the like
331 */
332
333 /* used for memory allocation */
334 typedef struct mark {
335 void *tmsav;
336 void *tasav;
337 int elem;
338 } MARK;
339
340 /* memory management stuff */
341 void *permalloc(size_t);
342 void *tmpcalloc(size_t);
343 void *tmpalloc(size_t);
344 void tmpfree(void);
345 char *newstring(char *, size_t);
346 char *tmpstrdup(char *str);
347 void markset(struct mark *m);
348 void markfree(struct mark *m);
349 void *xmalloc(int size);
350 void *xcalloc(int a, int b);
351 void *xstrdup(char *s);
352
353 int getlab(void);
354
355 /* command-line processing */
356 void mflags(char *);
357
358 void tprint(TWORD, TWORD);
359
360 /* pass t communication subroutines */
361 void topt_compile(struct interpass *);
362
363 /* pass 2 communication subroutines */
364 void pass2_compile(struct interpass *);
365
366 /* node routines */
367 NODE *nfree(NODE *);
368 void tfree(NODE *);
369 NODE *tcopy(NODE *);
370 void walkf(NODE *, void (*f)(NODE *, void *), void *);
371 void fwalk(NODE *t, void (*f)(NODE *, int, int *, int *), int down);
372 void flist(NODE *p, void (*f)(NODE *, void *), void *);
373 void listf(NODE *p, void (*f)(NODE *));
374 NODE *listarg(NODE *p, int n, int *cnt);
375 void cerror(const char *s, ...);
376 void werror(const char *s, ...);
377 void uerror(const char *s, ...);
378 void mkdope(void);
379 void tcheck(void);
380
381 extern int nerrors; /* number of errors seen so far */
382 extern int warniserr; /* treat warnings as errors */
383
384 /* gcc warning stuff */
385 #define Wtruncate 0
386 #define Wstrict_prototypes 1
387 #define Wmissing_prototypes 2
388 #define Wimplicit_int 3
389 #define Wimplicit_function_declaration 4
390 #define Wshadow 5
391 #define Wpointer_sign 6
392 #define Wsign_compare 7
393 #define Wunknown_pragmas 8
394 #define Wunreachable_code 9
395 #define Wdeprecated_declarations 10
396 #define Wattributes 11
397 #define Wuninitialized 12
398
399 void warner(int type, ...);
400 int Wset(char *, int, int);
401 void Wflags(char *);
402 TWORD deunsign(TWORD t);
403 TWORD enunsign(TWORD t);
404 #endif