1 /*	$Id: local.c,v 1.78 2014/05/29 19:20:03 plunky Exp $	*/
2 /*
3  * Copyright (c) 2003 Anders Magnusson (ragge@ludd.luth.se).
4  * 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  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 
27 
28 # include "pass1.h"
29 
30 /*	this file contains code which is dependent on the target machine */
31 
32 static int pointp(TWORD t);
33 static struct symtab *newfun(char *name, TWORD type);
34 
35 #define	PTRNORMAL	1
36 #define	PTRCHAR		2
37 #define	PTRSHORT	3
38 static int xptype(TWORD t);
39 
40 NODE *
clocal(NODE * p)41 clocal(NODE *p)
42 {
43 	/* this is called to do local transformations on
44 	   an expression tree preparitory to its being
45 	   written out in intermediate code.
46 	*/
47 
48 	/* the major essential job is rewriting the
49 	   automatic variables and arguments in terms of
50 	   REG and OREG nodes */
51 	/* conversion ops which are not necessary are also clobbered here */
52 	/* in addition, any special features (such as rewriting
53 	   exclusive or) are easily handled here as well */
54 
55 	register struct symtab *q;
56 	register NODE *r, *l, *oop;
57 	register int o;
58 	register int m, ml;
59 	int siz;
60 
61 #ifdef PCC_DEBUG
62 	if (xdebug) {
63 		printf("clocal: %p\n", p);
64 		fwalk(p, eprint, 0);
65 	}
66 #endif
67 
68 	switch( o = p->n_op ){
69 
70 	case NAME:
71 		if ((q = p->n_sp) == NULL)
72 			return p; /* Nothing to care about */
73 
74 		switch (q->sclass) {
75 
76 		case PARAM:
77 			/* First 7 parameters are in registers */
78 			/* XXX last may be double */
79 			if (q->soffset/SZINT < 7) {
80 				p->n_op = REG;
81 				p->n_rval = q->soffset/SZINT;
82 				break;
83 			} else
84 				q->soffset -= 7*SZINT;
85 
86 		case AUTO:
87 			/* fake up a structure reference */
88 			if (q->stype == CHAR || q->stype == UCHAR ||
89 			    q->stype == SHORT || q->stype == USHORT)
90 				r = block(REG, NIL, NIL, PTR+q->stype, 0, 0);
91 			else
92 				r = block(REG, NIL, NIL, PTR+STRTY, 0, 0);
93 			r->n_lval = 0;
94 			r->n_rval = FPREG;
95 			p = stref(block(STREF, r, p, 0, 0, 0));
96 			break;
97 
98 		case STATIC:
99 			if (q->slevel == 0)
100 				break;
101 			p->n_lval = 0;
102 			break;
103 
104 		case REGISTER:
105 			p->n_op = REG;
106 			p->n_lval = 0;
107 			p->n_rval = q->soffset;
108 			break;
109 
110 			}
111 		break;
112 
113 	case CALL:
114 		/* avoid recursive calls */
115 		r = tempnode(0, p->n_type, p->n_df, p->n_sue);
116 		l = tempnode(regno(r), p->n_type, p->n_df, p->n_sue);
117 		ecomp(buildtree(ASSIGN, r, p));
118 		p = l;
119 		break;
120 
121 	case PCONV:
122 		l = p->n_left;
123 		/*
124 		 * Handle frame pointer directly without conversion,
125 		 * for efficiency.
126 		 */
127 		if (l->n_op == REG && l->n_rval == 0) {
128 rmpc:			l->n_type = p->n_type;
129 			l->n_df = p->n_df;
130 			l->n_sue = p->n_sue;
131 			nfree(p);
132 			return l;
133 		}
134 		/* Convert ICON with name to new type */
135 		if (l->n_op == ICON && l->n_sp != NULL &&
136 		    l->n_type == INCREF(STRTY) &&
137 		    (p->n_type == INCREF(CHAR) ||
138 		    p->n_type == INCREF(UCHAR) ||
139 		    p->n_type == INCREF(SHORT) ||
140 		    p->n_type == INCREF(USHORT))) {
141 			l->n_lval *= (BTYPE(p->n_type) == CHAR ||
142 			    BTYPE(p->n_type) == UCHAR ? 4 : 2);
143 			goto rmpc;
144 		}
145 		/* Convert only address constants, never convert other */
146 		if (l->n_op == ICON) {
147 			if (l->n_sp == NULL)
148 				goto rmpc;
149 			if (p->n_type == INCREF(CHAR) ||
150 			    p->n_type == INCREF(UCHAR) ||
151 			    p->n_type == INCREF(VOID))
152 				l->n_lval = (l->n_lval & 07777777777) |
153 				    0700000000000LL;
154 			else if (p->n_type == INCREF(SHORT) ||
155 			    p->n_type == INCREF(USHORT))
156 				l->n_lval = (l->n_lval & 07777777777) |
157 				    0750000000000LL;
158 			else
159 				l->n_lval = l->n_lval & 07777777777;
160 			goto rmpc;
161 		}
162 
163 		/* Remove more conversions of identical pointers */
164 		/* Be careful! optim() may do bad things */
165 		if (ISPTR(DECREF(p->n_type))) {
166 			if (ISPTR(DECREF(l->n_type))) {
167 				if ((coptype(l->n_op) == UTYPE ||
168 				    coptype(l->n_op) == BITYPE) &&
169 				    (l->n_left->n_op == REG))
170 					l->n_left->n_type = p->n_type;
171 				goto rmpc;
172 			}
173 		}
174 
175 		/* Change PCONV from int to double pointer to right shift */
176 		if (ISPTR(p->n_type) && ISPTR(DECREF(p->n_type)) &&
177 		    (l->n_type == INT || l->n_type == UNSIGNED)) {
178 			p->n_op = RS;
179 			p->n_right = bcon(2);
180 			break;
181 		}
182 
183 		/* Check for cast integral -> pointer */
184 		if (BTYPE(l->n_type) == l->n_type)
185 			break;
186 
187 		/* Remove conversions to identical pointers */
188 		switch (xptype(p->n_type)) {
189 		case PTRNORMAL:
190 			if (xptype(l->n_type) == PTRNORMAL)
191 				goto rmpc;
192 			break;
193 
194 		case PTRSHORT:
195 			if (xptype(l->n_type) == PTRSHORT)
196 				goto rmpc;
197 			break;
198 
199 		case PTRCHAR:
200 			if (xptype(l->n_type) == PTRCHAR)
201 				goto rmpc;
202 			break;
203 		}
204 
205 		break;
206 
207 	case SCONV:
208 		l = p->n_left;
209 
210 		if ((p->n_type & TMASK) == 0 && (l->n_type & TMASK) == 0 &&
211 		    btdims[p->n_type].suesize == btdims[l->n_type].suesize) {
212 			if (p->n_type != FLOAT && p->n_type != DOUBLE &&
213 			     l->n_type != FLOAT && l->n_type != DOUBLE) {
214 				nfree(p);
215 				return l;
216 			}
217 		}
218 		/* cast to (void) XXX should be removed in MI code */
219 		if (p->n_type == VOID) {
220 			nfree(p);
221 			return l;
222 		}
223 		m = p->n_type;
224 		ml = l->n_type;
225 		if (m == ml) {
226 			nfree(p);
227 			return l;
228 		}
229 		o = l->n_op;
230 		if (ml == FLOAT || ml == DOUBLE) {
231 			if (o != FCON)
232 				break;
233 			ml = ISUNSIGNED(m) ? UNSIGNED : INT; /* LONG? */
234 			r = xbcon(ml == INT ? (int)p->n_left->n_dcon :
235 			                      (unsigned)p->n_left->n_dcon,
236 			          NULL, ml);
237 			nfree(p->n_left);
238 			p->n_left = r;
239 			o = ICON;
240 			if (m == ml) {
241 				r = p->n_left;
242 				nfree(p);
243 				return r;
244 			}
245 		}
246 		if (o == ICON) {
247 			CONSZ val = l->n_lval;
248 
249 			switch (m) {
250 			case CHAR:
251 				l->n_lval = val & 0777;
252 				if (val & 0400)
253 					l->n_lval |= ~((CONSZ)0777);
254 				break;
255 			case UCHAR:
256 				l->n_lval = val & 0777;
257 				break;
258 			case USHORT:
259 				l->n_lval = val & 0777777;
260 				break;
261 			case SHORT:
262 				l->n_lval = val & 0777777;
263 				if (val & 0400000)
264 					l->n_lval |= ~((CONSZ)0777777);
265 				break;
266 			case UNSIGNED:
267 				l->n_lval = val & 0777777777777LL;
268 				break;
269 			case INT:
270 				l->n_lval = val & 0777777777777LL;
271 				if (val & 0400000000000LL)
272 					l->n_lval |= ~(0777777777777LL);
273 				break;
274 			case LONGLONG:	/* XXX */
275 			case ULONGLONG:
276 				l->n_lval = val;
277 				break;
278 			case VOID:
279 				break;
280 			case DOUBLE:
281 			case FLOAT:
282 				l->n_op = FCON;
283 				l->n_dcon = 0;
284 				break;
285 			default:
286 				cerror("unknown type %d", m);
287 			}
288 			l->n_type = m;
289 			l->n_sue = 0;
290 			nfree(p);
291 			return l;
292 		}
293 		break;
294 
295 	case PMCONV:
296 	case PVCONV:
297 /*                if( p->n_right->n_op != ICON ) cerror( "bad conversion", 0); */
298                 nfree(p);
299                 return(buildtree(o==PMCONV?MUL:DIV, p->n_left, p->n_right));
300 
301 	case RS:
302 	case RSEQ:
303 		/* convert >> to << with negative shift count */
304 		/* Beware! constant shifts will be converted back in optim() */
305 
306 		if (p->n_right->n_op != UMINUS) {
307 			p->n_right = buildtree(UMINUS, p->n_right, NIL);
308 		} else {
309 			r = p->n_right;
310 			p->n_right = p->n_right->n_left;
311 			nfree(r);
312 		}
313 		if (p->n_op == RS)
314 			p->n_op = LS;
315 		else
316 			p->n_op = LSEQ;
317 		break;
318 
319 	case UMUL: /* Convert structure assignment to memcpy() */
320 		if (p->n_left->n_op == PLUS &&
321 		    p->n_left->n_left->n_op == PCONV &&
322 		    p->n_left->n_right->n_op == ICON &&
323 		    (p->n_type == CHAR || p->n_type == UCHAR ||
324 		    p->n_type == SHORT || p->n_type == USHORT)) {
325 			/* Can remove the left SCONV */
326 			l = p->n_left->n_left;
327 			p->n_left->n_left = l->n_left;
328 			nfree(l);
329 			break;
330 
331 		}
332 		if (p->n_left->n_op != STASG)
333 			break;
334 		oop = p;
335 		p = p->n_left;
336 		siz = p->n_sue->suesize/SZCHAR;
337 		l = p->n_left;
338 		r = p->n_right;
339 		if (l->n_type == STRTY || l->n_type == UNIONTY) {
340 			if (l->n_op == UMUL) {
341 				p->n_left = l->n_left;
342 				nfree(l);
343 				l = p->n_left;
344 			} else {
345 				l = block(ADDROF, l, NIL, INCREF(l->n_type),
346 				    0, 0);
347 			}
348 		}
349 		if ((l->n_type != (STRTY+PTR) && l->n_type != (UNIONTY+PTR)) ||
350 		    (r->n_type != (STRTY+PTR) && r->n_type != (UNIONTY+PTR)))
351 			cerror("bad stasg, l = %o, r = %o", l->n_type, r->n_type);
352 		q = newfun("__structcpy", p->n_type);
353 
354 		/* structure pointer block */
355 		l = block(CM, l, r, INT, 0, 0);
356 		/* Size block */
357 		r = block(CM, l, bcon(siz), INT, 0, 0);
358 
359 		l = xbcon(0, q, q->stype);
360 		p->n_left = l;
361 		p->n_right = r;
362 		p->n_op = CALL;
363 		oop->n_left = p;
364 		return oop;
365 
366 	case FORCE:
367 		p->n_op = ASSIGN;
368 		p->n_right = p->n_left;
369 		p->n_left = block(REG, NIL, NIL, p->n_type, 0, 0);
370 		p->n_left->n_rval = RETREG(p->n_type);
371 		break;
372 
373 	}
374 
375 	return(p);
376 }
377 
378 void
myp2tree(NODE * p)379 myp2tree(NODE *p)
380 {
381 	NODE *r;
382 
383 	switch (p->n_op) {
384 	case ULT: /* exor sign bit to avoid unsigned comparitions */
385 	case ULE:
386 	case UGT:
387 	case UGE:
388 		if (ISLONGLONG(p->n_left->n_type)) {
389 			/* XXX */
390 			r = xbcon(0x8000000000000000ULL, NULL, LONGLONG);
391 		} else
392 			r = xbcon(0400000000000LL, NULL, INT);
393 		p->n_left = buildtree(ER, p->n_left, r);
394 		if (ISUNSIGNED(p->n_left->n_type))
395 			p->n_left->n_type = DEUNSIGN(p->n_left->n_type);
396 
397 		if (ISLONGLONG(p->n_right->n_type)) {
398 			/* XXX */
399 			r = xbcon(0x8000000000000000ULL, NULL, LONGLONG);
400 		} else
401 			r = xbcon(0400000000000LL, NULL, INT);
402 		p->n_right = buildtree(ER, p->n_right, r);
403 		if (ISUNSIGNED(p->n_right->n_type))
404 			p->n_right->n_type = DEUNSIGN(p->n_right->n_type);
405 
406 		p->n_op -= (ULT-LT);
407 		break;
408 	case FCON:
409 		cerror("fix float constants");
410 	}
411 }
412 
413 
414 struct symtab *
newfun(char * name,TWORD type)415 newfun(char *name, TWORD type)
416 {
417 	struct symtab *sp;
418 
419 	sp = lookup(name, 0);
420 	if (sp->stype == VOID) {
421 		sp->stype = INCREF(type | FTN);
422 		sp->sclass = EXTERN;
423 		sp->soffset = 0;
424 	}
425 #ifdef notdef
426 	else if (!ISFTN(DECREF(sp->stype)))
427 		uerror("reserved name '%s' used illegally", name);
428 #endif
429 	return sp;
430 }
431 
432 /*ARGSUSED*/
433 int
andable(NODE * p)434 andable(NODE *p)
435 {
436 	return(1);  /* all names can have & taken on them */
437 }
438 
439 /*
440  * is an automatic variable of type t OK for a register variable
441  * Everything is trusted to be in register here.
442  */
443 int
cisreg(TWORD t)444 cisreg(TWORD t)
445 {
446 	return(1);
447 }
448 
449 int
xptype(TWORD t)450 xptype(TWORD t)
451 {
452 	int tt = BTYPE(t);
453 	int e, rv;
454 
455 	if (!ISPTR(t))
456 		cerror("not a pointer");
457 
458 	e = t & ~BTMASK;
459 	rv = e;
460 	while (e) {
461 		rv = e;
462 		if (DECREF(e) == 0)
463 			break;
464 		e = DECREF(e);
465 	}
466 	if (ISFTN(rv))
467 		return PTRNORMAL;
468 
469 	switch (tt) {
470 	case INT:
471 	case LONG:
472 	case LONGLONG:
473 	case FLOAT:
474 	case DOUBLE:
475 	case STRTY:
476 	case UNIONTY:
477 	case UNSIGNED:
478 	case ULONG:
479 	case ULONGLONG:
480 		return PTRNORMAL;
481 	case VOID:
482 	case CHAR:
483 	case UCHAR:
484 		if (DECREF(t) == tt || ISARY(rv))
485 			return PTRCHAR;
486 		return PTRNORMAL;
487 	case SHORT:
488 	case USHORT:
489 		if (DECREF(t) == tt || ISARY(rv))
490 			return PTRSHORT;
491 		return PTRNORMAL;
492 	default:
493 		break;
494 	}
495 	cerror("unknown type");
496 	return PTRNORMAL; /* XXX */
497 }
498 
499 /*
500  * Help routine to the one below; return true if it's not a word pointer.
501  */
502 static int
pointp(TWORD t)503 pointp(TWORD t)
504 {
505 	int rv = 0;
506 
507 	if (ISPTR(t) && ((t & TMASK1) == 0))
508 		return 1;
509 
510 	t &= ~BTMASK;
511 	while (t) {
512 		rv = ISARY(t);
513 		t = DECREF(t);
514 	}
515 	return rv;
516 }
517 
518 /*
519  * return a node, for structure references, which is suitable for
520  * being added to a pointer of type t, in order to be off bits offset
521  * into a structure
522  * t, d, and s are the type, dimension offset, and sizeoffset
523  * For pdp10, return the type-specific index number which calculation
524  * is based on its size. For example, short a[3] would return 3.
525  * Be careful about only handling first-level pointers, the following
526  * indirections must be fullword.
527  */
528 NODE *
offcon(OFFSZ off,TWORD t,union dimfun * d,struct suedef * sue)529 offcon(OFFSZ off, TWORD t, union dimfun *d, struct suedef *sue)
530 {
531 	register NODE *p;
532 
533 	if (xdebug)
534 		printf("offcon: OFFSZ %lld type %x dim %p siz %d\n",
535 		    off, t, d, sue->suesize);
536 
537 	p = bcon(0);
538 	p->n_lval = off/SZINT;	/* Default */
539 	if (ISPTR(DECREF(t)))
540 		return p;	/* Pointer/pointer reference */
541 	switch (BTMASK & t) {
542 	case INT:
543 	case UNSIGNED:
544 	case LONG:
545 	case ULONG:
546 	case STRTY:
547 	case UNIONTY:
548 	case LONGLONG:
549 	case ULONGLONG:
550 	case FLOAT:
551 	case DOUBLE:
552 		break;
553 
554 	case SHORT:
555 	case USHORT:
556 		if (pointp(t))
557 			p->n_lval = off/SZSHORT;
558 		break;
559 
560 	case VOID: /* void pointers */
561 	case CHAR:
562 	case UCHAR:
563 		if (pointp(t))
564 			p->n_lval = off/SZCHAR;
565 		break;
566 
567 	default:
568 		cerror("offcon, off %llo size %d type %x", off, sue->suesize, t);
569 	}
570 	if (xdebug)
571 		printf("offcon return 0%llo\n", p->n_lval);
572 	return(p);
573 }
574 
575 /*
576  * Allocate off bits on the stack.  p is a tree that when evaluated
577  * is the multiply count for off, t is a NAME node where to write
578  * the allocated address.
579  * Be aware that a pointer conversion may be needed when saving
580  * to node t!
581  */
582 void
spalloc(NODE * t,NODE * p,OFFSZ off)583 spalloc(NODE *t, NODE *p, OFFSZ off)
584 {
585 	NODE *sp;
586 
587 	if ((off % SZINT) == 0)
588 		p =  buildtree(MUL, p, bcon(off/SZINT));
589 	else if ((off % SZSHORT) == 0) {
590 		p = buildtree(MUL, p, bcon(off/SZSHORT));
591 		p = buildtree(PLUS, p, bcon(1));
592 		p = buildtree(RS, p, bcon(1));
593 	} else if ((off % SZCHAR) == 0) {
594 		p = buildtree(MUL, p, bcon(off/SZCHAR));
595 		p = buildtree(PLUS, p, bcon(3));
596 		p = buildtree(RS, p, bcon(2));
597 	} else
598 		cerror("roundsp");
599 
600 	/* save the address of sp */
601 	sp = block(REG, NIL, NIL, PTR+INT, t->n_df, t->n_sue);
602 	sp->n_lval = 0;
603 	sp->n_rval = STKREG;
604 	/* Cast sp to destination type (may be redundant) */
605 	sp = buildtree(CAST,
606 	    block(NAME, NIL, NIL, t->n_type, t->n_df, t->n_sue), sp);
607 	nfree(sp->n_left);
608 	nfree(sp);
609 	sp = sp->n_right;
610 	ecomp(buildtree(ASSIGN, t, sp)); /* Emit! */
611 
612 	/* add the size to sp */
613 	sp = block(REG, NIL, NIL, p->n_type, 0, 0);
614 	sp->n_lval = 0;
615 	sp->n_rval = STKREG;
616 	ecomp(buildtree(PLUSEQ, sp, p));
617 }
618 
619 #if 0
620 static int inwd;	/* current bit offsed in word */
621 static CONSZ word;	/* word being built from fields */
622 
623 /*
624  * Generate initialization code for assigning a constant c
625  * to a field of width sz
626  * we assume that the proper alignment has been obtained
627  * inoff is updated to have the proper final value
628  * we also assume sz  < SZINT
629  */
630 void
631 incode(NODE *p, int sz)
632 {
633 	char *s;
634 
635 	inoff += sz;
636 	if ((sz + inwd) > SZINT)
637 		cerror("incode: field > int");
638 
639 	word |= ((p->n_lval & ((1 << sz) - 1)) << (36 - inwd - sz));
640 
641 	inwd += sz;
642 	if (inoff % SZINT == 0) {
643 		s = isinlining ? permalloc(30) : tmpalloc(30);
644 		sprintf(s, "\t.long 0%llo\n", word);
645 		send_passt(IP_ASM, s);
646 		word = inwd = 0;
647 	}
648 	tfree(p);
649 }
650 
651 /* output code to initialize space of size sz to the value d */
652 /* the proper alignment has been obtained */
653 /* inoff is updated to have the proper final value */
654 /* on the target machine, write it out in octal! */
655 void
656 fincode(NODE *p, int sz)
657 {
658 	double d = p->n_dcon;
659 
660 	if(!nerrors)
661 		printf("	%s	0%c%.20e\n",
662 		    sz == SZDOUBLE ? ".double" : ".float",
663 		sz == SZDOUBLE ? 'd' : 'f', d);
664 	inoff += sz;
665 }
666 
667 void
668 cinit(NODE *p, int sz)
669 {
670 	NODE *l;
671 
672 	/*
673 	 * as a favor (?) to people who want to write
674 	 *     int i = 9600/134.5;
675 	 * we will, under the proper circumstances, do
676 	 * a coercion here.
677 	 */
678 	switch (p->n_type) {
679 	case INT:
680 	case UNSIGNED:
681 		l = p->n_left;
682 		if (l->n_op != SCONV || l->n_left->n_op != FCON)
683 			break;
684 		nfree(l);
685 		l = l->n_left;
686 		l->n_lval = (long)(l->n_dcon);
687 		l->n_sp = NULL;
688 		l->n_op = ICON;
689 		l->n_type = INT;
690 		p->n_left = l;
691 		break;
692 	}
693 	/* arrange for the initialization of p into a space of size sz */
694 	/* the proper alignment has been opbtained */
695 	/* inoff is updated to have the proper final value */
696 	ecode( p );
697 	inoff += sz;
698 }
699 
700 /*
701  * define n bits of zeros in a vfd
702  */
703 void
704 vfdzero(int n)
705 {
706 	char *s;
707 
708 	inoff += n;
709 	inwd += n;
710 	if (inoff%ALINT ==0) {
711 		s = isinlining ? permalloc(30) : tmpalloc(30);
712 		sprintf(s, "\t.long 0%llo\n", word);
713 		send_passt(IP_ASM, s);
714 		word = inwd = 0;
715 	}
716 }
717 #endif
718 
719 /* make a name look like an external name in the local machine */
720 char *
exname(char * p)721 exname(char *p)
722 {
723 	if (p == NULL)
724 		return "";
725 	return p;
726 }
727 
728 /*
729  * map types which are not defined on the local machine
730  */
731 TWORD
ctype(TWORD type)732 ctype(TWORD type)
733 {
734 	switch (BTYPE(type)) {
735 	case LONG:
736 		MODTYPE(type,INT);
737 		break;
738 	case ULONG:
739 		MODTYPE(type,UNSIGNED);
740 		break;
741 	case LDOUBLE:
742 		MODTYPE(type,DOUBLE);
743 		break;
744 	}
745 	return (type);
746 }
747 
748 /* curid is a variable which is defined but
749  * is not initialized (and not a function );
750  * This routine returns the stroage class for an uninitialized declaration
751  */
752 int
noinit()753 noinit()
754 {
755 	return(EXTERN);
756 }
757 
758 void
calldec(NODE * p,NODE * q)759 calldec(NODE *p, NODE *q)
760 {
761 }
762 
763 void
extdec(struct symtab * q)764 extdec(struct symtab *q)
765 {
766 }
767 
768 /* make a common declaration for id, if reasonable */
769 void
defzero(struct symtab * sp)770 defzero(struct symtab *sp)
771 {
772 	int off;
773 
774 	off = tsize(sp->stype, sp->sdf, sp->ssue);
775 	off = (off+(SZINT-1))/SZINT;
776 	printf("        .%scomm ", sp->sclass == STATIC ? "l" : "");
777 	if (sp->slevel == 0)
778 		printf("%s,0%o\n", exname(sp->soname), off);
779 	else
780 		printf(LABFMT ",0%o\n", sp->soffset, off);
781 }
782 
783 /*
784  * set fsz bits in sequence to zero.
785  */
786 void
zbits(OFFSZ off,int fsz)787 zbits(OFFSZ off, int fsz)
788 {
789 	cerror("zbits");
790 }
791 
792 /*
793  * Initialize a bitfield.
794  */
795 void
infld(CONSZ off,int fsz,CONSZ val)796 infld(CONSZ off, int fsz, CONSZ val)
797 {
798 //	if (idebug)
799 //		printf("infld off %lld, fsz %d, val %lld inbits %d\n",
800 //		    off, fsz, val, inbits);
801 	cerror("infld");
802 }
803 
804 /*
805  * print out a constant node, may be associated with a label.
806  * Do not free the node after use.
807  * off is bit offset from the beginning of the aggregate
808  * fsz is the number of bits this is referring to
809  */
810 int
ninval(CONSZ off,int fsz,NODE * p)811 ninval(CONSZ off, int fsz, NODE *p)
812 {
813 	cerror("ninval");
814 }
815 
816 
817 /*
818  * Give target the opportunity of handling pragmas.
819  */
820 int
mypragma(char * str)821 mypragma(char *str)
822 {
823 	return 0;
824 }
825 
826 /*
827  * Called when a identifier has been declared, to give target last word.
828  */
829 void
fixdef(struct symtab * sp)830 fixdef(struct symtab *sp)
831 {
832 }
833 
834 void
pass1_lastchance(struct interpass * ip)835 pass1_lastchance(struct interpass *ip)
836 {
837 }
838 
839