1*32813Sdonn /* pass2.h 4.4 87/12/10 */ 218384Sralph 318384Sralph #ifndef _PASS2_ 418384Sralph #define _PASS2_ 518384Sralph 618384Sralph #include "macdefs.h" 718384Sralph #include "mac2defs.h" 818384Sralph #include "manifest.h" 918384Sralph 1018384Sralph /* cookies, used as arguments to codgen */ 1118384Sralph #define FOREFF 01 /* compute for effects only */ 1218384Sralph #define INAREG 02 /* compute into a register */ 1318384Sralph #define INTAREG 04 /* compute into a scratch register */ 1418384Sralph #define INBREG 010 /* compute into a lvalue register */ 1518384Sralph #define INTBREG 020 /* compute into a scratch lvalue register */ 1618384Sralph #define FORCC 040 /* compute for condition codes only */ 1718384Sralph #define INTEMP 010000 /* compute into a temporary location */ 1818384Sralph #define FORARG 020000 /* compute for an argument of a function */ 1918384Sralph #define FORREW 040000 /* search the table for a rewrite rule */ 2018384Sralph 2118384Sralph /* 2218384Sralph * OP descriptors, 2318384Sralph * the ASG operator may be used on some of these 2418384Sralph */ 2518384Sralph #define OPSIMP 010000 /* +, -, &, |, ^ */ 2618384Sralph #define OPCOMM 010002 /* +, &, |, ^ */ 2718384Sralph #define OPMUL 010004 /* *, / */ 2818384Sralph #define OPDIV 010006 /* /, % */ 2918384Sralph #define OPUNARY 010010 /* unary ops */ 3018384Sralph #define OPLEAF 010012 /* leaves */ 3118384Sralph #define OPANY 010014 /* any op... */ 3218384Sralph #define OPLOG 010016 /* logical ops */ 3318384Sralph #define OPFLOAT 010020 /* +, -, *, or / (for floats) */ 3418384Sralph #define OPSHFT 010022 /* <<, >> */ 3518384Sralph #define OPLTYPE 010024 /* leaf type nodes (e.g, NAME, ICON, etc.) */ 3618384Sralph 3718384Sralph /* match returns */ 3818384Sralph #define MNOPE 010000 /* no match generated */ 3918384Sralph #define MDONE 010001 /* done evalution */ 4018384Sralph 4118384Sralph /* shapes */ 4218384Sralph #define SANY 01 /* same as FOREFF */ 4318384Sralph #define SAREG 02 /* same as INAREG */ 4418384Sralph #define STAREG 04 /* same as INTAREG */ 4518384Sralph #define SBREG 010 /* same as INBREG */ 4618384Sralph #define STBREG 020 /* same as INTBREG */ 4718384Sralph #define SCC 040 /* same as FORCC */ 4818384Sralph #define SNAME 0100 /* name */ 4918384Sralph #define SCON 0200 /* constant */ 5018384Sralph #define SFLD 0400 /* field */ 5118384Sralph #define SOREG 01000 /* offset from register */ 5218384Sralph /* indirection or wild card shapes */ 5318384Sralph #ifndef WCARD1 5418384Sralph #define STARNM 02000 /* indirect through name */ 5518384Sralph #endif 5618384Sralph #ifndef WCARD2 5718384Sralph #define STARREG 04000 /* indirect through register */ 5818384Sralph #endif 5918384Sralph #define SWADD 040000 /* word address */ 6018384Sralph #define SPECIAL 0100000 /* special stuff (follows) */ 6118384Sralph #define SZERO SPECIAL /* constant zero */ 6218384Sralph #define SONE (SPECIAL|1) /* constant +1 */ 6318384Sralph #define SMONE (SPECIAL|2) /* constant -1 */ 6418384Sralph #define SCCON (SPECIAL|3) /* -256 <= constant < 256 */ 6518384Sralph #define SSCON (SPECIAL|4) /* -32768 <= constant < 32768 */ 6618384Sralph #define SSOREG (SPECIAL|5) /* non-indexed OREG */ 6732812Sdonn #define SMCON (SPECIAL|6) /* constant < 0 */ 6818384Sralph /* FORARG and INTEMP are carefully not conflicting with shapes */ 6918384Sralph 7018384Sralph /* types */ 7118384Sralph #define TCHAR 01 /* char */ 7218384Sralph #define TSHORT 02 /* short */ 7318384Sralph #define TINT 04 /* int */ 7418384Sralph #define TLONG 010 /* long */ 7518384Sralph #define TFLOAT 020 /* float */ 7618384Sralph #define TDOUBLE 040 /* double */ 7718384Sralph #define TPOINT 0100 /* pointer to something */ 7818384Sralph #define TUCHAR 0200 /* unsigned char */ 7918384Sralph #define TUSHORT 0400 /* unsigned short */ 8018384Sralph #define TUNSIGNED 01000 /* unsigned int */ 8118384Sralph #define TULONG 02000 /* unsigned long */ 8218384Sralph #define TPTRTO 04000 /* pointer to one of the above */ 8318384Sralph #define TANY 010000 /* matches anything within reason */ 8418384Sralph #define TSTRUCT 020000 /* structure or union */ 8518384Sralph 8618384Sralph /* reclamation cookies */ 8718384Sralph #define RNULL 0 /* clobber result */ 8818384Sralph #define RLEFT 01 /* reclaim left resource */ 8918384Sralph #define RRIGHT 02 /* reclaim right resource */ 9018384Sralph #define RESC1 04 /* reclaim resource allocated #1 */ 9118384Sralph #define RESC2 010 /* reclaim resource allocated #2 */ 9218384Sralph #define RESC3 020 /* reclaim resource allocated #3 */ 9318384Sralph #define RESCC 04000 /* reclaim condition codes */ 9418384Sralph #define RNOP 010000 /* DANGER: can cause loops.. */ 9518384Sralph 9618384Sralph /* needs */ 9718384Sralph #define NAREG 01 /* need an A register */ 9818384Sralph #define NACOUNT 03 /* count mask of A registers */ 9918384Sralph #define NAMASK 017 /* A register need field mask */ 10018384Sralph #define NASL 04 /* need A register shared with left resource */ 10118384Sralph #define NASR 010 /* need A register shared with right resource */ 10218384Sralph #define NBREG 020 /* need a B register */ 10318384Sralph #define NBCOUNT 060 /* count mask of B register */ 10418384Sralph #define NBMASK 0360 /* B register need field mask */ 10518384Sralph #define NBSL 0100 /* need B register shared with left resource */ 10618384Sralph #define NBSR 0200 /* need B register shared with right resource */ 10718384Sralph #define NTEMP 0400 /* need temporary storage location */ 10818384Sralph #define NTMASK 07400 /* count mask of temporary storage locations */ 10918384Sralph #define REWRITE 010000 /* need rewrite */ 11018384Sralph #define EITHER 040000 /* allocate all resources or nothing */ 11118384Sralph 11218384Sralph #define MUSTDO 010000 /* force register requirements */ 11318384Sralph #ifndef NOPREF 11418384Sralph /* also defined in onepass.h */ 11518384Sralph #define NOPREF 020000 /* no preference for register assignment */ 11618384Sralph #endif 11729926Ssam #define NEVEN 0100000 /* even register required */ 11818384Sralph 11918384Sralph /* register allocation */ 12018384Sralph extern int rstatus[]; /* register status info */ 12118384Sralph extern int busy[]; /* register use info */ 12218384Sralph extern struct respref { 12318384Sralph int cform; 12418384Sralph int mform; 12518384Sralph } respref[]; /* resource preference rules */ 12618384Sralph 12718384Sralph #define isbreg(r) (rstatus[r]&SBREG) 12818384Sralph #define istreg(r) (rstatus[r]&(STBREG|STAREG)) 12918384Sralph #define istnode(p) (p->in.op==REG && istreg(p->tn.rval)) 13018384Sralph 13118384Sralph #define TBUSY 01000 /* register temporarily busy (during alloc) */ 132*32813Sdonn #define PBUSY 02000 /* this reg and next one are used as a pair */ 133*32813Sdonn #define ISBUSY(r) (((busy[r])&(PBUSY-1)) > 1) 13418384Sralph #define REGLOOP(i) for (i = 0; i < REGSZ; ++i) 13518384Sralph 13618384Sralph extern NODE *deltrees[DELAYS]; /* trees held for delayed evaluation */ 13718384Sralph extern int deli; /* mmmmm */ 13818384Sralph 13918384Sralph #define SETSTO(x,y) (stotree = (x), stocook = (y)) 14018384Sralph extern int stocook; 14118384Sralph extern NODE *stotree; 14218384Sralph extern int callflag; 14318384Sralph 14418384Sralph extern int fregs; 14518384Sralph 14618384Sralph #ifndef ONEPASS 14718384Sralph #include "ndu.h" 14818384Sralph #endif 14918384Sralph 15018384Sralph extern NODE node[]; 15118384Sralph 15218384Sralph /* code tables */ 15318384Sralph extern struct optab { 15418384Sralph int op; /* operator to match */ 15518384Sralph int visit; /* goal to match */ 15618384Sralph int lshape; /* left shape to match */ 15718384Sralph int ltype; /* left type to match */ 15818384Sralph int rshape; /* right shape to match */ 15918384Sralph int rtype; /* right type to match */ 16018384Sralph int needs; /* resource required */ 16118384Sralph int rewrite; /* how to rewrite afterwards */ 16218384Sralph char *cstring; /* code generation template */ 16318384Sralph } table[]; 16418384Sralph 16518384Sralph extern NODE resc[]; 16618384Sralph 16718384Sralph extern OFFSZ tmpoff; 16818384Sralph extern OFFSZ maxoff; 16918384Sralph extern OFFSZ baseoff; 17018384Sralph extern OFFSZ maxtemp; 17118384Sralph extern int maxtreg; 17218384Sralph extern int ftnno; 17318384Sralph extern int rtyflg; 17418384Sralph extern int nrecur; /* flag to keep track of recursions */ 17518384Sralph 17618384Sralph extern NODE 17718384Sralph *talloc(), 17818384Sralph *eread(), 17918384Sralph *tcopy(), 18018384Sralph *getlr(); 18118384Sralph 18218384Sralph extern CONSZ rdin(); 18318384Sralph extern int eprint(); 18418384Sralph extern char *rnames[]; 18518384Sralph 18618384Sralph extern int lineno; 18718384Sralph extern char filename[]; 18818384Sralph extern int fldshf, fldsz; 18918384Sralph extern int lflag, xdebug, udebug, edebug, odebug; 19018384Sralph extern int rdebug, radebug, tdebug, sdebug; 19118384Sralph #ifdef FORT 19218384Sralph extern int Oflag; 19318384Sralph #endif 19418384Sralph 19518384Sralph #ifndef callchk 19618384Sralph #define callchk(x) allchk() 19718384Sralph #endif 19818384Sralph 19918384Sralph #ifndef PUTCHAR 20018384Sralph #define PUTCHAR(x) putchar(x) 20118384Sralph #endif 20218384Sralph 20318384Sralph /* macros for doing double indexing */ 20418384Sralph #define R2PACK(x,y,z) (0200*((x)+1)+y+040000*z) /* pack 3 regs */ 20518384Sralph #define R2UPK1(x) ((((x)>>7)-1)&0177) /* unpack reg 1 */ 20618384Sralph #define R2UPK2(x) ((x)&0177) /* unpack reg 2 */ 20718384Sralph #define R2UPK3(x) (x>>14) /* unpack reg 3 */ 20818384Sralph #define R2TEST(x) ((x)>=0200) /* test if packed */ 20918384Sralph 21018384Sralph #ifdef MULTILEVEL 21118384Sralph union mltemplate { 21218384Sralph struct ml_head { 21318384Sralph int tag; /* tree class */ 21418384Sralph int subtag; /* subclass of tree */ 21518384Sralph union mltemplate *nexthead; /* linked by mlinit() */ 21618384Sralph } mlhead; 21718384Sralph struct ml_node { 21818384Sralph int op; /* operator or op description */ 21918384Sralph int nshape; /* node shape */ 22018384Sralph /* 22118384Sralph * Both op and nshape must match the node. 22218384Sralph * where the work is to be done entirely by 22318384Sralph * op, nshape can be SANY, visa versa, op can 22418384Sralph * be OPANY. 22518384Sralph */ 22618384Sralph int ntype; /* type descriptor */ 22718384Sralph } mlnode; 22818384Sralph }; 22918384Sralph extern union mltemplate mltree[]; 23018384Sralph #endif 23118384Sralph #endif 232