Fix bitfield selection operators to use c0 version of tree
authorNick Downing <downing.nick@gmail.com>
Fri, 10 Feb 2017 15:37:28 +0000 (02:37 +1100)
committerNick Downing <downing.nick@gmail.com>
Fri, 10 Feb 2017 15:37:28 +0000 (02:37 +1100)
13 files changed:
c12.c
c13.c
test/fld0.c [new file with mode: 0644]
test/fld0.dump [new file with mode: 0644]
test/fld0.s [new file with mode: 0644]
test/fld1.c [new file with mode: 0644]
test/fld1.dump [new file with mode: 0644]
test/fld1.s [new file with mode: 0644]
test/fld2.c [new file with mode: 0644]
test/fld2.dump [new file with mode: 0644]
test/fld2.s [new file with mode: 0644]
test/hello.dump [new file with mode: 0644]
test/hello.s [new file with mode: 0644]

diff --git a/c12.c b/c12.c
index 199f11e..c6e539e 100644 (file)
--- a/c12.c
+++ b/c12.c
 #define        max(a,b) (((a)>(b))?(a):(b))
 
 union tree *optim(tree1) register union tree *tree1; {
+ /*fprintf(stderr, "optim %d", tree1->t.op);
+ if ((opdope1[tree1->t.op] & LEAF) == 0)
+  fprintf(stderr, " left %d", tree1->t.tr1->t.op);
+ if (opdope1[tree1->t.op] & BINARY)
+  fprintf(stderr, " right %d", tree1->t.tr2->t.op);
+ fprintf(stderr, "\n");*/
        register int op, dope;
        int d1, d2;
        union tree *t;
@@ -311,6 +317,12 @@ union tree *optim(tree1) register union tree *tree1; {
 }
 
 union tree *unoptim(tree1) register union tree *tree1; {
+ /*fprintf(stderr, "unoptim %d", tree1->t.op);
+ if ((opdope1[tree1->t.op] & LEAF) == 0)
+  fprintf(stderr, " left %d", tree1->t.tr1->t.op);
+ if (opdope1[tree1->t.op] & BINARY)
+  fprintf(stderr, " right %d", tree1->t.tr2->t.op);
+ fprintf(stderr, "\n");*/
        register union tree *subtre, *p;
 
        if (tree1==NULL)
@@ -448,20 +460,24 @@ union tree *unoptim(tree1) register union tree *tree1; {
 
        case FSEL:
                tree1->t.op = AND;
              tree1->t.tr1 = tree1->t.tr2->t.tr1;
/*            tree1->t.tr1 = tree1->t.tr2->t.tr1;
                tree1->t.tr2->t.tr1 = subtre;
                tree1->t.tr2->t.op = RSHIFT;
-               tree1->t.tr1->c.value = (1 << tree1->t.tr1->c.value) - 1;
+               tree1->t.tr1->c.value = (1 << tree1->t.tr1->c.value) - 1;*/
+ tree1->t.tr1 = tconst1((1 << ((struct FS *)tree1->t.tr2)->flen) - 1, INT);
+ tree1->t.tr2 = tnode1(RSHIFT, INT, subtre, tconst1(((struct FS *)tree1->t.tr2)->bitoffs, INT));
                return(optim(tree1));
 
        case FSELR:
                tree1->t.op = LSHIFT;
                tree1->t.type = UNSIGN;
              tree1->t.tr1 = tree1->t.tr2;
/*            tree1->t.tr1 = tree1->t.tr2;
                tree1->t.tr1->t.op = AND;
                tree1->t.tr2 = tree1->t.tr2->t.tr2;
                tree1->t.tr1->t.tr2 = subtre;
-               tree1->t.tr1->t.tr1->c.value = (1 << tree1->t.tr1->t.tr1->c.value) -1;
+               tree1->t.tr1->t.tr1->c.value = (1 << tree1->t.tr1->t.tr1->c.value) -1;*/
+ tree1->t.tr1 = tnode1(AND, INT, tconst1((1 << ((struct FS *)tree1->t.tr2)->flen) - 1, INT), subtre);
+ tree1->t.tr2 = tconst1(((struct FS *)tree1->t.tr2)->bitoffs, INT);
                return(optim(tree1));
 
        case AMPER:
@@ -633,6 +649,7 @@ union tree *unoptim(tree1) register union tree *tree1; {
  * Pure assignment is handled specially.
  */
 
+/* note that t->t.tr1->t.op == FSEL */
 union tree *lvfield(t) register union tree *t; {
        register union tree *t1, *t2;
 
@@ -643,7 +660,9 @@ union tree *lvfield(t) register union tree *t; {
                t2->t.op = FSELA;
                t2->t.type = UNSIGN;
                t1 = t->t.tr1->t.tr2;
-               t2->F.mask = ((1<<t1->t.tr1->c.value)-1)<<t1->t.tr2->c.value;
+ /* t1 formerly pointed to a COMMA node holding 2 constants */
+ /* now it contains its pass 0 value which is the field descriptor */
+               t2->F.mask = ((1<</*t1->t.tr1->c.value*/((struct FS *)t1)->flen)-1)<</*t1->t.tr2->c.value*/((struct FS *)t1)->bitoffs;
                t2->t.tr1 = t->t.tr1;
                t2->t.tr2 = t->t.tr2;
                t = t2;
@@ -657,14 +676,22 @@ union tree *lvfield(t) register union tree *t; {
        case INCAFT:
        case DECBEF:
        case DECAFT:
+ /*t=ASANDN(FSEL(mos,COMMA(flen,bitoffs)),arg)*/
                t1 = t->t.tr1;
+ /*t1=FSEL(mos,COMMA(flen,bitoffs))*/
                t1->t.op = FSELR;
+ /*t1=FSELR(mos,COMMA(flen,bitoffs))*/
                t->t.tr1 = t1->t.tr1;
+ /*t=ASANDN(mos,arg)*/
                t1->t.tr1 = t->t.tr2;
+ /*t1=FSELR(arg,COMMA(flen,bitoffs))*/
                t->t.tr2 = t1;
+ /*t=ASANDN(mos,FSELR(arg,COMMA(flen,bitoffs)))*/
                t1 = t1->t.tr2;
-               t1 = tnode1(COMMA, INT, tconst1(t1->t.tr1->c.value, INT),
-                       tconst1(t1->t.tr2->c.value, INT));
+ /*t1=COMMA(flen,bitoffs)*/
+               /*t1 = tnode1(COMMA, INT, tconst1(t1->t.tr1->c.value, INT),
+                       tconst1(t1->t.tr2->c.value, INT));*/
+ /*t1=COMMA(flen,bitoffs)*/
                return(optim(tnode1(FSELT, UNSIGN, t, t1)));
 
        }
diff --git a/c13.c b/c13.c
index 4d3f62e..da40457 100644 (file)
--- a/c13.c
+++ b/c13.c
@@ -23,7 +23,7 @@ int opdope1[] = {
        007001, /* , */
        000000, /* field selection (10) */
        000000, /* reverse field selection */
-       000001, /* temporary field selection */
+       /*000001*/000000,       /* temporary field selection */
        000001, /* int->ptr */
        000001, /* ptr->int */
        000001, /* long->ptr */
diff --git a/test/fld0.c b/test/fld0.c
new file mode 100644 (file)
index 0000000..45a559e
--- /dev/null
@@ -0,0 +1,8 @@
+struct silly {
+  int i : 5;
+  int j : 5;
+} a;
+void main() {
+  a.i = 12;
+  a.j = 13;
+}
diff --git a/test/fld0.dump b/test/fld0.dump
new file mode 100644 (file)
index 0000000..7d54f3b
--- /dev/null
@@ -0,0 +1,33 @@
+CSPACE a 2
+SYMDEF main
+PROG
+RLABEL main
+SAVE
+SETREG 5
+BRANCH 1
+LABEL 2
+NAME EXTERN UNSIGN a
+AMPER PTR,UNSIGN
+CON INT 0
+PLUS PTR,UNSIGN
+STAR UNSIGN
+FSEL UNSIGN 0 5
+CON INT 12
+ASSIGN UNSIGN
+EXPR 6
+NAME EXTERN UNSIGN a
+AMPER PTR,UNSIGN
+CON INT 0
+PLUS PTR,UNSIGN
+STAR UNSIGN
+FSEL UNSIGN 5 5
+CON INT 13
+ASSIGN UNSIGN
+EXPR 7
+LABEL 3
+RETRN
+LABEL 1
+SETSTK 0
+BRANCH 2
+EOFC
+*EOFC
diff --git a/test/fld0.s b/test/fld0.s
new file mode 100644 (file)
index 0000000..12b257f
--- /dev/null
@@ -0,0 +1,15 @@
+.comm  _a,2
+.globl _main
+.text
+_main:
+~~main:
+jsr    r5,csv
+jbr    L1
+L2:bic $37,_a
+bis    $14,_a
+bic    $1740,_a
+bis    $640,_a
+L3:jmp cret
+L1:jbr L2
+.globl
+.data
diff --git a/test/fld1.c b/test/fld1.c
new file mode 100644 (file)
index 0000000..6bc9e27
--- /dev/null
@@ -0,0 +1,10 @@
+struct silly {
+  int i : 5;
+  int j : 5;
+} a;
+void main() {
+  int i = 12;
+  int j = 13;
+  a.i = i;
+  a.j = j;
+}
diff --git a/test/fld1.dump b/test/fld1.dump
new file mode 100644 (file)
index 0000000..fa5491b
--- /dev/null
@@ -0,0 +1,43 @@
+CSPACE a 2
+SYMDEF main
+PROG
+RLABEL main
+SAVE
+SETREG 5
+BRANCH 1
+LABEL 2
+NAME AUTO INT -10
+CON INT 12
+ASSIGN INT
+EXPR 6
+ANAME i -10
+NAME AUTO INT -12
+CON INT 13
+ASSIGN INT
+EXPR 7
+ANAME j -12
+NAME EXTERN UNSIGN a
+AMPER PTR,UNSIGN
+CON INT 0
+PLUS PTR,UNSIGN
+STAR UNSIGN
+FSEL UNSIGN 0 5
+NAME AUTO INT -10
+ASSIGN UNSIGN
+EXPR 8
+NAME EXTERN UNSIGN a
+AMPER PTR,UNSIGN
+CON INT 0
+PLUS PTR,UNSIGN
+STAR UNSIGN
+FSEL UNSIGN 5 5
+NAME AUTO INT -12
+ASSIGN UNSIGN
+EXPR 9
+LABEL 3
+RETRN
+LABEL 1
+SETSTK 4
+BRANCH 2
+EOFC
+*EOFC
diff --git a/test/fld1.s b/test/fld1.s
new file mode 100644 (file)
index 0000000..93ced2a
--- /dev/null
@@ -0,0 +1,25 @@
+.comm  _a,2
+.globl _main
+.text
+_main:
+~~main:
+jsr    r5,csv
+jbr    L1
+L2:mov $14,-12(r5)
+~i=177766
+mov    $15,-14(r5)
+~j=177764
+mov    -12(r5),r0
+bic    $-40,r0
+bic    $37,_a
+bis    r0,_a
+mov    -14(r5),r0
+bic    $-40,r0
+ash    $5,r0
+bic    $1740,_a
+bis    r0,_a
+L3:jmp cret
+L1:sub $4,sp
+jbr    L2
+.globl
+.data
diff --git a/test/fld2.c b/test/fld2.c
new file mode 100644 (file)
index 0000000..a5d0875
--- /dev/null
@@ -0,0 +1,10 @@
+struct silly {
+  int i : 5;
+  int j : 5;
+} a;
+void main() {
+  int i = 12;
+  int j = 13;
+  a.i += i;
+  a.j += j;
+}
diff --git a/test/fld2.dump b/test/fld2.dump
new file mode 100644 (file)
index 0000000..0dbd5d4
--- /dev/null
@@ -0,0 +1,43 @@
+CSPACE a 2
+SYMDEF main
+PROG
+RLABEL main
+SAVE
+SETREG 5
+BRANCH 1
+LABEL 2
+NAME AUTO INT -10
+CON INT 12
+ASSIGN INT
+EXPR 6
+ANAME i -10
+NAME AUTO INT -12
+CON INT 13
+ASSIGN INT
+EXPR 7
+ANAME j -12
+NAME EXTERN UNSIGN a
+AMPER PTR,UNSIGN
+CON INT 0
+PLUS PTR,UNSIGN
+STAR UNSIGN
+FSEL UNSIGN 0 5
+NAME AUTO INT -10
+ASPLUS UNSIGN
+EXPR 8
+NAME EXTERN UNSIGN a
+AMPER PTR,UNSIGN
+CON INT 0
+PLUS PTR,UNSIGN
+STAR UNSIGN
+FSEL UNSIGN 5 5
+NAME AUTO INT -12
+ASPLUS UNSIGN
+EXPR 9
+LABEL 3
+RETRN
+LABEL 1
+SETSTK 4
+BRANCH 2
+EOFC
+*EOFC
diff --git a/test/fld2.s b/test/fld2.s
new file mode 100644 (file)
index 0000000..ece24b9
--- /dev/null
@@ -0,0 +1,23 @@
+.comm  _a,2
+.globl _main
+.text
+_main:
+~~main:
+jsr    r5,csv
+jbr    L1
+L2:mov $14,-12(r5)
+~i=177766
+mov    $15,-14(r5)
+~j=177764
+mov    -12(r5),r0
+bic    $-40,r0
+add    r0,_a
+mov    -14(r5),r0
+bic    $-40,r0
+ash    $5,r0
+add    r0,_a
+L3:jmp cret
+L1:sub $4,sp
+jbr    L2
+.globl
+.data
diff --git a/test/hello.dump b/test/hello.dump
new file mode 100644 (file)
index 0000000..ae6e52c
--- /dev/null
@@ -0,0 +1,84 @@
+SYMDEF main
+PROG
+RLABEL main
+SAVE
+SETREG 5
+BRANCH 1
+LABEL 2
+ANAME fp -10
+*LABEL 4
+*BDATA 'h 'e 'l 'l 'o ', 32 '% 's 32 '% '. '* 's
+*BDATA 32 '% '5 '. '2 'f 10 0
+*LABEL 5
+*BDATA 'w 'o 'r 'l 'd 0
+*LABEL 6
+*BDATA 'f 'u 'n 0
+NAME EXTERN FUNC,INT printf
+NAME STATIC CHAR 4
+AMPER PTR,CHAR
+NAME STATIC CHAR 5
+AMPER PTR,CHAR
+COMMA INT
+CON INT 2
+COMMA INT
+NAME STATIC CHAR 6
+AMPER PTR,CHAR
+COMMA INT
+FCON DOUBLE 3.14159
+COMMA INT
+CALL INT
+EXPR 7
+*LABEL 7
+*BDATA 'h 'e 'l 'l 'o '. 't 'x 't 0
+*LABEL 8
+*BDATA 'w 0
+NAME AUTO PTR,STRUCT -10
+NAME EXTERN FUNC,PTR,STRUCT fopen
+NAME STATIC CHAR 7
+AMPER PTR,CHAR
+NAME STATIC CHAR 8
+AMPER PTR,CHAR
+COMMA INT
+CALL PTR,STRUCT
+ASSIGN PTR,STRUCT
+EXPR 8
+NAME AUTO PTR,STRUCT -10
+CON INT 0
+EQUAL INT
+CBRANCH 9 0 9
+*LABEL 10
+*BDATA 'h 'e 'l 'l 'o '. 't 'x 't 0
+NAME EXTERN FUNC,INT perror
+NAME STATIC CHAR 10
+AMPER PTR,CHAR
+CALL INT
+EXPR 10
+NAME EXTERN FUNC,INT exit
+CON INT 1
+CALL INT
+EXPR 11
+LABEL 9
+*LABEL 11
+*BDATA 'h 'e 'l 'l 'o ', 32 'w 'o 'r 'l 'd 10 0
+NAME EXTERN FUNC,INT fprintf
+NAME AUTO PTR,STRUCT -10
+NAME STATIC CHAR 11
+AMPER PTR,CHAR
+COMMA INT
+CALL INT
+EXPR 13
+NAME EXTERN FUNC,INT fclose
+NAME AUTO PTR,STRUCT -10
+CALL INT
+EXPR 14
+CON INT 0
+RFORCE INT
+EXPR 15
+BRANCH 3
+LABEL 3
+RETRN
+LABEL 1
+SETSTK 2
+BRANCH 2
+EOFC
+*EOFC
diff --git a/test/hello.s b/test/hello.s
new file mode 100644 (file)
index 0000000..f511a62
--- /dev/null
@@ -0,0 +1,51 @@
+.globl _main
+.text
+_main:
+~~main:
+jsr    r5,csv
+jbr    L1
+L2:~fp=177766
+.data
+L10000:40511;7717;100334;31562
+.text
+movf   L10000,r0
+movf   r0,-(sp)
+mov    $L6,-(sp)
+mov    $2,-(sp)
+mov    $L5,-(sp)
+mov    $L4,-(sp)
+jsr    pc,_printf
+add    $20,sp
+mov    $L8,(sp)
+mov    $L7,-(sp)
+jsr    pc,*$_fopen
+tst    (sp)+
+mov    r0,-12(r5)
+tst    -12(r5)
+jne    L9
+mov    $L10,(sp)
+jsr    pc,*$_perror
+mov    $1,(sp)
+jsr    pc,*$_exit
+L9:mov $L11,(sp)
+mov    -12(r5),-(sp)
+jsr    pc,*$_fprintf
+tst    (sp)+
+mov    -12(r5),(sp)
+jsr    pc,*$_fclose
+clr    r0
+jbr    L3
+L3:jmp cret
+L1:tst -(sp)
+jbr    L2
+.globl fltused
+.globl
+.data
+L4:.byte 150,145,154,154,157,54,40,45,163,40,45,56,52,163
+.byte 40,45,65,56,62,146,12,0
+L5:.byte 167,157,162,154,144,0
+L6:.byte 146,165,156,0
+L7:.byte 150,145,154,154,157,56,164,170,164,0
+L8:.byte 167,0
+L10:.byte 150,145,154,154,157,56,164,170,164,0
+L11:.byte 150,145,154,154,157,54,40,167,157,162,154,144,12,0