gesamt: sc aka. 'stackcontrol' als element eines knotes statt globale
authorBernhard Urban <lewurm@gmail.com>
Thu, 17 Jun 2010 17:59:26 +0000 (19:59 +0200)
committerBernhard Urban <lewurm@gmail.com>
Thu, 17 Jun 2010 17:59:26 +0000 (19:59 +0200)
variable... hat 20pkt gekostet :(

... und noch ein paar unwesentlichere aenderungen (aka cleanup)

gesamt/code.bfe
gesamt/parser.y
gesamt/tree.h

index a95ed5b6996ca83b07df25c842bad44043b77c4c..fb0044768de8a55751b29e1b723b739efa7faa0d 100644 (file)
@@ -187,17 +187,20 @@ void assign_var(struct treenode *bnode)
        printf("\tsub $%d, %%%s\n", KIDKID_VAL(0,1), KID_REG(1));
 }
 
-/* ... dirty */
-static short sc[8] = {0};
 void make_call(struct treenode *bnode)
 {
-       int j;
+       short *sc = bnode->sc;
+       int j, off = 0;
        printf("\t//params pushen\n");
        for(j = 0; j < bnode->soffset; j++) {
                if(sc[j] == 1)
-                       printf("\txchg %%%s, %d(%%rsp)\n", param_reg(j), j*8);
-               else if (sc[j] == 0)
-                       printf("\tpushq %%%s\n", param_reg(j));
+                       printf("\txchg %%%s, %d(%%rsp)\n", param_reg(j), (j - off)*8);
+               else {
+                       if (sc[j] == 0) {
+                               printf("\tpushq %%%s\n", param_reg(j));
+                               off++;
+                       }
+               }
        }
        printf("\t//vars pushen\n");
        for(j = bnode->soffset; j < bnode->soffset + bnode->vars; j++) {
@@ -221,16 +224,17 @@ void make_call(struct treenode *bnode)
                printf("\tpopq %%rax\n");
        }
 
-       /* vars poppen */
+       printf("\t//vars poppen\n");
        for(j = bnode->soffset + bnode->vars - 1; j > bnode->soffset - 1; j--) {
                printf("\tpopq %%%s\n", param_reg(j));
        }
 
-       /* params poppen */
+       printf("\t//params poppen (sc == 0)\n");
        for(j = bnode->soffset - 1; j >= 0; j--) {
                if(sc[j] == 0)
                        printf("\tpopq %%%s\n", param_reg(j));
        }
+       printf("\t//params poppen (sc != 0)\n");
        for(j = 0; j < bnode->soffset; j++) {
                if(sc[j] > 0)
                        printf("\tpopq %%%s\n", param_reg(j));
@@ -243,21 +247,21 @@ void make_call(struct treenode *bnode)
 
 void prep_arg(struct treenode *bnode, int moveit)
 {
+       short *sc = bnode->sc;
        printf("\t//args-nr-> %i (%%%s) [moveit= %i]\n", bnode->soffset, param_reg(bnode->soffset), moveit);
        sc[bnode->soffset] = 1;
-       if(moveit) { /* expr */
-               if((BN_REG == (char *) NULL) || (bnode->kids[1] != TREENULL && bnode->kids[1]->op == O_ID && bnode->kids[1]->kids[0] == TREENULL && bnode->kids[1]->kids[1] == TREENULL)) {
-                       if(bnode->kids[1]->name != (char *) NULL && strcmp(bnode->kids[1]->name,"this")!=0) {
-                               KIDREG2PARM(1);
-                               printf("\tpushq %%%s\n", KID_REG(1));
-                       } else {
-                               printf("\tpushq %%%s\n", param_reg(bnode->soffset));
-                               sc[bnode->soffset] = 2;
-                       }
+       if(moveit == 1) { /* expr */
+               if((  bnode->kids[0] != TREENULL && bnode->kids[0]->op == O_NOTHING &&
+                     bnode->kids[0] != TREENULL && bnode->kids[0]->op == O_NOTHING)) {
+                       printf("\tpushq %%%s\n", param_reg(bnode->soffset));
+                       sc[bnode->soffset] = 2;
                } else {
                        printf("\tpushq %%%s\n", BN_REG);
                }
-       } else { /* just O_ID */
+       } else if(moveit == 2) { /* O_ID right */
+               KIDREG2PARM(1);
+               printf("\tpushq %%%s\n", KID_REG(1));
+       } else if(moveit == 0) { /* O_ID left */
                KIDREG2PARM(0);
                printf("\tpushq %%%s\n", KID_REG(0));
        }
@@ -317,9 +321,10 @@ expr: O_ID # 0 #
 expr: imm # 1 # moveimm(BN_VAL, BN_REG);
 expr: O_BOOL(expr) # 0 #
 
-expr: O_CALL(expr) # 0 # make_call(bnode);
+expr: O_CALL(expr,expr) # 0 # make_call(bnode);
 expr: O_ARG(expr,expr) # 1 # prep_arg(bnode, 1);
 expr: O_ARG(O_ID,expr) # 1 # prep_arg(bnode, 0);
+expr: O_ARG(expr,O_ID) # 1 # prep_arg(bnode, 2);
 expr: O_NOTHING # 0 #
 
 expr: O_SUB(expr,expr)          # 2 # gen_e_eno(bnode, "subq");
index 107ede5c4992278fe35310d71b93909aeb1200a8..5dba8e00c69a4020a68525136b45bacfdcb1c562 100644 (file)
@@ -550,9 +550,10 @@ Term:
        | IDENT '(' Exprs ')'
          @{
            @i {
-                       @Term.node@ = new_call(@IDENT.name@, new_arg(@Exprs.node@, new_nothing(), 0) /*this*/,
-                                       TREENULL, @Term.gparamges@, @Term.vars_in@);
+                       @Term.node@ = new_call(@IDENT.name@, @Exprs.node@, new_arg(new_nothing(), new_nothing(), 0) /*this*/,
+                                       @Term.gparamges@, @Term.vars_in@);
                        @Term.node@->soffset = MAX(@Exprs.paramcount@, @Term.gparamges@);
+                       @Term.node@->sc = @Term.node@->kids[1]->sc = @Exprs.node@->sc;
                }
                @i @Exprs.cnt@ = 1;
                @i @Term.imm@ = 0;
@@ -563,14 +564,15 @@ Term:
        | Term '.' IDENT '(' Exprs ')'
          @{
            @i {
-                       @Term.node@ = new_call(@IDENT.name@, new_arg(@Exprs.node@, @Term.1.node@, 0) /*this*/,
-                                       TREENULL, @Term.gparamges@, @Term.vars_in@);
+                       @Term.node@ = new_call(@IDENT.name@, @Exprs.node@, new_arg(@Term.1.node@, new_nothing(), 0) /*this*/,
+                                       @Term.gparamges@, @Term.vars_in@);
                        @Term.node@->soffset = MAX(@Exprs.paramcount@, @Term.gparamges@);
+                       @Term.node@->sc = @Term.node@->kids[1]->sc = @Exprs.node@->sc;
                }
                @i @Exprs.cnt@ = 1;
                @i @Term.imm@ = 0;
                @i @Term.call@ = 1;
-               @reg @Exprs.node@->reg = @Term.1.node@->reg = @Term.node@->kids[0]->reg = @Term.node@->reg;
+               @reg @Exprs.node@->reg = @Term.1.node@->reg = @Term.node@->kids[1]->reg = @Term.node@->reg;
          @}
 
        ;
@@ -578,7 +580,10 @@ Term:
 Exprs:
          Expr ',' Exprs
          @{
-               @i @Exprs.0.node@ = new_arg(@Expr.0.node@, @Exprs.1.node@, @Exprs.0.cnt@);
+               @i {
+                       @Exprs.0.node@ = new_arg(@Exprs.1.node@, @Expr.0.node@, @Exprs.0.cnt@);
+                       @Exprs.0.node@->sc = @Exprs.1.node@->sc;
+               }
                @i @Exprs.0.paramcount@ = @Exprs.1.paramcount@;
                @i @Exprs.1.cnt@ = @Exprs.0.cnt@ + 1;
                @reg {
@@ -588,13 +593,19 @@ Exprs:
          @}
        | Expr
          @{
-               @i @Exprs.0.node@ = new_arg(@Expr.0.node@, new_nothing(), @Exprs.cnt@);
+               @i {
+                       @Exprs.0.node@ = new_arg(@Expr.0.node@, new_nothing(), @Exprs.cnt@);
+                       @Exprs.0.node@->sc = malloc(8 * sizeof(short));
+               }
                @i @Exprs.paramcount@ = @Exprs.cnt@ + 1;
                @reg @Expr.node@->reg = @Exprs.0.node@->reg;
          @}
        |
          @{
-               @i @Exprs.0.node@ = new_nothing();
+               @i {
+                       @Exprs.0.node@ = new_nothing();
+                       @Exprs.0.node@->sc = malloc(8 * sizeof(short));
+               }
                @i @Exprs.paramcount@ = @Exprs.cnt@;
          @}
        ;
index e7fd68f9297d8ae2e6771dd12b19963fef0ed5bc..704430f4bbaad2a054d7b06ed0ce6249d16d9863 100644 (file)
@@ -37,6 +37,7 @@ struct treenode {
        int soffset;
        int paramges;
        int vars;
+       short *sc;
 };
 
 typedef struct treenode *treenodep;