diff mc-nop-386.c @ 49:884c74e6a2f7

no compile error
author kono
date Sun, 16 Feb 2003 02:47:10 +0900
parents 8575ec496cd4
children 1ec39b34ed98
line wrap: on
line diff
--- a/mc-nop-386.c	Sun Feb 16 01:01:06 2003 +0900
+++ b/mc-nop-386.c	Sun Feb 16 02:47:10 2003 +0900
@@ -27,6 +27,8 @@
 extern void jmp(int l);
 extern void opening(char *filename);
 extern void ret(void);
+extern int assign_expr0(int e,int e1,int type,int type1);
+extern int integral(int t);
 
 static int edx_setup() ;
 static int	lvar(int l);
@@ -62,9 +64,12 @@
 extern void fwddef(int l);
 extern int backdef(void);
 extern int size(int t);
+extern int list4(int e1, int e2, int e3,int e4);
 extern int list3(int e1, int e2, int e3);
+extern int list2(int e1, int e2);
 extern int scalar(int);
 extern int reverse0(int);
+extern void remove0(int *list,int element); 
 
 #define TEXT_EMIT_MODE 0
 #define DATA_EMIT_MODE 1
@@ -1013,13 +1018,14 @@
 }
 
 /* goto arguments list */
-/* target list3(list2(tag,disp),cdr,ty) */
-/* source list4(tag,cdr,expr,ty) */
+/* target         list3(list2(tag,disp),cdr,ty) */
+/* source         list3(expr,cdr,ty) expr=listn(tag,...) */
+/* source (after) list3(list2(tag,disp),cdr,ty) */
 
 void
 disp_source(int e3) {
     printf("# jump arg list\n");
-    for (e3 = target; e3; e3 = cadr(e3)) {	
+    for (; e3; e3 = cadr(e3)) {	
 	printf("#    %d, expr %d, size %d\n",car(e3),caddr(e3),cadddr(e3));
     }
 }
@@ -1043,65 +1049,60 @@
 }
 
 int
-target_frame(int *source,int *target,int *processing)
+parallel_assign(int *source,int *target,int *processing)
 {
-    int t,s,e1;
+    int t,s,e1,p,sz,ty;
     while(*target) {
 	t=car(*target);
-	s=caddr(*source);
+	s=car(*source);
+	sz=size(ty=caddr(*target)); 
 	for(p=*processing;p;p=cadr(p)) {
 	    if(car(p)==t) { /*ターゲットが処理リスト中にある*/
-		remove(target,t); remove(source,s); remove(processing,p);
+		remove0(target,t); remove0(source,s); remove0(processing,p);
 		/*新しいレジスタ(or スタック)を取得する*/
-		sz=size(ty=caddr(t)); 
-		if (sz==size_of_int && (e1=get_register())!=-1)) {
+		if (sz==size_of_int && (e1=get_register())!=-1) {
 		    e1=list2(REGISTER,e1);
-		    g_expr(assign_expr(e1,car(s),ty,ty));
-		    return assign_expr(car(t),e1,ty,ty);
+		    g_expr(assign_expr0(e1,s,ty,ty));
+		    return list2(assign_expr0(t,e1,ty,ty),e1);
 		} else {
 		    disp+=sz;
-		    gen_jump_assign(car(s),disp,ty);
-		    return assign_expr(car(t),list2(LVAR,disp),ty,ty);
+		    g_expr(assign_expr0((e1=list2(LVAR,disp)),s,ty,ty));
+		    return list2(assign_expr0(t,e1,ty,ty),-1);
 		}
 	    }
 	}
 	if(car(t)==car(s) && cadr(t)==cadr(s)) {
             /*書き込み先が自分自身*/
-	    remove(target,t); remove(source,s);
-	} else if (overrap(t,source,caddr(t))) {
+	    remove0(target,t); remove0(source,s);
+	} else if (overrap(*target,*source)) {
             /*書き込み先がソースと重なっている*/
-	    *prcoessing=list2(t,*processing);
-	    remove(target,t); remove(source,s);
+	    *processing=list2(t,*processing);
+	    remove0(target,t); remove0(source,s);
             /*他のを先にする*/
-	    e1=target(source,target,processing);
+	    e1=parallel_assign(source,target,processing);
 	    /* これで空いたはず*/
-	    g_expr(assign_expr(car(t),car(s),ty,ty));
+	    g_expr(assign_expr0(t,car(s),ty,ty));
 	    /* 横によけたものがあれば、後始末をする*/
-	    if(e1) 
-		g_expr(e1);
+	    if(e1) {
+		if(car(e1))
+		    g_expr(e1);
+		if(cadr(e1)>0) {
+		    free_register(cadr(e1));
+		}
+	    }
 	} else {
-	    g_expr(assign_expr(car(t),car(s),ty,ty));
-	    remove(target,t); remove(source,s);
+	    g_expr(assign_expr0(t,s,ty,ty));
+	    remove0(target,t); remove0(source,s);
 	}
     }
     return 0;
 }
 
-void
-gen_jump_assign(int e3,int disp,int ty)
+void 
+remove0(int *parent,int e) 
 {
-    int stype,e2,e4;
-    e2=caddr(e3);
-    stype = type;
-    g_expr(assgin_expr((e4=list2(LVAR,disp)),e2,ty,ty));
-    type = stype;
-    heap[e3]=LVAR; heap[e3+2]=e4;
-}
-
-void 
-remove(int *parent,int e) {
     int list;
-    while (list=*parent) {
+    while ((list=*parent)) {
 	if (car(list)==e) {
 	    *parent= cadr(list);
 	} else {
@@ -1110,10 +1111,28 @@
     }
 }
 
+int
+is_simple(int e1) 
+{
+    return (
+	e1==CONST || e1==FNAME || e1==LVAR || e1==REGISTER ||
+	e1==GVAR
+    );
+}
+
+int
+is_same(int e1,int e2)
+{
+    if(car(e1)==car(e2)) {
+	return cadr(e1)==cadr(e2);
+    }
+    return 0;
+}
+
 void
 jump(int e1, int env)
 {
-    int e2,e3,sz,arg_size,ejmp,ty;
+    int e2,e3,e4,sz,arg_size,ty,max_regs,regs;
     NMTBL *code0;
     int target = 0;
     int source = 0;
@@ -1122,22 +1141,16 @@
     /* まず、サイズを計算しながら、決まった形に落す。 */
     arg_size = 0; regs = 0; max_regs = MAX_REGISTER_VAR;
     for (e3 = caddr(e1); e3; e3 = cadr(e3)) {	
-	e2 = car(e3); sz = size(ty=caddr(e3)); arg_size += sz;
+	e2 = car(e3); sz = size(ty=caddr(e3)); 
 	if (regs <= max_regs&&integral(ty)) {
 	    target=list3(list2(REGISTER,(regs++)+REG_ESI),target,ty);
 	} else {
-	    target=list3(list2(LVAR,arg_size-MAX_RGISTER_VAR),target,ty);
+	    arg_size += sz;
+	    target=list3(list2(LVAR,arg_size-MAX_REGISTER_VAR),target,ty);
 	}
-	switch (car(e2)) {
-	case CONST:     source = list4(CONST,source,e2,ty); break;
-	case LVAR:      source = list4(LVAR,source,e2,ty); break;
-	case REGISTER:  source = list4(REGISTER,source,e2,ty); break;
-	case GVAR:      source = list4(GVAR,source,e2,ty); break;
-	default:        source = list4(0,source,e2,ty); break;
+	source = list3(e2,source,ty);
     }
-    disp_source(source);
 
-    arg_size = arg_size-MAX_RGISTER_VAR*size_of_int;
     /* disp を飛び先似合わせて修正 */
     if (arg_size>disp) disp = arg_size;
 
@@ -1147,11 +1160,12 @@
     /*  ついでに、同じものがあれば、除く */
 
     for (e3 = source,e2 = target; e3; e3 = cadr(e3),e2 = cadr(e2)) {	
-	if (car(e3)==0) {
-	    disp+=size(ty=cadddr(e3));
-	    gen_jump_assign(e3,disp,ty);
-	} else if (car(e3)==car(e2)&&cadr(e3)==cadr(e2)) {
-	    remove(&source,e3);remove(&target,e2);
+	if (!is_simple(car(car(e3)))) {
+	    disp+=size(ty=caddr(e3));
+	    g_expr(assign_expr0((e4=list2(LVAR,disp)),car(e3),ty,ty));
+	    car(e3)=e4;
+	} else if (is_same(car(e2),car(e3))) {
+	    remove0(&source,e3);remove0(&target,e2);
 	}
     }
 
@@ -1169,7 +1183,7 @@
 
     /* 並列代入を実行 */
 
-    target_frame(&source,&target,&processing);
+    parallel_assign(&source,&target,&processing);
 
     if (!env && arg_size>disp) {
 	/* shrink stack if necessary */
@@ -1207,14 +1221,6 @@
     return offset_list;
 }
 
-int
-is_simple(int e1) 
-{
-    int e2 = car(e1);
-    return (
-	e2==CONST || e2==FNAME || e2==LVAR || e2==CRLVAR || e2==REGISTER
-    );
-}
 
 void
 jump(int e1, int env)