changeset 556:ef225b589888 s-dandy-work

s-dandy fix emit_copy register parallel rassign struct init alignment MIPS fregister save
author kono
date Fri, 06 Jan 2006 21:19:13 +0900
parents ac181d7f9c82
children c3053086f790
files .gdbinit Changes Idea Makefile mc-code-mips.c mc-code-powerpc.c mc-codegen.c mc-inline.c mc-macro.c mc-parse.c stdio.h test/bitfield1.c test/inline.c test/offset.c test/putenemy.c test/stralign.c
diffstat 16 files changed, 283 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/.gdbinit	Fri Jan 06 01:16:52 2006 +0900
+++ b/.gdbinit	Fri Jan 06 21:19:13 2006 +0900
@@ -49,4 +49,6 @@
 # run -DINLINE=inline test/scope.c
 # run -DINLINE=inline test/code-gen-all.c
 # run  -DINLINE=inline test/bitfield1.c
-run -s test/linux_kernel.c.--- 
+# run -s test/linux_kernel.c.--- 
+# run -s test/stralign.c
+run -s test/putenemy.c
--- a/Changes	Fri Jan 06 01:16:52 2006 +0900
+++ b/Changes	Fri Jan 06 21:19:13 2006 +0900
@@ -7908,4 +7908,44 @@
 ia32 では emit_pop_free で creg かどうか見てるみたいね。それでも
 いいんだけど...
 
-
+Fri Jan  6 13:31:32 JST 2006
+
+gen_inline で、peval してstatementがない時には、生成しないんだよね。
+ということは、argument のgexpr もなんとかしないといけないわけね。
+
+argument のreplaceは、lvalue でやらないと話がわやになってしまう。
+ってことは、de_ravlue っていうか lvalue() あるいは、paddress
+を通さないとダメなのね。
+
+
+##       spview[counttag]=spview[enemyfaste];^M
+## 904: : creg=$2 freg=$f12
+        la $11,spview
+        move $2,$11
+        li $10,24
+        la $8,enemyfaste
+        lw $9,0($8)
+        mult $9,$9,$10
+        addu $9,$9,$2
+        move $10,$11
+        li $7,24
+        lw $6,-92($fp)
+        mult $6,$6,$7
+        addu $6,$6,$10
+        li $6,24
+        move $5,$9
+        move $4,$6
+        jal memmove
+
+あーぁ、やってるよ。$6 にものの見事に上書きか。parallel assign している
+はずなんだけどね。
+
+emit_copy がparallel assign してませんでした。ARM を作ったときに
+いれたと思ったんだけどね。
+
+Fri Jan  6 19:19:16 JST 2006
+
+MIPS のfloat register の save_stackが間違ってました。
+
+PowerPC の math.h のinlcude がうまくいきません。
+
--- a/Idea	Fri Jan 06 01:16:52 2006 +0900
+++ b/Idea	Fri Jan 06 21:19:13 2006 +0900
@@ -1669,3 +1669,9 @@
 
 やっぱり。setjmp = return みたいにする? それはそれで、
 やさしいんだけど....
+
+
+Fri Jan  6 20:26:24 JST 2006
+
+environment = interface frame の切替えを用意しないとね。
+
--- a/Makefile	Fri Jan 06 01:16:52 2006 +0900
+++ b/Makefile	Fri Jan 06 21:19:13 2006 +0900
@@ -93,11 +93,13 @@
 	make check-inline TARGET=test/code-gen-all
 	make check TARGET=test/bitfield
 	make check TARGET=test/bitfield1
+	make check-inline TARGET=test/bitfield1
 	make check TARGET=test/cext
 	make check TARGET=test/const
 	make check TARGET=test/void_code
 	make check TARGET=test/putenemy
 	make check TARGET=test/inline
+	make check TARGET=test/offset
 #	make check TARGET=test/scope STDFLAG="-std=gnu99"
 #	make check-inline TARGET=test/scope STDFLAG="-std=gnu99"
 #MK =-make
--- a/mc-code-mips.c	Fri Jan 06 01:16:52 2006 +0900
+++ b/mc-code-mips.c	Fri Jan 06 21:19:13 2006 +0900
@@ -26,7 +26,7 @@
 #define __inline__\n\
 #define __STDC__ 1\n\
 #define __SIZE_TYPE__ int\n\
-#define __externsion__\n\
+#define __extension__\n\
 #define __attribute__(a)\n\
 #define __flexarr\n\
 #define __WCHAR_TYPE__ int\n\
@@ -1542,6 +1542,7 @@
     char *trn;
     char *drn;
     char *memmove = "memmove";
+    int l;
     int dreg = get_register(); if (!dreg) error(-1);
 
     drn	 = register_name(dreg);
@@ -1587,10 +1588,11 @@
 	}
 	clear_ptr_cache();
 	code_save_stacks();
+
+	l = list3(4,0,to);
+	l = list3(5,l,from);
+	parallel_rassign(l);
 	printf("\tli $6,%d\n",length>0?length:-length);
-	printf("\tmove $5,%s\n",frn);
-	// offset should not be used
-	printf("\tmove $4,%s\n",trn);
         /* overrap must be allowed */
 	if (is_code(fnptr)) {
 	    printf("\tla\t$25,%s\n",memmove);
@@ -5269,7 +5271,7 @@
     for(i=0;i<freg_sp;i++) {
         if ((reg=freg_stack[i])>=0) {
             code_dassign_lvar(
-                (freg_stack[i]=new_lvar(SIZE_OF_DOUBLE)),reg,1); 
+                (freg_stack[i]=new_lvar(SIZE_OF_FLOAT)),reg,0); 
             freg_stack[i]= freg_stack[i]-REG_LVAR_OFFSET;
 	    free_register(reg);
         }
--- a/mc-code-powerpc.c	Fri Jan 06 01:16:52 2006 +0900
+++ b/mc-code-powerpc.c	Fri Jan 06 21:19:13 2006 +0900
@@ -1159,8 +1159,8 @@
 	if(r!=reg)
 	    printf("\tmr %s,%s\n",crn,rrn);
     } else if (LARGE_OFFSET(offset)) {
-	printf("\tla   %s,ha16(%d)(%s)\n",crn,offset,rrn);
-	printf("\taddi %s,%s,lo16(%d)\n",crn,crn,offset);
+	printf("\tla   %s,lo16(%d)(%s)\n",crn,offset,rrn);
+	printf("\taddis %s,%s,ha16(%d)\n",crn,crn,offset);
     } else
 	printf("\taddi %s,%s,%d\n",crn,rrn,offset);
 }
@@ -1171,8 +1171,8 @@
     char *crn = register_name(reg);
     char *rrn = register_name(r);
     if (LARGE_OFFSET(offset)) {
-	printf("\tla   %s,ha16(%d)(%s)\n",crn,offset,rrn);
-	printf("\t%s %s,%s,lo16(%d)\n",ld,crn,crn,offset);
+	printf("\taddis %s,%s,ha16(%d)\n",crn,rrn,offset);
+	printf("\t%s %s,lo16(%d)(%s)\n",ld,crn,offset,crn);
     } else
 	printf("\t%s %s,%d(%s)\n",ld,crn,offset,rrn);
 }
@@ -1185,8 +1185,8 @@
     char *lrn;
     if (offset<-32768||32767<offset) {
 	lrn = register_name(reg = get_register());
-	printf("\tla   %s,ha16(%d)(%s)\n",lrn,offset,rrn);
-	printf("\t%s %s,%s,lo16(%d)\n",ld,crn,lrn,offset);
+	printf("\taddis %s,%s,ha16(%d)\n",lrn,rrn,offset);
+	printf("\t%s %s,lo16(%d)(%s)\n",ld,crn,offset,lrn);
 	free_register(reg);
     } else
 	printf("\t%s %s,%d(%s)\n",ld,crn,offset,rrn);
@@ -1548,6 +1548,7 @@
     char *trn;
     char *drn;
     char *memmove = "memmove";
+    int l;
     int dreg = get_register(); if (!dreg) error(-1);
 
     drn	 = register_name(dreg);
@@ -1593,9 +1594,12 @@
 	}
 	clear_ptr_cache();
 	code_save_stacks();
+
+        l = list3(3,0,to);
+        l = list3(4,l,from);
+        parallel_rassign(l);
+
 	printf("\tli r5,%d\n",length>0?length:-length);
-	printf("\tmr r4,%s\n",frn);
-	printf("\tmr r3,%s\n",trn);
 	/* offset should be ignored */
         /* overrap must be allowed */
 	printf("\tbl L_%s$stub\n",memmove);
--- a/mc-codegen.c	Fri Jan 06 01:16:52 2006 +0900
+++ b/mc-codegen.c	Fri Jan 06 21:19:13 2006 +0900
@@ -19,6 +19,8 @@
 int bit_of_byte;
 int endian;
 
+#define STRUCT_ALIGN 1
+
 static void assign(int e1);
 #if ASM_CODE
 static void gen_asm(int asm0,int in,int out,int opt,int e);
@@ -456,10 +458,16 @@
 	iassop(e1);
 	return INT;
 #if FLOAT_CODE
-    case FASS: case DASS: 
+    case FASS: 
+	dassign(e1);
+	return FLOAT;
+    case DASS: 
 	dassign(e1);
 	return DOUBLE;
-    case DASSOP: case FASSOP:
+    case FASSOP:
+	dassop(e1);
+	return FLOAT;
+    case DASSOP: 
 	dassop(e1);
 	return DOUBLE;
 #endif
@@ -2726,7 +2734,7 @@
     int assign = 0;
     char *p;
 
-    printf("## asm\n");
+//    printf("## asm\n");
     e = reverse0(e);
     for(i=out;i;i=cadr(i)) {
 	p = (char*)cadr(car(i));
@@ -2815,10 +2823,12 @@
 	    error(-1);
 #endif
 	}  else {
+#if STRUCT_ALIGN 
 	    sz = size(type0);
             if (sz%size_of_int==0) {
                 disp = ((disp+(size_of_int-1))&~(size_of_int-1));
             }
+#endif
 	}
 	if (n!=&null_nptr)
 	    fields = list4(type,fields,(int)(n->nm),disp);
@@ -3096,6 +3106,14 @@
 {
     int ass,sz,bfd;
 
+#if STRUCT_ALIGN
+    if (t!=-99) {
+	sz = size(t);
+	if (sz%size_of_int==0) {
+	    offset = ((offset+(size_of_int-1))&~(size_of_int-1));
+	}
+    }
+#endif
     if (car(e)==ADDRESS||car(e)==GVAR) {
 	if (scalar(t)) {
 	    t = list2(POINTER,VOID); // fake
@@ -3128,7 +3146,7 @@
 	if (!is_const(e)) error(INERR);
 	else emit_data(e,t,n);
     } else if(mode==SFDINIT) {
-printf("## %d sfdinit c0(e)=%d type=%d t=%d offset=%d\n",lineno,car(e),type,t,offset);
+// printf("## %d sfdinit c0(e)=%d type=%d t=%d offset=%d\n",lineno,car(e),type,t,offset);
 	decl_str_init=insert_ascend(decl_str_init,
 		list4(offset,0,e,list2(t,type)),str_init_eq);
     } else {
@@ -3175,7 +3193,7 @@
             assign_data(list2(CONST,offset-offset0),EMPTY,n,offset0);
         }
         type=cadr(cadddr(decl_str_init));
-printf("## %d flush   c0(e)=%d type=%d t=%d offset=%d\n",lineno,car(e),type,t,offset);
+// printf("## %d flush   c0(e)=%d type=%d t=%d offset=%d\n",lineno,car(e),type,t,offset);
         offset0 = assign_data(e,t,n,offset);
         decl_str_init = cadr(decl_str_init);
     }
@@ -4105,7 +4123,7 @@
 {
     int reg;
 if (car(e1)==BIT_FIELD) {
-    printf("## bit_field_bug\n");
+//    printf("## bit_field_bug\n");
     e1 = cadr(e1);
 }
     g_expr(e1);
--- a/mc-inline.c	Fri Jan 06 01:16:52 2006 +0900
+++ b/mc-inline.c	Fri Jan 06 21:19:13 2006 +0900
@@ -546,7 +546,7 @@
 static int
 pcomma(int e1,int e2)
 {
-    int e = pexpr(cadr(e1));
+    int e = pexpr(e1);
     return list3(COMMA,e,pexpr(e2));
 }
 
@@ -1130,8 +1130,12 @@
 	if (!anptr) break; // should not happen?
         t=caddr(e3);  // type
 	e4 = car(e3);
-	if (0 && is_const(e4) /* ||(is_memory(e3)&&is_readonly(e3)) */ ) {
-	    heap[pdisp+narg]=e4;
+	if ((has_attr(anptr,KONST) && !has_attr(anptr,HAS_ADDRESS)&& 
+		(is_const(e4) || (0 && is_memory(e4))))) {
+	    if (is_memory(e4))
+		heap[pdisp+narg]=rvalue_t(e4,t);
+	    else
+		heap[pdisp+narg]=e4;
 	} else {
 	    arg = heap[pdisp+narg]=list3(LVAR,new_lvar(size(t)),0);
 	    inline_lvars = glist2(arg,inline_lvars);
--- a/mc-macro.c	Fri Jan 06 01:16:52 2006 +0900
+++ b/mc-macro.c	Fri Jan 06 21:19:13 2006 +0900
@@ -164,7 +164,8 @@
     if (fp) {
 	p = name; 
     } else {
-	for(pp=include_path; *pp;pp++) {  // "" and <> case
+	// no deferenced on "" and <>?
+	for(pp=include_path; *pp;pp++) {
 	    p = expand_file_name(*pp,name);
 	    if(prev && nameeq(p,prev)) continue;
 	    if ((fp = fopen(p,"r"))) {
@@ -175,7 +176,7 @@
 		    break ;
 	    }
 	}
-        if (!fp && (end=='>'||filep->inc=='>')) {  // <> case only
+        if (!fp /* && (end=='>'||filep->inc=='>') */ ) {  // <> case only
 	    for(pp=l_include_path; *pp;pp++) {
 		p = expand_file_name(*pp,name);
 		if(prev && nameeq(p,prev)) continue;
--- a/mc-parse.c	Fri Jan 06 01:16:52 2006 +0900
+++ b/mc-parse.c	Fri Jan 06 21:19:13 2006 +0900
@@ -1525,7 +1525,7 @@
 			if (caddr(t) < i+1 ) {   /* too many data */
 			    // this check is sligtly odd (fix me)
 			    // error(INERR);
-			} else
+			} else if (!decl_str_init)
 			    assign_data(list2(CONST,caddr(t)-i),EMPTY,n,offset);
 		    }
 		    getsym(0);
--- a/stdio.h	Fri Jan 06 01:16:52 2006 +0900
+++ b/stdio.h	Fri Jan 06 21:19:13 2006 +0900
@@ -1,4 +1,4 @@
-#ifndef __micro_c__
+#ifndef __micro_c___
 #include "/usr/include/stdio.h"
 long long strtoll(const char *, char **, int);
 char *malloc(int);
--- a/test/bitfield1.c	Fri Jan 06 01:16:52 2006 +0900
+++ b/test/bitfield1.c	Fri Jan 06 21:19:13 2006 +0900
@@ -182,7 +182,7 @@
     main5();
     return 0;
 }
-INLINE
+INLINE   // too late
 void
 main5()
 {
--- a/test/inline.c	Fri Jan 06 01:16:52 2006 +0900
+++ b/test/inline.c	Fri Jan 06 21:19:13 2006 +0900
@@ -50,19 +50,19 @@
 
 extern int printf(char *,...);
 
-static inline const int f(int k)
+static inline const int f(const int k)
 {
     return k+1;
 }
 
-inline int in1(int i,int j)
+inline int in1(const int i,const int j)
 {
    if (i>j) return j;
    else return i;
 }
 
 static
-inline int ins(int i,int j)
+inline int ins(const int i,const int j)
 {
    printf("#0066:%d %d\n",i,j);
    if (f(i)>j) return j;
@@ -70,14 +70,14 @@
 }
 
 static
-inline int ins1(int i,int j, int k)
+inline int ins1(const int i,const int j, const int k)
 {
    printf("#0074:%d %d %d\n",i,j,k);
    if (f(i)>j) return j;
    else return i;
 }
 
-inline __attribute__((always_inline)) int in2(int p,int i,int j)
+inline __attribute__((always_inline)) int in2(const int p,int i,const int j)
 {
     int k = -20,m;
     int order=1;
--- a/test/offset.c	Fri Jan 06 01:16:52 2006 +0900
+++ b/test/offset.c	Fri Jan 06 21:19:13 2006 +0900
@@ -1,3 +1,4 @@
+extern int printf(const char *,...);
 
 #define BIT8 260
 #define BIT10 1030
@@ -7,7 +8,7 @@
 int midium[BIT12];
 int large[BIT16];
 
-
+int
 main0(int ac,char *av[])
 {
 int *p;
@@ -103,6 +104,7 @@
 
 }
 
+int
 main(int ac,char *av[])
 {
     int i=-1,j=-2,k=-3;
--- a/test/putenemy.c	Fri Jan 06 01:16:52 2006 +0900
+++ b/test/putenemy.c	Fri Jan 06 21:19:13 2006 +0900
@@ -1,4 +1,51 @@
+#include <math.h>
+
+// for rand
+#include <stdlib.h>
+
 extern int printf(char *,...);
+#define SANKAKU 100000
+
+static const double pi2 = M_PI * 2.0;
+
+int mysin[181];
+int mycos[181];
+
+void sankakuf()
+{
+    int i;
+    for(i=0;i<181;i++)
+    {
+        mysin[i]=sin(i /360.0*pi2)*SANKAKU;
+    }
+    for(i=0;i<181;i++)
+    {
+        mycos[i]=cos(i /360.0*pi2)*SANKAKU;
+    }
+}
+
+int Mycos(int c)
+{
+    c%=360;
+    if(c<0) c+=360;
+    if((c<=180))
+        return(mycos[c]);
+    if(c>180)
+        return(mycos[180-(c-180)]);
+    return(0);
+}
+
+int Mysin(int c)
+{
+    c%=360;
+    if(c<0) c+=360;
+    if(c<=180)
+        return(mysin[c]);
+    if(c>180)
+        return(mysin[180-(c-180)]*-1);
+    return(0);
+}
+
 void
 Putenemy(int charno,float x,float y,float sx,float sy,int move) {
      if(x)
@@ -10,10 +57,20 @@
 main()
 {
      int ix=32,iy=32; float fx=32,fy=32;
+     sankakuf();
+     printf("%d %d\n", Mysin(45),Mycos(-30));
+     {
+         float x=10,y=20;
+         Putenemy(3,x,y,(float) Mysin(15)*2/SANKAKU,(float)Mycos(15)*2/SANKAKU,0);
+         //Putenemy(3,x,y,(float) Mysin(15)*2.0/SANKAKU,(float)Mycos(15)*2.0/SANKAKU,0);
+         Putenemy(3,x,y,(float) Mysin(rand()%15*-1)*2/SANKAKU,(float)Mycos(rand()%15*-1)*2/SANKAKU,0);
+         // Putenemy(3,x,y,(float) Mysin(rand()%15*-1)*2.0/SANKAKU,(float)Mycos(rand()%15*-1)*2.0/SANKAKU,0);
+     }
      Putenemy(0,ix,iy,1,0,10);
      Putenemy(1,(float)ix,(float)iy,1,0,10);
      Putenemy(2,(float)ix,(float)iy,(float)ix,(float)iy,ix);
      Putenemy(3,(float)ix,(float)iy,(float)ix,0,ix);
      Putenemy(4,fx,fy,1,0,10);
+     return(0);
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/stralign.c	Fri Jan 06 21:19:13 2006 +0900
@@ -0,0 +1,110 @@
+
+extern int printf(const char *,...);
+
+#define BOOL char
+#define TRUE      1          // TRUE value
+#define FALSE     5          // FALSE value
+
+typedef struct player
+{
+  int x;
+  int y;
+  int ch;
+  int point;
+  BOOL  bf;
+  int muteki;
+  int zanki;
+  int ccount;
+}player;
+
+typedef struct laser
+{
+  float x;
+  float y;
+  float sx;
+  float sy;
+  int r;
+  int enemyno;
+}laser;
+
+typedef struct stge
+{
+  int stg;
+}stge;
+
+
+player jiki={60,200,3,0,FALSE,120,3,3};
+/*
+        .word   60
+        .word   200
+        .word   3
+        .word   0
+        .byte   0
+        .space  3
+        .word   120
+        .word   3
+        .word   3
+        .globl  lg
+        .align  2
+        .type    lg,@object
+        .size    lg,4
+
+ */
+
+stge lg={4096};
+
+/*
+        .word   4096
+        .globl  pg
+        .align  2
+        .type    pg,@object
+        .size    pg,4
+ */
+
+laser laser_lv3[64]={{0,0,0,0,64,0}};
+/*
+        .word   0x00000000              # 0 (float)
+        .word   0x00000000              # 0 (float)
+        .word   0x00000000              # 0 (float)
+        .word   0x00000000              # 0 (float)
+        .word   64
+        .word   0
+        .space  1512
+*/
+int se_key[6]={-1,-1,-1,-1,-1,-1};
+/*
+        .word   -1
+        .word   -1
+        .word   -1
+        .word   -1
+        .word   -1
+        .word   -1
+        .text
+*/
+
+
+int
+main()
+{
+
+    printf("%d\n",  jiki. x);
+    printf("%d\n",  jiki. y);
+    printf("%d\n",  jiki. ch);
+    printf("%d\n",  jiki. point);
+    printf("%d\n",  jiki.  bf);
+    printf("%d\n",  jiki. muteki);
+    printf("%d\n",  jiki. zanki);
+    printf("%d\n",  jiki. ccount);
+
+    printf("%g\n",    laser_lv3[0].x);
+    printf("%g\n",    laser_lv3[0].y);
+    printf("%g\n",    laser_lv3[0].sx);
+    printf("%g\n",    laser_lv3[0].sy);
+    printf("%d\n",    laser_lv3[0].r);
+    printf("%d\n",    laser_lv3[0].enemyno);
+
+    printf("%d\n",    lg.stg);
+
+
+
+}