xref: /csrg-svn/usr.bin/pascal/src/tmps.c (revision 3280)
13219Smckusick /* Copyright (c) 1979 Regents of the University of California */
23219Smckusick 
3*3280Smckusic static char sccsid[] = "@(#)tmps.c 1.2 03/16/81";
43219Smckusick 
53219Smckusick #include "whoami.h"
63219Smckusick #include "0.h"
7*3280Smckusic #ifdef PC
8*3280Smckusic #   include "pc.h"
9*3280Smckusic #endif PC
103219Smckusick 
113219Smckusick /*
12*3280Smckusic  * This routine defines the register allocation strategy
13*3280Smckusic  * All temporaries are allocated here, and this routines decides
14*3280Smckusic  * where they are to be put.
15*3280Smckusic  */
16*3280Smckusic #ifdef VAX
17*3280Smckusic #    define MAXREGS 6
18*3280Smckusic #    define REGSIZ 4
19*3280Smckusic #    define FIRSTREG 6
20*3280Smckusic #else
21*3280Smckusic #ifdef PDP11
22*3280Smckusic #    define MAXREGS 3
23*3280Smckusic #    define REGSIZ 2
24*3280Smckusic #    define FIRSTREG 2
25*3280Smckusic #else
26*3280Smckusic #    define MAXREGS 0
27*3280Smckusic #    define REGSIZ 0
28*3280Smckusic #    define FIRSTREG 0
29*3280Smckusic #endif PDP11
30*3280Smckusic #endif VAX
31*3280Smckusic 
32*3280Smckusic /*
333219Smckusick  * allocate runtime temporary variables
343219Smckusick  */
353219Smckusick long
36*3280Smckusic tmpalloc(size, type, mode)
373219Smckusick 	long size;
383219Smckusick 	struct nl *type;
39*3280Smckusic 	int mode;
403219Smckusick {
41*3280Smckusic 	register struct om *op = &sizes[ cbn ];
42*3280Smckusic 	register int offset;
433219Smckusick 
44*3280Smckusic #	ifdef PC
45*3280Smckusic 	    if (mode == REGOK && size <= REGSIZ &&
46*3280Smckusic 		op->curtmps.reg_off < MAXREGS) {
47*3280Smckusic 		    offset = op->curtmps.reg_off++;
48*3280Smckusic 		    if ( offset > op->reg_max ) {
49*3280Smckusic 			    op->reg_max = offset;
50*3280Smckusic 		    }
51*3280Smckusic 		    /*
52*3280Smckusic 		     * the register number is encoded as an odd negative number
53*3280Smckusic 		     * which can never appear as an address.
54*3280Smckusic 		     */
55*3280Smckusic 		    return -(((offset + FIRSTREG) << 1) + 1);
56*3280Smckusic 	    }
57*3280Smckusic #	endif PC
58*3280Smckusic 	offset = op->curtmps.om_off -= size;
59*3280Smckusic 	if ( offset < op->om_max ) {
60*3280Smckusic 	        op->om_max = offset;
613219Smckusick 	}
623219Smckusick #	ifdef PC
633219Smckusick 	    putlbracket( ftnno , -offset );
643219Smckusick #	endif PC
653219Smckusick 	return offset;
663219Smckusick }
67*3280Smckusic 
683219Smckusick /*
693219Smckusick  * deallocate runtime temporary variables
703219Smckusick  */
713219Smckusick tmpfree(restore)
72*3280Smckusic 	register struct tmps *restore;
733219Smckusick {
74*3280Smckusic 	register struct om *op = &sizes[ cbn ];
753219Smckusick 
76*3280Smckusic #	ifdef PC
77*3280Smckusic 	    if (restore->reg_off < op->curtmps.reg_off) {
78*3280Smckusic 		    op->curtmps.reg_off = restore->reg_off;
79*3280Smckusic 	    }
80*3280Smckusic #	endif PC
81*3280Smckusic 	if (restore->om_off > op->curtmps.om_off) {
82*3280Smckusic 		op->curtmps.om_off = restore->om_off;
833219Smckusick #		ifdef PC
84*3280Smckusic 		    putlbracket( ftnno , -restore->om_off );
853219Smckusick #		endif PC
863219Smckusick 	}
873219Smckusick }
88*3280Smckusic 
89*3280Smckusic #ifdef VAX
90*3280Smckusic /*
91*3280Smckusic  * create a save mask for registers which have been used
92*3280Smckusic  * in this level
93*3280Smckusic  */
94*3280Smckusic savmask()
95*3280Smckusic {
96*3280Smckusic 	short mask;
97*3280Smckusic 	int i;
98*3280Smckusic 
99*3280Smckusic 	mask = RSAVEMASK;
100*3280Smckusic 	if (opt('t'))
101*3280Smckusic 	        mask |= RUNCHECK;
102*3280Smckusic 	for (i = 0; i <= sizes[ cbn ].reg_max; i++)
103*3280Smckusic 		mask |= 1 << (FIRSTREG + i);
104*3280Smckusic 	return mask;
105*3280Smckusic }
106*3280Smckusic #endif VAX
107