From 146b4d2c403e663e1fb454621bb5656e4798ce57 Mon Sep 17 00:00:00 2001 From: Bernhard Urban Date: Mon, 7 Jun 2010 02:00:51 +0200 Subject: [PATCH] gesamt: hmm --- gesamt/TODO | 6 ++++++ gesamt/code.bfe | 18 +++++++++++++----- gesamt/parser.y | 25 ++++++++++++++----------- 3 files changed, 33 insertions(+), 16 deletions(-) create mode 100644 gesamt/TODO diff --git a/gesamt/TODO b/gesamt/TODO new file mode 100644 index 0000000..ec191c0 --- /dev/null +++ b/gesamt/TODO @@ -0,0 +1,6 @@ +- enter verwenden statt selbst prolog zu machen +- was ist wenn eine funktion die aufgerufen wird eine funktion aufruft die eine + viel laengere parameterliste hat? (die hinteren register wurden ja nicht + gesichert... :/) anmerkung: koennt vielleicht hinhauen weil ich die parameter + sichere (ohne ruecksicht darauf ob sie tatsaechlich paramter sind!) +- diff --git a/gesamt/code.bfe b/gesamt/code.bfe index 9e85ee1..1dc1e3f 100644 --- a/gesamt/code.bfe +++ b/gesamt/code.bfe @@ -187,10 +187,15 @@ void assign_var(struct treenode *bnode) void make_call(struct treenode *bnode) { int j; + /* params pushen */ + for(j = 0; j < bnode->soffset; j++) { + printf("\txchg %%%s, %d(%%rsp)\n", param_reg(j), j*8); + } /* vars pushen */ for(j = bnode->paramges; j < bnode->paramges + bnode->vars; j++) { printf("\tpushq %%%s\n", param_reg(j)); } + /* TODO: schoener machen... */ if(strcmp(BN_REG, "rax")!=0) { printf("\tpushq %%rax\n"); @@ -213,20 +218,23 @@ void make_call(struct treenode *bnode) } /* params poppen */ +#if 0 for(j = bnode->soffset - 1; j >= 0; j--) { +#else + for(j = 0; j < bnode->soffset; j++) { +#endif printf("\tpopq %%%s\n", param_reg(j)); } } void prep_arg(struct treenode *bnode, int moveit) { - printf("\t//args-nr.: %%%s to %%%s (moveit: %i)\n", BN_REG, param_reg(bnode->soffset), moveit); - printf("\tpushq %%%s\n", param_reg(bnode->soffset)); + printf("\t//args-nr.: %i (%%%s) [moveit: %i]\n", bnode->soffset, param_reg(bnode->soffset), moveit); if(moveit) { /* expr */ - move(BN_REG, param_reg(bnode->soffset)); + printf("\tpushq %%%s\n", BN_REG == (char *) NULL ? param_reg(bnode->soffset) : BN_REG); } else { /* just O_ID */ KIDREG2PARM(0); - move(KID_REG(0), param_reg(bnode->soffset)); + printf("\tpushq %%%s\n", KID_REG(0)); } } @@ -268,7 +276,7 @@ expr: O_ID # 0 # expr: imm # 1 # moveimm(BN_VAL, BN_REG); expr: O_BOOL(expr) # 0 # -expr: O_CALL(expr,expr) # 0 # make_call(bnode); +expr: O_CALL(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_NOTHING # 0 # diff --git a/gesamt/parser.y b/gesamt/parser.y index 4722ff8..20d0a51 100644 --- a/gesamt/parser.y +++ b/gesamt/parser.y @@ -49,7 +49,7 @@ @attributes { struct symbol *f; } Program Structdef; @attributes { struct symbol *f; int offsetcount; } FeldID @attributes { struct symbol *s; } Methoddef -@attributes { struct symbol *s; int gparamges; int vars_in; int paramcount; struct treenode *node; } Exprs +@attributes { struct symbol *s; int gparamges; int vars_in; int cnt; int paramcount; struct treenode *node; } Exprs @attributes { struct symbol *s; int gparamges; int lblcnt_in; int lblcnt_out; int vars_in; int vars_out; int call; } Statseq @attributes { struct symbol *s; int gparamges; int lblcnt_in; int lblcnt_out; int reallblcnt; int vars_in; int vars_out; int call; } Elsestat @attributes { struct symbol *s; int gparamges; int vars_in; struct treenode *node; short imm; int call; } Expr Minusterm Multerm Orterm Feld Term @@ -557,10 +557,11 @@ Term: | IDENT '(' Exprs ')' @{ @i { - @Term.node@ = new_call(@IDENT.name@, new_arg(new_nothing(), new_nothing(), 0) /*this*/, - @Exprs.node@, @Term.gparamges@, @Term.vars_in@); + @Term.node@ = new_call(@IDENT.name@, new_arg(@Exprs.node@, new_nothing(), 0) /*this*/, + TREENULL, @Term.gparamges@, @Term.vars_in@); @Term.node@->soffset = @Exprs.paramcount@; } + @i @Exprs.cnt@ = 1; @i @Term.imm@ = 0; @i @Term.call@ = 1; @reg @Exprs.node@->reg = @Term.node@->reg; @@ -569,10 +570,11 @@ Term: | Term '.' IDENT '(' Exprs ')' @{ @i { - @Term.node@ = new_call(@IDENT.name@, new_arg(@Term.1.node@, new_nothing(), 0) /*this*/, - @Exprs.node@, @Term.gparamges@, @Term.vars_in@); + @Term.node@ = new_call(@IDENT.name@, new_arg(@Exprs.node@, @Term.1.node@, 0) /*this*/, + TREENULL, @Term.gparamges@, @Term.vars_in@); @Term.node@->soffset = @Exprs.paramcount@; } + @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; @@ -583,20 +585,21 @@ Term: Exprs: Expr ',' Exprs @{ - @i @Exprs.0.node@ = new_arg(@Expr.0.node@, @Exprs.1.node@, @Exprs.1.paramcount@); - @i @Exprs.0.paramcount@ = @Exprs.1.paramcount@ + 1; - @reg @Expr.node@->reg = @Exprs.1.node@->reg = @Exprs.0.node@->reg; + @i @Exprs.0.node@ = new_arg(@Expr.0.node@, @Exprs.1.node@, @Exprs.0.cnt@); + @i @Exprs.0.paramcount@ = @Exprs.1.paramcount@; + @i @Exprs.1.cnt@ = @Exprs.0.cnt@ + 1; + @reg @Expr.node@->reg = @Exprs.0.node@->reg; @Exprs.1.node@->reg = next_reg(@Exprs.0.node@->reg, @Exprs.gparamges@); @} | Expr @{ - @i @Exprs.0.node@ = new_arg(@Expr.0.node@, new_nothing(), 1); - @i @Exprs.paramcount@ = 2; + @i @Exprs.0.node@ = new_arg(@Expr.0.node@, new_nothing(), @Exprs.cnt@); + @i @Exprs.paramcount@ = @Exprs.cnt@ + 1; @reg @Expr.node@->reg = @Exprs.0.node@->reg; @} | @{ @i @Exprs.0.node@ = new_nothing(); - @i @Exprs.paramcount@ = 1; + @i @Exprs.paramcount@ = @Exprs.cnt@; @} ; %% -- 2.25.1