#include #include #include #include #pragma lib "../cc/cc.a$O" #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; #define NHUNK 50000L #define BUFSIZ 8192 #define NSYMB 500 #define NHASH 1024 #define STRINGSZ 200 #define HISTSZ 20 #define YYMAXDEPTH 500 #define NTERM 10 #define MAXALIGN 7 #define SIGN(n) ((vlong)1<<(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 */ ushort* rstring; /* rune string */ Sym* sym; Type* type; long lineno; char op; char class; char 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; char 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; char shift; char nbits; char 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; long c; } fi; struct Io { Io* link; char* p; char* cb; char* cp; /* current point in cb */ char* cbe; /* end of cb */ long c; short f; }; #define I ((Io*)0) #define addioc(i, c) print("I '%C'\n", c) ; ((i->cp == i->cbe) ? extio(i, (c)) : (*i->cp++ = (c))) 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, OEND }; enum { TXXX, TCHAR, TUCHAR, TSHORT, TUSHORT, TINT, TUINT, TLONG, TULONG, TVLONG, TUVLONG, TFLOAT, TDOUBLE, TIND, TFUNC, TARRAY, TVOID, TSTRUCT, TUNION, TENUM, NTYPE, TAUTO = NTYPE, TEXTERN, TSTATIC, TTYPEDEF, TTYPESTR, TREGISTER, TCONSTNT, TVOLATILE, TUNSIGNED, TSIGNED, TDOT, TFILE, TOLD, NALLTYPES, }; 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<