xref: /inferno-os/utils/qa/a.h (revision d0e1d143ef6f03c75c008c7ec648859dd260cbab)
1 #include <lib9.h>
2 #include <bio.h>
3 #include "../qc/q.out.h"
4 
5 #ifndef	EXTERN
6 #define	EXTERN	extern
7 #endif
8 
9 typedef	struct	Sym	Sym;
10 typedef	struct	Gen	Gen;
11 typedef	struct	Io	Io;
12 typedef	struct	Hist	Hist;
13 
14 #define	MAXALIGN	7
15 #define	FPCHIP		1
16 #define	NSYMB		8192
17 #define	BUFSIZ		8192
18 #define	HISTSZ		20
19 #define	NINCLUDE	10
20 #define	NHUNK		10000
21 #define	EOF		(-1)
22 #define	IGN		(-2)
23 #define	GETC()		((--fi.c < 0)? filbuf(): *fi.p++ & 0xff)
24 #define	NHASH		503
25 #define	STRINGSZ	200
26 #define	NMACRO		10
27 
28 #define	ALLOC(lhs, type)\
29 	while(nhunk < sizeof(type))\
30 		gethunk();\
31 	lhs = (type*)hunk;\
32 	nhunk -= sizeof(type);\
33 	hunk += sizeof(type);
34 
35 #define	ALLOCN(lhs, len, n)\
36 	if(lhs+len != hunk || nhunk < n) {\
37 		while(nhunk <= len)\
38 			gethunk();\
39 		memmove(hunk, lhs, len);\
40 		lhs = hunk;\
41 		hunk += len;\
42 		nhunk -= len;\
43 	}\
44 	hunk += n;\
45 	nhunk -= n;
46 
47 struct	Sym
48 {
49 	Sym*	link;
50 	char*	macro;
51 	long	value;
52 	ushort	type;
53 	char	*name;
54 	char	sym;
55 };
56 #define	S	((Sym*)0)
57 
58 struct
59 {
60 	char*	p;
61 	int	c;
62 } fi;
63 
64 struct	Io
65 {
66 	Io*	link;
67 	char	b[BUFSIZ];
68 	char*	p;
69 	short	c;
70 	short	f;
71 };
72 #define	I	((Io*)0)
73 
74 struct
75 {
76 	Sym*	sym;
77 	short	type;
78 } h[NSYM];
79 
80 struct	Gen
81 {
82 	Sym*	sym;
83 	long	offset;
84 	short	type;
85 	short	reg;
86 	short	xreg;
87 	short	name;
88 	ushort	mask;
89 	double	dval;
90 	char	sval[8];
91 };
92 
93 struct	Hist
94 {
95 	Hist*	link;
96 	char*	name;
97 	long	line;
98 	long	offset;
99 };
100 #define	H	((Hist*)0)
101 
102 enum
103 {
104 	CLAST,
105 	CMACARG,
106 	CMACRO,
107 	CPREPROC
108 };
109 
110 EXTERN	char	debug[256];
111 EXTERN	Sym*	hash[NHASH];
112 EXTERN	char*	Dlist[30];
113 EXTERN	int	nDlist;
114 EXTERN	Hist*	ehist;
115 EXTERN	int	newflag;
116 EXTERN	Hist*	hist;
117 EXTERN	char*	hunk;
118 EXTERN	char*	include[NINCLUDE];
119 EXTERN	Io*	iofree;
120 EXTERN	Io*	ionext;
121 EXTERN	Io*	iostack;
122 EXTERN	long	lineno;
123 EXTERN	int	nerrors;
124 EXTERN	long	nhunk;
125 EXTERN	int	nosched;
126 EXTERN	int	ninclude;
127 EXTERN	Gen	nullgen;
128 EXTERN	char*	outfile;
129 EXTERN	int	pass;
130 EXTERN	char*	pathname;
131 EXTERN	long	pc;
132 EXTERN	int	peekc;
133 EXTERN	int	sym;
134 EXTERN	char	symb[NSYMB];
135 EXTERN	int	thechar;
136 EXTERN	char*	thestring;
137 EXTERN	long	thunk;
138 EXTERN	Biobuf	obuf;
139 
140 void	errorexit(void);
141 void	pushio(void);
142 void	newio(void);
143 void	newfile(char*, int);
144 Sym*	slookup(char*);
145 Sym*	lookup(void);
146 void	syminit(Sym*);
147 long	yylex(void);
148 int	getc(void);
149 int	getnsc(void);
150 void	unget(int);
151 int	escchar(int);
152 void	cinit(void);
153 void	pinit(char*);
154 void	cclean(void);
155 void	outcode(int, Gen*, int, Gen*);
156 void	outgcode(int, Gen*, int, Gen*, Gen*);
157 void	zname(char*, int, int);
158 void	zaddr(Gen*, int);
159 void	ieeedtod(Ieee*, double);
160 int	filbuf(void);
161 Sym*	getsym(void);
162 void	domacro(void);
163 void	macund(void);
164 void	macdef(void);
165 void	macexpand(Sym*, char*);
166 void	macinc(void);
167 void	macprag(void);
168 void	maclin(void);
169 void	macif(int);
170 void	macend(void);
171 void	dodefine(char*);
172 void	prfile(long);
173 void	outhist(void);
174 void	linehist(char*, int);
175 void	gethunk(void);
176 void	yyerror(char*, ...);
177 int	yyparse(void);
178 void	setinclude(char*);
179 int	assemble(char*);
180 
181 /*
182  *	system-dependent stuff from ../cc/compat.c
183  */
184 enum				/* keep in synch with ../cc/cc.h */
185 {
186 	Plan9	= 1<<0,
187 	Unix	= 1<<1,
188 	Windows	= 1<<2
189 };
190 int	mywait(int*);
191 int	mycreat(char*, int);
192 int	systemtype(int);
193 int	pathchar(void);
194 char*	mygetwd(char*, int);
195 int	myexec(char*, char*[]);
196 int	mydup(int, int);
197 int	myfork(void);
198 int	mypipe(int*);
199 void*	mysbrk(ulong);
200