Debian Codegraph @

arch/vax/local.c

raw symbols SCIP
1 /* $Id: local.c,v 1.34 2018/04/04 17:34:07 ragge Exp $ */
2 /*
3 * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * Redistributions of source code and documentation must retain the above
10 * copyright notice, this list of conditions and the following disclaimer.
11 * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditionsand the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed or owned by Caldera
17 * International, Inc.
18 * Neither the name of Caldera International, Inc. nor the names of other
19 * contributors may be used to endorse or promote products derived from
20 * this software without specific prior written permission.
21 *
22 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
23 * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE
27 * FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT,
31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
32 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36 # include "pass1.h"
37
38 #ifndef LANG_CXX
39 #define NODE P1ND
40 #undef NIL
41 #define NIL NULL
42 #define nfree p1nfree
43 #define fwalk p1fwalk
44 #endif
45
46 static void r1arg(NODE *p, NODE *q);
47
48 #define IALLOC(sz) (isinlining ? permalloc(sz) : tmpalloc(sz))
49
50 /* this file contains code which is dependent on the target machine */
51
52 NODE *
53 clocal(p) NODE *p; {
54
55 /* this is called to do local transformations on
56 an expression tree preparitory to its being
57 written out in intermediate code.
58 */
59
60 /* the major essential job is rewriting the
61 automatic variables and arguments in terms of
62 REG and OREG nodes */
63 /* conversion ops which are not necessary are also clobbered here */
64 /* in addition, any special features (such as rewriting
65 exclusive or) are easily handled here as well */
66
67 register struct symtab *q;
68 register NODE *r, *l;
69 register int o;
70 register int ml;
71
72
73 #ifdef PCC_DEBUG
74 if (xdebug) {
75 printf("clocal(%p)\n", p);
76 if (xdebug>1)
77 fwalk(p, eprint, 0);
78 }
79 #endif
80
81 switch( o = p->n_op ){
82
83 case NAME:
84 if((q = p->n_sp) == 0 ) { /* already processed; ignore... */
85 return(p);
86 }
87 switch( q->sclass ){
88
89 case REGISTER:
90 case AUTO:
91 case PARAM:
92 /* fake up a structure reference */
93 r = block( REG, NIL, NIL, PTR+STRTY, 0, 0 );
94 slval(r, 0);
95 regno(r) = q->sclass==PARAM?ARGREG:FPREG;
96 p = stref( block( STREF, r, p, 0, 0, 0 ) );
97 break;
98 }
99 break;
100
101 case FORCE:
102 p->n_op = ASSIGN;
103 p->n_right = p->n_left;
104 p->n_left = block(REG, NIL, NIL, p->n_type, 0, 0);
105 p->n_left->n_rval = p->n_left->n_type == BOOL ?
106 RETREG(CHAR) : RETREG(p->n_type);
107 break;
108
109 case SCONV:
110 l = p->n_left;
111 ml = p->n_type;
112 #if 0
113 if (ml == INT && l->n_type == UNSIGNED) {
114 p = nfree(p);
115 break;
116 }
117 #endif
118 if (l->n_op == ICON) {
119 if (l->n_sp == 0) {
120 p->n_type = UNSIGNED;
121 concast(l, p->n_type);
122 } else if (ml != INT && ml != UNSIGNED)
123 break;
124 l->n_type = ml;
125 l->n_ap = 0;
126 p = nfree(p);
127 break;
128 }
129 break;
130
131 case STCALL:
132 /* see if we have been here before */
133 for (r = p->n_right; r->n_op == CM; r = r->n_left)
134 ;
135 if (r->n_op == ASSIGN)
136 break;
137
138 /* FALLTHROUGH */
139 case USTCALL:
140 /* Allocate buffer on stack to bounce via */
141 /* create fake symtab here */
142 q = getsymtab("77fake", STEMP);
143 q->stype = BTYPE(p->n_type);
144 q->sdf = p->n_df;
145 q->sap = p->n_ap;
146 q->soffset = NOOFFSET;
147 q->sclass = AUTO;
148 oalloc(q, &autooff);
149 r1arg(p, buildtree(ADDROF, nametree(q), 0));
150 break;
151 }
152 #ifdef PCC_DEBUG
153 if (xdebug) {
154 printf("clocal end(%p)\n", p);
155 if (xdebug>1)
156 fwalk(p, eprint, 0);
157 }
158 #endif
159
160 return(p);
161 }
162
163 /*
164 * Add R1 with the dest address as arg to a struct return call.
165 */
166 static void
167 r1arg(NODE *p, NODE *q)
168 {
169 NODE *r;
170
171 r = block(REG, NIL, NIL, PTR|VOID, 0, 0);
172 regno(r) = R1;
173 r = buildtree(ASSIGN, r, q);
174 if (p->n_op == USTCALL) {
175 p->n_op = STCALL;
176 p->n_right = r;
177 } else if (p->n_right->n_op != CM) {
178 p->n_right = block(CM, r, p->n_right, INT, 0, 0);
179 } else {
180 for (q = p->n_right; q->n_left->n_op == CM; q = q->n_left)
181 ;
182 q->n_left = block(CM, r, q->n_left, INT, 0, 0);
183 }
184 }
185
186 void
187 myp2tree(NODE *p)
188 {
189 struct symtab *sp;
190
191 if ((cdope(p->n_op) & CALLFLG) && p->n_left->n_op == ADDROF &&
192 p->n_left->n_left->n_op == NAME) {
193 NODE *q = p->n_left->n_left;
194 nfree(p->n_left);
195 p->n_left = q;
196 q->n_op = ICON;
197 }
198
199 if (p->n_op != FCON)
200 return;
201
202 sp = IALLOC(sizeof(struct symtab));
203 sp->sclass = STATIC;
204 sp->sap = 0;
205 sp->slevel = 1; /* fake numeric label */
206 sp->soffset = getlab();
207 sp->sflags = 0;
208 sp->stype = p->n_type;
209 sp->squal = (CON >> TSHIFT);
210 sp->sname = NULL;
211
212 locctr(DATA, sp);
213 defloc(sp);
214 inval(0, tsize(sp->stype, sp->sdf, sp->sap), p);
215
216 p->n_op = NAME;
217 slval(p, 0);
218 p->n_sp = sp;
219
220 }
221
222 /*
223 * Can we take & of a NAME?
224 */
225 int
226 andable(NODE *p)
227 {
228 /* for now, delay name reference to table, for PIC code generation */
229 /* functions are called by name, convert they in myp2tree */
230 return 0;
231 }
232
233 /* is an automatic variable of type t OK for a register variable */
234 int
235 cisreg(TWORD t)
236 {
237 return(1); /* all are now */
238 }
239
240 /*
241 * Allocate off bits on the stack. p is a tree that when evaluated
242 * is the multiply count for off, t is a storeable node where to write
243 * the allocated address.
244 */
245 void
246 spalloc(NODE *t, NODE *p, OFFSZ off)
247 {
248 NODE *sp;
249
250 p = buildtree(MUL, p, bcon(off/SZCHAR)); /* XXX word alignment? */
251
252 /* sub the size from sp */
253 sp = block(REG, NIL, NIL, p->n_type, 0, 0);
254 slval(sp, 0);
255 sp->n_rval = STKREG;
256 ecomp(buildtree(MINUSEQ, sp, p));
257
258 /* save the address of sp */
259 sp = block(REG, NIL, NIL, PTR+INT, t->n_df, t->n_ap);
260 slval(sp, 0);
261 sp->n_rval = STKREG;
262 t->n_type = sp->n_type;
263 ecomp(buildtree(ASSIGN, t, sp)); /* Emit! */
264
265 }
266
267 char *
268 exname( p ) char *p; {
269 /* make a name look like an external name in the local machine */
270 /* vad is elf now */
271 if (p == NULL)
272 return "";
273 return( p );
274 }
275
276 /* map types which are not defined on the local machine */
277 TWORD
278 ctype(TWORD type) {
279 switch( BTYPE(type) ){
280
281 case LONG:
282 MODTYPE(type,INT);
283 break;
284
285 case ULONG:
286 MODTYPE(type,UNSIGNED);
287 break;
288
289 case LDOUBLE: /* for now */
290 MODTYPE(type,DOUBLE);
291 }
292 return( type );
293 }
294
295 void
296 calldec(NODE *p, NODE *q)
297 {
298 }
299
300 void
301 extdec(struct symtab *q)
302 {
303 }
304
305 /* make a common declaration for id, if reasonable */
306 void
307 defzero(struct symtab *sp)
308 {
309 int off, al;
310 char *name;
311
312 name = getexname(sp);
313 off = tsize(sp->stype, sp->sdf, sp->sap);
314 SETOFF(off,SZCHAR);
315 off /= SZCHAR;
316 al = talign(sp->stype, sp->sap)/SZCHAR;
317
318 if (sp->sclass == STATIC) {
319 if (sp->slevel == 0)
320 printf("\t.local %s\n", name);
321 else
322 printf("\t.local " LABFMT "\n", sp->soffset);
323 }
324 if (sp->slevel == 0) {
325 printf("\t.comm %s,0%o,%d\n", name, off, al);
326 } else
327 printf("\t.comm " LABFMT ",0%o,%d\n", sp->soffset, off, al);
328 }
329
330 /*
331 * print out a constant node, may be associated with a label.
332 * Do not free the node after use.
333 * off is bit offset from the beginning of the aggregate
334 * fsz is the number of bits this is referring to
335 * XXX - floating point constants may be wrong if cross-compiling.
336 */
337 int
338 ninval(CONSZ off, int fsz, NODE *p)
339 {
340 union { float f; double d; long double l; int i[3]; } u;
341
342 switch (p->n_type) {
343 case LDOUBLE:
344 u.i[2] = 0;
345 u.l = (long double)((FLT *)p->n_dcon)->fp;
346 printf("\t.long\t0x%x,0x%x,0x%x\n", u.i[0], u.i[1], u.i[2]);
347 break;
348 case DOUBLE:
349 u.d = (double)((FLT *)p->n_dcon)->fp;
350 printf("\t.long\t0x%x,0x%x\n", u.i[0], u.i[1]);
351 break;
352 case FLOAT:
353 u.f = (float)((FLT *)p->n_dcon)->fp;
354 printf("\t.long\t0x%x\n", u.i[0]);
355 break;
356 default:
357 return 0;
358 }
359 return 1;
360
361 }
362 /*
363 * Give target the opportunity of handling pragmas.
364 */
365 int
366 mypragma(char *str)
367 {
368 return 0;
369 }
370
371 /*
372 * Called when a identifier has been declared, to give target last word.
373 */
374 void
375 fixdef(struct symtab *sp)
376 {
377 }
378
379 void
380 pass1_lastchance(struct interpass *ip)
381 {
382 }