projects
/
uebersetzerbau-ss10.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
codea: weitere verbesserung in der registerbelegung
[uebersetzerbau-ss10.git]
/
codea
/
parser.y
diff --git
a/codea/parser.y
b/codea/parser.y
index fa8d988e2beaba4e79e879c48234d8bec38d7fce..b5a7e7d8fc7b0f5617be90720381076d6bb14012 100644
(file)
--- a/
codea/parser.y
+++ b/
codea/parser.y
@@
-34,16
+34,16
@@
* sout:
*/
@autoinh s gparamges
* sout:
*/
@autoinh s gparamges
-@autosyn node
+@autosyn node
imm
@attributes { char *name; } IDENT
@attributes { long val; } NUM
@attributes { struct symbol *f; int paramges; int parms; } Parms
@attributes { char *name; } IDENT
@attributes { long val; } NUM
@attributes { struct symbol *f; int paramges; int parms; } Parms
-@attributes { struct symbol *f;
int soffset; } Program
-@attributes { struct symbol *f; int
soffset; int offsetcount; } FeldID Structdef
+@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; } Methoddef
@attributes { struct symbol *s; int gparamges; } Statseq Exprs
-@attributes { struct symbol *s; int gparamges; struct treenode *node; int exprcount; } Expr Minusterm Multerm Orterm Feld Term
+@attributes { struct symbol *s; int gparamges; struct treenode *node; int exprcount;
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; } Statement
@attributes { struct symbol *s; int gparamges; struct treenode *node; } Lexpr
@attributes { struct symbol *sin; int gparamges; struct symbol *sout; struct treenode *node; } Statement
@@
-56,7
+56,6
@@
Input:
Program
@{
@i @Program.f@ = tab_new();
Program
@{
@i @Program.f@ = tab_new();
- @i @Program.soffset@ = 0;
@gen @revorder(1) printf("\t.text\n");
@}
;
@gen @revorder(1) printf("\t.text\n");
@}
;
@@
-66,14
+65,11
@@
Program:
@{
@i @Methoddef.s@ = @Program.0.f@;
@i @Program.1.f@ = @Program.0.f@;
@{
@i @Methoddef.s@ = @Program.0.f@;
@i @Program.1.f@ = @Program.0.f@;
- @i @Program.1.soffset@ = @Program.0.soffset@;
@}
| Structdef ';' Program
@{
@i @Program.1.f@ = tab_merge(@Program.0.f@, @Structdef.f@, 1);
@}
| Structdef ';' Program
@{
@i @Program.1.f@ = tab_merge(@Program.0.f@, @Structdef.f@, 1);
- @i @Structdef.offsetcount@ = @Program.0.soffset@;
- @i @Program.1.soffset@ = @Structdef.soffset@;
@}
|
;
@}
|
;
@@
-92,8
+88,7
@@
Structdef:
STRUCT FeldID END
@{
@i @Structdef.f@ = @FeldID.f@;
STRUCT FeldID END
@{
@i @Structdef.f@ = @FeldID.f@;
- @i @FeldID.offsetcount@ = @Structdef.offsetcount@;
- @i @Structdef.soffset@ = @FeldID.soffset@;
+ @i @FeldID.offsetcount@ = 0;
@}
;
@}
;
@@
-117,15
+112,12
@@
FeldID:
IDENT FeldID
@{
@i @FeldID.1.offsetcount@ = @FeldID.0.offsetcount@ + 1;
IDENT FeldID
@{
@i @FeldID.1.offsetcount@ = @FeldID.0.offsetcount@ + 1;
- @i @FeldID.0.soffset@ = @FeldID.1.soffset@;
- /* TODO: offset hier verwenden */
@i @FeldID.0.f@ = tab_add_symbol(@FeldID.1.f@, @IDENT.name@, S_FIELD, 1, -1, @FeldID.0.offsetcount@);
@}
|
@{
@i @FeldID.f@ = tab_new();
@i @FeldID.0.f@ = tab_add_symbol(@FeldID.1.f@, @IDENT.name@, S_FIELD, 1, -1, @FeldID.0.offsetcount@);
@}
|
@{
@i @FeldID.f@ = tab_new();
- @i @FeldID.soffset@ = @FeldID.offsetcount@;
@}
;
@}
;
@@
-230,14
+222,17
@@
Expr:
| NOT Term
@{
| NOT Term
@{
- @i @Expr.node@ = TREENULL;
@i @Expr.exprcount@ = @Term.exprcount@; fprintf(stderr, "(Expr)- NOT Term\n");
@i @Expr.exprcount@ = @Term.exprcount@; fprintf(stderr, "(Expr)- NOT Term\n");
+ @i @Expr.node@ = new_node(O_EQ, @Term.node@, new_node(O_NULL, TREENULL, TREENULL, @Expr.exprcount@), @Expr.exprcount@);
+
+ @reg @Term.node@->reg = @Expr.node@->reg;
@}
| Term Minusterm
@{
@i @Expr.exprcount@ = @Term.exprcount@ + @Minusterm.exprcount@; fprintf(stderr, "(Expr)- Term Minusterm\n");
@i @Expr.node@ = new_node(O_SUB, @Term.node@, @Minusterm.node@, @Expr.exprcount@);
@}
| Term Minusterm
@{
@i @Expr.exprcount@ = @Term.exprcount@ + @Minusterm.exprcount@; fprintf(stderr, "(Expr)- Term Minusterm\n");
@i @Expr.node@ = new_node(O_SUB, @Term.node@, @Minusterm.node@, @Expr.exprcount@);
+ @i @Expr.imm@ = @Term.imm@ && @Minusterm.imm@;
@reg {
/* TODO */
@reg {
/* TODO */
@@
-251,6
+246,7
@@
Expr:
@{
@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.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 */
@reg {
/* TODO */
@@
-264,6
+260,7
@@
Expr:
@{
@i @Expr.exprcount@ = @Term.exprcount@ + @Orterm.exprcount@; fprintf(stderr, "(Expr)- Term Orterm\n");
@i @Expr.node@ = new_node(O_OR, @Term.node@, @Orterm.node@, @Expr.exprcount@);
@{
@i @Expr.exprcount@ = @Term.exprcount@ + @Orterm.exprcount@; fprintf(stderr, "(Expr)- Term Orterm\n");
@i @Expr.node@ = new_node(O_OR, @Term.node@, @Orterm.node@, @Expr.exprcount@);
+ @i @Expr.imm@ = @Term.imm@ && @Orterm.imm@;
@reg {
/* TODO */
@reg {
/* TODO */
@@
-277,6
+274,7
@@
Expr:
@{
@i @Expr.exprcount@ = @Term.0.exprcount@ + @Term.1.exprcount@; fprintf(stderr, "(Expr)- Term < Term\n");
@i @Expr.node@ = new_node(O_LESS, @Term.0.node@, @Term.1.node@, @Expr.exprcount@);
@{
@i @Expr.exprcount@ = @Term.0.exprcount@ + @Term.1.exprcount@; fprintf(stderr, "(Expr)- Term < Term\n");
@i @Expr.node@ = new_node(O_LESS, @Term.0.node@, @Term.1.node@, @Expr.exprcount@);
+ @i @Expr.imm@ = @Term.0.imm@ && @Term.0.imm@;
@reg {
@Term.0.node@->reg = @Expr.node@->reg;
@reg {
@Term.0.node@->reg = @Expr.node@->reg;
@@
-288,6
+286,7
@@
Expr:
@{
@i @Expr.exprcount@ = @Term.0.exprcount@ + @Term.1.exprcount@; fprintf(stderr, "(Expr)- Term = Term\n");
@i @Expr.node@ = new_node(O_EQ, @Term.0.node@, @Term.1.node@, @Expr.exprcount@);
@{
@i @Expr.exprcount@ = @Term.0.exprcount@ + @Term.1.exprcount@; fprintf(stderr, "(Expr)- Term = Term\n");
@i @Expr.node@ = new_node(O_EQ, @Term.0.node@, @Term.1.node@, @Expr.exprcount@);
+ @i @Expr.imm@ = @Term.0.imm@ && @Term.0.imm@;
@reg {
@Term.0.node@->reg = @Expr.node@->reg;
@reg {
@Term.0.node@->reg = @Expr.node@->reg;
@@
-301,10
+300,15
@@
Minusterm:
@{
@i @Minusterm.0.exprcount@ = @Term.exprcount@ + @Minusterm.1.exprcount@; fprintf(stderr, "(Minusterm)- - Term Minusterm\n");
@i @Minusterm.node@ = new_node(O_ADD, @Minusterm.1.node@, @Term.node@, @Minusterm.0.exprcount@);
@{
@i @Minusterm.0.exprcount@ = @Term.exprcount@ + @Minusterm.1.exprcount@; fprintf(stderr, "(Minusterm)- - Term Minusterm\n");
@i @Minusterm.node@ = new_node(O_ADD, @Minusterm.1.node@, @Term.node@, @Minusterm.0.exprcount@);
+ @i @Minusterm.0.imm@ = @Term.imm@ && @Minusterm.1.imm@;
@reg {
@Minusterm.1.node@->reg = @Minusterm.node@->reg;
@reg {
@Minusterm.1.node@->reg = @Minusterm.node@->reg;
- @Term.node@->reg = next_reg(@Minusterm.1.node@->reg, @Minusterm.node@->skip, @Minusterm.gparamges@);
+ if(@Minusterm.1.imm@) {
+ @Term.node@->reg = @Minusterm.node@->reg;
+ } else {
+ @Term.node@->reg = next_reg(@Minusterm.1.node@->reg, @Minusterm.node@->skip, @Minusterm.gparamges@);
+ }
}
@}
}
@}
@@
-320,10
+324,15
@@
Multerm:
@{
@i @Multerm.0.exprcount@ = @Term.exprcount@ + @Multerm.1.exprcount@; fprintf(stderr, "(Multerm)- - Term Multerm\n");
@i @Multerm.node@ = new_node(O_MUL, @Multerm.1.node@, @Term.node@, @Multerm.0.exprcount@);
@{
@i @Multerm.0.exprcount@ = @Term.exprcount@ + @Multerm.1.exprcount@; fprintf(stderr, "(Multerm)- - Term Multerm\n");
@i @Multerm.node@ = new_node(O_MUL, @Multerm.1.node@, @Term.node@, @Multerm.0.exprcount@);
+ @i @Multerm.0.imm@ = @Term.imm@ && @Multerm.1.imm@;
@reg {
@Multerm.1.node@->reg = @Multerm.node@->reg;
@reg {
@Multerm.1.node@->reg = @Multerm.node@->reg;
- @Term.node@->reg = next_reg(@Multerm.1.node@->reg, @Multerm.node@->skip, @Multerm.gparamges@);
+ if(@Multerm.1.imm@) {
+ @Term.node@->reg = @Multerm.node@->reg;
+ } else {
+ @Term.node@->reg = next_reg(@Multerm.1.node@->reg, @Multerm.node@->skip, @Multerm.gparamges@);
+ }
}
@}
}
@}
@@
-339,10
+348,15
@@
Orterm:
@{
@i @Orterm.0.exprcount@ = @Term.exprcount@ + @Orterm.1.exprcount@; fprintf(stderr, "(Orterm)- - Term Orterm\n");
@i @Orterm.node@ = new_node(O_OR, @Orterm.1.node@, @Term.node@, @Orterm.0.exprcount@);
@{
@i @Orterm.0.exprcount@ = @Term.exprcount@ + @Orterm.1.exprcount@; fprintf(stderr, "(Orterm)- - Term Orterm\n");
@i @Orterm.node@ = new_node(O_OR, @Orterm.1.node@, @Term.node@, @Orterm.0.exprcount@);
+ @i @Orterm.0.imm@ = @Term.imm@ && @Orterm.1.imm@;
@reg {
@Orterm.1.node@->reg = @Orterm.node@->reg;
@reg {
@Orterm.1.node@->reg = @Orterm.node@->reg;
- @Term.node@->reg = next_reg(@Orterm.1.node@->reg, @Orterm.node@->skip, @Orterm.gparamges@);
+ if(@Orterm.1.imm@) {
+ @Term.node@->reg = @Orterm.node@->reg;
+ } else {
+ @Term.node@->reg = next_reg(@Orterm.1.node@->reg, @Orterm.node@->skip, @Orterm.gparamges@);
+ }
}
@}
| OR Term
}
@}
| OR Term
@@
-364,18
+378,21
@@
Term:
@{
@i @Term.exprcount@ = 0; fprintf(stderr, "(Term)- NUM\n");
@i @Term.node@ = new_number(@NUM.val@, @Term.exprcount@);
@{
@i @Term.exprcount@ = 0; fprintf(stderr, "(Term)- NUM\n");
@i @Term.node@ = new_number(@NUM.val@, @Term.exprcount@);
+ @i @Term.imm@ = 1;
@}
| '-' NUM
@{
@i @Term.exprcount@ = 0; fprintf(stderr, "(Term)- - NUM\n");
@i @Term.node@ = new_number(-1 * (@NUM.val@), @Term.exprcount@);
@}
| '-' NUM
@{
@i @Term.exprcount@ = 0; fprintf(stderr, "(Term)- - NUM\n");
@i @Term.node@ = new_number(-1 * (@NUM.val@), @Term.exprcount@);
+ @i @Term.imm@ = 1;
@}
| THIS
@{
@i @Term.exprcount@ = 0; fprintf(stderr, "(Term)- THIS\n");
@i @Term.node@ = new_param(O_ID, strdup("this"), TREENULL, TREENULL, 0, @Term.exprcount@);
@}
| THIS
@{
@i @Term.exprcount@ = 0; fprintf(stderr, "(Term)- THIS\n");
@i @Term.node@ = new_param(O_ID, strdup("this"), TREENULL, TREENULL, 0, @Term.exprcount@);
+ @i @Term.imm@ = 0;
@}
| IDENT
@}
| IDENT
@@
-383,6
+400,7
@@
Term:
@c check(@Term.s@, @IDENT.name@, S_VAR|S_PARM);
@i @Term.exprcount@ = 0; fprintf(stderr, "(Term)- IDENT\n");
@c check(@Term.s@, @IDENT.name@, S_VAR|S_PARM);
@i @Term.exprcount@ = 0; fprintf(stderr, "(Term)- IDENT\n");
+ @i @Term.imm@ = 0;
@i {
@Term.node@ = TREENULL;
if(tab_lookup(@Term.s@, @IDENT.name@, S_VAR|S_PARM) == SYMNULL) {
@i {
@Term.node@ = TREENULL;
if(tab_lookup(@Term.s@, @IDENT.name@, S_VAR|S_PARM) == SYMNULL) {
@@
-403,18
+421,21
@@
Term:
@{
@i @Term.node@ = @Feld.node@;
/*TODO*/@i @Term.exprcount@ = 0;
@{
@i @Term.node@ = @Feld.node@;
/*TODO*/@i @Term.exprcount@ = 0;
+ @i @Term.imm@ = 0;
@}
| IDENT '(' Exprs ')'
@{
@i @Term.node@ = TREENULL;
/*TODO*/@i @Term.exprcount@ = 0;
@}
| IDENT '(' Exprs ')'
@{
@i @Term.node@ = TREENULL;
/*TODO*/@i @Term.exprcount@ = 0;
+ @i @Term.imm@ = 0;
@}
| Term '.' IDENT '(' Exprs ')'
@{
@i @Term.node@ = TREENULL;
/*TODO*/@i @Term.exprcount@ = 0;
@}
| Term '.' IDENT '(' Exprs ')'
@{
@i @Term.node@ = TREENULL;
/*TODO*/@i @Term.exprcount@ = 0;
+ @i @Term.imm@ = 0;
@}
;
@}
;