|
|
1.1 root 1: /*
2: * C compiler.
3: * Tree space sub-allocator.
4: */
5: #ifdef vax
6: #include "INC$LIB:cc0.h"
7: #else
8: #include "cc0.h"
9: #endif
10:
11: /*
12: * Tree space management.
13: */
14: struct tree_space {
15: struct tree_space *ts_link;
16: char *ts_ptr;
17: char *ts_end;
18: char ts_base[];
19: } *ts_bp, *ts_cp;
20: int ts_size;
21:
22: /*
23: * Allocate some space from the tree area.
24: * Always allocate the size of a tree node,
25: * the other uses are too few and far between
26: * to bother with.
27: * Abort the compiler if no space to get.
28: * To make life a lot easier for the rest of the world,
29: * tree space is zeroed.
30: */
31: extern char *malloc();
32: char *talloc()
33: {
34: register char *p;
35: register int n;
36:
37: n = ts_size;
38: if (ts_cp->ts_ptr == ts_cp->ts_end) {
39: if (ts_cp->ts_link == NULL) {
40: if ((ts_cp->ts_link = malloc(sizeof(*ts_bp)+n*128)) == NULL)
41: cfatal("out of space in tree node allocator");
42: ts_cp->ts_link->ts_link = NULL;
43: }
44: ts_cp = ts_cp->ts_link;
45: ts_cp->ts_ptr = ts_cp->ts_base;
46: ts_cp->ts_end = ts_cp->ts_base+n*128;
47: }
48: p = ts_cp->ts_ptr += n;
49: while (--n >= 0) *--p = 0;
50: return (p);
51: }
52:
53: /*
54: * Clear tree space.
55: * If tsize == ts_size then reset the tree allocator.
56: * If tsize != ts_size then free all space allocated
57: * and if tsize != 0 then reallocate with new granularity.
58: * tsize is the size of the tree nodes allocated.
59: */
60: newtree(tsize) int tsize;
61: {
62: if (tsize != ts_size) {
63: while (ts_bp != NULL) {
64: ts_cp = ts_bp;
65: ts_bp = ts_bp->ts_link;
66: free(ts_cp);
67: }
68: if (ts_size = tsize) {
69: if ((ts_bp = malloc(sizeof(*ts_bp) + ts_size*128)) == NULL)
70: cfatal("no space in tree allocator");
71: ts_bp->ts_link = NULL;
72: } else {
73: ts_bp = NULL;
74: }
75: }
76: if (ts_cp = ts_bp) {
77: ts_cp->ts_ptr = ts_cp->ts_base;
78: ts_cp->ts_end = ts_cp->ts_base+ts_size*128;
79: }
80: }
81:
82: /*
83: * Reset tree space to saved location.
84: * Used to parse #if expressions in mid-expression.
85: */
86: treset(p) char *p;
87: {
88: for (ts_cp = ts_bp; ts_cp != NULL; ts_cp = ts_cp->ts_link)
89: if (ts_cp->ts_base <= p && p <= ts_cp->ts_end)
90: break;
91: if (ts_cp == NULL) cbotch("tree reset");
92: ts_cp->ts_ptr = p;
93: }
94:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.