1*29926Ssam /* pass2.h 4.2 86/10/29 */ 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 */ 6718384Sralph /* FORARG and INTEMP are carefully not conflicting with shapes */ 6818384Sralph 6918384Sralph /* types */ 7018384Sralph #define TCHAR 01 /* char */ 7118384Sralph #define TSHORT 02 /* short */ 7218384Sralph #define TINT 04 /* int */ 7318384Sralph #define TLONG 010 /* long */ 7418384Sralph #define TFLOAT 020 /* float */ 7518384Sralph #define TDOUBLE 040 /* double */ 7618384Sralph #define TPOINT 0100 /* pointer to something */ 7718384Sralph #define TUCHAR 0200 /* unsigned char */ 7818384Sralph #define TUSHORT 0400 /* unsigned short */ 7918384Sralph #define TUNSIGNED 01000 /* unsigned int */ 8018384Sralph #define TULONG 02000 /* unsigned long */ 8118384Sralph #define TPTRTO 04000 /* pointer to one of the above */ 8218384Sralph #define TANY 010000 /* matches anything within reason */ 8318384Sralph #define TSTRUCT 020000 /* structure or union */ 8418384Sralph 8518384Sralph /* reclamation cookies */ 8618384Sralph #define RNULL 0 /* clobber result */ 8718384Sralph #define RLEFT 01 /* reclaim left resource */ 8818384Sralph #define RRIGHT 02 /* reclaim right resource */ 8918384Sralph #define RESC1 04 /* reclaim resource allocated #1 */ 9018384Sralph #define RESC2 010 /* reclaim resource allocated #2 */ 9118384Sralph #define RESC3 020 /* reclaim resource allocated #3 */ 9218384Sralph #define RESCC 04000 /* reclaim condition codes */ 9318384Sralph #define RNOP 010000 /* DANGER: can cause loops.. */ 9418384Sralph 9518384Sralph /* needs */ 9618384Sralph #define NAREG 01 /* need an A register */ 9718384Sralph #define NACOUNT 03 /* count mask of A registers */ 9818384Sralph #define NAMASK 017 /* A register need field mask */ 9918384Sralph #define NASL 04 /* need A register shared with left resource */ 10018384Sralph #define NASR 010 /* need A register shared with right resource */ 10118384Sralph #define NBREG 020 /* need a B register */ 10218384Sralph #define NBCOUNT 060 /* count mask of B register */ 10318384Sralph #define NBMASK 0360 /* B register need field mask */ 10418384Sralph #define NBSL 0100 /* need B register shared with left resource */ 10518384Sralph #define NBSR 0200 /* need B register shared with right resource */ 10618384Sralph #define NTEMP 0400 /* need temporary storage location */ 10718384Sralph #define NTMASK 07400 /* count mask of temporary storage locations */ 10818384Sralph #define REWRITE 010000 /* need rewrite */ 10918384Sralph #define EITHER 040000 /* allocate all resources or nothing */ 11018384Sralph 11118384Sralph #define MUSTDO 010000 /* force register requirements */ 11218384Sralph #ifndef NOPREF 11318384Sralph /* also defined in onepass.h */ 11418384Sralph #define NOPREF 020000 /* no preference for register assignment */ 11518384Sralph #endif 116*29926Ssam #define NEVEN 0100000 /* even register required */ 11718384Sralph 11818384Sralph /* register allocation */ 11918384Sralph extern int rstatus[]; /* register status info */ 12018384Sralph extern int busy[]; /* register use info */ 12118384Sralph extern struct respref { 12218384Sralph int cform; 12318384Sralph int mform; 12418384Sralph } respref[]; /* resource preference rules */ 12518384Sralph 12618384Sralph #define isbreg(r) (rstatus[r]&SBREG) 12718384Sralph #define istreg(r) (rstatus[r]&(STBREG|STAREG)) 12818384Sralph #define istnode(p) (p->in.op==REG && istreg(p->tn.rval)) 12918384Sralph 13018384Sralph #define TBUSY 01000 /* register temporarily busy (during alloc) */ 13118384Sralph #define REGLOOP(i) for (i = 0; i < REGSZ; ++i) 13218384Sralph 13318384Sralph extern NODE *deltrees[DELAYS]; /* trees held for delayed evaluation */ 13418384Sralph extern int deli; /* mmmmm */ 13518384Sralph 13618384Sralph #define SETSTO(x,y) (stotree = (x), stocook = (y)) 13718384Sralph extern int stocook; 13818384Sralph extern NODE *stotree; 13918384Sralph extern int callflag; 14018384Sralph 14118384Sralph extern int fregs; 14218384Sralph 14318384Sralph #ifndef ONEPASS 14418384Sralph #include "ndu.h" 14518384Sralph #endif 14618384Sralph 14718384Sralph extern NODE node[]; 14818384Sralph 14918384Sralph /* code tables */ 15018384Sralph extern struct optab { 15118384Sralph int op; /* operator to match */ 15218384Sralph int visit; /* goal to match */ 15318384Sralph int lshape; /* left shape to match */ 15418384Sralph int ltype; /* left type to match */ 15518384Sralph int rshape; /* right shape to match */ 15618384Sralph int rtype; /* right type to match */ 15718384Sralph int needs; /* resource required */ 15818384Sralph int rewrite; /* how to rewrite afterwards */ 15918384Sralph char *cstring; /* code generation template */ 16018384Sralph } table[]; 16118384Sralph 16218384Sralph extern NODE resc[]; 16318384Sralph 16418384Sralph extern OFFSZ tmpoff; 16518384Sralph extern OFFSZ maxoff; 16618384Sralph extern OFFSZ baseoff; 16718384Sralph extern OFFSZ maxtemp; 16818384Sralph extern int maxtreg; 16918384Sralph extern int ftnno; 17018384Sralph extern int rtyflg; 17118384Sralph extern int nrecur; /* flag to keep track of recursions */ 17218384Sralph 17318384Sralph extern NODE 17418384Sralph *talloc(), 17518384Sralph *eread(), 17618384Sralph *tcopy(), 17718384Sralph *getlr(); 17818384Sralph 17918384Sralph extern CONSZ rdin(); 18018384Sralph extern int eprint(); 18118384Sralph extern char *rnames[]; 18218384Sralph 18318384Sralph extern int lineno; 18418384Sralph extern char filename[]; 18518384Sralph extern int fldshf, fldsz; 18618384Sralph extern int lflag, xdebug, udebug, edebug, odebug; 18718384Sralph extern int rdebug, radebug, tdebug, sdebug; 18818384Sralph #ifdef FORT 18918384Sralph extern int Oflag; 19018384Sralph #endif 19118384Sralph 19218384Sralph #ifndef callchk 19318384Sralph #define callchk(x) allchk() 19418384Sralph #endif 19518384Sralph 19618384Sralph #ifndef PUTCHAR 19718384Sralph #define PUTCHAR(x) putchar(x) 19818384Sralph #endif 19918384Sralph 20018384Sralph /* macros for doing double indexing */ 20118384Sralph #define R2PACK(x,y,z) (0200*((x)+1)+y+040000*z) /* pack 3 regs */ 20218384Sralph #define R2UPK1(x) ((((x)>>7)-1)&0177) /* unpack reg 1 */ 20318384Sralph #define R2UPK2(x) ((x)&0177) /* unpack reg 2 */ 20418384Sralph #define R2UPK3(x) (x>>14) /* unpack reg 3 */ 20518384Sralph #define R2TEST(x) ((x)>=0200) /* test if packed */ 20618384Sralph 20718384Sralph #ifdef MULTILEVEL 20818384Sralph union mltemplate { 20918384Sralph struct ml_head { 21018384Sralph int tag; /* tree class */ 21118384Sralph int subtag; /* subclass of tree */ 21218384Sralph union mltemplate *nexthead; /* linked by mlinit() */ 21318384Sralph } mlhead; 21418384Sralph struct ml_node { 21518384Sralph int op; /* operator or op description */ 21618384Sralph int nshape; /* node shape */ 21718384Sralph /* 21818384Sralph * Both op and nshape must match the node. 21918384Sralph * where the work is to be done entirely by 22018384Sralph * op, nshape can be SANY, visa versa, op can 22118384Sralph * be OPANY. 22218384Sralph */ 22318384Sralph int ntype; /* type descriptor */ 22418384Sralph } mlnode; 22518384Sralph }; 22618384Sralph extern union mltemplate mltree[]; 22718384Sralph #endif 22818384Sralph #endif 229