changeset 534:0f24e1dba811

*** empty log message ***
author kono
date Sat, 31 Dec 2005 01:25:25 +0900
parents 80b5058f0535
children c17f1ef0d2be
files Changes mc-code-ia32.c mc-code-powerpc.c mc-codegen.c mc-macro.c mc-parse.c test/basic.c test/inline.c
diffstat 8 files changed, 64 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Fri Dec 30 18:33:55 2005 +0900
+++ b/Changes	Sat Dec 31 01:25:25 2005 +0900
@@ -7689,6 +7689,14 @@
 一つにして型を持ち歩いた方がいいのか?
 
 配列のADDは、inline でどこに消えちゃったの?
+  (indirect で消しているみたいね)
 って、あと一つまでいったか。
 
-
+やっぱり offset がうまく動いてませんでした。
+
+お疲れ様。
+
+あぁ、-D が動いてないね。
+
+ia32 は  inline のregister_varをfreeしたことがなかったみたいだね。
+
--- a/mc-code-ia32.c	Fri Dec 30 18:33:55 2005 +0900
+++ b/mc-code-ia32.c	Sat Dec 31 01:25:25 2005 +0900
@@ -343,10 +343,19 @@
 
 void 
 free_register(int i) {    /* いらなくなったレジスタを開放 */
+    if (i==REG_L) {
+	reg_var=0;
+	regv[virtual(REG_ESI)]=regv[virtual(REG_EDI)]=0;
+    } else if (regs[i]==REG_VAR) { reg_var--;
+    } else if(i==REG_LCREG) { //? REG_L?
+	regv[virtual(REG_EAX)]=regv[virtual(REG_EDX)]=0;
+    }
     regv[i]=regs[i]=0;
-    if(i==REAL_MAX_REGISTER) {
+#if 0
+    if(i==REAL_MAX_REGISTER) { //? REG_L?
 	regv[virtual(REG_ESI)]=regv[virtual(REG_EDI)]=0;
     }
+#endif
 }
 
 extern void
@@ -508,12 +517,14 @@
     int freg_var = 0;
     int type;
     int reg;
+    int offset = 0;
     int is_code0 = is_code(fnptr);
 
     while (args) {
         /* process in reverse order */
         n = (NMTBL*)caddr(args);
         type = n->ty;
+	// n->dsp = offset;
 // printf("###  %s %d %d\n",n->nm,n->dsp,n->ty);
         if (scalar(type)) {
             if ((reg = get_input_register_var(reg_var,n,is_code0))) {
@@ -524,6 +535,7 @@
                 reg_var++;
                 cadddr(args)=SIZE_OF_INT; /* why we need this? */
             }
+	    offset+=SIZE_OF_INT;
         } else if (type==FLOAT||type==DOUBLE) {
             if ((reg = get_input_dregister_var(freg_var,n,is_code0,1))) {
                 n->sc = DREGISTER;
@@ -533,7 +545,9 @@
                 freg_var++;
                 cadddr(args)=size(type); /* why we need this? */
             }
-        }
+	    offset+=size(type);
+        } else
+	    offset+=size(type);
         args = cadr(args);
     }
 }
@@ -598,13 +612,15 @@
 get_register_var(NMTBL *nptr)
 {
     int i;
-    for(i=REG_ESI;i<REG_EBP;i++) {
-        if (! regs[i]) {    /* 使われていないなら */
-            regs[i]=REG_VAR;      /* そのレジスタを使うことを宣言し */
-            regv[i]=0;
-	    regvar[reg_var++]=i;
-            return list3(REGISTER,i,(int)nptr); /* その場所を表す番号を返す */
-        }
+    if (reg_var<2) {
+	for(i=REG_ESI;i<REG_EBP;i++) {
+	    if (! regs[i]) {    /* 使われていないなら */
+		regs[i]=REG_VAR;      /* そのレジスタを使うことを宣言し */
+		regv[i]=0;
+		regvar[reg_var++]=i;
+		return list3(REGISTER,i,(int)nptr); /* その場所を表す番号を返す */
+	    }
+	}
     }
     return list3(LVAR,new_lvar(SIZE_OF_INT),0);
 }
--- a/mc-code-powerpc.c	Fri Dec 30 18:33:55 2005 +0900
+++ b/mc-code-powerpc.c	Sat Dec 31 01:25:25 2005 +0900
@@ -1800,6 +1800,7 @@
 	    offset+=SIZE_OF_LONGLONG; reg_offset+=2;
 	    reg_var += 2;
 	} else {
+	    // n->dsp = offset;  this is no allowed becase of arg reorder
 	    offset += size(n->ty);
 	    continue;
 	}
--- a/mc-codegen.c	Fri Dec 30 18:33:55 2005 +0900
+++ b/mc-codegen.c	Sat Dec 31 01:25:25 2005 +0900
@@ -2474,6 +2474,7 @@
 	n = (NMTBL*)car(e);
 	if (1 || n->sc==EXTRN || n->sc==EXTRN1 || has_attr(n,FNAME)) {  
             // global or used as pointer
+	    // generate possibly called inline function
 	    pfdecl(n);
 	}
     }
--- a/mc-macro.c	Fri Dec 30 18:33:55 2005 +0900
+++ b/mc-macro.c	Sat Dec 31 01:25:25 2005 +0900
@@ -528,7 +528,7 @@
 	nptr->ty = -1;
     }
     // equal is allowed for -Dhoge=aho option
-    if (ch=='=') chptr++;
+    // if (ch=='=') chptr++;
     while((c=*chptr)==' '||c=='\t') chptr++;
     nptr->dsp = list2((int)cheap->ptr,args); /* macro body */
     body = (char **)&car(nptr->dsp);
--- a/mc-parse.c	Fri Dec 30 18:33:55 2005 +0900
+++ b/mc-parse.c	Sat Dec 31 01:25:25 2005 +0900
@@ -506,8 +506,9 @@
 #ifdef bsd
     macro_define("bsd 1\n");
 #endif
-    for(i=0;av[i]&&av[i][0]=='-'&&av[i][1]=='D';i++) {
-	macro_define(av[i]+2);
+    for(i=0;av[i];i++) {
+	if (av[i][0]=='-'&&av[i][1]=='D')
+	    macro_define(av[i]+2);
     }
     current_scope = 0;
     enter_scope();
@@ -1800,8 +1801,11 @@
 {
     int e;
     int args,nargs,cargs;
+    int offset=0;
     NMTBL *a,*n1;
 
+    top_init();
+
     stmode = (n->sc==EXTRN||n->sc==EXTRN1)?EXTRN:STATIC;
     if(!chk) gen_enter(n->nm);
     extrn_use(n);
@@ -1824,7 +1828,8 @@
 	n1->sc = a->sc==IVAR?LVAR:a->sc;
 	n1->attr = a->attr;
 
-	n1->dsp = a->dsp; // def have to be called?
+	n1->dsp = offset;
+	offset+= (scalar(n1->ty))?size_of_int:size(n1->ty);
 
 	nargs=list4(car(args),nargs,(int)n1,cadddr(args));
     }
--- a/test/basic.c	Fri Dec 30 18:33:55 2005 +0900
+++ b/test/basic.c	Sat Dec 31 01:25:25 2005 +0900
@@ -1,5 +1,11 @@
 int printf(const char *format, ...);
 
+// #define INLINE inline
+#ifdef INLINE
+#else
+#define INLINE
+#endif
+
 
 #define ARG_ADDRESS 0
 
@@ -22,6 +28,7 @@
 extern float refff;
 #endif
 
+INLINE
 int
 print(double d)
 {
@@ -45,6 +52,7 @@
     return 1;
 }
 
+INLINE
 void
 tmp () {
     char c;
@@ -55,6 +63,7 @@
     printf("#0051:%d\n",i);
 }
 
+INLINE
 int 
 g(
 int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,int a8
@@ -66,6 +75,7 @@
     return a8;
 }
 
+INLINE
 int 
 i50(
 int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,int a8,int a9,int a10,int a11,int a12,int a13,int a14,int a15,int a16,int a17,int a18,int a19,int a20,int a21,int a22,int a23,int a24,int a25,int a26,int a27,int a28,int a29,int a30,int a31,int a32,int a33,int a34,int a35,int a36,int a37,int a38,int a39,int a40,int a41,int a42,int a43,int a44,int a45,int a46,int a47,int a48,int a49
@@ -80,6 +90,7 @@
     return a8;
 }
 
+INLINE
 float 
 f50(
 float a0,float a1,float a2,float a3,float a4,float a5,float a6,float a7,float a8,float a9,float a10,float a11,float a12,float a13,float a14,float a15,float a16,float a17,float a18,float a19,float a20,float a21,float a22,float a23,float a24,float a25,float a26,float a27,float a28,float a29,float a30,float a31,float a32,float a33,float a34,float a35,float a36,float a37,float a38,float a39,float a40,float a41,float a42,float a43,float a44,float a45,float a46,float a47,float a48,float a49
@@ -91,6 +102,7 @@
     return a8;
 }
 
+INLINE
 double 
 d50(
 double a0,double a1,double a2,double a3,double a4,double a5,double a6,double a7,double a8,double a9,double a10,double a11,double a12,double a13,double a14,double a15,double a16,double a17,double a18,double a19,double a20,double a21,double a22,double a23,double a24,double a25,double a26,double a27,double a28,double a29,double a30,double a31,double a32,double a33,double a34,double a35,double a36,double a37,double a38,double a39,double a40,double a41,double a42,double a43,double a44,double a45,double a46,double a47,double a48,double a49
@@ -103,6 +115,7 @@
 }
 
 
+INLINE
 int 
 h( int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,int a8)
 {
@@ -110,6 +123,7 @@
 }
 
 
+INLINE
 double 
 f(
 double a0,double a1,double a2,double a3,double a4,double a5,double a6,double a7,double a8
@@ -121,6 +135,7 @@
     return a8;
 }
 
+INLINE
 void 
 tmp1 () { 
 #if ARG_ADDRESS
@@ -167,6 +182,7 @@
 
 }
 
+INLINE
 void
 double_int()
 {
--- a/test/inline.c	Fri Dec 30 18:33:55 2005 +0900
+++ b/test/inline.c	Sat Dec 31 01:25:25 2005 +0900
@@ -60,15 +60,15 @@
 
 inline __attribute__((always_inline)) int in2(int p,int i,int j)
 {
-    int k = 0,m;
+    int k = -20,m;
     do {
 	k += 3;
     } while ( k < j);
     printf("#0065: %d do %d\n",p,k);
 
-    while (k < j) {
+    while (k > j) {
 	k -= 3;
-    } while ( k < j);
+    } 
     printf("#0070: %d while %d\n",p,k);
 
     m = 0;