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