117726Sralph# include "macdefs" 217726Sralph# include "mac2defs" 317726Sralph# include "manifest" 417726Sralph 517726Sralph# ifdef ONEPASS 617726Sralph 717726Sralph/* bunch of stuff for putting the passes together... */ 817726Sralph# define crslab crs2lab 917726Sralph# define where where2 1017726Sralph# define xdebug x2debug 1117726Sralph# define tdebug t2debug 1217726Sralph# define deflab def2lab 1317726Sralph# define edebug e2debug 1417726Sralph# define eprint e2print 1517726Sralph# define getlab get2lab 1617726Sralph# define filename ftitle 1717726Sralph# endif 1817726Sralph 1917726Sralph/* cookies, used as arguments to codgen */ 2017726Sralph 2117726Sralph# define FOREFF 01 /* compute for effects only */ 2217726Sralph# define INAREG 02 /* compute into a register */ 2317726Sralph# define INTAREG 04 /* compute into a scratch register */ 2417726Sralph# define INBREG 010 /* compute into a lvalue register */ 2517726Sralph# define INTBREG 020 /* compute into a scratch lvalue register */ 2617726Sralph# define FORCC 040 /* compute for condition codes only */ 2717726Sralph# define INTEMP 010000 /* compute into a temporary location */ 2817726Sralph# define FORARG 020000 /* compute for an argument of a function */ 2917726Sralph# define FORREW 040000 /* search the table, looking for a rewrite rule */ 3017726Sralph 3117726Sralph /* OP descriptors */ 3217726Sralph /* the ASG operator may be used on some of these */ 3317726Sralph 3417726Sralph# define OPSIMP 010000 /* +, -, &, |, ^ */ 3517726Sralph# define OPCOMM 010002 /* +, &, |, ^ */ 3617726Sralph# define OPMUL 010004 /* *, / */ 3717726Sralph# define OPDIV 010006 /* /, % */ 3817726Sralph# define OPUNARY 010010 /* unary ops */ 3917726Sralph# define OPLEAF 010012 /* leaves */ 4017726Sralph# define OPANY 010014 /* any op... */ 4117726Sralph# define OPLOG 010016 /* logical ops */ 4217726Sralph# define OPFLOAT 010020 /* +, -, *, or / (for floats) */ 4317726Sralph# define OPSHFT 010022 /* <<, >> */ 4417726Sralph# define OPLTYPE 010024 /* leaf type nodes (e.g, NAME, ICON, etc. ) */ 4517726Sralph 4617726Sralph /* match returns */ 4717726Sralph 4817726Sralph# define MNOPE 010000 4917726Sralph# define MDONE 010001 5017726Sralph 5117726Sralph /* shapes */ 5217726Sralph 5317726Sralph# define SANY 01 /* same as FOREFF */ 5417726Sralph# define SAREG 02 /* same as INAREG */ 5517726Sralph# define STAREG 04 /* same as INTAREG */ 5617726Sralph# define SBREG 010 /* same as INBREG */ 5717726Sralph# define STBREG 020 /* same as INTBREG */ 5817726Sralph# define SCC 040 /* same as FORCC */ 5917726Sralph# define SNAME 0100 6017726Sralph# define SCON 0200 6117726Sralph# define SFLD 0400 6217726Sralph# define SOREG 01000 6317726Sralph/* indirection or wild card shapes */ 6417726Sralph# ifndef WCARD1 6517726Sralph# define STARNM 02000 6617726Sralph# endif 6717726Sralph# ifndef WCARD2 6817726Sralph# define STARREG 04000 6917726Sralph# endif 7017726Sralph# define SWADD 040000 7117726Sralph# define SPECIAL 0100000 7217726Sralph# define SZERO SPECIAL 7317726Sralph# define SONE (SPECIAL|1) 7417726Sralph# define SMONE (SPECIAL|2) 7517726Sralph# define SCCON (SPECIAL|3) /* -256 <= constant < 256 */ 7617726Sralph# define SSCON (SPECIAL|4) /* -32768 <= constant < 32768 */ 7717726Sralph# define SSOREG (SPECIAL|5) /* non-indexed OREG */ 7817726Sralph 7917726Sralph /* FORARG and INTEMP are carefully not conflicting with shapes */ 8017726Sralph 8117726Sralph /* types */ 8217726Sralph 8317726Sralph# define TCHAR 01 8417726Sralph# define TSHORT 02 8517726Sralph# define TINT 04 8617726Sralph# define TLONG 010 8717726Sralph# define TFLOAT 020 8817726Sralph# define TDOUBLE 040 8917726Sralph# define TPOINT 0100 9017726Sralph# define TUCHAR 0200 9117726Sralph# define TUSHORT 0400 9217726Sralph# define TUNSIGNED 01000 9317726Sralph# define TULONG 02000 9417726Sralph# define TPTRTO 04000 /* pointer to one of the above */ 9517726Sralph# define TANY 010000 /* matches anything within reason */ 9617726Sralph# define TSTRUCT 020000 /* structure or union */ 9717726Sralph 9817726Sralph /* reclamation cookies */ 9917726Sralph 10017726Sralph# define RNULL 0 /* clobber result */ 10117726Sralph# define RLEFT 01 10217726Sralph# define RRIGHT 02 10317726Sralph# define RESC1 04 10417726Sralph# define RESC2 010 10517726Sralph# define RESC3 020 10617726Sralph# define RESCC 04000 10717726Sralph# define RNOP 010000 /* DANGER: can cause loops.. */ 10817726Sralph 10917726Sralph /* needs */ 11017726Sralph 11117726Sralph# define NAREG 01 11217726Sralph# define NACOUNT 03 11317726Sralph# define NAMASK 017 11417726Sralph# define NASL 04 /* share left register */ 11517726Sralph# define NASR 010 /* share right register */ 11617726Sralph# define NBREG 020 11717726Sralph# define NBCOUNT 060 11817726Sralph# define NBMASK 0360 11917726Sralph# define NBSL 0100 12017726Sralph# define NBSR 0200 12117726Sralph# define NTEMP 0400 12217726Sralph# define NTMASK 07400 12317726Sralph# define REWRITE 010000 12417726Sralph# define EITHER 040000 /* "either" modifier for needs */ 12517726Sralph 12617726Sralph 12717726Sralph# define MUSTDO 010000 /* force register requirements */ 12817726Sralph# define NOPREF 020000 /* no preference for register assignment */ 12917726Sralph 13017726Sralph 13117726Sralph /* register allocation */ 13217726Sralph 13317726Sralphextern int rstatus[]; 13417726Sralphextern int busy[]; 13517726Sralph 13617726Sralphextern struct respref { int cform; int mform; } respref[]; 13717726Sralph 13817726Sralph# define isbreg(r) (rstatus[r]&SBREG) 13917726Sralph# define istreg(r) (rstatus[r]&(STBREG|STAREG)) 14017726Sralph# define istnode(p) (p->in.op==REG && istreg(p->tn.rval)) 14117726Sralph 14217726Sralph# define TBUSY 01000 14317726Sralph# define REGLOOP(i) for(i=0;i<REGSZ;++i) 14417726Sralph 14517726Sralph# define SETSTO(x,y) (stotree=(x),stocook=(y)) 14617726Sralphextern int stocook; 14717726Sralph# define DELAYS 20 14817726Sralphextern NODE *deltrees[DELAYS]; 14917726Sralphextern int deli; /* mmmmm */ 15017726Sralph 15117726Sralphextern NODE *stotree; 15217726Sralphextern int callflag; 15317726Sralph 15417726Sralphextern int fregs; 15517726Sralph 15617726Sralph# ifndef ONEPASS 15717726Sralphunion ndu { 15817726Sralph 15917726Sralph struct { 16017726Sralph int op; 16117726Sralph int rall; 16217726Sralph TWORD type; 16317726Sralph int su; 16417726Sralph#ifndef FLEXNAMES 16517726Sralph char name[NCHNAM]; 16617726Sralph#else 16717726Sralph char *name; 16817726Sralph#endif 169*17746Sralph int stalign; /* alignment of structure objects */ 17017726Sralph NODE *left; 17117726Sralph NODE *right; 17217726Sralph }in; /* interior node */ 17317726Sralph 17417726Sralph struct { 17517726Sralph int op; 17617726Sralph int rall; 17717726Sralph TWORD type; 17817726Sralph int su; 17917726Sralph#ifndef FLEXNAMES 18017726Sralph char name[NCHNAM]; 18117726Sralph#else 18217726Sralph char *name; 18317726Sralph#endif 184*17746Sralph int stalign; /* alignment of structure objects */ 18517726Sralph CONSZ lval; 18617726Sralph int rval; 18717726Sralph }tn; /* terminal node */ 18817726Sralph 18917726Sralph struct { 19017726Sralph int op, rall; 19117726Sralph TWORD type; 19217726Sralph int su; 19317726Sralph int label; /* for use with branching */ 19417726Sralph }bn; /* branch node */ 19517726Sralph 19617726Sralph struct { 19717726Sralph int op, rall; 19817726Sralph TWORD type; 19917726Sralph int su; 200*17746Sralph int stsize; /* sizes of structure objects */ 20117726Sralph int stalign; /* alignment of structure objects */ 20217726Sralph }stn; /* structure node */ 20317726Sralph 20417726Sralph }; 20517726Sralph#endif 20617726Sralph 20717726Sralphextern NODE node[]; 20817726Sralph 20917726Sralphextern struct optab { 21017726Sralph int op; 21117726Sralph int visit; 21217726Sralph int lshape; 21317726Sralph int ltype; 21417726Sralph int rshape; 21517726Sralph int rtype; 21617726Sralph int needs; 21717726Sralph int rewrite; 21817726Sralph char * cstring; 21917726Sralph } 22017726Sralph table[]; 22117726Sralph 22217726Sralphextern NODE resc[]; 22317726Sralph 22417726Sralphextern OFFSZ tmpoff; 22517726Sralphextern OFFSZ maxoff; 22617726Sralphextern OFFSZ baseoff; 22717726Sralphextern OFFSZ maxtemp; 22817726Sralphextern int maxtreg; 22917726Sralphextern int ftnno; 23017726Sralphextern int rtyflg; 23117726Sralph 23217726Sralphextern int nrecur; /* flag to keep track of recursions */ 23317726Sralph 23417726Sralph# define NRECUR (10*TREESZ) 23517726Sralph 23617726Sralphextern NODE 23717726Sralph *talloc(), 23817726Sralph *eread(), 23917726Sralph *tcopy(), 24017726Sralph *getlr(); 24117726Sralph 24217726Sralphextern CONSZ rdin(); 24317726Sralph 24417726Sralphextern int eprint(); 24517726Sralph 24617726Sralphextern char *rnames[]; 24717726Sralph 24817726Sralphextern int lineno; 24917726Sralphextern char filename[]; 25017726Sralphextern int fldshf, fldsz; 25117726Sralphextern int lflag, xdebug, udebug, edebug, odebug, rdebug, radebug, tdebug, sdebug; 252*17746Sralph#ifdef FORT 253*17746Sralphextern int Oflag; 254*17746Sralph#endif 25517726Sralph 25617726Sralph#ifndef callchk 25717726Sralph#define callchk(x) allchk() 25817726Sralph#endif 25917726Sralph 26017726Sralph#ifndef PUTCHAR 26117726Sralph# define PUTCHAR(x) putchar(x) 26217726Sralph#endif 26317726Sralph 26417726Sralph /* macros for doing double indexing */ 26517726Sralph# define R2PACK(x,y,z) (0200*((x)+1)+y+040000*z) 26617726Sralph# define R2UPK1(x) ((((x)>>7)-1)&0177) 26717726Sralph# define R2UPK2(x) ((x)&0177) 26817726Sralph# define R2UPK3(x) (x>>14) 26917726Sralph# define R2TEST(x) ((x)>=0200) 27017726Sralph 27117726Sralph# ifdef MULTILEVEL 27217726Sralph 27317726Sralphunion mltemplate{ 27417726Sralph struct ml_head{ 27517726Sralph int tag; /* identifies class of tree */ 27617726Sralph int subtag; /* subclass of tree */ 27717726Sralph union mltemplate * nexthead; /* linked by mlinit() */ 27817726Sralph } mlhead; 27917726Sralph struct ml_node{ 28017726Sralph int op; /* either an operator or op description */ 28117726Sralph int nshape; /* shape of node */ 28217726Sralph /* both op and nshape must match the node. 28317726Sralph * where the work is to be done entirely by 28417726Sralph * op, nshape can be SANY, visa versa, op can 28517726Sralph * be OPANY. 28617726Sralph */ 28717726Sralph int ntype; /* type descriptor from mfile2 */ 28817726Sralph } mlnode; 28917726Sralph }; 29017726Sralph 29117726Sralph# endif 292