xref: /csrg-svn/usr.bin/pascal/src/tmps.c (revision 3281)
13219Smckusick /* Copyright (c) 1979 Regents of the University of California */
23219Smckusick 
3*3281Smckusic static char sccsid[] = "@(#)tmps.c 1.3 03/16/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  */
16*3281Smckusic #ifdef PC
173280Smckusic #ifdef VAX
183280Smckusic #    define MAXREGS 6
193280Smckusic #    define REGSIZ 4
203280Smckusic #    define FIRSTREG 6
213280Smckusic #else
223280Smckusic #ifdef PDP11
233280Smckusic #    define MAXREGS 3
243280Smckusic #    define REGSIZ 2
253280Smckusic #    define FIRSTREG 2
263280Smckusic #else
273280Smckusic #    define MAXREGS 0
283280Smckusic #    define REGSIZ 0
293280Smckusic #    define FIRSTREG 0
303280Smckusic #endif PDP11
313280Smckusic #endif VAX
32*3281Smckusic #endif PC
333280Smckusic 
343280Smckusic /*
353219Smckusick  * allocate runtime temporary variables
363219Smckusick  */
373219Smckusick long
383280Smckusic tmpalloc(size, type, mode)
393219Smckusick 	long size;
403219Smckusick 	struct nl *type;
413280Smckusic 	int mode;
423219Smckusick {
433280Smckusic 	register struct om *op = &sizes[ cbn ];
443280Smckusic 	register int offset;
453219Smckusick 
463280Smckusic #	ifdef PC
473280Smckusic 	    if (mode == REGOK && size <= REGSIZ &&
483280Smckusic 		op->curtmps.reg_off < MAXREGS) {
493280Smckusic 		    offset = op->curtmps.reg_off++;
503280Smckusic 		    if ( offset > op->reg_max ) {
513280Smckusic 			    op->reg_max = offset;
523280Smckusic 		    }
533280Smckusic 		    /*
543280Smckusic 		     * the register number is encoded as an odd negative number
553280Smckusic 		     * which can never appear as an address.
563280Smckusic 		     */
573280Smckusic 		    return -(((offset + FIRSTREG) << 1) + 1);
583280Smckusic 	    }
593280Smckusic #	endif PC
603280Smckusic 	offset = op->curtmps.om_off -= size;
613280Smckusic 	if ( offset < op->om_max ) {
623280Smckusic 	        op->om_max = offset;
633219Smckusick 	}
643219Smckusick #	ifdef PC
653219Smckusick 	    putlbracket( ftnno , -offset );
663219Smckusick #	endif PC
673219Smckusick 	return offset;
683219Smckusick }
693280Smckusic 
703219Smckusick /*
713219Smckusick  * deallocate runtime temporary variables
723219Smckusick  */
733219Smckusick tmpfree(restore)
743280Smckusic 	register struct tmps *restore;
753219Smckusick {
763280Smckusic 	register struct om *op = &sizes[ cbn ];
773219Smckusick 
783280Smckusic #	ifdef PC
793280Smckusic 	    if (restore->reg_off < op->curtmps.reg_off) {
803280Smckusic 		    op->curtmps.reg_off = restore->reg_off;
813280Smckusic 	    }
823280Smckusic #	endif PC
833280Smckusic 	if (restore->om_off > op->curtmps.om_off) {
843280Smckusic 		op->curtmps.om_off = restore->om_off;
853219Smckusick #		ifdef PC
863280Smckusic 		    putlbracket( ftnno , -restore->om_off );
873219Smckusick #		endif PC
883219Smckusick 	}
893219Smckusick }
903280Smckusic 
91*3281Smckusic #ifdef PC
923280Smckusic #ifdef VAX
933280Smckusic /*
943280Smckusic  * create a save mask for registers which have been used
953280Smckusic  * in this level
963280Smckusic  */
973280Smckusic savmask()
983280Smckusic {
993280Smckusic 	short mask;
1003280Smckusic 	int i;
1013280Smckusic 
1023280Smckusic 	mask = RSAVEMASK;
1033280Smckusic 	if (opt('t'))
1043280Smckusic 	        mask |= RUNCHECK;
1053280Smckusic 	for (i = 0; i <= sizes[ cbn ].reg_max; i++)
1063280Smckusic 		mask |= 1 << (FIRSTREG + i);
1073280Smckusic 	return mask;
1083280Smckusic }
1093280Smckusic #endif VAX
110*3281Smckusic #endif PC
111