xref: /inferno-os/utils/5c/gc.h (revision e45fa0eb0763b57d6fb0649c064bc3b95ccdea6c)
1 #include	"../cc/cc.h"
2 #include	"../5c/5.out.h"
3 
4 /*
5  * 5c/arm
6  * Arm
7  */
8 #define	SZ_CHAR		1
9 #define	SZ_SHORT	2
10 #define	SZ_INT		4
11 #define	SZ_LONG		4
12 #define	SZ_IND		4
13 #define	SZ_FLOAT	4
14 #define	SZ_VLONG	8
15 #define	SZ_DOUBLE	8
16 #define	FNX		100
17 
18 typedef	struct	Adr	Adr;
19 typedef	struct	Prog	Prog;
20 typedef	struct	Case	Case;
21 typedef	struct	C1	C1;
22 typedef	struct	Multab	Multab;
23 typedef	struct	Hintab	Hintab;
24 typedef	struct	Var	Var;
25 typedef	struct	Reg	Reg;
26 typedef	struct	Rgn	Rgn;
27 
28 
29 #define	R0ISZERO	0
30 
31 struct	Adr
32 {
33 	long	offset;
34 	double	dval;
35 	char	sval[NSNAME];
36 	Ieee	ieee;
37 
38 	Sym*	sym;
39 	char	type;
40 	char	reg;
41 	char	name;
42 	char	etype;
43 };
44 #define	A	((Adr*)0)
45 
46 #define	INDEXED	9
47 struct	Prog
48 {
49 	Adr	from;
50 	Adr	to;
51 	Prog*	link;
52 	long	lineno;
53 	char	as;
54 	char	reg;
55 	uchar	scond;
56 };
57 #define	P	((Prog*)0)
58 
59 struct	Case
60 {
61 	Case*	link;
62 	vlong	val;
63 	long	label;
64 	char	def;
65 	char isv;
66 };
67 #define	C	((Case*)0)
68 
69 struct	C1
70 {
71 	vlong	val;
72 	long	label;
73 };
74 
75 struct	Multab
76 {
77 	long	val;
78 	char	code[20];
79 };
80 
81 struct	Hintab
82 {
83 	ushort	val;
84 	char	hint[10];
85 };
86 
87 struct	Var
88 {
89 	long	offset;
90 	Sym*	sym;
91 	char	name;
92 	char	etype;
93 };
94 
95 struct	Reg
96 {
97 	long	pc;
98 	long	rpo;		/* reverse post ordering */
99 
100 	Bits	set;
101 	Bits	use1;
102 	Bits	use2;
103 
104 	Bits	refbehind;
105 	Bits	refahead;
106 	Bits	calbehind;
107 	Bits	calahead;
108 	Bits	regdiff;
109 	Bits	act;
110 
111 	long	regu;
112 	long	loop;		/* could be shorter */
113 
114 
115 	Reg*	log5;
116 	long	active;
117 
118 	Reg*	p1;
119 	Reg*	p2;
120 	Reg*	p2link;
121 	Reg*	s1;
122 	Reg*	s2;
123 	Reg*	link;
124 	Prog*	prog;
125 };
126 #define	R	((Reg*)0)
127 
128 #define	NRGN	600
129 struct	Rgn
130 {
131 	Reg*	enter;
132 	short	cost;
133 	short	varno;
134 	short	regno;
135 };
136 
137 EXTERN	long	breakpc;
138 EXTERN	long	nbreak;
139 EXTERN	Case*	cases;
140 EXTERN	Node	constnode;
141 EXTERN	Node	fconstnode;
142 EXTERN	long	continpc;
143 EXTERN	long	curarg;
144 EXTERN	long	cursafe;
145 EXTERN	Prog*	firstp;
146 EXTERN	Prog*	lastp;
147 EXTERN	long	maxargsafe;
148 EXTERN	int	mnstring;
149 EXTERN	Multab	multab[20];
150 EXTERN	int	hintabsize;
151 EXTERN	Node*	nodrat;
152 EXTERN	Node*	nodret;
153 EXTERN	Node*	nodsafe;
154 EXTERN	long	nrathole;
155 EXTERN	long	nstring;
156 EXTERN	Prog*	p;
157 EXTERN	long	pc;
158 EXTERN	Node	regnode;
159 EXTERN	char	string[NSNAME];
160 EXTERN	Sym*	symrathole;
161 EXTERN	Node	znode;
162 EXTERN	Prog	zprog;
163 EXTERN	char	reg[NREG+NFREG];
164 EXTERN	long	exregoffset;
165 EXTERN	long	exfregoffset;
166 EXTERN	int	suppress;
167 
168 #define	BLOAD(r)	band(bnot(r->refbehind), r->refahead)
169 #define	BSTORE(r)	band(bnot(r->calbehind), r->calahead)
170 #define	LOAD(r)		(~r->refbehind.b[z] & r->refahead.b[z])
171 #define	STORE(r)	(~r->calbehind.b[z] & r->calahead.b[z])
172 
173 #define	bset(a,n)	((a).b[(n)/32]&(1L<<(n)%32))
174 
175 #define	CLOAD	4
176 #define	CREF	5
177 #define	CINF	1000
178 #define	LOOP	3
179 
180 EXTERN	Rgn	region[NRGN];
181 EXTERN	Rgn*	rgp;
182 EXTERN	int	nregion;
183 EXTERN	int	nvar;
184 
185 EXTERN	Bits	externs;
186 EXTERN	Bits	params;
187 EXTERN	Bits	consts;
188 EXTERN	Bits	addrs;
189 
190 EXTERN	long	regbits;
191 EXTERN	long	exregbits;
192 
193 EXTERN	int	change;
194 
195 EXTERN	Reg*	firstr;
196 EXTERN	Reg*	lastr;
197 EXTERN	Reg	zreg;
198 EXTERN	Reg*	freer;
199 EXTERN	Var	var[NVAR];
200 EXTERN	long*	idom;
201 EXTERN	Reg**	rpo2r;
202 EXTERN	long	maxnr;
203 
204 extern	char*	anames[];
205 extern	Hintab	hintab[];
206 
207 /*
208  * sgen.c
209  */
210 void	codgen(Node*, Node*);
211 void	gen(Node*);
212 void	noretval(int);
213 void	usedset(Node*, int);
214 void	xcom(Node*);
215 int	bcomplex(Node*, Node*);
216 
217 /*
218  * cgen.c
219  */
220 void	cgen(Node*, Node*);
221 void	cgenrel(Node*, Node*, int);
222 void	reglcgen(Node*, Node*, Node*);
223 void	lcgen(Node*, Node*);
224 void	bcgen(Node*, int);
225 void	boolgen(Node*, int, Node*);
226 void	sugen(Node*, Node*, long);
227 void	layout(Node*, Node*, int, int, Node*);
228 
229 /*
230  * txt.c
231  */
232 void	ginit(void);
233 void	gclean(void);
234 void	nextpc(void);
235 void	gargs(Node*, Node*, Node*);
236 void	garg1(Node*, Node*, Node*, int, Node**);
237 Node*	nodconst(long);
238 Node*	nod32const(vlong);
239 Node*	nodfconst(double);
240 void	nodreg(Node*, Node*, int);
241 void	regret(Node*, Node*);
242 int	tmpreg(void);
243 void	regalloc(Node*, Node*, Node*);
244 void	regfree(Node*);
245 void	regialloc(Node*, Node*, Node*);
246 void	regsalloc(Node*, Node*);
247 void	regaalloc1(Node*, Node*);
248 void	regaalloc(Node*, Node*);
249 void	regind(Node*, Node*);
250 void	gprep(Node*, Node*);
251 void	raddr(Node*, Prog*);
252 void	naddr(Node*, Adr*);
253 void	gmovm(Node*, Node*, int);
254 void	gmove(Node*, Node*);
255 void	gmover(Node*, Node*);
256 void	gins(int a, Node*, Node*);
257 void	gopcode(int, Node*, Node*, Node*);
258 int	samaddr(Node*, Node*);
259 void	gbranch(int);
260 void	patch(Prog*, long);
261 int	sconst(Node*);
262 int	sval(long);
263 void	gpseudo(int, Sym*, Node*);
264 
265 /*
266  * swt.c
267  */
268 int	swcmp(void*, void*);
269 void	doswit(Node*);
270 void	swit1(C1*, int, long, Node*);
271 void	swit2(C1*, int, long, Node*, Node*);
272 void	casf(void);
273 void	bitload(Node*, Node*, Node*, Node*, Node*);
274 void	bitstore(Node*, Node*, Node*, Node*, Node*);
275 long	outstring(char*, long);
276 int	mulcon(Node*, Node*);
277 Multab*	mulcon0(long);
278 void	nullwarn(Node*, Node*);
279 void	gextern(Sym*, Node*, long, long);
280 void	outcode(void);
281 void	ieeedtod(Ieee*, double);
282 
283 /*
284  * list
285  */
286 void	listinit(void);
287 int	Pconv(Fmt*);
288 int	Aconv(Fmt*);
289 int	Dconv(Fmt*);
290 int	Sconv(Fmt*);
291 int	Nconv(Fmt*);
292 int	Bconv(Fmt*);
293 int	Rconv(Fmt*);
294 
295 /*
296  * reg.c
297  */
298 Reg*	rega(void);
299 int	rcmp(void*, void*);
300 void	regopt(Prog*);
301 void	addmove(Reg*, int, int, int);
302 Bits	mkvar(Adr*, int);
303 void	prop(Reg*, Bits, Bits);
304 void	loopit(Reg*, long);
305 void	synch(Reg*, Bits);
306 ulong	allreg(ulong, Rgn*);
307 void	paint1(Reg*, int);
308 ulong	paint2(Reg*, int);
309 void	paint3(Reg*, int, long, int);
310 void	addreg(Adr*, int);
311 
312 /*
313  * peep.c
314  */
315 void	peep(void);
316 void	excise(Reg*);
317 Reg*	uniqp(Reg*);
318 Reg*	uniqs(Reg*);
319 int	regtyp(Adr*);
320 int	regzer(Adr*);
321 int	anyvar(Adr*);
322 int	subprop(Reg*);
323 int	copyprop(Reg*);
324 int	shiftprop(Reg*);
325 void	constprop(Adr*, Adr*, Reg*);
326 int	copy1(Adr*, Adr*, Reg*, int);
327 int	copyu(Prog*, Adr*, Adr*);
328 
329 int	copyas(Adr*, Adr*);
330 int	copyau(Adr*, Adr*);
331 int	copyau1(Prog*, Adr*);
332 int	copysub(Adr*, Adr*, Adr*, int);
333 int	copysub1(Prog*, Adr*, Adr*, int);
334 
335 long	RtoB(int);
336 long	FtoB(int);
337 int	BtoR(long);
338 int	BtoF(long);
339 
340 void	predicate(void);
341 int	isbranch(Prog *);
342 int	predicable(Prog *p);
343 int	modifiescpsr(Prog *p);
344 
345 #pragma	varargck	type	"A"	int
346 #pragma	varargck	type	"B"	Bits
347 #pragma	varargck	type	"D"	Adr*
348 #pragma	varargck	type	"N"	Adr*
349 #pragma	varargck	type	"R"	Adr*
350 #pragma	varargck	type	"P"	Prog*
351 #pragma	varargck	type	"S"	char*
352