xref: /netbsd/external/bsd/pcc/dist/pcc/f77/fcom/defs.h (revision 16ebabc4)
1 /*	Id: defs.h,v 1.23 2011/12/12 09:18:25 plunky Exp 	*/
2 /*	$NetBSD: defs.h,v 1.1.1.4 2012/01/11 20:33:25 plunky Exp $	*/
3 /*
4  * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * Redistributions of source code and documentation must retain the above
11  * copyright notice, this list of conditions and the following disclaimer.
12  * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditionsand the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  * All advertising materials mentioning features or use of this software
16  * must display the following acknowledgement:
17  * 	This product includes software developed or owned by Caldera
18  *	International, Inc.
19  * Neither the name of Caldera International, Inc. nor the names of other
20  * contributors may be used to endorse or promote products derived from
21  * this software without specific prior written permission.
22  *
23  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
24  * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
25  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  * DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
28  * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
32  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
33  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  */
36 #include <stdio.h>
37 #include <ctype.h>
38 #include <stdlib.h>
39 
40 /* Copied from ../../cc/ccom/pass1.h. */
41 #define DATA	1
42 #define RDATA	2
43 #define UDATA	4
44 
45 #define VL 6
46 #define XL 8
47 
48 #define MAXINCLUDES 10
49 #define MAXLITERALS 20
50 #define MAXCTL 20
51 #define MAXHASH 401
52 #define MAXSTNO 1000
53 #define MAXEXT 200
54 #define MAXEQUIV 150
55 #define MAXLABLIST 100
56 
57 typedef struct bigblock *bigptr;
58 typedef union chainedblock *chainp;
59 
60 extern FILE *infile;
61 extern FILE *diagfile;
62 extern long int headoffset;
63 
64 extern char token [ ];
65 extern int toklen;
66 extern int lineno;
67 extern char *infname;
68 extern int needkwd;
69 extern struct labelblock *thislabel;
70 
71 extern int mflag, tflag;
72 
73 extern flag profileflag;
74 extern flag optimflag;
75 extern flag quietflag;
76 extern flag nowarnflag;
77 extern flag ftn66flag;
78 extern flag shiftcase;
79 extern flag undeftype;
80 extern flag shortsubs;
81 extern flag onetripflag;
82 extern flag checksubs;
83 extern flag debugflag;
84 extern int nerr;
85 extern int nwarn;
86 extern int ndata;
87 
88 extern int parstate;
89 extern flag headerdone;
90 extern int blklevel;
91 extern flag saveall;
92 extern flag substars;
93 extern int impltype[ ];
94 extern int implleng[ ];
95 extern int implstg[ ];
96 
97 extern int tyint;
98 extern int tylogical;
99 extern ftnint typesize[];
100 extern int typealign[];
101 extern int procno;
102 extern int proctype;
103 extern char * procname;
104 extern int rtvlabel[ ];
105 extern int fudgelabel;	/* to confuse the pdp11 optimizer */
106 extern struct bigblock *typeaddr;
107 extern struct bigblock *retslot;
108 extern int cxslot;
109 extern int chslot;
110 extern int chlgslot;
111 extern int procclass;
112 extern ftnint procleng;
113 extern int nentry;
114 extern flag multitype;
115 extern int blklevel;
116 extern int lastlabno;
117 extern int lastvarno;
118 extern int lastargslot;
119 extern int argloc;
120 extern ftnint autoleng;
121 extern ftnint bssleng;
122 extern int retlabel;
123 extern int ret0label;
124 extern int dorange;
125 extern int regnum[ ];
126 extern bigptr regnamep[ ];
127 extern int maxregvar;
128 extern int highregvar;
129 
130 extern chainp templist;
131 extern chainp holdtemps;
132 extern chainp entries;
133 extern chainp rpllist;
134 extern chainp curdtp;
135 extern ftnint curdtelt;
136 extern flag toomanyinit;
137 
138 extern flag inioctl;
139 extern int iostmt;
140 extern struct bigblock *ioblkp;
141 extern int nioctl;
142 extern int nequiv;
143 extern int nintnames;
144 extern int nextnames;
145 
146 struct chain
147 	{
148 	chainp nextp;
149 	bigptr datap;
150 	};
151 
152 extern chainp chains;
153 
154 struct ctlframe
155 	{
156 	unsigned ctltype:8;
157 	unsigned dostepsign:8;
158 	int ctlabels[4];
159 	int dolabel;
160 	struct bigblock *donamep;
161 	bigptr domax;
162 	bigptr dostep;
163 	};
164 #define endlabel ctlabels[0]
165 #define elselabel ctlabels[1]
166 #define dobodylabel ctlabels[1]
167 #define doposlabel ctlabels[2]
168 #define doneglabel ctlabels[3]
169 extern struct ctlframe ctls[ ];
170 extern struct ctlframe *ctlstack;
171 extern struct ctlframe *lastctl;
172 
173 struct extsym
174 	{
175 	char extname[XL];
176 	unsigned extstg:4;
177 	unsigned extsave:1;
178 	unsigned extinit:1;
179 	chainp extp;
180 	ftnint extleng;
181 	ftnint maxleng;
182 	};
183 
184 extern struct extsym extsymtab[ ];
185 extern struct extsym *nextext;
186 extern struct extsym *lastext;
187 
188 struct labelblock
189 	{
190 	int labelno;
191 	unsigned blklevel:8;
192 	unsigned labused:1;
193 	unsigned labinacc:1;
194 	unsigned labdefined:1;
195 	unsigned labtype:2;
196 	ftnint stateno;
197 	};
198 
199 extern struct labelblock labeltab[ ];
200 extern struct labelblock *labtabend;
201 extern struct labelblock *highlabtab;
202 
203 struct entrypoint
204 	{
205 	chainp nextp;
206 	struct extsym *entryname;
207 	chainp arglist;
208 	int entrylabel;
209 	int typelabel;
210 	ptr enamep;
211 	};
212 
213 struct primblock
214 	{
215 	struct bigblock *namep;
216 	struct bigblock *argsp;
217 	bigptr fcharp;
218 	bigptr lcharp;
219 	};
220 
221 
222 struct hashentry
223 	{
224 	int hashval;
225 	struct bigblock *varp;
226 	};
227 extern struct hashentry hashtab[ ];
228 extern struct hashentry *lasthash;
229 
230 struct intrpacked	/* bits for intrinsic function description */
231 	{
232 	unsigned f1:3;
233 	unsigned f2:4;
234 	unsigned f3:7;
235 	};
236 
237 struct nameblock
238 	{
239 	char varname[VL];
240 	unsigned vdovar:1;
241 	unsigned vdcldone:1;
242 	unsigned vadjdim:1;
243 	unsigned vsave:1;
244 	unsigned vprocclass:3;
245 	unsigned vregno:4;
246 	union	{
247 		int varno;
248 		chainp vstfdesc;	/* points to (formals, expr) pair */
249 		struct intrpacked intrdesc;	/* bits for intrinsic function */
250 		} vardesc;
251 	struct dimblock *vdim;
252 	int voffset;
253 	};
254 
255 
256 struct paramblock
257 	{
258 	char varname[VL];
259 	bigptr paramval;
260 	} ;
261 
262 
263 struct exprblock
264 	{
265 	unsigned opcode:6;
266 	bigptr leftp;
267 	bigptr rightp;
268 	};
269 
270 struct dcomplex {
271 	double dreal, dimag;
272 };
273 
274 union constant
275 	{
276 	char *ccp;
277 	ftnint ci;
278 	double cd[2];
279 	struct dcomplex dc;
280 	};
281 
282 struct constblock
283 	{
284 	union constant fconst;
285 	};
286 
287 
288 struct listblock
289 	{
290 	chainp listp;
291 	};
292 
293 
294 
295 struct addrblock
296 	{
297 	int memno;
298 	bigptr memoffset;
299 	unsigned istemp:1;
300 	unsigned ntempelt:10;
301 	};
302 
303 
304 
305 struct errorblock
306 	{
307 	int pad;
308 	};
309 
310 
311 struct dimblock
312 	{
313 	int ndim;
314 	bigptr nelt;
315 	bigptr baseoffset;
316 	bigptr basexpr;
317 	struct
318 		{
319 		bigptr dimsize;
320 		bigptr dimexpr;
321 		} dims[1];
322 	};
323 
324 
325 struct impldoblock  /* XXXX */
326 	{
327 #define	isactive vtype
328 #define isbusy vclass
329 	struct bigblock *varnp;
330 	struct bigblock *varvp;
331 	bigptr implb;
332 	bigptr impub;
333 	bigptr impstep;
334 	ftnint impdiff;
335 	ftnint implim;
336 	chainp datalist;
337 	};
338 
339 
340 struct rplblock	/* name replacement block */
341 	{
342 	chainp nextp;
343 	struct bigblock *rplnp;
344 	ptr rplvp;
345 	struct bigblock *rplxp;
346 	int rpltag;
347 	};
348 
349 
350 
351 struct equivblock
352 	{
353 	ptr equivs;
354 	unsigned eqvinit:1;
355 	long int eqvtop;
356 	long int eqvbottom;
357 	} ;
358 #define eqvleng eqvtop
359 
360 extern struct equivblock eqvclass[ ];
361 
362 
363 struct eqvchain
364 	{
365 	chainp nextp;
366 	ptr eqvitem;
367 	long int eqvoffset;
368 	} ;
369 
370 union chainedblock
371 	{
372 	struct chain chain;
373 	struct entrypoint entrypoint;
374 	struct rplblock rplblock;
375 	struct eqvchain eqvchain;
376 	};
377 
378 
379 struct bigblock {
380 	unsigned tag:4;
381 	unsigned vtype:4;
382 	unsigned vclass:4;
383 	unsigned vstg:4;
384 	bigptr vleng;
385 	union {
386 		struct exprblock _expr;
387 		struct addrblock _addr;
388 		struct constblock _const;
389 		struct errorblock _error;
390 		struct listblock _list;
391 		struct primblock _prim;
392 		struct nameblock _name;
393 		struct paramblock _param;
394 		struct impldoblock _impldo;
395 	} _u;
396 #define	b_expr		_u._expr
397 #define	b_addr		_u._addr
398 #define	b_const		_u._const
399 #define	b_error		_u._error
400 #define	b_list		_u._list
401 #define	b_prim		_u._prim
402 #define	b_name		_u._name
403 #define	b_param		_u._param
404 #define	b_impldo	_u._impldo
405 };
406 
407 struct literal
408 	{
409 	short littype;
410 	short litnum;
411 	union	{
412 		ftnint litival;
413 		double litdval;
414 		struct	{
415 			char litclen;	/* small integer */
416 			char litcstr[XL];
417 			} litcval;
418 		} litval;
419 	};
420 
421 extern struct literal litpool[ ];
422 extern int nliterals;
423 
424 
425 
426 
427 
428 /* popular functions with non integer return values */
429 #define	expptr bigptr
430 #define	tagptr bigptr
431 
432 ptr cpblock(int ,void *);
433 
434 ptr ckalloc(int);
435 char *varstr(int, char *), *nounder(int, char *), *varunder(int, char *);
436 char *copyn(int, char *), *copys(char *);
437 chainp hookup(chainp, chainp), mkchain(bigptr, chainp);
438 ftnint convci(int, char *), iarrlen(struct bigblock *q);
439 ftnint lmin(ftnint, ftnint), lmax(ftnint, ftnint);
440 ftnint simoffset(expptr *);
441 char *memname(int, int), *convic(ftnint), *setdoto(char *);
442 double convcd(int, char *);
443 struct extsym *mkext(char *),
444 	*newentry(struct bigblock *),
445 	*comblock(int, char *s);
446 struct bigblock *mkname(int, char *);
447 struct labelblock *mklabel(ftnint);
448 struct bigblock *addrof(expptr), *call1(int, char *, expptr),
449 	*call2(int, char *, expptr, expptr),
450 	*call3(int, char *, expptr, expptr, expptr),
451 	*call4(int, char *, expptr, expptr, expptr, expptr);
452 struct bigblock *call0(int, char *), *mkexpr(int, bigptr, bigptr);
453 struct bigblock *callk(int, char *, bigptr);
454 
455 struct bigblock *builtin(int, char *), *fmktemp(int, bigptr),
456 	*mktmpn(int, int, bigptr), *nextdata(ftnint *, ftnint *),
457 	*autovar(int, int, bigptr), *mklhs(struct bigblock *),
458 	*mkaddr(struct bigblock *), *putconst(struct bigblock *),
459 	*memversion(struct bigblock *);
460 struct bigblock *mkscalar(struct bigblock *np);
461 struct bigblock *realpart(struct bigblock *p);
462 struct bigblock *imagpart(struct bigblock *p);
463 
464 struct bigblock *mkintcon(ftnint), *mkbitcon(int, int, char *),
465 	*mklogcon(int), *mkaddcon(int), *mkrealcon(int, double),
466 	*mkstrcon(int, char *), *mkcxcon(bigptr,bigptr);
467 bigptr mkconst(int t);
468 
469 bigptr mklist(chainp p);
470 bigptr mkiodo(chainp, chainp);
471 
472 
473 bigptr mkconv(int, bigptr),
474 	mkfunct(struct bigblock *), fixexpr(struct bigblock *),
475 	fixtype(bigptr);
476 
477 
478 bigptr cpexpr(bigptr), mkprim(bigptr, struct bigblock *, bigptr, bigptr);
479 struct bigblock *mkarg(int, int);
480 struct bigblock *errnode(void);
481 void initkey(void), prtail(void), puteof(void), done(int);
482 void fileinit(void), procinit(void), endproc(void), doext(void), preven(int);
483 int inilex(char *), yyparse(void), newlabel(void), lengtype(int, int);
484 void err(char *, ...), warn(char *, ...), fatal(char *, ...), enddcl(void);
485 void p2pass(char *s), frexpr(bigptr), execerr(char *, ...);
486 void setimpl(int, ftnint, int, int), setlog(void), newproc(void);
487 void prdbginfo(void), impldcl(struct bigblock *p);
488 void putbracket(void), enddcl(void), doequiv(void);
489 void puthead(char *), startproc(struct extsym *, int);
490 void dclerr(char *s, struct bigblock *v), putforce(int, bigptr);
491 void entrypt(int, int, ftnint, struct extsym *, chainp);
492 void settype(struct bigblock *, int, int), putlabel(int);
493 void putbranch(struct bigblock *p), goret(int), putrbrack(int);
494 void prolog(struct entrypoint *, struct bigblock *), prendproc(void);
495 void prlocvar(char *, ftnint), prext(char *, ftnint, int);
496 void vardcl(struct bigblock *v), frchain(chainp *p);
497 void frtemp(struct bigblock *p), incomm(struct extsym *, struct bigblock *);
498 void setintr(struct bigblock * v), setext(struct bigblock * v);
499 struct uux { expptr lb, ub; };
500 void setbound(struct bigblock *, int, struct uux []);
501 void setfmt(struct labelblock *lp), frdata(chainp), frrpl(void),
502 	dataval(struct bigblock *, struct bigblock *),
503 	consnegop(struct bigblock *p), exdo(int, chainp), exelse(void),
504 	exendif(void), exif(bigptr), exelif(bigptr),
505 	exequals(struct bigblock *, bigptr),
506 	exassign(struct bigblock *, struct labelblock *),
507 	exarif(bigptr, struct labelblock *, struct labelblock *,
508 	    struct labelblock *);
509 
510 
511 
512 int intrfunct(char s[VL]), eqn(int, char *, char *);
513 int fmtstmt(struct labelblock *lp);
514 int cktype(int, int, int);
515 int yylex(void), inregister(struct bigblock *);
516 int inilex(char *), iocname(void);
517 int maxtype(int, int), flog2(ftnint), hextoi(int);
518 int cmpstr(char *, char *, ftnint, ftnint);
519 int enregister(struct bigblock *np);
520 int conssgn(bigptr p);
521 int fixargs(int, struct bigblock *);
522 int addressable(bigptr p);
523 
524 void prlabel(int);
525 void prconi(FILE *, int, ftnint);
526 void prcona(ftnint);
527 void prconr(FILE *, int, double);
528 void prarif(bigptr, int, int, int);
529 void putstr(char *, ftnint);
530 NODE *putex1(bigptr p);
531 void puteq(bigptr, bigptr);
532 void popstack(chainp *p);
533 void consconv(int, union constant *, int, union constant *);
534 void yyerror(char *s);
535 void enddo(int);
536 void doinclude(char *);
537 void flline(void);
538 void startioctl(void);
539 void endioctl(void), endio(void), ioclause(int, bigptr), doio(chainp);
540 void excall(struct bigblock *, struct bigblock *, int, struct labelblock *[]);
541 void exreturn(expptr p);
542 void exstop(int, expptr);
543 void exgoto(struct labelblock *);
544 void exasgoto(bigptr);
545 void putcmgo(expptr, int, struct labelblock *[]);
546 void putexpr(expptr p);
547 void putif(expptr, int);
548 void putgoto(int);
549 void deregister(struct bigblock *np);
550 NODE *putx(expptr p);
551 void cpn(int, char *, char *);
552 void prcmgoto(expptr, int, int, int);
553 char *lexline(ftnint *n);
554 bigptr suboffset(struct bigblock *p);
555 struct bigblock *intraddr(struct bigblock *np);
556 struct bigblock *intrcall(bigptr, bigptr, int);
557 void setloc(int);
558 void prnloc(char *name);
559 void fprint(bigptr p, int indx);
560 void ckfree(void *p);
561 
562 #undef expptr
563 #undef tagptr
564 
565 #define	err1 err
566 #define err2 err
567 #define	warn1 warn
568 #define	fatal1 fatal
569