codea: offset fuer feldzugriff
authorBernhard Urban <lewurm@gmail.com>
Wed, 5 May 2010 19:04:43 +0000 (21:04 +0200)
committerBernhard Urban <lewurm@gmail.com>
Wed, 5 May 2010 19:04:43 +0000 (21:04 +0200)
codea/parser.y
codea/symtable.c
codea/symtable.h

index 736cb233a8aa3073ab0547a7608bbfb493dfe4e8..a6bb1d3a059a43fa0d98676876fd9a2ae9ef6c05 100644 (file)
@@ -39,7 +39,8 @@
 @attributes { char *name; } IDENT
 @attributes { long val; } NUM
 @attributes { struct symbol *f; int paramges; int parms; } Parms
-@attributes { struct symbol *f; } FeldID Structdef Program
+@attributes { struct symbol *f; int soffset; } Program
+@attributes { struct symbol *f; int soffset; int offsetcount; } FeldID Structdef
 @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 Term Multerm Orterm
@@ -55,6 +56,7 @@ Input:
          Program
          @{
            @i @Program.f@ = tab_new();
+               @i @Program.soffset@ = 0;
            @gen @revorder(1) printf("\t.text\n");
          @}
        ;
@@ -64,11 +66,14 @@ Program:
          @{
            @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);
+               @i @Structdef.offsetcount@ = @Program.0.soffset@;
+               @i @Program.1.soffset@ = @Structdef.soffset@;
          @}
        |
        ;
@@ -87,6 +92,8 @@ Structdef:
          STRUCT FeldID END
          @{
            @i @Structdef.f@ = @FeldID.f@;
+               @i @FeldID.offsetcount@ = @Structdef.offsetcount@;
+               @i @Structdef.soffset@ = @FeldID.soffset@;
          @}
        ;
 
@@ -94,9 +101,9 @@ Parms:
          /* lokale Vars werden in Statement in die tabelle eingefuegt */
          IDENT Parms
          @{
-           @i @Parms.1.parms@ = @Parms.parms@ + 1;
+           @i @Parms.1.parms@ = @Parms.0.parms@ + 1;
                @i @Parms.0.paramges@ = @Parms.1.paramges@;
-           @i @Parms.0.f@ = tab_add_symbol(@Parms.1.f@, @IDENT.name@, S_PARM, 1, @Parms.parms@);
+           @i @Parms.0.f@ = tab_add_symbol(@Parms.1.f@, @IDENT.name@, S_PARM, 1, @Parms.parms@, -1);
          @}
 
        |
@@ -109,12 +116,16 @@ Parms:
 FeldID:
          IDENT FeldID
          @{
-           @i @FeldID.0.f@ = tab_add_symbol(@FeldID.1.f@, @IDENT.name@, S_FIELD, 1, -1);
+           @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.soffset@ = @FeldID.offsetcount@;
          @}
        ;
 
@@ -142,7 +153,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, -1);
+               @i @Statement.sout@ = tab_add_symbol(tab_clone(@Statement.sin@), @IDENT.name@, S_VAR, 1, -1, -1);
                xxputsin(@Expr.s@,)
            @i @Statement.node@ = TREENULL;
          @}
index dc11f878318a6c4cc56450778a6ad93ca2d62a19..b38500040d542ab5fce25f7226da6b2ce2009237 100755 (executable)
@@ -21,18 +21,18 @@ struct symbol *tab_clone(struct symbol *tab)
 #endif
 
        while(elm != SYMNULL) {
-               ntab = tab_add_symbol(ntab, elm->ident, elm->type, 0, elm->param_index ? elm->param_index : 0);
+               ntab = tab_add_symbol(ntab, elm->ident, elm->type, 0, elm->param_index, elm->soffset);
                elm = elm->next;
        }
        return ntab;
 }
 
-struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short check, int param_index)
+struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short check, int param_index, int soffset)
 {
        struct symbol *elm = tab;
        struct symbol *new_elm;
 #ifdef DD
-       fprintf(stderr, "tab_add_symbol: tab(%08X), ident(%s), type(%i), check(%i), param_index(%i)\n", tab, ident, type, check, param_index);
+       fprintf(stderr, "tab_add_symbol: tab(%08X), ident(%s), type(%i), check(%i), param_index(%i), soffset(%i)\n", tab, ident, type, check, param_index, soffset);
 #endif
 
        if(param_index >= 6) {
@@ -53,9 +53,8 @@ struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short
        new_elm->next = SYMNULL;
        new_elm->ident = strdup(ident);
        new_elm->type = type;
-       if(type == S_PARM) {
-               new_elm->param_index = param_index;
-       }
+       new_elm->param_index = param_index;
+       new_elm->soffset = soffset;
 
        if(tab == SYMNULL) {
                return new_elm;
@@ -96,7 +95,7 @@ struct symbol *tab_merge(struct symbol *tab, struct symbol *to_add, short check)
 #endif
        
        while(elm != SYMNULL) {
-               ntab = tab_add_symbol(ntab, elm->ident, elm->type, check, elm->param_index ? elm->param_index : 0);
+               ntab = tab_add_symbol(ntab, elm->ident, elm->type, check, elm->param_index, elm->soffset);
                elm = elm->next;
        }
 
index 5db4ed6d34dc419648efa9619c05fd7580d9a748..9892899a871ed7b692bd158535ec96911ee80a74 100755 (executable)
@@ -12,11 +12,12 @@ struct symbol {
        struct symbol *next;
        short type;
        int param_index;
+       int soffset;
 };
 
 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, int param_index);
+struct symbol *tab_add_symbol(struct symbol *tab, char *ident, short type, short check, int param_index, int soffset);
 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);