codeb: (opt) bei zuweisungen wie 'x := x-1' nur ein subq befehl statt movq,subq,movq
authorBernhard Urban <lewurm@gmail.com>
Sun, 30 May 2010 13:34:13 +0000 (15:34 +0200)
committerBernhard Urban <lewurm@gmail.com>
Sun, 30 May 2010 13:34:13 +0000 (15:34 +0200)
codeb/code.bfe

index 791135b84e1bc82cf6e8e7f62e6a3fb6de00f1a1..8615fab3d1222133a0a14eda3fcf0f270bf71415 100644 (file)
@@ -172,6 +172,16 @@ void gen_subspecial(struct treenode *bnode, short e)
        printf("\taddq %%%s, %%%s\n", KIDKID_REG(1,1), BN_REG);
 }
 
+void assign_var(struct treenode *bnode)
+{
+       KIDREG2PARM(1);
+       if (strcmp(bnode->kids[0]->kids[0]->name, bnode->kids[1]->name) != 0) {
+               KIDKIDREG2PARM(0,0);
+               printf("\tmov %%%s, %%%s\n", KIDKID_REG(0,0), KID_REG(1));
+       } /*else:  x := x - 1 geht in einem befehl */
+       printf("\tsub $%d, %%%s\n", KIDKID_VAL(0,1), KID_REG(1));
+}
+
 %}
 
 %start begin
@@ -188,6 +198,8 @@ assign: O_ASSIGN(expr, O_ID) # 1 # KIDREG2PARM(1); printf("\tmovq %%%s, %%%s\n",
 assign: O_ASSIGN(imm, O_ID) # 1 # KIDREG2PARM(1); printf("\tmovq $%d, %%%s\n", KID_VAL(0), KID_REG(1));
 assign: O_ASSIGN(O_ID, O_ID) # 1 # KIDREG2PARM(1); KIDREG2PARM(0); printf("\tmovq %%%s, %%%s\n", KID_REG(0), KID_REG(1));
 
+assign: O_ASSIGN(O_SUB(O_ID,O_NUM), O_ID) # 1 # assign_var(bnode);
+
 assign: O_ASSIGN(expr, O_FIELD(expr)) # 1 # KIDKIDREG2PARM(1,0); printf("\tmovq %%%s, %d(%%%s)\n", BN_REG, bnode->kids[1]->soffset * 8, KIDKID_REG(1,0));
 assign: O_ASSIGN(O_ID, O_FIELD(expr)) # 1 # KIDREG2PARM(0); KIDKIDREG2PARM(1,0); printf("\tmovq %%%s, %d(%%%s)\n", KID_REG(0), bnode->kids[1]->soffset * 8, KIDKID_REG(1,0));