1 /*	$Id: manifest.h,v 1.104 2014/06/07 07:04:10 plunky 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 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 #define	NIPPREGS	BIT2BYTE(MAXREGS)/sizeof(bittype)
266 	bittype ipp_regs[NIPPREGS];
267 				/* Bitmask of registers to save */
268 	int ipp_autos;		/* Size on stack needed */
269 	int ip_tmpnum;		/* # allocated temp nodes so far */
270 	int ip_lblnum;		/* # used labels so far */
271 	int *ip_labels;		/* labels used in computed goto */
272 #ifdef TARGET_IPP_MEMBERS
273 	TARGET_IPP_MEMBERS
274 #endif
275 };
276 #else
277 struct interpass { int dummy; };
278 struct interpass_prolog;
279 #endif /* !MKEXT */
280 
281 /*
282  * Epilog/prolog takes following arguments (in order):
283  * - type
284  * - regs
285  * - autos
286  * - name
287  * - type
288  * - retlab
289  */
290 
291 #define	ip_node	_un._p
292 #define	ip_locc	_un._locctr
293 #define	ip_lbl	_un._label
294 #define	ip_name	_un._name
295 #define	ip_asm	_un._name
296 #define	ip_off	_un._curoff
297 
298 /* Types of inter-pass structs */
299 #define	IP_NODE		1
300 #define	IP_PROLOG	2
301 #define	IP_EPILOG	4
302 #define	IP_DEFLAB	5
303 #define	IP_DEFNAM	6
304 #define	IP_ASM		7
305 #define	MAXIP		7
306 
307 void send_passt(int type, ...);
308 /*
309  * External declarations, typedefs and the like
310  */
311 
312 /* used for memory allocation */
313 typedef struct mark {
314 	void *tmsav;
315 	void *tasav;
316 	int elem;
317 } MARK;
318 
319 /* memory management stuff */
320 void *permalloc(size_t);
321 void *tmpcalloc(size_t);
322 void *tmpalloc(size_t);
323 void tmpfree(void);
324 char *newstring(char *, size_t);
325 char *tmpstrdup(char *str);
326 void markset(struct mark *m);
327 void markfree(struct mark *m);
328 
329 /* command-line processing */
330 void mflags(char *);
331 
332 void tprint(TWORD, TWORD);
333 
334 /* pass t communication subroutines */
335 void topt_compile(struct interpass *);
336 
337 /* pass 2 communication subroutines */
338 void pass2_compile(struct interpass *);
339 
340 /* node routines */
341 NODE *nfree(NODE *);
342 void tfree(NODE *);
343 NODE *tcopy(NODE *);
344 void walkf(NODE *, void (*f)(NODE *, void *), void *);
345 void fwalk(NODE *t, void (*f)(NODE *, int, int *, int *), int down);
346 void flist(NODE *p, void (*f)(NODE *, void *), void *);
347 void listf(NODE *p, void (*f)(NODE *));
348 NODE *listarg(NODE *p, int n, int *cnt);
349 void cerror(char *s, ...);
350 void werror(char *s, ...);
351 void uerror(char *s, ...);
352 void mkdope(void);
353 void tcheck(void);
354 
355 extern	int nerrors;		/* number of errors seen so far */
356 extern	int warniserr;		/* treat warnings as errors */
357 
358 /* gcc warning stuff */
359 #define	Wtruncate			0
360 #define	Wstrict_prototypes		1
361 #define	Wmissing_prototypes		2
362 #define	Wimplicit_int			3
363 #define	Wimplicit_function_declaration	4
364 #define	Wshadow				5
365 #define	Wpointer_sign			6
366 #define	Wsign_compare			7
367 #define	Wunknown_pragmas		8
368 #define	Wunreachable_code		9
369 #define	Wdeprecated_declarations	10
370 #define	Wattributes			11
371 
372 void warner(int type, ...);
373 int Wset(char *, int, int);
374 void Wflags(char *);
375 TWORD deunsign(TWORD t);
376 TWORD enunsign(TWORD t);
377 #endif
378