codea: multiplikation
authorBernhard Urban <lewurm@gmail.com>
Wed, 5 May 2010 12:43:24 +0000 (14:43 +0200)
committerBernhard Urban <lewurm@gmail.com>
Wed, 5 May 2010 12:43:24 +0000 (14:43 +0200)
codea/code.bfe
codea/parser.y

index 52803e40b34493631b2ed5a62c6f9076f86682df..03e2111ab7d3dc01ec42b3c582e653b71122b722 100644 (file)
@@ -33,12 +33,17 @@ expr: O_SUB(imm,exprno) # 3 # moveimm(KID_VAL(0), BN_REG); KIDREG2PARM(1); print
 expr: O_ADD(expr,exprno) # 1 # KIDREG2PARM(1); printf("\taddq %%%s, %%%s\n", KID_REG(1), KID_REG(0));
 expr: O_ADD(imm,expr) # 1 # printf("\taddq $%li, %%%s\n", KID_VAL(1), KID_REG(0)); move(KID_REG(0), BN_REG);
 
+expr: O_MUL(expr,exprno) # 1 # KIDREG2PARM(1); printf("\timulq %%%s, %%%s\n", KID_REG(1), KID_REG(0));
+expr: O_MUL(expr,imm) # 2 # printf("\timulq $%li, %%%s\n", KID_VAL(1), KID_REG(0)); move(KID_REG(0), BN_REG);
+expr: O_MUL(imm,exprno) # 3 # moveimm(KID_VAL(0), BN_REG); KIDREG2PARM(1); printf("\timulq %%%s, %%%s\n", KID_REG(1), BN_REG);
+
 exprno: O_ID # 0 # /* brauchen wir nicht 'zwischenlagern', weil nur gelesen wird */
 exprno: expr
 
 
 imm: O_ADD(imm,imm) # 0 # BN_VAL = KID_VAL(0)+KID_VAL(1);
 imm: O_SUB(imm,imm) # 0 # BN_VAL = KID_VAL(0)-KID_VAL(1);
+imm: O_MUL(imm,imm) # 0 # BN_VAL = KID_VAL(0)*KID_VAL(1);
 imm: O_NUM # 0 #
 
 %%
index 0c58a77d51466bcd558ba33c06e038b83fc2203e..4e460e087d662fbf093802aad1a673039990487c 100644 (file)
@@ -43,8 +43,8 @@
 @attributes { struct symbol *f; } FeldID Structdef Program
 @attributes { struct symbol *s; } Methoddef
 @attributes { struct symbol *s; int gparamges; } Statseq Exprs
-@attributes { struct symbol *s; int gparamges; struct treenode *node; short imm; int exprcount; } Expr Minusterm Term
-@attributes { struct symbol *s; int gparamges; struct treenode *node; int exprcount; } Orterm Multerm
+@attributes { struct symbol *s; int gparamges; struct treenode *node; short imm; int exprcount; } Expr Minusterm Term Multerm
+@attributes { struct symbol *s; int gparamges; struct treenode *node; int exprcount; } Orterm
 @attributes { struct symbol *s; int gparamges; struct treenode *node; } Lexpr Feld
 @attributes { struct symbol *sin; int gparamges; struct symbol *sout; struct treenode *node; } Statement
 
@@ -236,8 +236,16 @@ Expr:
 
        | Term Multerm
          @{
-           @i @Expr.node@ = TREENULL;
                @i @Expr.exprcount@ = @Term.exprcount@ + @Multerm.exprcount@; fprintf(stderr, "(Expr)- Term Multerm\n");
+           @i @Expr.node@ = new_node(O_MUL, @Term.node@, @Multerm.node@, @Expr.exprcount@);
+               @i @Expr.imm@ = @Term.imm@ && @Multerm.imm@;
+
+               @reg {
+                       /* TODO */
+                       @Term.node@->reg = @Expr.node@->reg;
+                       @Term.node@->skip = 0;
+                       @Multerm.node@->reg = next_reg(@Term.node@->reg, @Expr.node@->skip, @Expr.gparamges@);
+               }
          @}
 
        | Term Orterm
@@ -285,16 +293,19 @@ Multerm:
          '*' Term Multerm
          @{
                @i @Multerm.0.exprcount@ = @Term.exprcount@ + @Multerm.1.exprcount@; fprintf(stderr, "(Multerm)- - Term Multerm\n");
-               /* TODO */
-               /* TODO: imm */
-           @i @Multerm.node@ = TREENULL;
+           @i @Multerm.node@ = new_node(O_MUL, @Multerm.1.node@, @Term.node@, @Multerm.0.exprcount@);
+               @i @Multerm.imm@ = @Term.imm@ && @Multerm.1.imm@;
+
+           @reg {
+                       @Multerm.1.node@->reg = @Multerm.node@->reg;
+                       @Term.node@->reg = next_reg(@Multerm.1.node@->reg, @Multerm.node@->skip, @Multerm.gparamges@);
+               }
          @}
 
        | '*' Term
          @{
                @i @Multerm.exprcount@ = @Term.exprcount@; fprintf(stderr, "(Multerm)- - Term\n");
-               /* TODO */
-           @i @Multerm.node@ = TREENULL;
+           @reg @Term.node@->reg = @Multerm.node@->reg;
          @}
        ;