From 9fa7e43000403e78ecad7f3cd8c33b719958cf64 Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Wed, 5 May 2010 14:43:24 +0200 Subject: [PATCH] codea: multiplikation --- codea/code.bfe | 5 +++++ codea/parser.y | 27 +++++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/codea/code.bfe b/codea/code.bfe index 52803e4..03e2111 100644 --- a/codea/code.bfe +++ b/codea/code.bfe @@ -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 # %% diff --git a/codea/parser.y b/codea/parser.y index 0c58a77..4e460e0 100644 --- a/codea/parser.y +++ b/codea/parser.y @@ -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; @} ; -- 2.25.1