xref: /csrg-svn/usr.bin/pascal/src/tmps.c (revision 3839)
13219Smckusick /* Copyright (c) 1979 Regents of the University of California */
23219Smckusick 
3*3839Speter static char sccsid[] = "@(#)tmps.c 1.5 06/01/81";
43219Smckusick 
53219Smckusick #include "whoami.h"
63219Smckusick #include "0.h"
73280Smckusic #ifdef PC
83280Smckusic #   include "pc.h"
93280Smckusic #endif PC
103219Smckusick 
113219Smckusick /*
123280Smckusic  * This routine defines the register allocation strategy
133280Smckusic  * All temporaries are allocated here, and this routines decides
143280Smckusic  * where they are to be put.
153280Smckusic  */
163281Smckusic #ifdef PC
173280Smckusic #ifdef VAX
183280Smckusic #    define MAXREGS 6
19*3839Speter #    define MINREGSIZE 4
20*3839Speter #    define MAXREGSIZE 4
213280Smckusic #    define FIRSTREG 6
223280Smckusic #else
233280Smckusic #ifdef PDP11
243280Smckusic #    define MAXREGS 3
25*3839Speter #    define MINREGSIZE 2
26*3839Speter #    define MAXREGSIZE 2
273280Smckusic #    define FIRSTREG 2
283280Smckusic #else
293280Smckusic #    define MAXREGS 0
30*3839Speter #    define MINREGSIZE 0
31*3839Speter #    define MAXREGSIZE 0
323280Smckusic #    define FIRSTREG 0
333280Smckusic #endif PDP11
343280Smckusic #endif VAX
353281Smckusic #endif PC
363280Smckusic 
373280Smckusic /*
383219Smckusick  * allocate runtime temporary variables
393219Smckusick  */
40*3839Speter struct nl *
413280Smckusic tmpalloc(size, type, mode)
423219Smckusick 	long size;
433219Smckusick 	struct nl *type;
443280Smckusic 	int mode;
453219Smckusick {
463280Smckusic 	register struct om *op = &sizes[ cbn ];
473280Smckusic 	register int offset;
48*3839Speter 	register struct nl	*nlp;
493219Smckusick 
503280Smckusic #	ifdef PC
51*3839Speter 	    if (mode == REGOK && size >= MINREGSIZE && size <= MAXREGSIZE &&
523280Smckusic 		op->curtmps.reg_off < MAXREGS) {
533280Smckusic 		    offset = op->curtmps.reg_off++;
543280Smckusic 		    if ( offset > op->reg_max ) {
553280Smckusic 			    op->reg_max = offset;
563280Smckusic 		    }
57*3839Speter 		    nlp = defnl( 0 , VAR , type , offset + FIRSTREG );
58*3839Speter 		    nlp -> extra_flags = NLOCAL | NREGVAR;
59*3839Speter 		    return nlp;
603280Smckusic 	    }
613280Smckusic #	endif PC
623580Speter 	offset = op->curtmps.om_off -= leven( size );
633280Smckusic 	if ( offset < op->om_max ) {
643280Smckusic 	        op->om_max = offset;
653219Smckusick 	}
66*3839Speter 	nlp = defnl( 0 , VAR , type , offset );
673219Smckusick #	ifdef PC
68*3839Speter 	    nlp -> extra_flags = NLOCAL;
693219Smckusick 	    putlbracket( ftnno , -offset );
703219Smckusick #	endif PC
71*3839Speter 	return nlp;
723219Smckusick }
733280Smckusic 
743219Smckusick /*
753219Smckusick  * deallocate runtime temporary variables
763219Smckusick  */
773219Smckusick tmpfree(restore)
783280Smckusic 	register struct tmps *restore;
793219Smckusick {
803280Smckusic 	register struct om *op = &sizes[ cbn ];
813219Smckusick 
823280Smckusic #	ifdef PC
833280Smckusic 	    if (restore->reg_off < op->curtmps.reg_off) {
843280Smckusic 		    op->curtmps.reg_off = restore->reg_off;
853280Smckusic 	    }
863280Smckusic #	endif PC
873280Smckusic 	if (restore->om_off > op->curtmps.om_off) {
883280Smckusic 		op->curtmps.om_off = restore->om_off;
893219Smckusick #		ifdef PC
903280Smckusic 		    putlbracket( ftnno , -restore->om_off );
913219Smckusick #		endif PC
923219Smckusick 	}
933219Smckusick }
943280Smckusic 
953281Smckusic #ifdef PC
963280Smckusic #ifdef VAX
973280Smckusic /*
983280Smckusic  * create a save mask for registers which have been used
993280Smckusic  * in this level
1003280Smckusic  */
1013280Smckusic savmask()
1023280Smckusic {
103*3839Speter 	int mask;
1043280Smckusic 	int i;
1053280Smckusic 
1063280Smckusic 	mask = RSAVEMASK;
1073280Smckusic 	if (opt('t'))
1083280Smckusic 	        mask |= RUNCHECK;
1093280Smckusic 	for (i = 0; i <= sizes[ cbn ].reg_max; i++)
1103280Smckusic 		mask |= 1 << (FIRSTREG + i);
1113280Smckusic 	return mask;
1123280Smckusic }
1133280Smckusic #endif VAX
1143281Smckusic #endif PC
115