xref: /original-bsd/usr.bin/pascal/src/tmps.c (revision 6c57d260)
1 /* Copyright (c) 1979 Regents of the University of California */
2 
3 static char sccsid[] = "@(#)tmps.c 1.4 04/21/81";
4 
5 #include "whoami.h"
6 #include "0.h"
7 #ifdef PC
8 #   include "pc.h"
9 #endif PC
10 
11 /*
12  * This routine defines the register allocation strategy
13  * All temporaries are allocated here, and this routines decides
14  * where they are to be put.
15  */
16 #ifdef PC
17 #ifdef VAX
18 #    define MAXREGS 6
19 #    define REGSIZ 4
20 #    define FIRSTREG 6
21 #else
22 #ifdef PDP11
23 #    define MAXREGS 3
24 #    define REGSIZ 2
25 #    define FIRSTREG 2
26 #else
27 #    define MAXREGS 0
28 #    define REGSIZ 0
29 #    define FIRSTREG 0
30 #endif PDP11
31 #endif VAX
32 #endif PC
33 
34 /*
35  * allocate runtime temporary variables
36  */
37 long
38 tmpalloc(size, type, mode)
39 	long size;
40 	struct nl *type;
41 	int mode;
42 {
43 	register struct om *op = &sizes[ cbn ];
44 	register int offset;
45 
46 #	ifdef PC
47 	    if (mode == REGOK && size <= REGSIZ &&
48 		op->curtmps.reg_off < MAXREGS) {
49 		    offset = op->curtmps.reg_off++;
50 		    if ( offset > op->reg_max ) {
51 			    op->reg_max = offset;
52 		    }
53 		    /*
54 		     * the register number is encoded as an odd negative number
55 		     * which can never appear as an address.
56 		     */
57 		    return -(((offset + FIRSTREG) << 1) + 1);
58 	    }
59 #	endif PC
60 	offset = op->curtmps.om_off -= leven( size );
61 	if ( offset < op->om_max ) {
62 	        op->om_max = offset;
63 	}
64 #	ifdef PC
65 	    putlbracket( ftnno , -offset );
66 #	endif PC
67 	return offset;
68 }
69 
70 /*
71  * deallocate runtime temporary variables
72  */
73 tmpfree(restore)
74 	register struct tmps *restore;
75 {
76 	register struct om *op = &sizes[ cbn ];
77 
78 #	ifdef PC
79 	    if (restore->reg_off < op->curtmps.reg_off) {
80 		    op->curtmps.reg_off = restore->reg_off;
81 	    }
82 #	endif PC
83 	if (restore->om_off > op->curtmps.om_off) {
84 		op->curtmps.om_off = restore->om_off;
85 #		ifdef PC
86 		    putlbracket( ftnno , -restore->om_off );
87 #		endif PC
88 	}
89 }
90 
91 #ifdef PC
92 #ifdef VAX
93 /*
94  * create a save mask for registers which have been used
95  * in this level
96  */
97 savmask()
98 {
99 	short mask;
100 	int i;
101 
102 	mask = RSAVEMASK;
103 	if (opt('t'))
104 	        mask |= RUNCHECK;
105 	for (i = 0; i <= sizes[ cbn ].reg_max; i++)
106 		mask |= 1 << (FIRSTREG + i);
107 	return mask;
108 }
109 #endif VAX
110 #endif PC
111