Debian Codegraph @

arch/i86/local2.c

raw symbols SCIP
1 /* $Id: local2.c,v 1.9 2018/11/13 17:47:32 ragge Exp $ */
2 /*
3 * Copyright (c) 2003 Anders Magnusson ([email protected]).
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 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 # include "pass2.h"
30 # include <ctype.h>
31 # include <string.h>
32
33 #define EXPREFIX "_"
34
35 static int stkpos;
36
37 static int suppress_type; /* Don't display a type on the
38 next expansion */
39
40 void
41 deflab(int label)
42 {
43 printf(LABFMT ":\n", label);
44 }
45
46 static int regoff[7];
47 static TWORD ftype;
48
49 /*
50 * Print out the prolog assembler.
51 * addto and regoff are already calculated.
52 */
53 static void
54 prtprolog(struct interpass_prolog *ipp, int addto)
55 {
56 int i;
57
58 #if 1
59 /* FIXME: can't use enter/leave if generating i8086 */
60 if (addto == 0 || addto > 65535 || 1) {
61 printf(" push bp\n\tmov bp,sp\n");
62 if (addto)
63 printf(" sub sp,#%d\n", addto);
64 } else
65 printf(" enter %d,0\n", addto);
66 #endif
67 for (i = 0; i < MAXREGS; i++)
68 if (TESTBIT(p2env.p_regs, i))
69 printf(" mov -%d[%s],%s\n",
70 regoff[i], rnames[FPREG], rnames[i]);
71 }
72
73 /*
74 * calculate stack size and offsets
75 */
76 static int
77 offcalc(struct interpass_prolog *ipp)
78 {
79 int i, addto;
80
81 addto = p2maxautooff;
82 if (addto >= AUTOINIT/SZCHAR)
83 addto -= AUTOINIT/SZCHAR;
84 for (i = 0; i < MAXREGS; i++)
85 if (TESTBIT(p2env.p_regs, i)) {
86 addto += SZINT/SZCHAR;
87 regoff[i] = addto;
88 }
89 return addto;
90 }
91
92 void
93 prologue(struct interpass_prolog *ipp)
94 {
95 int addto;
96
97 ftype = ipp->ipp_type;
98
99 #ifdef LANG_F77
100 if (ipp->ipp_vis)
101 printf(" .globl %s\n", ipp->ipp_name);
102 printf(" .align 4\n");
103 printf("%s:\n", ipp->ipp_name);
104 #endif
105 /*
106 * We here know what register to save and how much to
107 * add to the stack.
108 */
109 addto = offcalc(ipp);
110 prtprolog(ipp, addto);
111 }
112
113 void
114 eoftn(struct interpass_prolog *ipp)
115 {
116 int i;
117
118 if (ipp->ipp_ip.ip_lbl == 0)
119 return; /* no code needs to be generated */
120
121 /* return from function code */
122 for (i = 0; i < MAXREGS; i++)
123 if (TESTBIT(p2env.p_regs, i))
124 printf(" mov %s,-%d[%s]\n",
125 rnames[i],regoff[i], rnames[FPREG]);
126
127 /* struct return needs special treatment */
128 if (ftype == STRTY || ftype == UNIONTY) {
129 printf(" mov ax, 8[bp]\n");
130 printf(" leave\n");
131 /* FIXME: ret n is not in 8086 */
132 printf(" ret %d\n", 4 + ipp->ipp_argstacksize);
133 } else {
134 printf(" mov sp, bp\n");
135 printf(" pop bp\n");
136 if (ipp->ipp_argstacksize)
137 /* CHECK ME */
138 printf(" add sp, #%d\n", ipp->ipp_argstacksize);
139 printf(" ret\n");
140 }
141 }
142
143 /*
144 * add/sub/...
145 *
146 * Param given:
147 */
148 void
149 hopcode(int f, int o)
150 {
151 char *str;
152
153 switch (o) {
154 case PLUS:
155 str = "add";
156 break;
157 case MINUS:
158 str = "sub";
159 break;
160 case AND:
161 str = "and";
162 break;
163 case OR:
164 str = "or";
165 break;
166 case ER:
167 str = "xor";
168 break;
169 default:
170 comperr("hopcode2: %d", o);
171 str = 0; /* XXX gcc */
172 }
173 printf("%s", str); /* don't need %c f as far as I can see */
174 }
175
176 /*
177 * Return type size in bytes. Used by R2REGS, arg 2 to offset().
178 */
179 int
180 tlen(NODE *p)
181 {
182 switch(p->n_type) {
183 case CHAR:
184 case UCHAR:
185 return(1);
186
187 case SHORT:
188 case USHORT:
189 case INT:
190 case UNSIGNED:
191 return(SZINT/SZCHAR);
192
193 case DOUBLE:
194 return(SZDOUBLE/SZCHAR);
195
196 case LONG:
197 case ULONG:
198 return(SZLONG/SZCHAR);
199
200 case LONGLONG:
201 case ULONGLONG:
202 return SZLONGLONG/SZCHAR;
203
204 default:
205 if (!ISPTR(p->n_type))
206 comperr("tlen type %d not pointer");
207 return SZPOINT(p->n_type)/SZCHAR;
208 }
209 }
210
211 /*
212 * Emit code to compare two long numbers.
213 */
214 static void
215 twollcomp(NODE *p)
216 {
217 int u;
218 int s = getlab2();
219 int e = p->n_label;
220 int cb1, cb2;
221
222 u = p->n_op;
223 switch (p->n_op) {
224 case NE:
225 cb1 = 0;
226 cb2 = NE;
227 break;
228 case EQ:
229 cb1 = NE;
230 cb2 = 0;
231 break;
232 case LE:
233 case LT:
234 u += (ULE-LE);
235 /* FALLTHROUGH */
236 case ULE:
237 case ULT:
238 cb1 = GT;
239 cb2 = LT;
240 break;
241 case GE:
242 case GT:
243 u += (ULE-LE);
244 /* FALLTHROUGH */
245 case UGE:
246 case UGT:
247 cb1 = LT;
248 cb2 = GT;
249 break;
250
251 default:
252 cb1 = cb2 = 0; /* XXX gcc */
253 }
254 if (p->n_op >= ULE)
255 cb1 += 4, cb2 += 4;
256 expand(p, 0, " cmp UL,UR\n");
257 if (cb1) cbgen(cb1, s);
258 if (cb2) cbgen(cb2, e);
259 expand(p, 0, " cmp AL,AR\n");
260 cbgen(u, e);
261 deflab(s);
262 }
263
264 int
265 fldexpand(NODE *p, int cookie, char **cp)
266 {
267 comperr("fldexpand");
268 return 0;
269 }
270
271 /*
272 * Push a structure on stack as argument.
273 * the scratch registers are already free here
274 */
275 static void
276 starg(NODE *p)
277 {
278 NODE *q = p->n_left;
279 int s = (attr_find(p->n_ap, ATTR_P2STRUCT)->iarg(0) + 1) & ~1;
280
281 if (s == 2)
282 printf(" dec sp\n dec sp\n");
283 else
284 printf(" sub sp,#%d\n", s);
285 p->n_left = mklnode(OREG, 0, SP, INT);
286 zzzcode(p, 'Q');
287 tfree(p->n_left);
288 p->n_left = q;
289 }
290
291 /*
292 * Compare two floating point numbers.
293 */
294 static void
295 fcomp(NODE *p)
296 {
297 static char *fpcb[] = { "jz", "jnz", "jbe", "jc", "jnc", "ja" };
298
299 if ((p->n_su & DORIGHT) == 0)
300 expand(p, 0, "\tfxch\n");
301 expand(p, 0, "\tfucomip %st(1),%st\n"); /* emit compare insn */
302 expand(p, 0, "\tfstp %st(0)\n"); /* pop fromstack */
303
304 if (p->n_op == NE || p->n_op == GT || p->n_op == GE)
305 expand(p, 0, "\tjp LC\n");
306 else if (p->n_op == EQ)
307 printf("\tjp 1f\n");
308 printf(" %s ", fpcb[p->n_op - EQ]);
309 expand(p, 0, "LC\n");
310 if (p->n_op == EQ)
311 printf("1:\n");
312 }
313
314 /*
315 * Convert an unsigned long long to floating point number.
316 */
317 static void
318 ulltofp(NODE *p)
319 {
320 int jmplab;
321
322 jmplab = getlab2();
323 expand(p, 0, " push UL\n push AL\n");
324 expand(p, 0, " fildq [sp]\n");
325 expand(p, 0, " add sp, #8\n");
326 expand(p, 0, " cmp UL, #0\n");
327 printf(" jge " LABFMT "\n", jmplab);
328
329 printf(" faddp %%st,%%st(1)\n");
330 printf(LABFMT ":\n", jmplab);
331 }
332
333 static int
334 argsiz(NODE *p)
335 {
336 TWORD t = p->n_type;
337 if (t < LONG)
338 return 2;
339 if (t == LONG || t == ULONG || t == LONGLONG || t == ULONGLONG)
340 return 4;
341 if (t == FLOAT)
342 return 4;
343 if (t > BTMASK)
344 return 2;
345 if (t == DOUBLE)
346 return 8;
347 if (t == LDOUBLE)
348 return 12;
349 if (t == STRTY || t == UNIONTY)
350 return (attr_find(p->n_ap, ATTR_P2STRUCT)->iarg(0)+1) & ~1;
351 comperr("argsiz");
352 return 0;
353 }
354
355 static void
356 fcast(NODE *p)
357 {
358 TWORD t = p->n_type;
359 int sz, c;
360
361 if (t >= p->n_left->n_type)
362 return; /* cast to more precision */
363 if (t == FLOAT)
364 sz = 4, c = 's';
365 else
366 sz = 8, c = 'l';
367
368 printf(" sub sp, #%d\n", sz);
369 printf(" fstp%c (%%sp)\n", c);
370 printf(" fld%c (%%sp)\n", c);
371 printf(" add sp, #%d\n", sz);
372 }
373
374
375 #if 0
376
377 static void
378 llshft(NODE *p)
379 {
380 NODE *r = p->n_right;
381 /* FIXME: we have sal/shl/sar/shr but we are limited to
382 shift right or left 1
383 shift right or left by CL */
384 char *d[3];
385 /* We ought to shortcut this earlier but it's not obivous how
386 to do a match and say 'any old register pair' FIXME */
387 if (r->n_op == ICON) {
388 /* FIXME: we need different versions of this for signed right
389 shifting. Just test code - register setup needs checking
390 for ordering etc yet */
391 if (getrval(r) == 16) {
392 if (p->n_op == RS)
393 printf("\tmov ax, dx\n\txor dx,dx\n");
394 else
395 printf("\tmov dx, ax\n\txor ax,ax\n");
396 return;
397 }
398 if (getrval(r) == 8) {
399 if (p->n_op == RS)
400 printf("\tmov al, ah\n\tmov ah, dl\n\tmov dl, dh\n\txor dh,dh\n");
401 else
402 printf("\tmov ah, al\n\tmov dl, ah\n\tmov dh, dl\n\txor al, al\n");
403 return;
404 }
405 if (getrval(r) == 24) {
406 if (p->n_op == RS)
407 printf("\txor dx,dx\n\tmov al, dh\n\txor ax,ax\n");
408 else
409 printf("\txor ax,ax\n\tmov dh, al\n\txor dx,dx\n");
410 return;
411 }
412 }
413 if (p->n_op == LS) {
414 d[0] = "l", d[1] = "ax", d[2] = "dx";
415 } else
416 d[0] = "r", d[1] = "dx", d[2] = "ax";
417
418 printf("\tsh%sdl %s,%s\n",d[0], d[1], d[2]);
419 printf("\ts%s%sl %%cl,%s\n", p->n_op == RS &&
420 (p->n_left->n_type == ULONG || p->n_left->n_type == ULONGLONG) ?
421 "h" : "a", d[0], d[1]);
422 printf("\ttestb $16,%%cl\n");
423 printf("\tje 1f\n");
424 printf("\tmov %s,%s\n", d[1], d[2]);
425 if (p->n_op == RS && (p->n_left->n_type == LONGLONG|| p->n_left->n_type == LONG))
426 printf("\tsarl $31,%%edx\n");
427 else
428 printf("\txor %s,%s\n",d[1],d[1]);
429 printf("1:\n");
430 }
431 #endif
432
433 void
434 zzzcode(NODE *p, int c)
435 {
436 struct attr *ap;
437 NODE *l;
438 int pr, lr;
439 char *ch;
440 char sv;
441
442 switch (c) {
443 case 'A': /* swap st0 and st1 if right is evaluated second */
444 if ((p->n_su & DORIGHT) == 0) {
445 if (logop(p->n_op))
446 printf(" fxch\n");
447 else
448 printf("r");
449 }
450 break;
451
452 case 'C': /* remove from stack after subroutine call */
453 #ifdef notdef
454 if (p->n_left->n_flags & FSTDCALL)
455 break;
456 #endif
457 pr = p->n_qual;
458 if (attr_find(p->n_ap, ATTR_I86_FPPOP))
459 printf(" fstp st(0)\n");
460 if (p->n_op == UCALL)
461 return; /* XXX remove ZC from UCALL */
462 if (pr) {
463 if (pr == 2)
464 printf(" inc sp\n inc sp\n");
465 else
466 printf(" add sp,#%d\n", pr);
467 }
468 break;
469
470 case 'D': /* Long comparision */
471 twollcomp(p);
472 break;
473
474 case 'F': /* Structure argument */
475 starg(p);
476 break;
477
478 case 'G': /* Floating point compare */
479 fcomp(p);
480 break;
481
482 case 'H': /* assign of long between regs */
483 rmove(DECRA(p->n_right->n_reg, 0),
484 DECRA(p->n_left->n_reg, 0), LONGLONG);
485 break;
486
487 case 'I': /* float casts */
488 fcast(p);
489 break;
490
491 case 'J': /* convert unsigned long long to floating point */
492 ulltofp(p);
493 break;
494
495 case 'K': /* Load long reg into another reg */
496 rmove(regno(p), DECRA(p->n_reg, 0), LONGLONG);
497 break;
498
499 case 'M': /* Output sconv move, if needed */
500 l = getlr(p, 'L');
501 /* XXX fixneed: regnum */
502 pr = DECRA(p->n_reg, 0);
503 lr = DECRA(l->n_reg, 0);
504 if ((pr == AL && lr == AX) || (pr == BL && lr == BX) ||
505 (pr == CL && lr == CX) || (pr == DL && lr == DX))
506 ;
507 else
508 printf(" mov %s, %cL\n",
509 rnames[pr], rnames[lr][1]);
510 l->n_rval = l->n_reg = p->n_reg; /* XXX - not pretty */
511 break;
512
513 case 'N': /* output extended reg name */
514 printf("%s", rnames[getlr(p, '1')->n_rval]);
515 break;
516
517 case 'O': /* print out emulated ops */
518 pr = 8;
519 sv = 'l';
520 #if 0
521 if (p->n_op == RS || p->n_op == LS) {
522 llshft(p);
523 break;
524 }
525 #endif
526 if (p->n_op != RS && p->n_op != LS) {
527 /* For 64bit we will need to push pointers
528 not u64 */
529 expand(p, INCREG, "\tpush UR\n\tpush AR\n");
530 expand(p, INCREG, "\tpush UL\n\tpush AL\n");
531 } else {
532 /* AR is a BREG so this goes wrong.. need an AREG
533 but putting an AREG in the table rule makes the
534 compiler shit itself - FIXME */
535 expand(p, INAREG, "\tpush AR\n");
536 expand(p, INCREG, "\tpush UL\n\tpush AL\n");
537 pr = 6;
538 }
539
540 if (p->n_type == LONGLONG || p->n_type == ULONGLONG)
541 sv = 'L';
542 if (p->n_op == DIV && (p->n_type == ULONG || p->n_type == ULONGLONG))
543 ch = "udiv";
544 else if (p->n_op == MUL && (p->n_type == ULONG || p->n_type == ULONGLONG))
545 ch = "umul";
546 else if (p->n_op == DIV) ch = "div";
547 else if (p->n_op == MUL) ch = "mul";
548 else if (p->n_op == MOD && (p->n_type == ULONG || p->n_type == ULONGLONG))
549 ch = "umod";
550 else if (p->n_op == MOD) ch = "mod";
551 else if (p->n_op == LS) ch = "ls";
552 else if (p->n_op == RS && (p->n_type == ULONG || p->n_type == ULONGLONG))
553 ch = "rs";
554 else if (p->n_op == RS) ch = "urs";
555 else ch = 0, comperr("ZO");
556 printf("\tcall " EXPREFIX "__%c%sdi3\n\tadd %s,#%d\n",
557 sv, ch, rnames[SP], pr);
558 break;
559
560 case 'P': /* typeless right hand */
561 suppress_type = 1;
562 break;
563
564 case 'Q': /* emit struct assign */
565 /*
566 * Put out some combination of movs{b,w}
567 * si/di/cx are available.
568 * FIXME: review es: and direction flag implications
569 */
570 expand(p, INAREG, " lea al,di\n");
571 ap = attr_find(p->n_ap, ATTR_P2STRUCT);
572 if (ap->iarg(0) < 32) {
573 int i = ap->iarg(0) >> 1;
574 while (i) {
575 expand(p, INAREG, " movsw\n");
576 i--;
577 }
578 } else {
579 printf("\tmov cx, #%d\n", ap->iarg(0) >> 1);
580 printf(" rep movsw\n");
581 }
582 if (ap->iarg(0) & 2)
583 printf(" movsw\n");
584 if (ap->iarg(0) & 1)
585 printf(" movsb\n");
586 break;
587
588 case 'S': /* emit eventual move after cast from long */
589 pr = DECRA(p->n_reg, 0);
590 lr = p->n_left->n_rval;
591 switch (p->n_type) {
592 case CHAR:
593 case UCHAR:
594 if (rnames[pr][1] == 'L' && rnames[lr][1] == 'X' &&
595 rnames[pr][0] == rnames[lr][0])
596 break;
597 if (rnames[lr][1] == 'X') {
598 printf("\tmov %s, %cL\n",
599 rnames[pr], rnames[lr][0]);
600 break;
601 }
602 /* Must go via stack */
603 expand(p, INAREG, "\tmov A2,AL\n");
604 expand(p, INBREG, "\tmov A1,A2\n");
605 #ifdef notdef
606 /* cannot use freetemp() in instruction emission */
607 s = freetemp(1);
608 printf("\tmov %ci,%d(bp)\n", rnames[lr][0], s);
609 printf("\tmov %s, %d(bp)\n", rnames[pr], s);
610 #endif
611 break;
612
613 case INT:
614 case UNSIGNED:
615 if (rnames[lr][0] == rnames[pr][1] &&
616 rnames[lr][1] == rnames[pr][2])
617 break;
618 printf("\tmov %s, %c%c\n",
619 rnames[pr], rnames[lr][0], rnames[lr][1]);
620 break;
621
622 default:
623 if (rnames[lr][0] == rnames[pr][1] &&
624 rnames[lr][1] == rnames[pr][2])
625 break;
626 comperr("SCONV2 %s->%s", rnames[lr], rnames[pr]);
627 break;
628 }
629 break;
630 case 'T':
631 /* Conversions from unsigned char to int/ptr */
632 /* Cannot be in DI or SI */
633 l = getlr(p, 'L');
634 lr = regno(l);
635 pr = regno(getlr(p, '1'));
636 if (l->n_op != REG) { /* NAME or OREG */
637 /* Need to force a mov into the low half, using
638 a movw might fail in protected mode or with
639 mmio spaces */
640 printf(" mov %cl, ", rnames[pr][0]);
641 expand(p, INAREG, "AL\n");
642 } else {
643 if ((lr == AL && pr == AX) ||
644 (lr == BL && pr == BX) ||
645 (lr == CL && pr == CX) ||
646 (lr == DL && pr == DX))
647 ;
648 else
649 printf(" mov %cl,%cl\n",
650 rnames[pr][0],rnames[lr][0]);
651 }
652 printf(" xor %ch,%ch\n",
653 rnames[pr][0], rnames[pr][0]);
654 break;
655 break;
656 default:
657 comperr("zzzcode %c", c);
658 }
659 }
660
661 int canaddr(NODE *);
662 int
663 canaddr(NODE *p)
664 {
665 int o = p->n_op;
666
667 if (o==NAME || o==REG || o==ICON || o==OREG ||
668 (o==UMUL && shumul(p->n_left, SOREG)))
669 return(1);
670 return(0);
671 }
672
673 /*
674 * Does the bitfield shape match?
675 */
676 int
677 flshape(NODE *p)
678 {
679 comperr("flshape");
680 return 0;
681 }
682
683 /* INTEMP shapes must not contain any temporary registers */
684 /* XXX should this go away now? */
685 int
686 shtemp(NODE *p)
687 {
688 return 0;
689 #if 0
690 int r;
691
692 if (p->n_op == STARG )
693 p = p->n_left;
694
695 switch (p->n_op) {
696 case REG:
697 return (!istreg(p->n_rval));
698
699 case OREG:
700 r = p->n_rval;
701 if (R2TEST(r)) {
702 if (istreg(R2UPK1(r)))
703 return(0);
704 r = R2UPK2(r);
705 }
706 return (!istreg(r));
707
708 case UMUL:
709 p = p->n_left;
710 return (p->n_op != UMUL && shtemp(p));
711 }
712
713 if (optype(p->n_op) != LTYPE)
714 return(0);
715 return(1);
716 #endif
717 }
718
719 void
720 adrcon(CONSZ val)
721 {
722 printf("$" CONFMT, val);
723 }
724
725 void
726 conput(FILE *fp, NODE *p)
727 {
728 int val = getlval(p);
729
730 switch (p->n_op) {
731 case ICON:
732 if (p->n_name[0] != '\0') {
733 fprintf(fp, "#%s", p->n_name);
734 if (val)
735 fprintf(fp, "+%d", val);
736 } else
737 fprintf(fp, "#%d", val);
738 return;
739
740 default:
741 comperr("illegal conput, p %p", p);
742 }
743 }
744
745 /*ARGSUSED*/
746 void
747 insput(NODE *p)
748 {
749 comperr("insput");
750 }
751
752 /*
753 * Write out the upper address, like the upper register of a 2-register
754 * reference, or the next memory location.
755 */
756 void
757 upput(NODE *p, int size)
758 {
759
760 size /= SZCHAR;
761 switch (p->n_op) {
762 case REG:
763 printf("%s", &rnames[p->n_rval][2]);
764 break;
765
766 case NAME:
767 case OREG:
768 setlval(p, getlval(p) + size);
769 adrput(stdout, p);
770 setlval(p, getlval(p) - size);
771 break;
772 case ICON:
773 printf("#"CONFMT, getlval(p) >> 16);
774 break;
775 default:
776 comperr("upput bad op %d size %d", p->n_op, size);
777 }
778 }
779
780 static void do_adrput(FILE *io, NODE *p, int ut)
781 {
782 int r;
783 /* output an address, with offsets, from p */
784
785 switch (p->n_op) {
786
787 case NAME:
788 if (!ut) {
789 switch (p->n_type) {
790 case SHORT:
791 case USHORT:
792 case INT:
793 case UNSIGNED:
794 printf("word ptr ");
795 break;
796 case CHAR:
797 case UCHAR:
798 printf("byte ptr ");
799 }
800 }
801 if (p->n_name[0] != '\0') {
802 fputs(p->n_name, io);
803 if (getlval(p) != 0)
804 fprintf(io, "+" CONFMT, getlval(p));
805 } else
806 fprintf(io, "#"CONFMT, getlval(p));
807 return;
808
809 case OREG:
810 r = p->n_rval;
811 if (p->n_name[0])
812 printf("%s%s", p->n_name, getlval(p) ? "+" : "");
813 if (getlval(p))
814 fprintf(io, "%d", (int)getlval(p));
815 printf("[");
816 if (R2TEST(r)) {
817 fprintf(io, "%s,%s,4", rnames[R2UPK1(r)],
818 rnames[R2UPK2(r)]);
819 } else
820 fprintf(io, "%s", rnames[p->n_rval]);
821 printf("]");
822 return;
823 case ICON:
824 /* addressable value of the constant */
825 if (!ut) {
826 switch (p->n_type) {
827 case SHORT:
828 case USHORT:
829 case INT:
830 case UNSIGNED:
831 printf("word ");
832 break;
833 case CHAR:
834 case UCHAR:
835 printf("byte ");
836 }
837 }
838 conput(io, p);
839 return;
840
841 case REG:
842 switch (p->n_type) {
843 case LONGLONG:
844 case ULONGLONG:
845 case LONG:
846 case ULONG:
847 fprintf(io, "%c%c", rnames[p->n_rval][0],
848 rnames[p->n_rval][1]);
849 break;
850 default:
851 fprintf(io, "%s", rnames[p->n_rval]);
852 }
853 return;
854
855 default:
856 comperr("illegal address, op %d, node %p", p->n_op, p);
857 return;
858
859 }
860 }
861
862 void adrput(FILE *io, NODE *p)
863 {
864 do_adrput(io, p, suppress_type);
865 suppress_type = 0;
866 }
867
868 static char *
869 ccbranches[] = {
870 "je", /* jumpe */
871 "jne", /* jumpn */
872 "jle", /* jumple */
873 "jl", /* jumpl */
874 "jge", /* jumpge */
875 "jg", /* jumpg */
876 "jbe", /* jumple (jlequ) */
877 "jb", /* jumpl (jlssu) */
878 "jae", /* jumpge (jgequ) */
879 "ja", /* jumpg (jgtru) */
880 };
881
882
883 /* printf conditional and unconditional branches */
884 void
885 cbgen(int o, int lab)
886 {
887 if (o < EQ || o > UGT)
888 comperr("bad conditional branch: %s", opst[o]);
889 printf(" %s " LABFMT "\n", ccbranches[o-EQ], lab);
890 }
891
892 static void
893 fixcalls(NODE *p, void *arg)
894 {
895 /* Prepare for struct return by allocating bounce space on stack */
896 switch (p->n_op) {
897 case STCALL:
898 case USTCALL:
899 if (attr_find(p->n_ap, ATTR_P2STRUCT)->iarg(0)+p2autooff > stkpos)
900 stkpos = attr_find(p->n_ap, ATTR_P2STRUCT)->iarg(0)+p2autooff;
901 break;
902 case LS:
903 case RS:
904 if (p->n_type != LONGLONG && p->n_type != ULONGLONG
905 && p->n_type != LONG && p->n_type != ULONG)
906 break;
907 if (p->n_right->n_op == ICON) /* constants must be char */
908 p->n_right->n_type = CHAR;
909 break;
910 }
911 }
912
913 /*
914 * Must store floats in memory if there are two function calls involved.
915 */
916 static int
917 storefloat(struct interpass *ip, NODE *p)
918 {
919 int l, r;
920
921 switch (optype(p->n_op)) {
922 case BITYPE:
923 l = storefloat(ip, p->n_left);
924 r = storefloat(ip, p->n_right);
925 if (p->n_op == CM)
926 return 0; /* arguments, don't care */
927 if (callop(p->n_op))
928 return 1; /* found one */
929 #define ISF(p) ((p)->n_type == FLOAT || (p)->n_type == DOUBLE || \
930 (p)->n_type == LDOUBLE)
931 if (ISF(p->n_left) && ISF(p->n_right) && l && r) {
932 /* must store one. store left */
933 struct interpass *nip;
934 TWORD t = p->n_left->n_type;
935 NODE *ll;
936 int off;
937
938 off = freetemp(szty(t));
939 ll = mklnode(OREG, off, FPREG, t);
940 nip = ipnode(mkbinode(ASSIGN, ll, p->n_left, t));
941 p->n_left = mklnode(OREG, off, FPREG, t);
942 DLIST_INSERT_BEFORE(ip, nip, qelem);
943 }
944 return l|r;
945
946 case UTYPE:
947 l = storefloat(ip, p->n_left);
948 if (callop(p->n_op))
949 l = 1;
950 return l;
951 default:
952 return 0;
953 }
954 }
955
956 static void
957 outfargs(struct interpass *ip, NODE **ary, int num, int *cwp, int c)
958 {
959 struct interpass *ip2;
960 NODE *q, *r;
961 int i;
962
963 for (i = 0; i < num; i++)
964 if (XASMVAL(cwp[i]) == c && (cwp[i] & (XASMASG|XASMINOUT)))
965 break;
966 if (i == num)
967 return;
968 q = ary[i]->n_left;
969 r = mklnode(REG, 0, c == 'u' ? 040 : 037, q->n_type);
970 ary[i]->n_left = tcopy(r);
971 ip2 = ipnode(mkbinode(ASSIGN, q, r, q->n_type));
972 DLIST_INSERT_AFTER(ip, ip2, qelem);
973 }
974
975 static void
976 infargs(struct interpass *ip, NODE **ary, int num, int *cwp, int c)
977 {
978 struct interpass *ip2;
979 NODE *q, *r;
980 int i;
981
982 for (i = 0; i < num; i++)
983 if (XASMVAL(cwp[i]) == c && (cwp[i] & XASMASG) == 0)
984 break;
985 if (i == num)
986 return;
987 q = ary[i]->n_left;
988 q = (cwp[i] & XASMINOUT) ? tcopy(q) : q;
989 r = mklnode(REG, 0, c == 'u' ? 040 : 037, q->n_type);
990 if ((cwp[i] & XASMINOUT) == 0)
991 ary[i]->n_left = tcopy(r);
992 ip2 = ipnode(mkbinode(ASSIGN, r, q, q->n_type));
993 DLIST_INSERT_BEFORE(ip, ip2, qelem);
994 }
995
996 /*
997 * Extract float args to XASM and ensure that they are put on the stack
998 * in correct order.
999 * This should be done sow other way.
1000 */
1001 static void
1002 fixxfloat(struct interpass *ip, NODE *p)
1003 {
1004 NODE *w, **ary;
1005 int nn, i, c, *cwp;
1006
1007 nn = 1;
1008 w = p->n_left;
1009 if (w->n_op == ICON && w->n_type == STRTY)
1010 return;
1011 /* index all xasm args first */
1012 for (; w->n_op == CM; w = w->n_left)
1013 nn++;
1014 ary = tmpcalloc(nn * sizeof(NODE *));
1015 cwp = tmpcalloc(nn * sizeof(int));
1016 for (i = 0, w = p->n_left; w->n_op == CM; w = w->n_left) {
1017 ary[i] = w->n_right;
1018 cwp[i] = xasmcode(ary[i]->n_name);
1019 i++;
1020 }
1021 ary[i] = w;
1022 cwp[i] = xasmcode(ary[i]->n_name);
1023 for (i = 0; i < nn; i++)
1024 if (XASMVAL(cwp[i]) == 't' || XASMVAL(cwp[i]) == 'u')
1025 break;
1026 if (i == nn)
1027 return;
1028
1029 for (i = 0; i < nn; i++) {
1030 c = XASMVAL(cwp[i]);
1031 if (c >= '0' && c <= '9')
1032 cwp[i] = (cwp[i] & ~0377) | XASMVAL(cwp[c-'0']);
1033 }
1034 infargs(ip, ary, nn, cwp, 'u');
1035 infargs(ip, ary, nn, cwp, 't');
1036 outfargs(ip, ary, nn, cwp, 't');
1037 outfargs(ip, ary, nn, cwp, 'u');
1038 }
1039
1040 static NODE *
1041 lptr(NODE *p)
1042 {
1043 if (p->n_op == ASSIGN && p->n_right->n_op == REG &&
1044 regno(p->n_right) == BP)
1045 return p->n_right;
1046 if (p->n_op == FUNARG && p->n_left->n_op == REG &&
1047 regno(p->n_left) == BP)
1048 return p->n_left;
1049 return NIL;
1050 }
1051
1052 /*
1053 * Find arg reg that should be struct reference instead.
1054 */
1055 static void
1056 updatereg(NODE *p, void *arg)
1057 {
1058 NODE *q;
1059
1060 if (p->n_op != STCALL)
1061 return;
1062 if (p->n_right->n_op != CM)
1063 p = p->n_right;
1064 else for (p = p->n_right;
1065 p->n_op == CM && p->n_left->n_op == CM; p = p->n_left)
1066 ;
1067 if (p->n_op == CM) {
1068 if ((q = lptr(p->n_left)))
1069 ;
1070 else
1071 q = lptr(p->n_right);
1072 } else
1073 q = lptr(p);
1074 if (q == NIL)
1075 comperr("bad STCALL hidden reg");
1076
1077 /* q is now the hidden arg */
1078 q->n_op = MINUS;
1079 q->n_type = INCREF(CHAR);
1080 q->n_left = mklnode(REG, 0, BP, INCREF(CHAR));
1081 q->n_right = mklnode(ICON, stkpos, 0, INT);
1082 }
1083
1084 void
1085 myreader(struct interpass *ipole)
1086 {
1087 struct interpass *ip;
1088
1089 stkpos = p2autooff;
1090 DLIST_FOREACH(ip, ipole, qelem) {
1091 if (ip->type != IP_NODE)
1092 continue;
1093 walkf(ip->ip_node, fixcalls, 0);
1094 storefloat(ip, ip->ip_node);
1095 if (ip->ip_node->n_op == XASM)
1096 fixxfloat(ip, ip->ip_node);
1097 }
1098 if (stkpos != p2autooff) {
1099 DLIST_FOREACH(ip, ipole, qelem) {
1100 if (ip->type != IP_NODE)
1101 continue;
1102 walkf(ip->ip_node, updatereg, 0);
1103 }
1104 }
1105 if (stkpos > p2autooff)
1106 p2autooff = stkpos;
1107 if (stkpos > p2maxautooff)
1108 p2maxautooff = stkpos;
1109 if (x2debug)
1110 printip(ipole);
1111 }
1112
1113 /*
1114 * Remove some PCONVs after OREGs are created.
1115 */
1116 static void
1117 pconv2(NODE *p, void *arg)
1118 {
1119 NODE *q;
1120 if (p->n_op == PLUS) {
1121 if (p->n_type == (PTR|SHORT) || p->n_type == (PTR|USHORT)) {
1122 if (p->n_right->n_op != ICON)
1123 return;
1124 if (p->n_left->n_op != PCONV)
1125 return;
1126 if (p->n_left->n_left->n_op != OREG)
1127 return;
1128 q = p->n_left->n_left;
1129 nfree(p->n_left);
1130 p->n_left = q;
1131 /*
1132 * This will be converted to another OREG later.
1133 */
1134 }
1135 }
1136 }
1137
1138 void
1139 mycanon(NODE *p)
1140 {
1141 walkf(p, pconv2, 0);
1142 }
1143
1144 void
1145 myoptim(struct interpass *ip)
1146 {
1147 }
1148
1149 static char rl[] =
1150 { AX, AX, AX, AX, AX, DX, DX, DX, DX, CX, CX, CX, BX, BX, SI };
1151 static char rh[] =
1152 { DX, CX, BX, SI, DI, CX, BX, SI, DI, BX, SI, DI, SI, DI, DI };
1153
1154 void
1155 rmove(int s, int d, TWORD t)
1156 {
1157 int sl, sh, dl, dh;
1158
1159 switch (t) {
1160 case LONGLONG:
1161 case ULONGLONG:
1162 case LONG:
1163 case ULONG: /* ?? FIXME check */
1164 #if 1
1165 sl = rl[s-AXDX];
1166 sh = rh[s-AXDX];
1167 dl = rl[d-AXDX];
1168 dh = rh[d-AXDX];
1169
1170 /* sanity checks, remove when satisfied */
1171 if (memcmp(rnames[s], rnames[sl], 2) != 0 ||
1172 memcmp(rnames[s]+2, rnames[sh], 2) != 0)
1173 comperr("rmove source error");
1174 if (memcmp(rnames[d], rnames[dl], 2) != 0 ||
1175 memcmp(rnames[d]+2, rnames[dh], 2) != 0)
1176 comperr("rmove dest error");
1177 #define SW(x,y) { int i = x; x = y; y = i; }
1178 if (sh == dl) {
1179 /* Swap if overwriting */
1180 SW(sl, sh);
1181 SW(dl, dh);
1182 }
1183 if (sl != dl)
1184 printf(" mov %s,%s\n", rnames[dl], rnames[sl]);
1185 if (sh != dh)
1186 printf(" mov %s,%s\n", rnames[dh], rnames[sh]);
1187 #else
1188 if (memcmp(rnames[s], rnames[d], 2) != 0)
1189 printf(" mov %c%c,%c%c\n",
1190 rnames[d][0],rnames[d][1],
1191 rnames[s][0],rnames[s][1]);
1192 if (memcmp(&rnames[s][2], &rnames[d][2], 2) != 0)
1193 printf(" mov %c%c,%c%c\n",
1194 rnames[d][2],rnames[d][3]
1195 rnames[s][2],rnames[s][3]);
1196 #endif
1197 break;
1198 case CHAR:
1199 case UCHAR:
1200 printf(" mov %s,%s\n", rnames[d], rnames[s]);
1201 break;
1202 case FLOAT:
1203 case DOUBLE:
1204 case LDOUBLE:
1205 #ifdef notdef
1206 /* a=b()*c(); will generate this */
1207 comperr("bad float rmove: %d %d", s, d);
1208 #endif
1209 break;
1210 default:
1211 printf(" mov %s,%s\n", rnames[d], rnames[s]);
1212 }
1213 }
1214
1215 /*
1216 * For class c, find worst-case displacement of the number of
1217 * registers in the array r[] indexed by class.
1218 */
1219 int
1220 COLORMAP(int c, int *r)
1221 {
1222 int num;
1223
1224 switch (c) {
1225 case CLASSA:
1226 num = r[CLASSB] > 4 ? 4 : r[CLASSB];
1227 num += 2*r[CLASSC];
1228 num += r[CLASSA];
1229 return num < 6;
1230 case CLASSB:
1231 num = r[CLASSA];
1232 num += 2*r[CLASSC];
1233 num += r[CLASSB];
1234 return num < 4;
1235 case CLASSC:
1236 num = r[CLASSA];
1237 num += r[CLASSB] > 4 ? 4 : r[CLASSB];
1238 num += 2*r[CLASSC];
1239 return num < 5;
1240 case CLASSD:
1241 return r[CLASSD] < DREGCNT;
1242 }
1243 return 0; /* XXX gcc */
1244 }
1245
1246 char *rnames[] = {
1247 "ax", "dx", "cx", "bx", "si", "di", "bp", "sp",
1248 "al", "ah", "dl", "dh", "cl", "ch", "bl", "bh",
1249 "axdx", "axcx", "axbx", "axsi", "axdi", "dxcx",
1250 "dxbx", "dxsi", "dxdi", "cxbx", "cxsi", "cxdi",
1251 "bxsi", "bxdi", "sidi",
1252 "st0", "st1", "st2", "st3", "st4", "st5", "st6", "st7",
1253 };
1254
1255 /*
1256 * Return a class suitable for a specific type.
1257 */
1258 int
1259 gclass(TWORD t)
1260 {
1261 if (t == CHAR || t == UCHAR)
1262 return CLASSB;
1263 if (t == LONGLONG || t == ULONGLONG || t == LONG || t == ULONG)
1264 return CLASSC;
1265 if (t == FLOAT || t == DOUBLE || t == LDOUBLE)
1266 return CLASSD;
1267 return CLASSA;
1268 }
1269
1270 /*
1271 * Calculate argument sizes.
1272 */
1273 void
1274 lastcall(NODE *p)
1275 {
1276 NODE *op = p;
1277 int size = 0;
1278
1279 p->n_qual = 0;
1280 if (p->n_op != CALL && p->n_op != FORTCALL && p->n_op != STCALL)
1281 return;
1282 for (p = p->n_right; p->n_op == CM; p = p->n_left) {
1283 if (p->n_right->n_op != ASSIGN)
1284 size += argsiz(p->n_right);
1285 }
1286 if (p->n_op != ASSIGN)
1287 size += argsiz(p);
1288
1289 op->n_qual = size; /* XXX */
1290 }
1291
1292 /*
1293 * Special shapes.
1294 */
1295 int
1296 special(NODE *p, int shape)
1297 {
1298 int o = p->n_op;
1299
1300 switch (shape) {
1301 case SFUNCALL:
1302 if (o == STCALL || o == USTCALL)
1303 return SRREG;
1304 break;
1305 case SPCON:
1306 if (o != ICON || p->n_name[0] ||
1307 getlval(p) < 0 || getlval(p) > 0x7fffffff)
1308 break;
1309 return SRDIR;
1310 case SMIXOR:
1311 return tshape(p, SZERO);
1312 case SMILWXOR:
1313 if (o != ICON || p->n_name[0] ||
1314 getlval(p) == 0 || getlval(p) & 0xffffffff)
1315 break;
1316 return SRDIR;
1317 case SMIHWXOR:
1318 if (o != ICON || p->n_name[0] ||
1319 getlval(p) == 0 || (getlval(p) >> 32) != 0)
1320 break;
1321 return SRDIR;
1322 case STWO:
1323 if (o == ICON && p->n_name[0] == 0 && getlval(p) == 2)
1324 return SRDIR;
1325 break;
1326 case SMTWO:
1327 if (o == ICON && p->n_name[0] == 0 && getlval(p) == -2)
1328 return SRDIR;
1329 break;
1330 }
1331 return SRNOPE;
1332 }
1333
1334 /*
1335 * Target-dependent command-line options.
1336 */
1337 void
1338 mflags(char *str)
1339 {
1340 }
1341
1342 /*
1343 * Do something target-dependent for xasm arguments.
1344 */
1345 int
1346 myxasm(struct interpass *ip, NODE *p)
1347 {
1348 struct interpass *ip2;
1349 int Cmax[] = { 31, 63, 127, 0xffff, 3, 255 };
1350 NODE *in = 0, *ut = 0;
1351 TWORD t;
1352 char *w;
1353 int reg;
1354 int c, cw;
1355 CONSZ v;
1356
1357 cw = xasmcode(p->n_name);
1358 if (cw & (XASMASG|XASMINOUT))
1359 ut = p->n_left;
1360 if ((cw & XASMASG) == 0)
1361 in = p->n_left;
1362
1363 c = XASMVAL(cw);
1364 switch (c) {
1365 case 'D': reg = DI; break;
1366 case 'S': reg = SI; break;
1367 case 'a': reg = AX; break;
1368 case 'b': reg = BX; break;
1369 case 'c': reg = CX; break;
1370 case 'd': reg = DX; break;
1371
1372 case 't':
1373 case 'u':
1374 p->n_name = tmpstrdup(p->n_name);
1375 w = strchr(p->n_name, XASMVAL(cw));
1376 *w = 'r'; /* now reg */
1377 return 1;
1378
1379 case 'A': reg = AXDX; break;
1380 case 'q': {
1381 /* Set edges in MYSETXARG */
1382 if (p->n_left->n_op == REG || p->n_left->n_op == TEMP)
1383 return 1;
1384 t = p->n_left->n_type;
1385 if (in && ut)
1386 in = tcopy(in);
1387 p->n_left = mklnode(TEMP, 0, p2env.epp->ip_tmpnum++, t);
1388 if (ut) {
1389 ip2 = ipnode(mkbinode(ASSIGN, ut, tcopy(p->n_left), t));
1390 DLIST_INSERT_AFTER(ip, ip2, qelem);
1391 }
1392 if (in) {
1393 ip2 = ipnode(mkbinode(ASSIGN, tcopy(p->n_left), in, t));
1394 DLIST_INSERT_BEFORE(ip, ip2, qelem);
1395 }
1396 return 1;
1397 }
1398
1399 case 'I':
1400 case 'J':
1401 case 'K':
1402 case 'L':
1403 case 'M':
1404 case 'N':
1405 if (p->n_left->n_op != ICON) {
1406 if ((c = XASMVAL1(cw)) != 0) {
1407 p->n_name++;
1408 return 0; /* Try again */
1409 }
1410 uerror("xasm arg not constant");
1411 }
1412 v = getlval(p->n_left);
1413 if ((c == 'K' && v < -128) ||
1414 (c == 'L' && v != 0xff && v != 0xffff) ||
1415 (c != 'K' && v < 0) ||
1416 (v > Cmax[c-'I']))
1417 uerror("xasm val out of range");
1418 p->n_name = "i";
1419 return 1;
1420
1421 default:
1422 return 0;
1423 }
1424 /* If there are requested either memory or register, delete memory */
1425 w = p->n_name = tmpstrdup(p->n_name);
1426 if (*w == '=')
1427 w++;
1428 *w++ = 'r';
1429 *w = 0;
1430
1431 t = p->n_left->n_type;
1432 if (reg == AXDX) {
1433 ;
1434 } else {
1435 if (t == CHAR || t == UCHAR) {
1436 reg = reg * 2 + 8;
1437 }
1438 }
1439 if (t == FLOAT || t == DOUBLE || t == LDOUBLE) {
1440 reg += 037;
1441 }
1442
1443 if (in && ut)
1444 in = tcopy(in);
1445 p->n_left = mklnode(REG, 0, reg, t);
1446 if (ut) {
1447 ip2 = ipnode(mkbinode(ASSIGN, ut, tcopy(p->n_left), t));
1448 DLIST_INSERT_AFTER(ip, ip2, qelem);
1449 }
1450 if (in) {
1451 ip2 = ipnode(mkbinode(ASSIGN, tcopy(p->n_left), in, t));
1452 DLIST_INSERT_BEFORE(ip, ip2, qelem);
1453 }
1454 return 1;
1455 }
1456
1457 void
1458 targarg(char *w, void *arg)
1459 {
1460 NODE **ary = arg;
1461 NODE *p, *q;
1462
1463 if (ary[(int)w[1]-'0'] == 0)
1464 p = ary[(int)w[1]-'0'-1]->n_left; /* XXX */
1465 else
1466 p = ary[(int)w[1]-'0']->n_left;
1467 if (optype(p->n_op) != LTYPE)
1468 comperr("bad xarg op %d", p->n_op);
1469 q = tcopy(p);
1470 if (q->n_op == REG) {
1471 if (*w == 'k') {
1472 q->n_type = INT;
1473 } else if (*w != 'w') {
1474 if (q->n_type > UCHAR) {
1475 regno(q) = regno(q)*2+8;
1476 if (*w == 'h')
1477 regno(q)++;
1478 }
1479 q->n_type = INT;
1480 } else
1481 q->n_type = SHORT;
1482 }
1483 adrput(stdout, q);
1484 tfree(q);
1485 }
1486
1487 /*
1488 * target-specific conversion of numeric arguments.
1489 */
1490 int
1491 numconv(void *ip, void *p1, void *q1)
1492 {
1493 NODE *p = p1, *q = q1;
1494 int cw = xasmcode(q->n_name);
1495
1496 switch (XASMVAL(cw)) {
1497 case 'a':
1498 case 'b':
1499 case 'c':
1500 case 'd':
1501 p->n_name = tmpcalloc(2);
1502 p->n_name[0] = (char)XASMVAL(cw);
1503 return 1;
1504 default:
1505 return 0;
1506 }
1507 }
1508
1509 static struct {
1510 char *name; int num;
1511 } xcr[] = {
1512 { "ax", AX },
1513 { "bx", BX },
1514 { "cx", CX },
1515 { "dx", DX },
1516 { "si", SI },
1517 { "di", DI },
1518 { NULL, 0 },
1519 };
1520
1521 /*
1522 * Check for other names of the xasm constraints registers.
1523 */
1524
1525 /*
1526 * Check for other names of the xasm constraints registers.
1527 */
1528 int xasmconstregs(char *s)
1529 {
1530 int i;
1531
1532 if (strncmp(s, "st", 2) == 0) {
1533 int off =0;
1534 if (s[2] == '(' && s[4] == ')')
1535 off = s[3] - '0';
1536 return SIDI + 1 + off;
1537 }
1538
1539 for (i = 0; xcr[i].name; i++)
1540 if (strcmp(xcr[i].name, s) == 0)
1541 return xcr[i].num;
1542 return -1;
1543 }
1544