changeset 53:64a4e3789fd2 parallel-assign

parallel assign works.
author kono
date Tue, 18 Feb 2003 20:14:19 +0900
parents ddaa1aa5b49b
children 1a6b6a7bdca6
files .gdbinit Idea mc-nop-386.c mc-parse.c test/arg.c test/fact-a.c test/tmp.c
diffstat 7 files changed, 127 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/.gdbinit	Mon Feb 17 13:06:18 2003 +0900
+++ b/.gdbinit	Tue Feb 18 20:14:19 2003 +0900
@@ -14,4 +14,4 @@
 end
 b error
 b errmsg
-r -s test/fact-a.c
+r -s test/arg.c
--- a/Idea	Mon Feb 17 13:06:18 2003 +0900
+++ b/Idea	Tue Feb 18 20:14:19 2003 +0900
@@ -1581,3 +1581,30 @@
 並列代入は出来たみたい。代入は小さいものを先にすべきなのか?
 まぁ、できりゃいいんだけど、横に避けるものが大きいのはいや
 だよね。
+
+Tue Feb 18 11:56:10 JST 2003
+
+overraped 用の emit_copy
+float/double
+long long
+
+Tue Feb 18 19:34:31 JST 2003
+
+code argument の符号を反転させると、list2(LVAR,offset)
+のoffsetがアドレスの方向と一致しているという前提が
+崩れる。それで、構造体の格納順序がずれてしまう...
+
+ということは... def(n) でcodeの時はargumentは、局所変数と同じ
+扱いでマイナス符号で処理した方が良い。
+
+できたみたい。でもさ、
+   
+int main( int ac, char *av[])
+{
+    int n;
+    goto arg1(0,1,2,3,4,return,environment);
+}
+
+って、きっと return 文がないと、文句を
+言われるよね。むむむ。
+
--- a/mc-nop-386.c	Mon Feb 17 13:06:18 2003 +0900
+++ b/mc-nop-386.c	Tue Feb 18 20:14:19 2003 +0900
@@ -34,7 +34,6 @@
 
 static int edx_setup() ;
 static int	lvar(int l);
-static int      cvar(int l);
 static void	jump(int e1, int env);
 static void    data_mode(char *name);
 static void    text_mode(void);
@@ -86,26 +85,28 @@
 static int func_disp_label;
 
 /*
-                                           -16  local2
-                                           -12  local1
-                                            -8  arg1
-                                            -4  arg2
-                                             0  arg3
-                                             0  (%edi)
-         local1 <----14 local variable       0  (%esi)
+                                           -16  -8 local2
+                                           -12  -4 local1
+                                            -8  8  arg3
+                                            -4  4  arg2
+                                             0  0  arg1
+         local2     -20 4                    0    (%edi)
+         local1 <-- -16 0 local variable     0    (%esi)
         %edi        -12  <- disp_offset          %ebp
         %esi         -8
         %ebx         -4
         %ebp = %esp   0
         %eip          4   <- arg_offset
-          arg1        8
+          arg1        8 0
+          arg2       12 4
             see enter/enter1/leave           see code_enter
  */
 int arg_offset = 8;
-int code_arg_offset = -4;
 int disp_offset = -12;
 int func_disp_offset = -12;
-int code_disp_offset = -4;
+int code_disp_offset = 0;
+int jump_offset = 0;
+
 int size_of_int = 4;
 int endian = 0;
 int MAX_REGISTER=6;         /* intel386のレジスタを4つまで使う*/
@@ -1106,7 +1107,7 @@
 		    return list2(assign_expr0(t,e1,ty,ty),e1);
 		} else {
 		    disp-=sz;
-		    g_expr(assign_expr0((e1=list2(LVAR,cvar(disp))),s,ty,ty));
+		    g_expr(assign_expr0((e1=list2(LVAR,disp)),s,ty,ty));
 		    return list2(assign_expr0(t,e1,ty,ty),-1);
 		}
 	    }
@@ -1214,16 +1215,15 @@
     int processing = 0;
 
     /* まず、サイズを計算しながら、決まった形に落す。 */
-    /* ここで、書込先アドレスを決める */
 
     arg_size = 0; regs = 0; max_regs = MAX_REGISTER_VAR-1;
     for (e3 = reverse0(caddr(e1)); e3; e3 = cadr(e3)) {	
 	e2 = car(e3); sz = size(ty=caddr(e3)); 
-	if (regs <= max_regs&&integral(ty)) {
+	if (regs <= max_regs&&scalar(ty)) {
 	    target=list4(list2(REGISTER,virtual((regs++)+REG_ESI)),
 		target,ty,e2);
 	} else {
-	    target=list4(list2(LVAR,cvar(arg_size)),
+	    target=list4(list2(LVAR,0),
 		target,ty,e2);
 	    arg_size += sz;
 	}
@@ -1235,8 +1235,10 @@
     /* disp を飛び先似合わせて修正 */
     if (fnptr->sc==CODE) {
 	if (-arg_size<disp) disp = -arg_size;
+	jump_offset = 0;
     } else {
 	if (disp_offset-arg_size<disp) disp = disp_offset-arg_size;
+	jump_offset = 0;
     }
 
     /*  複雑な式を前もって計算しておく     */
@@ -1246,9 +1248,14 @@
     for (e2 = target; e2; e2 = cadr(e2)) {	
 	t0=car(e2); s0=cadddr(e2);
 	sz=size(ty=caddr(e2));
+	if(car(t0)==LVAR) {
+	    /* ここで、書込先アドレスを決める */
+	    cadr(t0)=-arg_size+jump_offset;
+	    arg_size-=sz;
+	}
 	if (!is_simple(car(s0))) {
 	    disp-=sz;
-	    g_expr(assign_expr0((e4=list2(LVAR,cvar(disp))),s0,ty,ty));
+	    g_expr(assign_expr0((e4=list2(LVAR,disp)),s0,ty,ty));
 	    cadddr(e2)=e4;
 	    s0=e4;
         } else if (is_same_type(t0,s0)) {
@@ -1868,18 +1875,14 @@
 {
     code_disp_label=fwdlabel();
     printf("\tlea _%d(%%ebp),%%esp\n",code_disp_label);
-    /*
-    if(disp0) {
-	printf("\tsubl $%d,%%esp\n",disp0);
-    }
-     */
+
 printf("## args %d disp %d code_arg_offset=%d code_disp_offset=%d\n",args,disp,code_arg_offset,code_disp_offset); 
 }
 
 void
 code_leave(char *name)
 {
-    printf("\t.set _%d,%d\n",code_disp_label,cvar(disp));
+    printf("\t.set _%d,%d\n",code_disp_label,disp+code_disp_offset);
     printf("_%d:\n",labelno);
     printf("\t.size\t%s,_%d-%s\n",name,labelno,name);
     local_table();
@@ -2086,7 +2089,7 @@
 lvar(int l)
 {
     if (fnptr->sc==CODE) {
-	return (l<0)?  l+code_disp_offset: -l+code_arg_offset;
+	return l+code_disp_offset;
     } else if (l<0) {
 	return l+disp_offset;
     } else {
@@ -2094,10 +2097,5 @@
     }
 }
 
-int
-cvar(int l)
-{
-    return (fnptr->sc==CODE)?l:l+disp_offset;
-}
 
 /* end */
--- a/mc-parse.c	Mon Feb 17 13:06:18 2003 +0900
+++ b/mc-parse.c	Tue Feb 18 20:14:19 2003 +0900
@@ -678,8 +678,12 @@
     }
     nsc=ndsp=0;
     if(car(type)==FUNCTION) {	
-	fcheck(n);
-	return n;
+	if (n->sc==EXTRN || (mode==GDECL)) {
+	    fcheck(n);
+	    return n;
+	} else {
+	    type=list2(POINTER,type);
+	}
     }
     if (n->sc!=EMPTY && 
 	    !(n->sc==GVAR&&n->dsp==EXTRN) &&
@@ -732,10 +736,9 @@
 	nsc = TYPE;
 	break;
     case ADECL:
-	arglist = list2((int)n,arglist);
-	if (stmode==REGISTER && reg_var <MAX_REGISTER_VAR) {
-	    if (type!=CHAR && !scalar(type)) 
-		error(TYERR);
+	arglist = list3((int)n,arglist,0);
+	if (stmode==REGISTER && reg_var <MAX_REGISTER_VAR &&
+	    !(type!=CHAR && !scalar(type))) {
 	    n->sc = REGISTER;
 	    reg_var++;
 	    if (n->dsp==0) {
@@ -744,11 +747,11 @@
 		} 
 		use_register_var(n->dsp); /* it has now value in it */
 	    } 
+	    caddr(arglist)=size_of_int;
 	    return n;
 	}
 	n->sc = LVAR;
 	if(type==CHAR) {
-	    /* n->ty=INT; */
 	    if (n->dsp==0) {
 		n->dsp = args;
 		if (endian) 
@@ -760,6 +763,7 @@
 		n->dsp = args;
 	    args += sz;
 	}
+	caddr(arglist)=sz;
 	if(type==VOID) {
 	} else if (!scalar(type)) {
 	    if((t=car(type))==STRUCT || t==UNION) {
@@ -976,6 +980,8 @@
 void
 code_decl(NMTBL *n)
 {
+    int t;
+
     if (n->sc==EMPTY) n->sc = CODE;
     code_enter(n->nm);
     fnptr=n;
@@ -989,7 +995,12 @@
     }
     if (args) disp = -args;
     else args = -disp;
-    init_vars=0;
+    /* reverse all argument offset (with size) */
+    for(t=arglist;t;t=cadr(t)) {
+	n=(NMTBL *)car(t);
+	if(n->sc==LVAR)
+	    n->dsp = -n->dsp-caddr(t);
+    }
     /* local variable declaration */
     stmode=0;
     mode=STAT;
@@ -1091,7 +1102,7 @@
 void
 fcheck(NMTBL *n)
 {
-    if(mode!=GDECL||car(type)!=FUNCTION) error(DCERR);
+    if(!(mode==GDECL||mode==ADECL)||car(type)!=FUNCTION) error(DCERR);
     if(n->sc==FUNCTION) compatible(car(n->ty),cadr(type));
     else {
 	if(n->sc!=EMPTY) 
@@ -2023,6 +2034,8 @@
 	} else if(t==STRUCT || t==UNION) { 
 	    t = cadr(type); /* size */
 	    return list3(RSTRUCT,e,t);
+	} else if(t==FUNCTION) {
+	    return e;
 	} else if(t!=POINTER) error(TYERR);
     }
     switch(car(e)) {
@@ -2084,7 +2097,7 @@
 	    e=list2(INDIRECT,list3(ADD,e,list2(CONST,nptr->dsp)));
 	    break; 
 	case LVAR:
-	    e=list2(car(e),cadr(e) + nptr->dsp);
+	    e=list2(LVAR,cadr(e) + nptr->dsp);
 	    break;
 	case INDIRECT:
 	    e=list2(INDIRECT,list3(ADD,cadr(e),list2(CONST,nptr->dsp)));
@@ -2217,8 +2230,11 @@
 
     /* function call */
 
+    if(car(type)==POINTER)
+	if (car(cadr(type))==FUNCTION||car(cadr(type))==CODE)
+	    e1=indop(e1);
     t=type;
-    if(integral(t)|| (car(t)!=FUNCTION && car(t)!=CODE))
+    if(integral(t)|| ((car(t)!=FUNCTION)&&(car(t)!=CODE)))
 	error(TYERR);
     getsym();
     arglist=0;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/arg.c	Tue Feb 18 20:14:19 2003 +0900
@@ -0,0 +1,33 @@
+#include "stdio.h"
+
+struct arg {
+   int a0;int a1;int a2;int a3;int a4;
+};
+
+code arg1(int arg0,int arg1,int arg2,int arg3,int arg4,code(*exit1)(),void *env)
+{
+    struct arg args0;
+    printf("arg1: %d %d %d %d %d : %x %x\n",arg0,arg1,arg2,arg3,arg4,exit1,env);
+    args0.a0 = arg0;
+    args0.a1 = arg1;
+    args0.a2 = arg2;
+    args0.a3 = arg3;
+    args0.a4 = arg4;
+    goto args(args0,exit1,env);
+}
+
+code args(struct arg args0,code exit1(),void *env)
+{
+    printf("args: %d %d %d %d %d : %x %x\n",
+	args0.a0,args0.a1,args0.a2,args0.a3,args0.a4,
+    exit1,env);
+    goto (*exit1)(0),env;
+}
+
+
+int main( int ac, char *av[])
+{
+    int n;
+    goto arg1(0,1,2,3,4,return,environment);
+}
+
--- a/test/fact-a.c	Mon Feb 17 13:06:18 2003 +0900
+++ b/test/fact-a.c	Tue Feb 18 20:14:19 2003 +0900
@@ -24,7 +24,7 @@
 
 code print(int n,int result,int orig,code(*print)(),(*exit1)(),void*exit1env)
 {
-    printf("%d! = %d\n",n, result);
+    printf("%d! = %d\n",orig, result);
     goto (*exit1)(1),exit1env;
 }
 
--- a/test/tmp.c	Mon Feb 17 13:06:18 2003 +0900
+++ b/test/tmp.c	Tue Feb 18 20:14:19 2003 +0900
@@ -1,3 +1,14 @@
+
+int
+main1(int ac,char *av[],int (*f)(),int g())
+{
+return (*f)(ac)+g(ac);
+}
+
+int
+g(int k) {
+   return k+1;
+}
 
 main0(ac,av)
 {
@@ -16,4 +27,5 @@
     i = p[1];
     p = p+i;
     printf("%d %s\n",i,p-i);
+    printf("%d\n",main1(ac,av,g,g));
 }