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