Quick Search:

View

Revision:
Expand:  
Changeset: MAIN:ragge:20020324105723

Diff

Diff from 1.1 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/pcc/pcc/mip/common.c

Annotated File View

ragge
1.1
1 /*      common.c        4.5     88/05/11        */
2
3 #ifdef PASS1COMMON
4 #include "pass1.h"
5 #else
6 #ifdef PASS2COMMON
7 #include "pass2.h"
8 #endif
9 #endif
10
11 #ifdef FORT
12 #undef BUFSTDERR
13 #endif
14 #ifndef ONEPASS
15 #undef BUFSTDERR
16 #endif
17 # ifndef EXIT
18 # define EXIT exit
19 # endif
20
21 int nerrors = 0;  /* number of errors */
22
23 extern unsigned int offsz;
24
25 unsigned caloff(){
26         register i;
27         unsigned int temp;
28         unsigned int off;
29         temp = 1;
30         i = 0;
31         do {
32                 temp <<= 1;
33                 ++i;
34                 } whiletemp != 0 );
35         off = 1 << (i-1);
36         return (off);
37         }
38
39 NODE *lastfree;  /* pointer to last free node; (for allocator) */
40
41         /* VARARGS1 */
42 uerrorsa ) char *s; { /* nonfatal error message */
43         /* the routine where is different for pass 1 and pass 2;
44         /*  it tells where the error took place */
45
46         ++nerrors;
47         where('u');
48         fprintfstderrsa );
49         fprintfstderr"\n" );
50 #ifdef BUFSTDERR
51         fflush(stderr);
52 #endif
53         ifnerrors > 30 ) cerror"too many errors");
54         }
55
56         /* VARARGS1 */
57 cerrorsabc ) char *s; { /* compiler error: die */
58         where('c');
59         ifnerrors && nerrors <= 30 ){ /* give the compiler the benefit of the doubt */
60                 fprintfstderr"cannot recover from earlier errors: goodbye!\n" );
61                 }
62         else {
63                 fprintfstderr"compiler error: " );
64                 fprintfstderrsabc );
65                 fprintfstderr"\n" );
66                 }
67 #ifdef BUFSTDERR
68         fflush(stderr);
69 #endif
70         EXIT(1);
71         }
72
73 int Wflag = 0/* Non-zero means do not print warnings */
74
75         /* VARARGS1 */
76 werrorsab ) char *s; {  /* warning */
77         if(Wflagreturn;
78         where('w');
79         fprintfstderr"warning: " );
80         fprintfstderrsab );
81         fprintfstderr"\n" );
82 #ifdef BUFSTDERR
83         fflush(stderr);
84 #endif
85         }
86
87 tinit(){ /* initialize expression tree search */
88
89         register NODE *p;
90
91         forp=nodep<= &node[TREESZ-1]; ++p ) p->in.op = FREE;
92         lastfree = node;
93
94         }
95
96 # define TNEXT(p) (p== &node[TREESZ-1]?node:p+1)
97
98 NODE *
99 talloc(){
100         register NODE *p, *q;
101
102         q = lastfree;
103         forp = TNEXT(q); p!=qpTNEXT(p))
104                 ifp->in.op ==FREE )
105                         return(lastfree=p);
106
107         cerror"out of tree space; simplify expression");
108         /* NOTREACHED */
109         }
110
111 tcheck(){ /* ensure that all nodes have been freed */
112
113         register NODE *p;
114
115         if( !nerrors )
116                 forp=nodep<= &node[TREESZ-1]; ++p )
117                         ifp->in.op != FREE )
118                                 cerror"wasted space: %o"p );
119         tinit();
120 #ifdef FLEXNAMES
121         freetstr();
122 #endif
123         }
124 tfreep )  NODE *p; {
125         /* free the tree p */
126         extern tfree1();
127
128         ifp->in.op != FREE ) walkfptfree1 );
129
130         }
131
132 tfree1(p)  NODE *p; {
133         ifp == 0 ) cerror"freeing blank tree!");
134         else p->in.op = FREE;
135         }
136
137 fwalktfdown ) register NODE *tint (*f)(); {
138
139         int down1down2;
140
141         more:
142         down1 = down2 = 0;
143
144         (*f)( tdown, &down1, &down2 );
145
146         switchoptypet->in.op ) ){
147
148         case BITYPE:
149                 fwalkt->in.leftfdown1 );
150                 t = t->in.right;
151                 down = down2;
152                 goto more;
153
154         case UTYPE:
155                 t = t->in.left;
156                 down = down1;
157                 goto more;
158
159                 }
160         }
161
162 #ifndef vax
163 walkftf ) register NODE *t;  int (*f)(); {
164         register opty;
165
166         opty = optype(t->in.op);
167
168         ifopty != LTYPE ) walkft->in.leftf );
169         ifopty == BITYPE ) walkft->in.rightf );
170         (*f)( t );
171         }
172 #else
173 #define NR      32
174
175 /*
176  * Deliberately avoids recursion -- use this version on machines with
177  * expensive procedure calls.
178  */
179 walkf(tf)
180         register NODE *t;
181         register int (*f)();
182 {
183         NODE *Aat[NR];
184         int Aao[NR];
185         register int i = 1;
186         register int opty = optype(t->in.op);
187         register NODE **at = Aat;
188         register int *ao = Aao;
189
190 #define PUSH(dir, state) \
191         (ao[i] = stateat[i++] = tt = t->in.diropty = optype(t->in.op))
192 #define POP() \
193         (opty = ao[--i], t = at[i])
194
195         do {
196                 switch (opty) {
197                 case LTYPE:     (*f)(t); POP(); break;
198                 case UTYPE:     PUSH(leftLTYPE); break;
199                 case BITYPE:    PUSH(leftBITYPE+1); break;
200                 case BITYPE+1:  PUSH(rightLTYPE); break;
201                 default:
202                         cerror("bad op type in walkf");
203                 }
204                 if (i >= NR) {
205                         walkf(tf);
206                         POP();
207                 }
208         } while (i > 0);
209 }
210 #undef NR
211 #undef PUSH
212 #undef POP
213 #endif
214
215
216
217 int dopeDSIZE ];
218 char *opst[DSIZE];
219
220 struct dopest { int dopeopchar opst[8]; int dopeval; } indope[] = {
221
222         NAME"NAME"LTYPE,
223         STRING"STRING"LTYPE,
224         REG"REG"LTYPE,
225         OREG"OREG"LTYPE,
226         ICON"ICON"LTYPE,
227         FCON"FCON"LTYPE,
228         DCON"DCON"LTYPE,
229         CCODES"CCODES"LTYPE,
230         UNARY MINUS"U-"UTYPE,
231         UNARY MUL"U*"UTYPE,
232         UNARY AND"U&"UTYPE,
233         UNARY CALL"UCALL"UTYPE|CALLFLG,
234         UNARY FORTCALL"UFCALL"UTYPE|CALLFLG,
235         NOT"!"UTYPE|LOGFLG,
236         COMPL"~"UTYPE,
237         FORCE"FORCE"UTYPE,
238         INIT"INIT"UTYPE,
239         SCONV"SCONV"UTYPE,
240         PCONV"PCONV"UTYPE,
241         PLUS"+"BITYPE|FLOFLG|SIMPFLG|COMMFLG,
242         ASG PLUS"+="BITYPE|ASGFLG|ASGOPFLG|FLOFLG|SIMPFLG|COMMFLG,
243         MINUS"-"BITYPE|FLOFLG|SIMPFLG,
244         ASG MINUS"-="BITYPE|FLOFLG|SIMPFLG|ASGFLG|ASGOPFLG,
245         MUL"*"BITYPE|FLOFLG|MULFLG,
246         ASG MUL"*="BITYPE|FLOFLG|MULFLG|ASGFLG|ASGOPFLG,
247         AND"&"BITYPE|SIMPFLG|COMMFLG,
248         ASG AND"&="BITYPE|SIMPFLG|COMMFLG|ASGFLG|ASGOPFLG,
249         QUEST"?"BITYPE,
250         COLON":"BITYPE,
251         ANDAND"&&"BITYPE|LOGFLG,
252         OROR"||"BITYPE|LOGFLG,
253         CM","BITYPE,
254         COMOP",OP"BITYPE,
255         ASSIGN"="BITYPE|ASGFLG,
256         DIV"/"BITYPE|FLOFLG|MULFLG|DIVFLG,
257         ASG DIV"/="BITYPE|FLOFLG|MULFLG|DIVFLG|ASGFLG|ASGOPFLG,
258         MOD"%"BITYPE|DIVFLG,
259         ASG MOD"%="BITYPE|DIVFLG|ASGFLG|ASGOPFLG,
260         LS"<<"BITYPE|SHFFLG,
261         ASG LS"<<="BITYPE|SHFFLG|ASGFLG|ASGOPFLG,
262         RS">>"BITYPE|SHFFLG,
263         ASG RS">>="BITYPE|SHFFLG|ASGFLG|ASGOPFLG,
264         OR"|"BITYPE|COMMFLG|SIMPFLG,
265         ASG OR"|="BITYPE|COMMFLG|SIMPFLG|ASGFLG|ASGOPFLG,
266         ER"^"BITYPE|COMMFLG|SIMPFLG,
267         ASG ER"^="BITYPE|COMMFLG|SIMPFLG|ASGFLG|ASGOPFLG,
268         INCR"++"BITYPE|ASGFLG,
269         DECR"--"BITYPE|ASGFLG,
270         STREF"->"BITYPE,
271         CALL"CALL"BITYPE|CALLFLG,
272         FORTCALL"FCALL"BITYPE|CALLFLG,
273         EQ"=="BITYPE|LOGFLG,
274         NE"!="BITYPE|LOGFLG,
275         LE"<="BITYPE|LOGFLG,
276         LT"<"BITYPE|LOGFLG,
277         GE">"BITYPE|LOGFLG,
278         GT">"BITYPE|LOGFLG,
279         UGT"UGT"BITYPE|LOGFLG,
280         UGE"UGE"BITYPE|LOGFLG,
281         ULT"ULT"BITYPE|LOGFLG,
282         ULE"ULE"BITYPE|LOGFLG,
283 #ifdef ARS
284         ARS"A>>"BITYPE,
285 #endif
286         TYPE"TYPE"LTYPE,
287         LB"["BITYPE,
288         CBRANCH"CBRANCH"BITYPE,
289         FLD"FLD"UTYPE,
290         PMCONV"PMCONV"BITYPE,
291         PVCONV"PVCONV"BITYPE,
292         RETURN"RETURN"BITYPE|ASGFLG|ASGOPFLG,
293         CAST"CAST"BITYPE|ASGFLG|ASGOPFLG,
294         GOTO"GOTO"UTYPE,
295         STASG"STASG"BITYPE|ASGFLG,
296         STARG"STARG"UTYPE,
297         STCALL"STCALL"BITYPE|CALLFLG,
298         UNARY STCALL"USTCALL"UTYPE|CALLFLG,
299
300         -1,     "",     0
301 };
302
303 mkdope(){
304         register struct dopest *q;
305
306         forq = indopeq->dopeop >= 0; ++q ){
307                 dope[q->dopeop] = q->dopeval;
308                 opst[q->dopeop] = q->opst;
309                 }
310         }
311 # ifndef BUG4
312 tprintt )  TWORD t; { /* output a nice description of the type of t */
313
314         static char * tnames[] = {
315                 "undef",
316                 "farg",
317                 "char",
318                 "short",
319                 "int",
320                 "long",
321                 "float",
322                 "double",
323                 "strty",
324                 "unionty",
325                 "enumty",
326                 "moety",
327                 "uchar",
328                 "ushort",
329                 "unsigned",
330                 "ulong",
331                 "?""?"
332                 };
333
334         for(;; t = DECREF(t) ){
335
336                 ifISPTR(t) ) printf"PTR " );
337                 else ifISFTN(t) ) printf"FTN " );
338                 else ifISARY(t) ) printf"ARY " );
339                 else {
340                         printf"%s"tnames[t] );
341                         return;
342                         }
343                 }
344         }
345 # endif
346
347 #ifdef FLEXNAMES
348 #define NTSTRBUF        40
349 #define TSTRSZ          2048
350 char    itstrbuf[TSTRSZ];
351 char    *tstrbuf[NTSTRBUF] = { itstrbuf };
352 char    **curtstr = tstrbuf;
353 int     tstrused;
354 char    *malloc();
355 char    *strcpy();
356
357 char *
358 tstr(cp)
359         register char *cp;
360 {
361         register int i = strlen(cp);
362         register char *dp;
363         
364         if (tstrused + i >= TSTRSZ) {
365                 if (++curtstr >= &tstrbuf[NTSTRBUF])
366                         cerror("out of temporary string space");
367                 tstrused = 0;
368                 if (*curtstr == 0) {
369                         dp = malloc(TSTRSZ);
370                         if (dp == 0)
371                                 cerror("out of memory (tstr)");
372                         *curtstr = dp;
373                 }
374         }
375         (voidstrcpy(dp = *curtstr+tstrusedcp);
376         tstrused += i + 1;
377         return (dp);
378 }
379 #endif
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-08-20 22:27 +0200