1 /* Id: manifest.h,v 1.110 2015/08/11 20:08:22 ragge Exp */ 2 /* $NetBSD: manifest.h,v 1.1.1.7 2016/02/09 20:29:14 plunky 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 */ 176 extern int gflag, kflag, pflag; 177 extern int sspflag; 178 extern int xssa, xtailcall, xtemps, xdeljumps, xdce; 179 extern int xuchar; 180 181 int yyparse(void); 182 void 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 */ 243 struct 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 */ 261 struct 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 int *ip_labels; /* labels used in computed goto */ 273 #ifdef TARGET_IPP_MEMBERS 274 TARGET_IPP_MEMBERS 275 #endif 276 }; 277 #else 278 struct interpass { int dummy; }; 279 struct interpass_prolog; 280 #endif /* !MKEXT */ 281 282 /* 283 * Epilog/prolog takes following arguments (in order): 284 * - type 285 * - regs 286 * - autos 287 * - name 288 * - type 289 * - retlab 290 */ 291 292 #define ip_node _un._p 293 #define ip_locc _un._locctr 294 #define ip_lbl _un._label 295 #define ip_name _un._name 296 #define ip_asm _un._name 297 #define ip_off _un._curoff 298 299 /* Types of inter-pass structs */ 300 #define IP_NODE 1 301 #define IP_PROLOG 2 302 #define IP_EPILOG 4 303 #define IP_DEFLAB 5 304 #define IP_DEFNAM 6 305 #define IP_ASM 7 306 #define MAXIP 7 307 308 void send_passt(int type, ...); 309 310 311 /* 312 * Attributes common to all passes. 313 */ 314 enum { 315 ATTR_NONE, 316 #ifdef GCC_COMPAT 317 GCC_ATYP_STDCALL, 318 GCC_ATYP_CDECL, 319 #endif 320 #ifdef ATTR_MI_TARGET 321 ATTR_MI_TARGET, 322 #endif 323 ATTR_MI_MAX 324 }; 325 326 struct attr *attr_add(struct attr *orig, struct attr *new); 327 struct attr *attr_new(int, int); 328 struct attr *attr_find(struct attr *, int); 329 struct attr *attr_copy(struct attr *src, struct attr *dst, int nelem); 330 struct attr *attr_dup(struct attr *ap); 331 332 /* 333 * External declarations, typedefs and the like 334 */ 335 336 /* used for memory allocation */ 337 typedef struct mark { 338 void *tmsav; 339 void *tasav; 340 int elem; 341 } MARK; 342 343 /* memory management stuff */ 344 void *permalloc(size_t); 345 void *tmpcalloc(size_t); 346 void *tmpalloc(size_t); 347 void tmpfree(void); 348 char *newstring(char *, size_t); 349 char *tmpstrdup(char *str); 350 void markset(struct mark *m); 351 void markfree(struct mark *m); 352 void *xmalloc(int size); 353 void *xcalloc(int a, int b); 354 void *xstrdup(char *s); 355 356 int getlab(void); 357 358 /* command-line processing */ 359 void mflags(char *); 360 361 void tprint(TWORD, TWORD); 362 363 /* pass t communication subroutines */ 364 void topt_compile(struct interpass *); 365 366 /* pass 2 communication subroutines */ 367 void pass2_compile(struct interpass *); 368 369 /* node routines */ 370 NODE *nfree(NODE *); 371 void tfree(NODE *); 372 NODE *tcopy(NODE *); 373 void walkf(NODE *, void (*f)(NODE *, void *), void *); 374 void fwalk(NODE *t, void (*f)(NODE *, int, int *, int *), int down); 375 void flist(NODE *p, void (*f)(NODE *, void *), void *); 376 void listf(NODE *p, void (*f)(NODE *)); 377 NODE *listarg(NODE *p, int n, int *cnt); 378 void cerror(const char *s, ...); 379 void werror(const char *s, ...); 380 void uerror(const char *s, ...); 381 void mkdope(void); 382 void tcheck(void); 383 384 extern int nerrors; /* number of errors seen so far */ 385 extern int warniserr; /* treat warnings as errors */ 386 387 /* gcc warning stuff */ 388 #define Wtruncate 0 389 #define Wstrict_prototypes 1 390 #define Wmissing_prototypes 2 391 #define Wimplicit_int 3 392 #define Wimplicit_function_declaration 4 393 #define Wshadow 5 394 #define Wpointer_sign 6 395 #define Wsign_compare 7 396 #define Wunknown_pragmas 8 397 #define Wunreachable_code 9 398 #define Wdeprecated_declarations 10 399 #define Wattributes 11 400 401 void warner(int type, ...); 402 int Wset(char *, int, int); 403 void Wflags(char *); 404 TWORD deunsign(TWORD t); 405 TWORD enunsign(TWORD t); 406 #endif 407