Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.71
 
1.72
 
MAIN:ragge:20031215220206
 
reader.c
_>11 /*      $Id$    */
 22 /*
<> 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+ * 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+/*
330  * Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
 431  *
 532  * Redistribution and use in source and binary forms, with or without
     
 !
4673 int udebug = 0;
 4774 int ftnno;
 4875 static int thisline;
<> 76+int fregs;
4977 
<>50 -NODE *stotree, *nodepole;
 51 -int stocook;
  78+NODE *nodepole;
5279 static int saving;
 5380 
 5481 static struct templst {
     
 !
6996 int findleaf(NODE *p, int);
 7097 int relops(NODE *p);
 7198 int asgops(NODE *p, int);
<> 99+NODE *store(NODE *);
72100 
 73101 static void genregs(NODE *p);
<>74 -static void gencode(NODE *p);
  102+static void gencode(NODE *p, int cookie);
75103 
 76104 /*
 77105  * Layout of findops() return value:
     
 !
248276         eoftn(regs, autos, retlab);
 249277 }
 250278 
<>251 -static int gotcall; /* XXX */
252279 /*
 253280  * generate the code for p;
<>254 - * order may call codgen recursively
  281+ * store may call codgen recursively
255282  * cookie is used to describe the context
 256283  */
 257284 void
 258285 codgen(NODE *p, int cookie)
 259286 {
 260287         int o;
 261288 
<>262 -        /*
 263 -         * Loop around to find sub-trees to store.
 264 -         * This mostly applies to arguments.
 265 -         */
 266 -        for (;;) {
 267 -                nodepole = p;
 268 -                canon(p);  /* creats OREG from * if possible and does sucomp */
 269 -                stotree = NIL;
 270 -#ifdef PCC_DEBUG
 271 -                if (e2debug) {
 272 -                        printf("store called on:\n");
 273 -                        fwalk(p, e2print, 0);
 274 -                }
 275 -#endif
 276 -                store(p);
 277 -                if (stotree == NIL)
 278 -                        break;
 279 -                geninsn(stotree, stocook);
 280 -                sucomp(stotree); /* Calculate sub-tree evaluation order */
 281 -                genregs(stotree); /* allocate registers for instructions */
 282 -                gencode(stotree); /* Emit instructions */
 283 -        }
 284 -
285289         nodepole = p;
 286290         canon(p);  /* creats OREG from * if possible and does sucomp */
 287291 #ifdef PCC_DEBUG
     
 !
291295         }
 292296 #endif
 293297         do {
<>294 -                gotcall = 0;
295298                 geninsn(p, cookie); /* Assign instructions for tree */
<>296 -        } while (gotcall && !(p->n_op == REG && p->n_type == VOID));
 297 -        sucomp(p);  /* Calculate sub-tree evaluation order */
  299+        } while (sucomp(p) < 0);  /* Calculate sub-tree evaluation order */
298300 #ifdef PCC_DEBUG
 299301         if (udebug) {
 300302                 printf("genregs called on:\n");
 301303                 fwalk(p, e2print, 0);
 302304         }
 303305 #endif
<> 306+        /*
  307+         * When here it is known that the tree can be evaluated.
  308+         * Assign registers for all instructions.
  309+         */
304310         genregs(p); /* allocate registers for instructions */
<> 311+#ifdef PCC_DEBUG
  312+        if (udebug) {
  313+                printf("gencode called on:\n");
  314+                fwalk(p, e2print, 0);
  315+        }
  316+#endif
305317         switch (p->n_op) {
 306318         case CBRANCH:
 307319                 o = p->n_left->n_op;
<>308 -                gencode(p);
  320+                gencode(p, FORCC);
309321                 cbgen(o, p->n_right->n_lval);
<>310 -                reclaim(p, RNULL, 0);
311322                 break;
 312323         case FORCE:
<>313 -                gencode(p->n_left);
 314 -                reclaim(p, RLEFT, INTAREG|INTBREG);
  324+                gencode(p->n_left, INTAREG|INTBREG);
315325                 break;
 316326         default:
 317327                 if (p->n_op != REG || p->n_type != VOID) /* XXX */
<>318 -                        gencode(p); /* Emit instructions */
  328+                        gencode(p, FOREFF); /* Emit instructions */
319329         }
<>320 -#if 0
 321 -        for (;;) {
 322 -                canon(p);  /* creats OREG from * if possible and does sucomp */
 323 -                stotree = NIL;
 324 -#ifdef PCC_DEBUG
 325 -                if (e2debug) {
 326 -                        printf("store called on:\n");
 327 -                        fwalk(p, e2print, 0);
 328 -                }
 329 -#endif
 330 -                store(p);
 331 -                if( stotree==NIL ) break;
 332 -
 333 -                /* because it's minimal, can do w.o. stores */
 334 -
 335 -                order( stotree, stocook );
 336 -        }
 337 -        order( p, cookie );
 338 -#endif
339330 }
 340331 
 341332 #ifdef PCC_DEBUG
     
 !
356347         "FORARG",
 357348         "SWADD",
 358349         0,
<>359 -        };
  350+};
360351 
 361352 /*
 362353  * print a nice-looking description of cookie
     
 !
487478                 if (istnode(p))
 488479                         comperr("geninsn REG");
 489480                 /* FALLTHROUGH */
<> 481+        case NAME:
490482         case ICON:
 491483         case OREG:
 492484                 if ((cookie & (INTAREG|INTBREG)) == 0)
     
 !
505497         case INIT:
 506498         case GOTO:
 507499         case FUNARG:
<> 500+        case UCALL:
508501                 if ((rv = finduni(p, cookie)) < 0) {
 509502                         if (setuni(p, cookie))
 510503                                 goto again;
     
 !
525518                 p->n_su = rv;
 526519                 break;
 527520 
<>528 -        case UCALL:
 529 -                p->n_right = NIL;
 530 -        case CALL:
 531 -                p->n_op = UCALL;
  521+#if 0
532522                 if (gencall(p, cookie))
 533523                         goto failed;
 534524                 if (cookie == FOREFF)
 535525                         p->n_type = VOID; /* XXX */
 536526                 gotcall = 1;
 537527                 break;
<> 528+#endif
538529 
 539530         case CBRANCH:
 540531                 p1 = p->n_left;
     
 !
551542                 break;
 552543 
 553544         default:
<>554 -                cerror("geninsn: bad op %d", o);
  545+                comperr("geninsn: bad op %d, node %p", o, p);
555546         }
 556547         return;
 557548 
     
 !
562553         cerror("Cannot generate code for op %d\n", o);
 563554 }
 564555 
<>565 -#if 0
 566 -void
 567 -order(NODE *p, int cook)
  556+/*
  557+ * Store a given subtree in a temporary location.
  558+ * Return an OREG node where it is located.
  559+ */
  560+NODE *
  561+store(NODE *p)
568562 {
<>569 -//      struct optab *q;
 570 -        int o, ty, m, rv;
 571 -        int cookie;
 572 -        NODE *p1, *p2;
  563+        NODE *q, *r, *s;
573564 
<>574 -        /*
 575 -         * by this time, p should be able to be generated without stores;
 576 -         * the only question is how
 577 -         */
 578 -        again:
 579 -
 580 -        cookie = cook;
 581 -        rcount();
 582 -        canon(p);
 583 -        rallo(p, p->n_rall);
 584 -
 585 -#ifdef PCC_DEBUG
 586 -        if (odebug) {
 587 -                printf("order(%p, ", p);
 588 -                prcook(cookie);
 589 -                printf(")\n");
 590 -                fwalk(p, e2print, 0);
 591 -        }
 592 -#endif
 593 -
 594 -        o = p->n_op;
 595 -        ty = optype(o);
 596 -
 597 -        /* first of all, for most ops, see if it is in the table */
 598 -
 599 -        /* look for ops */
 600 -
 601 -        switch (m = p->n_op) {
 602 -
 603 -#if 0
 604 -        case ASSIGN:
 605 -                /*
 606 -                 * For ASSIGN the left node must be directly addressable,
 607 -                 * the right can be put into a register.
 608 -                 * XXX - Will not try to match any smart instructions yet.
 609 -                 */
 610 -//printf("foo\n");
 611 -//fwalk(p, e2print, 0);
 612 -                if (!canaddr(p->n_left)) {
 613 -                        if (p->n_left->n_op == UMUL) {
 614 -                                offstar(p->n_left->n_left);
 615 -                                goto again;
 616 -                        }
 617 -                        cerror("bad assign lvalue");
 618 -                }
 619 -//printf("foo1\n");
 620 -//fwalk(p, e2print, 0);
 621 -                if (!canaddr(p->n_right)) {
 622 -                        if (p->n_right->n_op == UMUL) {
 623 -                                offstar(p->n_right->n_left);
 624 -                                goto again;
 625 -                        }
 626 -                        order(p->n_right, INTAREG|INTBREG);
 627 -                }
 628 -//printf("foo2\n");
 629 -//fwalk(p, e2print, 0);
 630 -                rv = asgops(p, cook);
 631 -//printf("foo6 : %x\n", rv);
 632 -                if (rv < 0)
 633 -                        goto nomat;
 634 -                if (rv & RREG)
 635 -                        order(p->n_right, INTAREG|INTBREG);
 636 -                q = &table[rv >> 2];
 637 -//printf("foo7\n");
 638 -                if (!allo(p, q))
 639 -                        cerror("assign allo failed");
 640 -//printf("foo3\n");
 641 -                expand(p, cook, q->cstring);
 642 -                reclaim(p, q->rewrite, cook);
 643 -//printf("foo4\n");
 644 -//fwalk(p, e2print, 0);
 645 -                goto cleanup;
 646 -#endif
 647 -
 648 -        case PLUS:
 649 -        case MINUS:
 650 -        case AND:
 651 -        case OR:
 652 -        case ER:
 653 -        case DIV:
 654 -        case MOD:
 655 -        case MUL:
 656 -        case LS:
 657 -        case RS:
 658 -
 659 -                /*
 660 -                 * Get a suitable op.
 661 -                 */
 662 -                if ((rv = findops(p, cook)) < 0) {
 663 -                        if (setbin(p))
 664 -                                goto again;
 665 -                        goto nomat;
 666 -                }
 667 -
 668 -                /*
 669 -                 * Do subnodes conversions (if needed).
 670 -                 */
 671 -                switch (rv & LMASK) {
 672 -                case LREG:
 673 -                        order(p->n_left, INTAREG|INTBREG);
 674 -                        break;
 675 -                case LOREG:
 676 -                        offstar(p->n_left->n_left);
 677 -                        canon(p->n_left);
 678 -                        break;
 679 -                case LTEMP:
 680 -                        order(p->n_left, INTEMP);
 681 -                        break;
 682 -                }
 683 -
 684 -                switch (rv & RMASK) {
 685 -                case RREG:
 686 -                        order(p->n_right, INTAREG|INTBREG);
 687 -                        break;
 688 -                case ROREG:
 689 -                        offstar(p->n_right->n_left);
 690 -                        canon(p->n_right);
 691 -                        break;
 692 -                case RTEMP:
 693 -                        order(p->n_right, INTEMP);
 694 -                        break;
 695 -                }
 696 -                p->n_su = rv;
 697 -                return;
 698 -#if 0
 699 -                /*
 700 -                 * Be sure that both sides are addressable.
 701 -                 */
 702 -//printf("newstyle node %p\n", p);
 703 -                if (!canaddr(p->n_left)) {
 704 -                        if (p->n_left->n_op == UMUL) {
 705 -                                offstar(p->n_left->n_left);
 706 -                                goto again;
 707 -                        }
 708 -                        order(p->n_left, INTAREG|INTBREG);
 709 -                }
 710 -//printf("newstyle addrl %p\n", p);
 711 -                if (!canaddr(p->n_right)) {
 712 -                        if (p->n_right->n_op == UMUL) {
 713 -                                offstar(p->n_right->n_left);
 714 -                                goto again;
 715 -                        }
 716 -                        order(p->n_right, INTAREG|INTBREG);
 717 -                }
 718 -//printf("newstyle addrr %p\n", p);
 719 -
 720 -                /*
 721 -                 *
 722 -                 */
 723 -                m = INTAREG|INTBREG;
 724 -                rv = findops(p);
 725 -foo:            if (rv < 0) {
 726 -                        if (setbin(p))
 727 -                                goto again;
 728 -                        goto nomat;
 729 -                }
 730 -                if (rv & LREG) {
 731 -                        if (p->n_left->n_op == UMUL) {
 732 -                                offstar(p->n_left->n_left);
 733 -                                goto again;
 734 -                        }
 735 -                        order(p->n_left, INTAREG|INTBREG);
 736 -                }
 737 -//printf("newstyle ltmp %p\n", p);
 738 -                if (rv & RREG) {
 739 -                        if (p->n_right->n_op == UMUL) {
 740 -                                offstar(p->n_right->n_left);
 741 -                                goto again;
 742 -                        }
 743 -                        order(p->n_right, INTAREG|INTBREG);
 744 -                }
 745 -//printf("newstyle rtmp %p\n", p);
 746 -                
 747 -
 748 -                q = &table[rv >> 2];
 749 -                if (!allo(p, q)) {
 750 -                        /*
 751 -                         * Ran out of suitable temp regs.
 752 -                         * Force everything onto stack.
 753 -                         * Be careful to avoid loops.
 754 -                         * XXX - this is bad code!
 755 -                         */
 756 -                        if ((rv & LREG) == 0 && istnode(p->n_left)) {
 757 -                                order(p->n_left, INTEMP);
 758 -                                goto again;
 759 -                        } else if (!(rv & RREG) &&istnode(p->n_right)) {
 760 -                                order(p->n_right, INTEMP);
 761 -                                goto again;
 762 -                        }
 763 -                        cerror("allo failed");
 764 -                }
 765 -                expand(p, m, q->cstring);
 766 -                reclaim(p, q->rewrite, m);
 767 -//printf("newstyle ute %p\n", p);
 768 -                goto cleanup;
 769 -
 770 -#endif
 771 -
 772 -                /*
 773 -                 * For now just be sure that the trees on each side
 774 -                 * are adressable.
 775 -                 */
 776 -        case EQ:
 777 -        case NE:
 778 -        case LE:
 779 -        case LT:
 780 -        case GE:
 781 -        case GT:
 782 -        case ULE:
 783 -        case ULT:
 784 -        case UGE:
 785 -        case UGT:
 786 -
 787 -                if (!canaddr(p->n_left)) {
 788 -                        if (p->n_left->n_op == UMUL) {
 789 -                                offstar(p->n_left->n_left);
 790 -                                goto again;
 791 -                        }
 792 -                        order(p->n_left, INTAREG|INTBREG|INAREG|INBREG);
 793 -                }
 794 -                if (!canaddr(p->n_right)) {
 795 -                        if (p->n_right->n_op == UMUL) {
 796 -                                offstar(p->n_right->n_left);
 797 -                                goto again;
 798 -                        }
 799 -                        order(p->n_right, INTAREG|INTBREG|INAREG|INBREG);
 800 -                }
 801 -                rv = relops(p);
 802 -                m = FORCC;
 803 -                break;
 804 -
 805 -        default:
 806 -                /* look for op in table */
 807 -                for (;;) {
 808 -                        if ((m = match(p, cookie)) == MDONE)
 809 -                                goto cleanup;
 810 -                        else if (m == MNOPE) {
 811 -                                if (!(cookie = nextcook(p, cookie)))
 812 -                                        goto nomat;
 813 -                                continue;
 814 -                        } else
 815 -                                break;
 816 -                }
 817 -                break;
 818 -
 819 -        case FORCE:
 820 -        case CBRANCH:
 821 -        case UCALL:
 822 -        case CALL:
 823 -        case USTCALL:
 824 -        case STCALL:
 825 -        case UFORTCALL:
 826 -        case FORTCALL:
 827 -                /* don't even go near the table... */
 828 -                ;
 829 -
 830 -        }
 831 -        /*
 832 -         * get here to do rewriting if no match or
 833 -         * fall through from above for hard ops
 834 -         */
 835 -
 836 -        p1 = p->n_left;
 837 -        if (ty == BITYPE)
 838 -                p2 = p->n_right;
 839 -        else
 840 -                p2 = NIL;
 841 -        
 842 -#ifdef PCC_DEBUG
 843 -        if (odebug) {
 844 -                printf("order(%p, ", p);
 845 -                prcook(cook);
 846 -                printf("), cookie ");
 847 -                prcook(cookie);
 848 -                printf(", rewrite %s\n", opst[m]);
 849 -        }
 850 -#endif
 851 -        switch (m) {
 852 -        default:
 853 -                nomat:
 854 -                cerror( "no table entry for op %s", opst[p->n_op] );
 855 -
 856 -        case FORCE:
 857 -                cook = INTAREG|INTBREG;
 858 -                order(p->n_left, cook);
 859 -                reclaim(p, RLEFT, cook);
 860 -                return;
 861 -
 862 -        case CBRANCH:
 863 -                p1->n_label = p2->n_lval;
 864 -                o = p1->n_op;
 865 -                codgen(p1, FORCC);
 866 -                cbgen(o, p2->n_lval);
 867 -                reclaim(p1, RNULL, 0);
 868 -                nfree(p2);
 869 -                nfree(p);
 870 -                return;
 871 -
 872 -        case FLD:       /* fields of funny type */
 873 -                if ( p1->n_op == UMUL ){
 874 -                        offstar( p1->n_left );
 875 -                        goto again;
 876 -                        }
 877 -
 878 -        case UMINUS:
 879 -                order( p1, INBREG|INAREG);
 880 -                goto again;
 881 -
 882 -        case NAME:
 883 -                /* all leaves end up here ... */
 884 -                if( o == REG ) goto nomat;
 885 -                order( p, INTAREG|INTBREG );
 886 -                goto again;
 887 -
 888 -        case INIT:
 889 -                uerror("init: illegal initialization");
 890 -                return;
 891 -
 892 -        case UFORTCALL:
 893 -                p->n_right = NIL;
 894 -        case FORTCALL:
 895 -                o = p->n_op = UFORTCALL;
 896 -                if( genfcall( p, cookie ) ) goto nomat;
 897 -                goto cleanup;
 898 -
 899 -        case UCALL:
 900 -                p->n_right = NIL;
 901 -        case CALL:
 902 -                o = p->n_op = UCALL;
 903 -                if( gencall( p, cookie ) ) goto nomat;
 904 -                goto cleanup;
 905 -
 906 -        case USTCALL:
 907 -                p->n_right = NIL;
 908 -        case STCALL:
 909 -                o = p->n_op = USTCALL;
 910 -                if( genscall( p, cookie ) ) goto nomat;
 911 -                goto cleanup;
 912 -
 913 -                /* if arguments are passed in register, care must be taken that reclaim
 914 -                 * not throw away the register which now has the result... */
 915 -
 916 -        case UMUL:
 917 -                if( cook == FOREFF ){
 918 -                        /* do nothing */
 919 -                        order( p->n_left, FOREFF );
 920 -                        nfree(p);
 921 -                        return;
 922 -                }
 923 -                offstar( p->n_left );
 924 -#if 0
 925 -                canon(p);
 926 -                if( canaddr(p) && cook != INTEMP )
 927 -                        goto cleanup;
 928 -#endif
 929 -                goto again;
 930 -
 931 -        case INCR/* INCR and DECR */
 932 -                if( setincr(p) ) goto again;
 933 -
 934 -                /* x++ becomes (x = x + 1) -1; */
 935 -
 936 -                p1 = tcopy(p);
 937 -                if (cook & FOREFF) {
 938 -                        nfree(p->n_right);
 939 -                        p->n_right = p1;
 940 -                        p1->n_op = (p->n_op == INCR) ? PLUS: MINUS;
 941 -                        p->n_op = ASSIGN;
 942 -                } else {
 943 -                        p2 = talloc();
 944 -                        p2->n_rall = NOPREF;
 945 -                        p2->n_name = "";
 946 -                        p2->n_op = ASSIGN;
 947 -                        p2->n_type = p->n_type;
 948 -                        p2->n_left = p->n_left;
 949 -                        p2->n_right = p1;
 950 -                        p1->n_op = (p->n_op == INCR) ? PLUS: MINUS;
 951 -                        p->n_op = (p->n_op == INCR) ? MINUS : PLUS;
 952 -                        p->n_left = p2;
 953 -                }
 954 -                goto again;
 955 -
 956 -        case STASG:
 957 -                if( setstr( p ) ) goto again;
 958 -                goto nomat;
 959 -
 960 -        case ASSIGN:
 961 -                if (setasg(p, cook))
 962 -                        goto again;
 963 -                goto nomat;
 964 -
 965 -        case BITYPE:
 966 -                if( setbin( p ) ) goto again;
 967 -                goto nomat;
 968 -
 969 -                }
 970 -
 971 -        cleanup:
 972 -
 973 -        /* if it is not yet in the right state, put it there */
 974 -
 975 -        if( cook & FOREFF ){
 976 -                reclaim( p, RNULL, 0 );
 977 -                return;
 978 -                }
 979 -
 980 -        if( p->n_op==FREE ) return;
 981 -
 982 -        if( tshape( p, cook ) ) return;
 983 -
 984 -        if( (m=match(p,cook) ) == MDONE ) return;
 985 -
 986 -        /* we are in bad shape, try one last chance */
 987 -        if (lastchance(p, cook))
 988 -                goto again;
 989 -
 990 -        goto nomat;
  565+        q = talloc();
  566+        r = talloc();
  567+        s = talloc();
  568+        q->n_op = OREG;
  569+        q->n_type = p->n_type;
  570+        q->n_name = "";
  571+        q->n_rval = FPREG;
  572+        q->n_lval = BITOOR(freetemp(szty(p->n_type)));
  573+        *r = *q;
  574+        s->n_op = ASSIGN;
  575+        s->n_type = p->n_type;
  576+        s->n_name = "";
  577+        s->n_left = q;
  578+        s->n_right = p;
  579+        codgen(s, FOREFF);
  580+        return r;
991581 }
 992582 
<>993 -#endif
 994 -
995583 /*
 996584  * Count the number of registers needed to evaluate a tree.
 997585  * This is the trivial implementation, for machines with symmetric
     
 !
1009597         if (p->n_su == -1)
 1010598                 return sucomp(p->n_left);
 1011599 
<> 600+        if (p->n_op == UCALL) {
  601+                if (sucomp(p->n_left) < 0)
  602+                        return -1;
  603+                return fregs;
  604+        }
  605+
1012606         nreg = (q->needs & NACOUNT) * szty(p->n_type);
 1013607 
 1014608         switch (p->n_su & RMASK) {
 1015609         case RREG:
 1016610         case ROREG:
<>1017 -                right = sucomp(p->n_right);
  611+                if ((right = sucomp(p->n_right)) < 0)
  612+                        return right;
1018613                 break;
 1019614         case RTEMP:
 1020615                 cerror("sucomp RTEMP");
     
 !
1024619         switch (p->n_su & LMASK) {
 1025620         case LREG:
 1026621         case LOREG:
<>1027 -                left = sucomp(p->n_left);
  622+                if ((left = sucomp(p->n_left)) < 0)
  623+                        return left;
1028624                 break;
 1029625         case LTEMP:
 1030626                 cerror("sucomp LTEMP");
 1031627         default:
 1032628                 left = 0;
 1033629         }
<>1034 -//printf("sucomp: right %d left %d\n", right, left);
  630+//printf("sucomp: node %p right %d left %d\n", p, right, left);
  631+        if ((p->n_su & RMASK) && (p->n_su & LMASK) &&
  632+            right + szty(p->n_left->n_type) > fregs &&
  633+            left + szty(p->n_right->n_type) > fregs) {
  634+                /*
  635+                 * Must store one subtree. Store the tree
  636+                 * with highest SU, or left.
  637+                 */
  638+                if (right > left)
  639+                        p->n_right = store(p->n_right);
  640+                else
  641+                        p->n_left = store(p->n_left);
  642+                return -1;
  643+        }
1035644         if (right > left)
 1036645                 p->n_su |= DORIGHT;
<> 646+        if (left && right && (q->needs & (NASL|NDLEFT)))
  647+                p->n_su |= DORIGHT;
1037648         if (right > nreg)
 1038649                 nreg = right;
 1039650         if (left > nreg)
<>1040 -                nreg = right;
  651+                nreg = left;
1041652         return nreg;
 1042653 }
 1043654 
     
 !
1047658         rallo(p, NOPREF);
 1048659 }
 1049660 
<> 661+int
  662+alloregs(NODE *p, int wantreg)
  663+{
  664+        int rall;
  665+
  666+        rall = allo(p, wantreg);
  667+}
  668+
1050669 void
<>1051 -gencode(NODE *p)
  670+gencode(NODE *p, int cookie)
1052671 {
 1053672         struct optab *q = &table[TBLIDX(p->n_su)];
 1054673 
 1055674         if (p->n_su == -1) /* For OREGs and similar */
<>1056 -                return gencode(p->n_left);
  675+                return gencode(p->n_left, cookie);
1057676 
 1058677         if (p->n_su & DORIGHT) {
<>1059 -                gencode(p->n_right);
  678+                gencode(p->n_right, INTAREG|INTBREG);
1060679                 if ((p->n_su & RMASK) == ROREG)
 1061680                         canon(p);
 1062681         }
 1063682         if (p->n_su & LMASK) {
<>1064 -                gencode(p->n_left);
  683+                gencode(p->n_left, INTAREG|INTBREG);
1065684                 if ((p->n_su & LMASK) == LOREG)
 1066685                         canon(p);
 1067686         }
 1068687         if ((p->n_su & RMASK) && !(p->n_su & DORIGHT)) {
<>1069 -                gencode(p->n_right);
  688+                gencode(p->n_right, INTAREG|INTBREG);
1070689                 if ((p->n_su & RMASK) == ROREG)
 1071690                         canon(p);
 1072691         }
 1073692         if (!allo(p, q))
<>1074 -                cerror("failed register allocation");
 1075 -        expand(p, FOREFF, q->cstring);
 1076 -        if ((dope[p->n_op] & LOGFLG))
 1077 -                reclaim(p, q->rewrite, FORCC); /* XXX */
 1078 -        else
 1079 -                reclaim(p, q->rewrite, INTAREG); /* XXX */
  693+                comperr("failed register allocation, node %p", p);
  694+        expand(p, cookie, q->cstring);
  695+        reclaim(p, q->rewrite, cookie);
1080696 }
 1081697 
<>1082 -
 1083 -int callflag;
 1084 -int fregs;
 1085 -
 1086 -void
 1087 -store( p ) NODE *p; {
 1088 -
 1089 -        /* find a subtree of p which should be stored */
 1090 -
 1091 -        int o, ty;
 1092 -
 1093 -        o = p->n_op;
 1094 -        ty = optype(o);
 1095 -
 1096 -        if( ty == LTYPE ) return;
 1097 -
 1098 -        switch( o ){
 1099 -
 1100 -        case UCALL:
 1101 -        case UFORTCALL:
 1102 -        case USTCALL:
 1103 -                ++callflag;
 1104 -                break;
 1105 -
 1106 -        case UMUL:
 1107 -                if (asgop(p->n_left->n_op))
 1108 -                        stoasg(p->n_left, UMUL);
 1109 -                break;
 1110 -
 1111 -        case CALL:
 1112 -        case FORTCALL:
 1113 -        case STCALL:
 1114 -                store( p->n_left );
 1115 -                stoarg( p->n_right, o );
 1116 -                ++callflag;
 1117 -                return;
 1118 -
 1119 -                }
 1120 -
 1121 -        if (ty == UTYPE) {
 1122 -                store(p->n_left);
 1123 -                return;
 1124 -        }
 1125 -
 1126 -        if (asgop(p->n_right->n_op))
 1127 -                stoasg(p->n_right, o);
 1128 -
 1129 -        if( p->n_su>fregs ){ /* must store */
 1130 -                mkadrs( p );  /* set up stotree and stocook to subtree
 1131 -                                 that must be stored */
 1132 -                }
 1133 -
 1134 -        store( p->n_right );
 1135 -        store( p->n_left );
 1136 -        }
 1137 -
 1138 -/* mark off calls below the current node */
 1139 -void
 1140 -markcall(NODE *p)
 1141 -{
 1142 -
 1143 -        again:
 1144 -        switch( p->n_op ){
 1145 -
 1146 -        case UCALL:
 1147 -        case USTCALL:
 1148 -        case UFORTCALL:
 1149 -        case CALL:
 1150 -        case STCALL:
 1151 -        case FORTCALL:
 1152 -                ++callflag;
 1153 -                return;
 1154 -
 1155 -                }
 1156 -
 1157 -        switch( optype( p->n_op ) ){
 1158 -
 1159 -        case BITYPE:
 1160 -                markcall( p->n_right );
 1161 -        case UTYPE:
 1162 -                p = p->n_left;
 1163 -                /* eliminate recursion (aren't I clever...) */
 1164 -                goto again;
 1165 -        case LTYPE:
 1166 -                return;
 1167 -                }
 1168 -
 1169 -}
 1170 -
 1171 -void
 1172 -stoarg(NODE *p, int calltype)
 1173 -{
 1174 -        /* arrange to store the args */
 1175 -        if( p->n_op == CM ){
 1176 -                stoarg( p->n_left, calltype );
 1177 -                p = p->n_right ;
 1178 -                }
 1179 -        if( calltype == CALL ){
 1180 -                STOARG(p);
 1181 -                }
 1182 -        else if( calltype == STCALL ){
 1183 -                STOSTARG(p);
 1184 -                }
 1185 -        else {
 1186 -                STOFARG(p);
 1187 -                }
 1188 -        callflag = 0;
 1189 -        store(p);
 1190 -#ifdef NO_NESTCALLS
 1191 -        if( callflag ){ /* prevent two calls from being active at once  */
 1192 -                SETSTO(p,INTEMP);
 1193 -                store(p); /* do again to preserve bottom up nature....  */
 1194 -        }
 1195 -#endif
 1196 -}
 1197 -
<_1198698 int negrel[] = { NE, EQ, GT, GE, LT, LE, UGT, UGE, ULT, ULE } ;  /* negatives of relationals */
 1199699 
 1200700 void
FishEye: Open Source License registered to PCC.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-09-02 01:37 +0200