1 /* Copyright (c) 1979 Regents of the University of California */ 2 3 static char sccsid[] = "@(#)tmps.c 1.5 06/01/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 MINREGSIZE 4 20 # define MAXREGSIZE 4 21 # define FIRSTREG 6 22 #else 23 #ifdef PDP11 24 # define MAXREGS 3 25 # define MINREGSIZE 2 26 # define MAXREGSIZE 2 27 # define FIRSTREG 2 28 #else 29 # define MAXREGS 0 30 # define MINREGSIZE 0 31 # define MAXREGSIZE 0 32 # define FIRSTREG 0 33 #endif PDP11 34 #endif VAX 35 #endif PC 36 37 /* 38 * allocate runtime temporary variables 39 */ 40 struct nl * 41 tmpalloc(size, type, mode) 42 long size; 43 struct nl *type; 44 int mode; 45 { 46 register struct om *op = &sizes[ cbn ]; 47 register int offset; 48 register struct nl *nlp; 49 50 # ifdef PC 51 if (mode == REGOK && size >= MINREGSIZE && size <= MAXREGSIZE && 52 op->curtmps.reg_off < MAXREGS) { 53 offset = op->curtmps.reg_off++; 54 if ( offset > op->reg_max ) { 55 op->reg_max = offset; 56 } 57 nlp = defnl( 0 , VAR , type , offset + FIRSTREG ); 58 nlp -> extra_flags = NLOCAL | NREGVAR; 59 return nlp; 60 } 61 # endif PC 62 offset = op->curtmps.om_off -= leven( size ); 63 if ( offset < op->om_max ) { 64 op->om_max = offset; 65 } 66 nlp = defnl( 0 , VAR , type , offset ); 67 # ifdef PC 68 nlp -> extra_flags = NLOCAL; 69 putlbracket( ftnno , -offset ); 70 # endif PC 71 return nlp; 72 } 73 74 /* 75 * deallocate runtime temporary variables 76 */ 77 tmpfree(restore) 78 register struct tmps *restore; 79 { 80 register struct om *op = &sizes[ cbn ]; 81 82 # ifdef PC 83 if (restore->reg_off < op->curtmps.reg_off) { 84 op->curtmps.reg_off = restore->reg_off; 85 } 86 # endif PC 87 if (restore->om_off > op->curtmps.om_off) { 88 op->curtmps.om_off = restore->om_off; 89 # ifdef PC 90 putlbracket( ftnno , -restore->om_off ); 91 # endif PC 92 } 93 } 94 95 #ifdef PC 96 #ifdef VAX 97 /* 98 * create a save mask for registers which have been used 99 * in this level 100 */ 101 savmask() 102 { 103 int mask; 104 int i; 105 106 mask = RSAVEMASK; 107 if (opt('t')) 108 mask |= RUNCHECK; 109 for (i = 0; i <= sizes[ cbn ].reg_max; i++) 110 mask |= 1 << (FIRSTREG + i); 111 return mask; 112 } 113 #endif VAX 114 #endif PC 115