commit bb663d195fde2e1d89e3700f82899b469cd3fb8c
Author:     Roberto E. Vargas Caballero <[email protected]>
AuthorDate: Fri Jun 17 13:55:27 2016 +0200
Commit:     Roberto E. Vargas Caballero <[email protected]>
CommitDate: Fri Jun 17 13:55:27 2016 +0200

    [cc2-qbe] Force to have a label in bb
    
    Qbe needs a label at the beginning of every basic block
    so we have to check this condition.

diff --git a/cc2/arch/qbe/code.c b/cc2/arch/qbe/code.c
index a856a35..5216f06 100644
--- a/cc2/arch/qbe/code.c
+++ b/cc2/arch/qbe/code.c
@@ -304,6 +304,7 @@ writeout(void)
        Symbol *p;
        Type *tp;
        char *sep, *name;
+       int haslabel;
 
        if (curfun->kind == SGLOB)
                fputs("export ", stdout);
@@ -315,14 +316,21 @@ writeout(void)
                        break;
                printf("%s%s %s.val", sep, size2asm(&p->type), symname(p));
        }
-       puts(")\n{\[email protected]");
+       puts(")\n{");
 
        /* emit assembler instructions */
        for (pc = prog; pc; pc = pc->next) {
-               if (pc->label)
+               if (pc->label) {
+                       haslabel = 1;
                        printf("%s\n", symname(pc->label));
-               if (pc->op)
-                       (*optbl[pc->op].fun)();
+               }
+               if (!pc->op)
+                       continue;
+               if (pc->flags&BBENTRY && !haslabel)
+                       printf("%s\n", symname(newlabel()));
+               (*optbl[pc->op].fun)();
+               if (!pc->label)
+                       haslabel = 0;
        }
 
        puts("}");
@@ -486,7 +494,8 @@ getbblocks(void)
                case ASCALLL:
                case ASCALLD:
                case ASCALL:
-                       pc->flags |= BBENTRY;
+                       if (pc->next)
+                               pc->next->flags |= BBENTRY;
                        break;
                }
        }

Reply via email to