/* * This file is part of the UCB release of Plan 9. It is subject to the license * terms in the LICENSE file found in the top-level directory of this * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No * part of the UCB release of Plan 9, including this file, may be copied, * modified, propagated, or distributed except according to the terms contained * in the LICENSE file. */ #include #include #include #include // For Harvey typedef unsigned short ushort; typedef unsigned char uchar; typedef unsigned long ulong; typedef unsigned int uint; typedef signed char schar; typedef long long vlong; typedef unsigned long long uvlong; #define YYSIZE_T usize #ifndef EXTERN #define EXTERN extern #endif typedef struct Node Node; typedef struct Sym Sym; typedef struct Type Type; typedef struct Funct Funct; typedef struct Decl Decl; typedef struct Io Io; typedef struct Hist Hist; typedef struct Term Term; typedef struct Init Init; typedef struct Bits Bits; typedef Rune TRune; /* target system type */ #define NHUNK 50000L #define BUFSIZ 8192 #define NSYMB 1500 #define NHASH 1024 #define STRINGSZ 200 #define HISTSZ 20 #define YYMAXDEPTH 1500 #define NTERM 10 #define MAXALIGN 7 #define SIGN(n) (1ULL<<(n-1)) #define MASK(n) (SIGN(n)|(SIGN(n)-1)) #define BITS 5 #define NVAR (BITS*sizeof(ulong)*8) struct Bits { ulong b[BITS]; }; struct Node { Node* left; Node* right; void* label; long pc; int reg; long xoffset; double fconst; /* fp constant */ vlong vconst; /* non fp const */ char* cstring; /* character string */ TRune* rstring; /* rune string */ Sym* sym; Type* type; long lineno; char op; char oldop; char xcast; char class; u8 etype; char complex; char addable; char scale; char garb; }; #define Z ((Node*)0) struct Sym { Sym* link; Type* type; Type* suetag; Type* tenum; char* macro; long varlineno; long offset; vlong vconst; double fconst; Node* label; ushort lexical; char *name; ushort block; ushort sueblock; u8 class; char sym; char aused; char sig; }; #define S ((Sym*)0) enum{ SIGNONE = 0, SIGDONE = 1, SIGINTERN = 2, SIGNINTERN = 1729*325*1729, }; struct Decl { Decl* link; Sym* sym; Type* type; long varlineno; long offset; short val; ushort block; char class; char aused; }; #define D ((Decl*)0) struct Type { Sym* sym; Sym* tag; Funct* funct; Type* link; Type* down; long width; long offset; long lineno; schar shift; char nbits; u8 etype; char garb; }; #define T ((Type*)0) #define NODECL ((void(*)(int, Type*, Sym*))0) struct Init /* general purpose initialization */ { int code; ulong value; char* s; }; EXTERN struct { char* p; int c; } fi; struct Io { Io* link; char* p; char b[BUFSIZ]; short c; short f; }; #define I ((Io*)0) struct Hist { Hist* link; char* name; long line; long offset; }; #define H ((Hist*)0) EXTERN Hist* hist; struct Term { vlong mult; Node *node; }; enum { Axxx, Ael1, Ael2, Asu2, Aarg0, Aarg1, Aarg2, Aaut3, NALIGN, }; enum /* also in ../{8a,0a}.h */ { Plan9 = 1<<0, Unix = 1<<1, Windows = 1<<2, }; enum { DMARK, DAUTO, DSUE, DLABEL, }; enum { OXXX, OADD, OADDR, OAND, OANDAND, OARRAY, OAS, OASI, OASADD, OASAND, OASASHL, OASASHR, OASDIV, OASHL, OASHR, OASLDIV, OASLMOD, OASLMUL, OASLSHR, OASMOD, OASMUL, OASOR, OASSUB, OASXOR, OBIT, OBREAK, OCASE, OCAST, OCOMMA, OCOND, OCONST, OCONTINUE, ODIV, ODOT, ODOTDOT, ODWHILE, OENUM, OEQ, OFOR, OFUNC, OGE, OGOTO, OGT, OHI, OHS, OIF, OIND, OINDREG, OINIT, OLABEL, OLDIV, OLE, OLIST, OLMOD, OLMUL, OLO, OLS, OLSHR, OLT, OMOD, OMUL, ONAME, ONE, ONOT, OOR, OOROR, OPOSTDEC, OPOSTINC, OPREDEC, OPREINC, OPROTO, OREGISTER, ORETURN, OSET, OSIGN, OSIZE, OSTRING, OLSTRING, OSTRUCT, OSUB, OSWITCH, OUNION, OUSED, OWHILE, OXOR, ONEG, OCOM, OPOS, OELEM, OTST, /* used in some compilers */ OINDEX, OFAS, OREGPAIR, OEXREG, OEND }; enum { TXXX, TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, TVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND, TFUNC, TARRAY, TVOID, TSTRUCT, TUNION, TENUM, TDOT, NTYPE, TAUTO = NTYPE, TEXTERN, TSTATIC, TTYPEDEF, TTYPESTR, TREGISTER, TCONSTNT, TVOLATILE, TUNSIGNED, TSIGNED, TFILE, TOLD, NALLTYPES, /* adapt size of Rune to target system's size */ TRUNE = sizeof(TRune)==4? TUINT: TUSHORT, }; enum { CXXX, CAUTO, CEXTERN, CGLOBL, CSTATIC, CLOCAL, CTYPEDEF, CTYPESTR, CPARAM, CSELEM, CLABEL, CEXREG, NCTYPES, }; enum { GXXX = 0, GCONSTNT = 1<<0, GVOLATILE = 1<<1, NGTYPES = 1<<2, GINCOMPLETE = 1<<2, }; enum { BCHAR = 1L<