changeset 186:6391432ca002

nkf binary fix
author kono
date Mon, 01 Dec 2003 15:36:22 +0900
parents 427008a06333
children dffcccf8b1cb
files Changes Makefile mc-code-ia32.c mc-code-powerpc.c mc-codegen.c mc-parse.c test/int.c
diffstat 7 files changed, 194 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Mon Dec 01 03:24:30 2003 +0900
+++ b/Changes	Mon Dec 01 15:36:22 2003 +0900
@@ -3630,3 +3630,48 @@
 
 やっぱり、nkf.c は、一発では動かないみたいね。compile は
 できたけどさ。
+
+   >> は符号依存 テストルーチンが入ってなかった
+
+うーん、K&Rの引数の順序が関数の引数とずれているときは、
+関数の順序の方を優先しないといけない... う、うーん。
+
+{
+   extern hoge...
+}
+
+int
+h_conv(f, c2, c1)
+    FILE  *f; int    c1, c2;
+
+まぁ、いろいろあるねぇ。
+
+#define hex(c)   (('0'<=c&&c<='9')?(c-'0'):\
+     ('A'<=c&&c<='F')?(c-'A'+10):('a'<=c&&c<='f')?(c-'a'+10):0)
+fprintf(stderr,"mime_getc h: %d c2 %d c3 %d\n",((hex(c2)<<4) + hex(c3)),c2,c3);
+        return ((hex(c2)<<4) + hex(c3));
+
+ふむ。(?::)+(?::) みたいな時には、code-set-fixed-register のregistger
+が二ついるわけね。push できないの?
+
+    case COND:        /* a?0:1 should consider non-brach instruction */
+    case DCOND:
+    case FCOND:
+        d = (car(e1)==COND?INT:car(e1)==DCOND?DOUBLE:FLOAT);
+        e2=fwdlabel();
+        if(d==INT) emit_push(); else emit_dpush(d);
+        b_expr(cadr(e1),0,e2,0);
+        g_expr_u(assign_expr0(stack_top(d),caddr(e1),d,d));
+        jmp(e3=fwdlabel());
+        fwddef(e2);
+        g_expr_u(assign_expr0(stack_top(d),cadddr(e1),d,d));
+        fwddef(e3);
+        if (d==INT) emit_pop_free(emit_pop(0));
+        else emit_dpop_free(emit_dpop(d),d);
+        return t;
+
+は、あんまり良くない。register machine ならいいんだけど。
+結構、実装が変わるから、code-$(ARCH) に移した方がいいかな。
+
+
+
--- a/Makefile	Mon Dec 01 03:24:30 2003 +0900
+++ b/Makefile	Mon Dec 01 15:36:22 2003 +0900
@@ -97,6 +97,14 @@
 	-gcc $(TARGET).s $(MLIB)
 	-./a.out > $(TARGET).code-out
 
+tags:   tags-$(ARCH)
+
+tags-$(ARCH):  
+	ctags mc.h mc-code.h mc-code-$(ARCH).c  mc-codegen.c mc-codegen.h \
+		mc-parse.c mc-tree.c \
+	    conv/c.c conv/c.h \
+	    conv/conv.h conv/convdef.h 
+
 tar :
 	make clean
 	tar cBf - . | gzip > ../comp.tgz 
--- a/mc-code-ia32.c	Mon Dec 01 03:24:30 2003 +0900
+++ b/mc-code-ia32.c	Mon Dec 01 15:36:22 2003 +0900
@@ -542,6 +542,52 @@
     return xreg;
 }
 
+int
+stack_top(int type)
+{
+    int xreg;
+    if (type==INT) {
+        xreg = reg_stack[reg_sp];
+        if (xreg<= -REG_LVAR_OFFSET) {
+            return list2(LVAR,REG_LVAR_OFFSET+xreg);
+        } else {
+            return list2(REGISTER,xreg);
+        }
+    } else {
+        xreg = freg_stack[freg_sp];
+        if (xreg<= -REG_LVAR_OFFSET) {
+            return list2(LVAR,REG_LVAR_OFFSET+xreg);
+        else {
+            return list2(DREGISTER,xreg);
+        }
+    }
+    return xreg;
+}
+
+
+int
+stack_top(int type)
+{
+    int xreg;
+    if (type==INT) {
+        xreg = reg_stack[reg_sp];
+        if (xreg<= -REG_LVAR_OFFSET) {
+            return list2(LVAR,REG_LVAR_OFFSET+xreg);
+        } else {
+            return list2(REGISTER,xreg);
+        }
+    } else {
+        xreg = freg_stack[freg_sp];
+        if (xreg<= -REG_LVAR_OFFSET) {
+            return list2(LVAR,REG_LVAR_OFFSET+xreg);
+        else {
+            return list2(DREGISTER,xreg);
+        }
+    }
+    return xreg;
+}
+
+
 void 
 code_label(int labelno)
 {
--- a/mc-code-powerpc.c	Mon Dec 01 03:24:30 2003 +0900
+++ b/mc-code-powerpc.c	Mon Dec 01 15:36:22 2003 +0900
@@ -691,6 +691,28 @@
     return xreg;
 }
 
+int
+stack_top(int type)
+{
+    int xreg;
+    if (type==INT) {
+	xreg = reg_stack[reg_sp];
+	if (xreg<= -REG_LVAR_OFFSET) {
+	    return list2(LVAR,REG_LVAR_OFFSET+xreg);
+	} else {
+	    return list2(REGISTER,xreg);
+	}
+    } else {
+	xreg = freg_stack[freg_sp];
+	if (xreg<= -REG_LVAR_OFFSET) {
+	    return list2(LVAR,REG_LVAR_OFFSET+xreg);
+	} else {
+	    return list2(DREGISTER,xreg);
+	}
+    }
+    return xreg;
+}
+
 static int code_base;
 
 #define MAX_PTR_CACHE 10
@@ -1664,11 +1686,11 @@
 	regv[creg]=1;
 	return;
     case RSHIFT:
-	shift("srw",oreg);
+	shift("sraw",oreg);
 	regv[creg]=1;
 	return;
     case URSHIFT:
-	shift("sraw",oreg);
+	shift("srw",oreg);
 	regv[creg]=1;
 	return;
     }
@@ -1734,7 +1756,7 @@
 {
     char *crn = register_name(creg);
     char *rrn = register_name(reg);
-    printf("\t%s %s,%s,%s\n",op,crn,rrn,crn);
+    printf("\t%s %s,%s,%s\n",op,crn,crn,rrn);
 }
 
 void
--- a/mc-codegen.c	Mon Dec 01 03:24:30 2003 +0900
+++ b/mc-codegen.c	Mon Dec 01 15:36:22 2003 +0900
@@ -287,14 +287,14 @@
         d = (car(e1)==COND?INT:car(e1)==DCOND?DOUBLE:FLOAT);
 	e2=fwdlabel();
 	b_expr(cadr(e1),0,e2,0);
-	code_set_fixed_creg(0,d);
-	t = g_expr0(caddr(e1));
-	code_set_fixed_creg(1,t);
+        code_set_fixed_creg(0,d);
+        t = g_expr0(caddr(e1));
+        code_set_fixed_creg(1,t);
 	jmp(e3=fwdlabel());
 	fwddef(e2);
-	code_set_fixed_creg(0,d);
-	t = g_expr0(cadddr(e1));
-	code_set_fixed_creg(1,t);
+        code_set_fixed_creg(0,d);
+        t = g_expr0(cadddr(e1));
+        code_set_fixed_creg(1,t);
 	fwddef(e3);
 	return t;
     case STASS: 
--- a/mc-parse.c	Mon Dec 01 03:24:30 2003 +0900
+++ b/mc-parse.c	Mon Dec 01 15:36:22 2003 +0900
@@ -92,6 +92,7 @@
 static void set_converter(char *s);
 static void statement(void);
 static int correct_type(int e,int t);
+static int arg_reorder(int old_arg,int new_arg);
 
 
 static int struct_return  = 0;
@@ -428,9 +429,17 @@
 	getsym(0);
 	conv->register_();
     } else if(sym==EXTRN) {
-	getsym(0);
-	conv->extern_();
-	stmode=EXTRN;
+	if(mode==LDECL) {
+		getsym(0);
+		conv->static_();
+		mode=GDECL;
+		stmode=EXTRN;
+	} else if(mode==GDECL) {
+	    getsym(0);
+	    conv->extern_();
+	    stmode=EXTRN;
+	} else
+	    error(DCERR);
     } else if(sym==TYPEDEF) {
 	if(mode==GDECL) {
 		getsym(0);
@@ -1298,12 +1307,14 @@
     mode=ADECL;
     if (sym!=LC) {
 	reg_var=0;
-	args=0; fnptr->dsp=0;
+	arglist=fnptr->dsp;
+	args=fnptr->dsp=0;
 	while (sym!=LC) { /* argument declaration !ANSI */
 	    decl(); getsym(0);
 	}
-	fnptr->dsp=reverse0(fnptr->dsp);
 	disp = -args;
+	fnptr->dsp = arg_reorder(arglist,fnptr->dsp);
+	// fnptr->dsp = reverse0(fnptr->dsp);
     }
     /* reverse all argument offset (with size) */
     arglist = fnptr->dsp;
@@ -1362,10 +1373,45 @@
 
 /* function define */
 
+static int
+arg_reorder(int arg,int new_arg)
+{
+    /*	list4(type,fnptr->dsp,(int)n,size); */
+    int i,j,sz;
+    int dsp = 0;
+    NMTBL *n,*n1;
+// fprintf(stderr,"arg_reorder old:\n");
+    for(j=new_arg;j;j=cadr(j)) {
+	    n=(NMTBL *)caddr(j);
+// fprintf(stderr,"dsp %d %s sz %d type %d\n",n->dsp,n->nm,cadddr(j),car(j));
+    }
+// fprintf(stderr,"arg_reorder new:\n");
+    for(j=arg;j;j=cadr(j)) {
+	n=(NMTBL *)caddr(j);
+	for(i=new_arg;i;i=cadr(i)) {
+	    n1=(NMTBL *)caddr(i);
+	    if (!neqname(n1->nm,n->nm)) break;
+	    // if (n1==n) break;
+	}
+// fprintf(stderr,"dsp %d %s %s sz %d type %d\n",dsp,n->nm,n1->nm,cadddr(i),car(i));
+	if(n->sc==LVAR) {
+	    n->dsp = dsp;
+	    car(j)=car(i);
+	    caddr(j)=caddr(i);
+	    cadddr(j)=sz= cadddr(i);
+	    if (sz==1||sz==size_of_short) sz = size_of_int;
+	    dsp += sz;
+	}
+    }
+// fprintf(stderr,"arg_reorder end:\n");
+    return arg;
+}
+
 static void
 fdecl(NMTBL *n)
 {
     int sd = stypedecl;
+    int sarg;
     if(!chk) enter(n->nm);
     fnptr=n;
     retlabel=fwdlabel();
@@ -1378,11 +1424,13 @@
     n->sc = FUNCTION;
     mode=ADECL;
     if (sym!=LC) {
-	args=0; fnptr->dsp=0;
+	sarg = fnptr->dsp;
+	fnptr->dsp =args=0; 
 	while (sym!=LC) { /* argument declaration !ANSI */
 	    stmode=0;
 	    decl(); getsym(0);
 	}
+	fnptr->dsp = arg_reorder(reverse0(sarg),reverse0(fnptr->dsp));
     } else
 	fnptr->dsp=reverse0(fnptr->dsp);
     fdecl_struct(fnptr->ty); /* insert extra argument for struct passing */
@@ -1504,19 +1552,6 @@
     }
 }
 
-#if 0
-static void
-statement0(void);
-
-extern    void code_gexpr();
-static void
-statement(void)
-{
-    statement0();
-    code_gexpr();
-}
-#endif
-
 static void
 statement(void)
 {
--- a/test/int.c	Mon Dec 01 03:24:30 2003 +0900
+++ b/test/int.c	Mon Dec 01 15:36:22 2003 +0900
@@ -171,7 +171,11 @@
 
     g = 3.0;
     printf("%d:%d\t",n++,g);
-    g1 = g<<g;
+    g1 = g<<2;
+    g1 = g<<f;
+    printf("%d:%d\t",n++,g1);
+    g1 = g>>2;
+    g1 = g>>f;
     printf("%d:%d\t",n++,g1);
     g = g%g1;
     printf("%d:%d\t",n++,g);
@@ -183,6 +187,11 @@
     printf("%d:%d\t",n++,g);
     printf("\n");
 
+    g = -120;
+    g1 = g>>2;
+    g1 = g>>f;
+    printf("%d:%d\t",n++,g1);
+
     printf("simple unsigned ");
     f = f+f;
     printf("%d:%d\t",n++,f);