1: #
   2: /*
   3:  * pi - Pascal interpreter code translator
   4:  *
   5:  * Charles Haley, Bill Joy UCB
   6:  * Version 1.2 January 1979
   7:  *
   8:  *
   9:  * pxp - Pascal execution profiler
  10:  *
  11:  * Bill Joy UCB
  12:  * Version 1.2 January 1979
  13:  */
  14: 
  15: #include "0.h"
  16: 
  17: /*
  18:  * TREE SPACE DECLARATIONS
  19:  */
  20: struct tr {
  21:     int *tr_low;
  22:     int *tr_high;
  23: } ttab[MAXTREE], *tract;
  24: 
  25: /*
  26:  * The variable space is the
  27:  * absolute base of the tree segments.
  28:  * (exactly the same as ttab[0].tr_low)
  29:  * Spacep is maintained to point at the
  30:  * beginning of the next tree slot to
  31:  * be allocated for use by the grammar.
  32:  * Spacep is used "extern" by the semantic
  33:  * actions in pas.y.
  34:  * The variable tract is maintained to point
  35:  * at the tree segment out of which we are
  36:  * allocating (the active segment).
  37:  */
  38: int *space, *spacep;
  39: 
  40: /*
  41:  * TREENMAX is the maximum width
  42:  * in words that any tree node
  43:  * due to the way in which the parser uses
  44:  * the pointer spacep.
  45:  */
  46: #define TREENMAX    6
  47: 
  48: int trspace[ITREE];
  49: int *space  trspace;
  50: int *spacep trspace;
  51: struct  tr *tract   ttab;
  52: 
  53: /*
  54:  * Inittree allocates the first tree slot
  55:  * and sets up the first segment descriptor.
  56:  * A lot of this work is actually done statically
  57:  * above.
  58:  */
  59: inittree()
  60: {
  61: 
  62:     ttab[0].tr_low = space;
  63:     ttab[0].tr_high = &space[ITREE];
  64: }
  65: 
  66: /*
  67:  * Tree builds the nodes in the
  68:  * parse tree. It is rarely called
  69:  * directly, rather calls are made
  70:  * to tree[12345] which supplies the
  71:  * first argument to save space in
  72:  * the code. Tree also guarantees
  73:  * that spacep points to the beginning
  74:  * of the next slot it will return,
  75:  * a property required by the parser
  76:  * which was always true before we
  77:  * segmented the tree space.
  78:  */
  79: int *tree(cnt, a)
  80:     int cnt;
  81: {
  82:     register int *p, *q;
  83:     register int i;
  84: 
  85:     i = cnt;
  86:     p = spacep;
  87:     q = &a;
  88:     do
  89:         *p++ = *q++;
  90:     while (--i);
  91:     q = spacep;
  92:     spacep = p;
  93:     if (p+TREENMAX >= tract->tr_high)
  94:         /*
  95: 		 * this peek-ahead should
  96: 		 * save a great number of calls
  97: 		 * to tralloc.
  98: 		 */
  99:         tralloc(TREENMAX);
 100:     return (q);
 101: }
 102: 
 103: /*
 104:  * Tralloc preallocates enough
 105:  * space in the tree to allow
 106:  * the grammar to use the variable
 107:  * spacep, as it did before the
 108:  * tree was segmented.
 109:  */
 110: tralloc(howmuch)
 111: {
 112:     register char *cp;
 113:     register i;
 114: 
 115:     if (spacep + howmuch >= tract->tr_high) {
 116:         i = TRINC;
 117:         cp = alloc(i*2);
 118:         if (cp == -1) {
 119:             yerror("Ran out of memory (tralloc)");
 120:             pexit(DIED);
 121:         }
 122:         spacep = cp;
 123:         tract++;
 124:         if (tract >= &ttab[MAXTREE]) {
 125:             yerror("Ran out of tree tables");
 126:             pexit(DIED);
 127:         }
 128:         tract->tr_low = cp;
 129:         tract->tr_high = tract->tr_low+i;
 130:     }
 131: }
 132: 
 133: extern  int yylacnt;
 134: extern  bottled;
 135: #ifdef PXP
 136: #endif
 137: /*
 138:  * Free up the tree segments
 139:  * at the end of a block.
 140:  * If there is scanner lookahead,
 141:  * i.e. if yylacnt != 0 or there is bottled output, then we
 142:  * cannot free the tree space.
 143:  * This happens only when errors
 144:  * occur and the forward move extends
 145:  * across "units".
 146:  */
 147: trfree()
 148: {
 149: 
 150:     if (yylacnt != 0 || bottled != NIL)
 151:         return;
 152: #ifdef PXP
 153:     if (needtree())
 154:         return;
 155: #endif
 156:     spacep = space;
 157:     while (tract->tr_low > spacep || tract->tr_high <= spacep) {
 158:         free(tract->tr_low);
 159:         tract->tr_low = NIL;
 160:         tract->tr_high = NIL;
 161:         tract--;
 162:         if (tract < ttab)
 163:             panic("ttab");
 164:     }
 165: #ifdef PXP
 166:     packtree();
 167: #endif
 168: }
 169: 
 170: /*
 171:  * Copystr copies a token from
 172:  * the "token" buffer into the
 173:  * tree space.
 174:  */
 175: copystr(token)
 176:     register char *token;
 177: {
 178:     register char *cp;
 179:     register int i;
 180: 
 181:     i = (strlen(token) + 2) & ~1;
 182:     tralloc(i >> 1);
 183:     strcpy(spacep, token);
 184:     cp = spacep;
 185:     spacep = cp + i;
 186:     tralloc(TREENMAX);
 187:     return (cp);
 188: }

Defined functions

inittree defined in line 59; used 1 times
tralloc defined in line 110; used 3 times
trfree defined in line 147; used 4 times

Defined variables

space defined in line 49; used 3 times
spacep defined in line 50; used 13 times
tract defined in line 51; used 14 times
trspace defined in line 50; never used
ttab defined in line 51; used 4 times

Defined struct's

tr defined in line 20; used 2 times
  • in line 51(2)

Defined macros

TREENMAX defined in line 46; used 3 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 850
Valid CSS Valid XHTML 1.0 Strict