X-Git-Url: http://wien.tomnetworks.com/gitweb/?p=uebersetzerbau-ss10.git;a=blobdiff_plain;f=codeb%2Fparser.y;h=427a7330f1f1b5a1c5978a730ae57c15f8192323;hp=cda1e7bfcf500e6b653db7512b7b98c621338dd3;hb=3407cfe88d2d45f0970ac724d81335414dfdc5e7;hpb=128163389fedc8bc6029a0efd522ba286eff0c9a diff --git a/codeb/parser.y b/codeb/parser.y index cda1e7b..427a733 100644 --- a/codeb/parser.y +++ b/codeb/parser.y @@ -23,6 +23,10 @@ * geht nicht, weil verschachtelte macros deaktiviert sind */ @end +@macro lblcountinout() + @i @Statement.lblcnt_out@ = @Statement.lblcnt_in@; +@end + /* beschreibung der attribute * s: symboltabelle * f: symboltabelle fuer quirks mit structur und parameter @@ -41,11 +45,11 @@ @attributes { struct symbol *f; } Program Structdef; @attributes { struct symbol *f; int offsetcount; } FeldID @attributes { struct symbol *s; } Methoddef -@attributes { struct symbol *s; int gparamges; } Statseq Exprs +@attributes { struct symbol *s; int gparamges; } Exprs +@attributes { struct symbol *s; int gparamges; int lblcnt_in; int lblcnt_out; } Statseq @attributes { struct symbol *s; int gparamges; struct treenode *node; short imm; } Expr Minusterm Multerm Orterm Feld Term @attributes { struct symbol *s; int gparamges; struct treenode *node; } Lexpr -@attributes { struct symbol *sin; int gparamges; struct symbol *sout; struct -treenode *node; int vars; } Statement +@attributes { struct symbol *sin; int gparamges; struct symbol *sout; struct treenode *node; int vars; int lblcnt_in; int lblcnt_out; } Statement @traversal @postorder c @traversal @preorder reg @@ -80,6 +84,7 @@ Methoddef: @i @Parms.parms@ = 1; @i @Statseq.s@ = tab_merge(@Methoddef.s@, @Parms.f@, 0); @i @Statseq.gparamges@ = @Parms.paramges@; + @i @Statseq.lblcnt_in@ = 0; @gen func_header(@IDENT.name@); @} ; @@ -125,17 +130,26 @@ Statseq: Statement ';' Statseq @{ @i @Statement.sin@ = @Statseq.0.s@; + @i @Statement.lblcnt_in@ = @Statseq.0.lblcnt_in@; + @i @Statseq.1.s@ = @Statement.sout@; + @i @Statseq.1.lblcnt_in@ = @Statement.lblcnt_out@; @i @Statseq.1.gparamges@ = @Statseq.0.gparamges@ + @Statement.vars@; + + @i @Statseq.0.lblcnt_out@ = @Statseq.1.lblcnt_out@; @} | + @{ + @i @Statseq.0.lblcnt_out@ = @Statseq.0.lblcnt_in@; + @} ; Statement: Lexpr ASSIGN Expr @{ statinout() + lblcountinout() xxputsin(@Lexpr.s@,) xxputsin(@Expr.s@,) @i @Statement.node@ = new_node(O_ASSIGN, @Lexpr.node@, @Expr.node@); @@ -150,6 +164,7 @@ Statement: /* tab_clone ist hier noetig, vgl. folgendes statement * > var x := x - 1; */ @i @Statement.sout@ = tab_add_symbol(tab_clone(@Statement.sin@), @IDENT.name@, S_VAR, 1, @Statement.gparamges@, -1); + lblcountinout() xxputsin(@Expr.s@,) @i @Statement.node@ = new_node(O_ASSIGN, new_param(O_ID, @IDENT.name@, TREENULL, TREENULL, @Statement.gparamges@), @Expr.node@); @@ -162,6 +177,7 @@ Statement: | Expr @{ statinout() + lblcountinout() xxputsin(@Expr.s@,) @i @Statement.node@ = TREENULL; @i @Statement.vars@ = 0; @@ -170,6 +186,8 @@ Statement: | IF Expr THEN Statseq END @{ statinout() + @i @Statseq.lblcnt_in@ = @Statement.lblcnt_in@ + 1; + @i @Statement.lblcnt_out@ = @Statseq.lblcnt_out@; xxputsin(@Expr.s@,) xxputsin(@Statseq.s@,) @@ -180,14 +198,18 @@ Statement: @gen { write_tree(@Statement.node@, 0); burm_label(@Statement.node@); burm_reduce(@Statement.node@, 1); /* TODO: kann ich mir das test wirklich wegan and davor sparen? */ - printf("\ttest %s1, %%rax\n\tjz if_end\n", "$"); + printf("\ttest %s1, %%rax\n\tjz %s_ifend_%d\n", "$", get_func_name(), @Statement.lblcnt_in@); } - @gen @revorder(1) printf("if_end:\n"); + @gen @revorder(1) printf("%s_ifend_%d:\n", get_func_name(), @Statement.lblcnt_in@); @} | IF Expr THEN Statseq ELSE Statseq END @{ statinout() + lblcountinout() + /* TODO */ + @i @Statseq.0.lblcnt_in@ = @Statement.lblcnt_in@ + 1; + @i @Statseq.1.lblcnt_in@ = @Statement.lblcnt_in@ + 1; xxputsin(@Expr.s@,) xxputsin(@Statseq.0.s@,) xxputsin(@Statseq.1.s@,) @@ -198,6 +220,9 @@ Statement: | WHILE Expr DO Statseq END @{ statinout() + lblcountinout() + /* TODO */ + @i @Statseq.0.lblcnt_in@ = @Statement.lblcnt_in@ + 1; xxputsin(@Expr.s@,) xxputsin(@Statseq.s@,) @i @Statement.node@ = TREENULL; @@ -207,6 +232,7 @@ Statement: | RETURN Expr @{ statinout() + lblcountinout() xxputsin(@Expr.s@,) @i @Statement.vars@ = 0;