char *next_reg(char *s, short skip)
{
+ /* TODO: warum enthaelt das register die parameter enthalten koennten? */
char *regs[] = {"rax", "r10", "r11", "r9", "r8", "rcx", "rdx", "rsi", "rdi"};
int i=0;
if (s != (char*) NULL) {
@attributes { char *name; } IDENT
@attributes { long val; } NUM
-@attributes { struct symbol *f; } FeldID Parms Structdef Program
+@attributes { struct symbol *f; int parms; } Parms
+@attributes { struct symbol *f; } FeldID Structdef Program
@attributes { struct symbol *s; } Methoddef Statseq Exprs
@attributes { struct symbol *s; struct treenode *node; } Lexpr Expr Minusterm Multerm Orterm Term Feld
@attributes { struct symbol *sin; struct symbol *sout; struct treenode *node; } Statement
Methoddef:
METHOD IDENT '(' Parms ')' Statseq END
@{
+ @i @Parms.parms@ = 1;
@i @Statseq.s@ = tab_merge(@Methoddef.s@, @Parms.f@, 0);
@gen @revorder(1) func_header(@IDENT.name@);
@}
/* lokale Vars werden in Statement in die tabelle eingefuegt */
IDENT Parms
@{
- @i @Parms.0.f@ = tab_add_symbol(@Parms.1.f@, @IDENT.name@, S_PARM, 1);
+ @i @Parms.1.parms@ = @Parms.parms@ + 1;
+ @i @Parms.0.f@ = tab_add_symbol(@Parms.1.f@, @IDENT.name@, S_PARM, 1, @Parms.parms@);
@}
|
FeldID:
IDENT FeldID
@{
- @i @FeldID.0.f@ = tab_add_symbol(@FeldID.1.f@, @IDENT.name@, S_FIELD, 1);
+ @i @FeldID.0.f@ = tab_add_symbol(@FeldID.1.f@, @IDENT.name@, S_FIELD, 1, 0);
@}
|
@{
/* 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);
+ @i @Statement.sout@ = tab_add_symbol(tab_clone(@Statement.sin@), @IDENT.name@, S_VAR, 1, 0);
xxputsin(@Expr.s@,)
@i @Statement.node@ = TREENULL;
@}
| IDENT
@{
@c check(@Term.s@, @IDENT.name@, S_VAR|S_PARM);
- @i @Term.node@ = new_node(O_ID, TREENULL, TREENULL); @Term.node@->param_index=1;
+ @i @Term.node@ = new_node(O_ID, TREENULL, TREENULL); {
+ struct symbol *tmp;
+ if((tmp = tab_lookup(@Term.s@, @IDENT.name@, S_PARM)) != TREENULL) {
+ @Term.node@->param_index = tmp->param_index;
+ }
+ }
@reg fprintf(stderr, "wtf5\n");
@}
#include <stdio.h>
#include "symtable.h"
-#if 0
+#if 1
#define DD
#endif
struct symbol *elm = tab;
struct symbol *ntab = tab_new();
#ifdef DD
- printf("tab_clone: tab(%08X)\n", tab);
+ fprintf(stderr, "tab_clone: tab(%08X)\n", tab);
#endif
while(elm != SYMNULL) {
- ntab = tab_add_symbol(ntab, elm->ident, elm->type, 0);
+ ntab = tab_add_symbol(ntab, elm->ident, elm->type, 0, elm->param_index ? elm->param_index : 0);
elm = elm->next;
}
return ntab;
}
-struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short check)
+struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short check, int param_index)
{
struct symbol *elm = tab;
struct symbol *new_elm;
#ifdef DD
- printf("tab_add_symbol: tab(%08X), ident(%s), type(%i), check(%i)\n", tab, ident, type, check);
+ fprintf(stderr, "tab_add_symbol: tab(%08X), ident(%s), type(%i), check(%i), param_index(%i)\n", tab, ident, type, check, param_index);
#endif
if(tab_lookup(tab, ident, type) != SYMNULL) {
new_elm->next = SYMNULL;
new_elm->ident = strdup(ident);
new_elm->type = type;
+ if(type == S_PARM) {
+ new_elm->param_index = param_index;
+ }
if(tab == SYMNULL) {
return new_elm;
struct symbol *elm = to_add;
struct symbol *ntab = tab_clone(tab);
#ifdef DD
- printf("tab_merge: tab(%08X), to_add(%08X), check(%i), ntab(%08X)\n", tab, to_add, check, ntab);
+ fprintf(stderr, "tab_merge: tab(%08X), to_add(%08X), check(%i), ntab(%08X)\n", tab, to_add, check, ntab);
#endif
while(elm != SYMNULL) {
- ntab = tab_add_symbol(ntab, elm->ident, elm->type, check);
+ ntab = tab_add_symbol(ntab, elm->ident, elm->type, check, elm->param_index ? elm->param_index : 0);
elm = elm->next;
}
{
struct symbol *elm;
#ifdef DD
- printf("check: tab(%08X), ident(%s), type(%i), elm(%08X)\n", tab, ident, type, elm);
+ fprintf(stderr, "check: tab(%08X), ident(%s), type(%i), elm(%08X)\n", tab, ident, type, elm);
#endif
if(type & (S_VAR | S_PARM)) {
char *ident;
struct symbol *next;
short type;
+ int param_index;
};
struct symbol *tab_clone(struct symbol *tab);
struct symbol *tab_new(void);
-struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short check);
+struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short check, int param_index);
struct symbol *tab_lookup(struct symbol *tab, char *ident, short type);
struct symbol *tab_remove_symbol(struct symbol *tab, char *ident, short type);
struct symbol *tab_merge(struct symbol *tab, struct symbol *to_add, short check);