1 /* Copyright (c) 1979 Regents of the University of California */ 2 3 static char sccsid[] = "@(#)tmps.c 1.6 07/23/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 = 63 roundup((int)(op->curtmps.om_off - size), (long)align(type)); 64 if ( offset < op->om_max ) { 65 op->om_max = offset; 66 } 67 nlp = defnl( 0 , VAR , type , offset ); 68 # ifdef PC 69 nlp -> extra_flags = NLOCAL; 70 putlbracket( ftnno , -offset ); 71 # endif PC 72 return nlp; 73 } 74 75 /* 76 * deallocate runtime temporary variables 77 */ 78 tmpfree(restore) 79 register struct tmps *restore; 80 { 81 register struct om *op = &sizes[ cbn ]; 82 83 # ifdef PC 84 if (restore->reg_off < op->curtmps.reg_off) { 85 op->curtmps.reg_off = restore->reg_off; 86 } 87 # endif PC 88 if (restore->om_off > op->curtmps.om_off) { 89 op->curtmps.om_off = restore->om_off; 90 # ifdef PC 91 putlbracket( ftnno , -restore->om_off ); 92 # endif PC 93 } 94 } 95 96 #ifdef PC 97 #ifdef VAX 98 /* 99 * create a save mask for registers which have been used 100 * in this level 101 */ 102 savmask() 103 { 104 int mask; 105 int i; 106 107 mask = RSAVEMASK; 108 if (opt('t')) 109 mask |= RUNCHECK; 110 for (i = 0; i <= sizes[ cbn ].reg_max; i++) 111 mask |= 1 << (FIRSTREG + i); 112 return mask; 113 } 114 #endif VAX 115 #endif PC 116