|
|
1.1 root 1: /*
2: * Sydney C Compiler.
3: *
4: * Copyright 1984, Bruce Ellis.
5: *
6: * Unauthorised possesion, sale or use prohibited.
7: */
8:
9: #include "defs.h"
10: #include "cnodes.h"
11: #include "flow.h"
12:
13: /*
14: * Trace the case tree.
15: */
16: void
17: trace_tree(c)
18: register cnode *c;
19: {
20: while (c != NULL)
21: {
22: trace_tree(c->c_left);
23: trace_life(c->c_label);
24:
25: c = c->c_right;
26: }
27: }
28:
29: /*
30: * Trace case labels.
31: */
32: void
33: trace_choice(ch)
34: register choice *ch;
35: {
36: trace_tree(ch->ch_case);
37: trace_life(ch->ch_def->c_label);
38: }
39:
40: /*
41: * Trace down a list of label refs.
42: */
43: void
44: trace_link(l)
45: register cnode *l;
46: {
47: while (l != NULL)
48: {
49: /*
50: * If C_SWITCH it is a fake node. Follow
51: * the link to the ct_switch node.
52: */
53: if ((l->c_flags & C_SWITCH) != 0)
54: {
55: register cnode *s;
56:
57: s = l->c_switch;
58:
59: if ((s->c_flags & C_X_CUT) == 0 && s->c_ord == L_NONE)
60: {
61: s->c_ord = L_ACTIVE;
62: trace_back(s->c_last);
63: }
64:
65: trace_choice(s->c_choice);
66: }
67: else
68: trace_life(l);
69:
70: l = l->c_link;
71: }
72: }
73:
74: /*
75: * Trace back from c.
76: */
77: void
78: trace_back(c)
79: register cnode *c;
80: {
81: while (c != NULL && c->c_ord == L_NONE && !in(mip_dead_ends, c->c_what))
82: {
83: switch (c->c_what)
84: {
85: case ct_label:
86: /*
87: * Mark the label and branch.
88: * (When you're going up the labels branch.)
89: */
90: c->c_ord = L_ACTIVE;
91: trace_link(c->c_value.c);
92: break;
93:
94: case ct_jmpf:
95: case ct_jmpt:
96: /*
97: * Mark conditional jumps and trace their destinations.
98: */
99: c->c_ord = L_ACTIVE;
100: trace_life(c->c_value.c);
101: break;
102:
103: default:
104: if ((c->c_flags & C_X_CUT) != 0)
105: return;
106:
107: c->c_ord = L_ACTIVE;
108: }
109:
110: c = c->c_last;
111: }
112: }
113:
114: /*
115: * Trace the life from c. Trace the successors and trace back.
116: */
117: void
118: trace_life(c)
119: register cnode *c;
120: {
121: trace_back(c->c_last);
122:
123: while (c != NULL && c->c_ord == L_NONE)
124: {
125: c->c_ord = L_ACTIVE;
126:
127: switch (c->c_what)
128: {
129: case ct_label:
130: trace_link(c->c_value.c);
131: break;
132:
133: case ct_switch:
134: if ((c->c_flags & C_X_CUT) == 0)
135: trace_choice(c->c_choice);
136:
137: return;
138:
139: case ct_jmp:
140: c = c->c_value.c;
141: trace_back(c->c_last);
142: continue;
143:
144: case ct_jmpf:
145: case ct_jmpt:
146: trace_life(c->c_value.c);
147: break;
148:
149: default:
150: if
151: (
152: in(mip_dead_ends, c->c_what)
153: ||
154: (c->c_flags & C_X_CUT) != 0
155: )
156: return;
157: }
158:
159: c = c->c_next;
160: }
161: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.