xref: /original-bsd/usr.bin/pascal/src/tmps.c (revision b64b0d54)
1 /* Copyright (c) 1979 Regents of the University of California */
2 
3 static char sccsid[] = "@(#)tmps.c 1.8 02/28/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 #include "tmps.h"
12 
13 /*
14  * This routine defines the register allocation strategy
15  * All temporaries are allocated here, and this routines decides
16  * where they are to be put.
17  */
18 #ifdef PC
19     /*
20      *	registers are allocated from highreg towards lowreg.
21      *	registers are of size regsize.
22      *	stack variables are allocated on a downward growing stack.
23      */
24 
25 #ifdef vax
26     /*
27      *	first pass register declaration constants
28      */
29 #   define	LONGREGTYPE	0
30 struct	regtype {
31     long	lowreg;
32     long	highreg;
33     long	regsize;
34 } regtypes[NUMREGTYPES] = {
35 	{ 6, 11, 4 },
36 };
37 #endif vax
38 
39 #ifdef mc68000
40     /*
41      *	first pass register declaration constants
42      */
43 #   define	DATAREGTYPE	0
44 #   define	ADDRREGTYPE	1
45 struct	regtype {
46     long	lowreg;
47     long	highreg;
48     long	regsize;
49 } regtypes[NUMREGTYPES] = {
50 	{ 2, 7, 0 },		/* off for now */
51 	{ 2, 5, 0 },		/* off for now */
52 };
53 #endif mc68000
54 #endif PC
55 
56 tmpinit(cbn)
57 	int	cbn;
58 {
59 	struct om	*sizesp = &sizes[cbn];
60 	int	i;
61 
62 	sizesp->om_max = -DPOFF1;
63 	sizesp->curtmps.om_off = -DPOFF1;
64 #	ifdef PC
65 		for (i = 0; i < NUMREGTYPES; i++) {
66 			sizesp->low_water[i] = regtypes[i].highreg + 1;
67 			sizesp->curtmps.next_avail[i] = regtypes[i].highreg;
68 		}
69 #	endif PC
70 }
71 
72 /*
73  * allocate runtime temporary variables
74  */
75 struct nl *
76 tmpalloc(size, type, mode)
77 	long size;
78 	struct nl *type;
79 	int mode;
80 {
81 	register struct om	*op = &sizes[ cbn ];
82 	register int		offset;
83 	register struct nl	*nlp;
84 
85 #	ifdef PC
86 #	    ifdef vax
87 		if (  mode == REGOK
88 		   && size == regtypes[REG_GENERAL].regsize
89 		   && op->curtmps.next_avail[REG_GENERAL]
90 			    >= regtypes[REG_GENERAL].lowreg) {
91 			offset = op->curtmps.next_avail[REG_GENERAL]--;
92 			if (offset < op->low_water[REG_GENERAL]) {
93 				op->low_water[REG_GENERAL] = offset;
94 			}
95 			nlp = defnl( 0 , VAR , type , offset );
96 			nlp -> extra_flags = NLOCAL | NREGVAR;
97 			putlbracket(ftnno, op);
98 			return nlp;
99 		}
100 #	    endif vax
101 #	endif PC
102         op->curtmps.om_off =
103 	    roundup((int)(op->curtmps.om_off - size), (long)align(type));
104 	offset = op->curtmps.om_off;
105 	if ( offset < op->om_max ) {
106 	        op->om_max = offset;
107 	}
108 	nlp = defnl( 0 , VAR , type , offset );
109 #	ifdef PC
110 	    nlp -> extra_flags = NLOCAL;
111 	    putlbracket(ftnno, op);
112 #	endif PC
113 	return nlp;
114 }
115 
116 /*
117  * deallocate runtime temporary variables
118  */
119 tmpfree(restore)
120     register struct tmps	*restore;
121 {
122     register struct om		*op = &sizes[ cbn ];
123     bool			change = FALSE;
124 
125 #   ifdef PC
126 	    /* i think this never gives back storage!	... peter */
127 #	ifdef vax
128 	    if (restore->next_avail[REG_GENERAL]
129 		> op->curtmps.next_avail[REG_GENERAL]) {
130 		    op->curtmps.next_avail[REG_GENERAL]
131 			= restore->next_avail[REG_GENERAL];
132 		    change = TRUE;
133 	    }
134 #	endif vax
135 #   endif PC
136     if (restore->om_off > op->curtmps.om_off) {
137 	    op->curtmps.om_off = restore->om_off;
138 	    change = TRUE;
139     }
140 #   ifdef PC
141 	if (change) {
142 	    putlbracket(ftnno, op);
143 	}
144 #   endif PC
145 }
146 
147 #ifdef PC
148 #ifdef vax
149 /*
150  * create a save mask for registers which have been used
151  * in this level
152  */
153 savmask()
154 {
155 	int mask;
156 	int i;
157 
158 	mask = RSAVEMASK;
159 	if (opt('t'))
160 	        mask |= RUNCHECK;
161 	for (i = 0; i <= regtypes[REG_GENERAL].highreg; i++) {
162 	    if (i >= sizes[cbn].low_water[REG_GENERAL]) {
163 		mask |= 1 << i;
164 	    }
165 	}
166 	return mask;
167 }
168 #endif vax
169 #endif PC
170