changeset 223:1ac647873577

*** empty log message ***
author kono
date Mon, 26 Apr 2004 11:01:43 +0900
parents 3d214303bae9
children 82a55cc6b5fc
files Changes mc-code-powerpc.c mc-codegen.c mc-codegen.h mc-parse.c test/code-gen.c
diffstat 6 files changed, 87 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Mon Apr 26 08:58:34 2004 +0900
+++ b/Changes	Mon Apr 26 11:01:43 2004 +0900
@@ -4049,3 +4049,4 @@
 
 一応、no long long は通ったみたいだが。。
 
+構造体の戻値を持つ場合に、引数がないとうまくいかない。
--- a/mc-code-powerpc.c	Mon Apr 26 08:58:34 2004 +0900
+++ b/mc-code-powerpc.c	Mon Apr 26 11:01:43 2004 +0900
@@ -1542,10 +1542,13 @@
 // printf("# use reg %d\n",arg);
     if (arg<0||arg> REAL_MAX_REGISTER+REAL_MAX_FREGISTER+ REAL_MAX_LREGISTER)
 	error(-1);
+    clear_ptr_cache_reg(arg);
     regs[arg]=USING_REG;
     if (is_longlong_reg(arg)) {
 	regs[regv_l(arg)]=USING_REG;
+	clear_ptr_cache_reg(regv_l(arg));
 	regs[regv_h(arg)]=USING_REG;
+	clear_ptr_cache_reg(regv_h(arg));
     }
 }
 
@@ -1600,15 +1603,15 @@
 }
 
 int
+simple_p(int e3)
+{
+    return (e3==FUNCTION||e3==CONV||e3==RSTRUCT||e3==STASS|| (e3&LOP));
+}
+
+int
 simple_args(int e3)
 {
-    return 
-	!contains_in_list(e3,FUNCTION) &&
-	!contains_in_list(e3,CONV) &&
-	!contains_in_list(e3,RSTRUCT) &&
-	!contains_in_list(e3,STASS)
-        // and more?
-    ;
+    return !contains_in_list_p(e3,simple_p);
 }
 
 int
@@ -1687,7 +1690,7 @@
 	    if (reg_arg+1>=MAX_INPUT_REGISTER_VAR) { 
 		arg = list2(LVAR,caller_arg_offset_v(nargs));
 	    } else if (!simple_args(e3) && cadr(e3)) {
-		arg = get_register_var(0); 
+		arg = get_lregister_var(0); 
 		arg_assign = list2(
 		    assign_expr0(get_input_lregister_var(reg_arg,0,0),
 			arg,t,t),
@@ -3653,6 +3656,8 @@
 static void
 code_ldiv_lib(int oreg) // ___divdi3$stub
 {
+    code_save_stacks();
+    clear_ptr_cache();
     set_lreg(RET_LREGISTER,1);
     set_lreg_operand(oreg,1);
     extern_conv("__divdi3");
@@ -3661,6 +3666,8 @@
 static void
 code_ludiv_lib(int oreg) // ___udivdi3$stub
 {
+    code_save_stacks();
+    clear_ptr_cache();
     set_lreg(RET_LREGISTER,1);
     set_lreg_operand(oreg,1);
     extern_conv("__udivdi3");
@@ -3669,6 +3676,8 @@
 static void
 code_lmod_lib(int oreg) // ___moddi3$stub
 {
+    code_save_stacks();
+    clear_ptr_cache();
     set_lreg(RET_LREGISTER,1);
     set_lreg_operand(oreg,1);
     extern_conv("__moddi3");
@@ -3677,6 +3686,8 @@
 static void
 code_lumod_lib(int oreg) // ___umoddi3$stub
 {
+    code_save_stacks();
+    clear_ptr_cache();
     set_lreg(RET_LREGISTER,1);
     set_lreg_operand(oreg,1);
     extern_conv("__umoddi3");
@@ -3697,6 +3708,7 @@
 	error(-1);
     } else if (oreg<= -REG_LVAR_OFFSET) {
 	dx = get_lregister(); if (dx<0) error(-1);
+	use_reg(dx);
         code_rlvar(oreg+REG_LVAR_OFFSET,dx);
 	oreg = dx;
     }
@@ -3746,7 +3758,10 @@
 	break;
     case LMUL:
     case LUMUL:
+	code_save_stacks();
+	clear_ptr_cache();
 	dx=get_lregister();
+	use_reg(dx);
 	drn_l = lregister_name_low(dx);
 	drn_h = lregister_name_high(dx);
         /*
@@ -3836,6 +3851,7 @@
     case LLSHIFT:
     case LULSHIFT:
 	greg = get_register();
+	use_reg(greg);
 	grn = register_name(greg);
 	printf("\tsrwi %s,%s,%d\n",grn,crn_h,32-v);
 	printf("\tslwi %s,%s,%d\n",crn_l,crn_l,v);
@@ -3845,6 +3861,7 @@
 	return;
     case LRSHIFT:
 	greg = get_register();
+	use_reg(greg);
 	grn = register_name(greg);
 	printf("\tsrwi %s,%s,%d\n",grn,crn_l,v);
 	printf("\tinsrwi %s,%s,%d\n",grn,crn_h,v);
@@ -3854,6 +3871,7 @@
 	return;
     case LURSHIFT:
 	greg = get_register();
+	use_reg(greg);
 	grn = register_name(greg);
 	printf("\tslwi %s,%s,%d\n",grn,crn_l,32-v);
 	printf("\tsrwi %s,%s,%d\n",crn_l,crn_h,v);
@@ -4128,29 +4146,29 @@
 {
     int xreg;
     int edx,edx0=-1;
-    char *crn;
 
     // (*creg) op = pop()
     xreg = emit_lpop(0);       /* pop e3 value */
     if (!is_int_reg(creg)) error(-1);
     edx = ireg;
+    emit_push();
     use_longlong(reg);
     if (regv_l(lreg)==edx || regv_h(lreg)==edx) {
 	edx0 = get_register(); if(!edx0) error(-1);
 	printf("# lassop\n\tmr %s,%s\n",register_name(edx0),register_name(edx));
 	edx = edx0;
     }
-    crn=register_name(edx);
-    use_reg(edx);
     printf("\tlwz %s,0(%s)\n",lregister_name_high(reg),
 	register_name(edx));
     printf("\tlwz %s,%d(%s)\n",lregister_name_low(reg),
-	size_of_int,crn);
+	size_of_int,register_name(edx));
+    free_register(edx);
     ltosop(op,reg,xreg);
+    edx = emit_pop(0);
     printf("\tstw %s,0(%s)\n",lregister_name_high(reg),
 	register_name(edx));
     printf("\tstw %s,%d(%s)\n",lregister_name_low(reg),
-	size_of_int,crn);
+	size_of_int,register_name(edx));
     free_register(edx);
     emit_lpop_free(xreg);
 }
@@ -4189,8 +4207,8 @@
 #if LONGLONG_CODE
     for(i=0;i<lreg_sp;i++) {
         if ((reg=lreg_stack[i])>=0) {
-            code_assign_lvar(
-                (lreg_stack[i]=new_lvar(size_of_longlong)),reg,0); 
+            code_lassign_lvar(
+                (lreg_stack[i]=new_lvar(size_of_longlong)),reg); 
             lreg_stack[i]= lreg_stack[i]-REG_LVAR_OFFSET;
         }
     }
--- a/mc-codegen.c	Mon Apr 26 08:58:34 2004 +0900
+++ b/mc-codegen.c	Mon Apr 26 11:01:43 2004 +0900
@@ -1635,4 +1635,49 @@
     return 0;
 }
 
+int
+contains_in_list_p(int e,int (*p)(int))
+{
+    while(e) {
+	if(contains_p(car(e),p)) return 1;
+	e = cadr(e);
+    }
+    return 0;
+}
+
+int
+contains_p(int e,int (*p)(int))
+{
+    while(e) {
+	if (p(car(e))) return 1;
+	if (LIST_ARGS(car(e))){
+        /* list arguments */
+	    return contains_in_list_p(caddr(e),p);
+	} else if (UNARY_ARGS(car(e))) {
+        /* unary operators */
+	    e = cadr(e);
+	    continue;
+	} else if (BINARY_ARGS(car(e))) {
+        /* biary operators */
+	    if (contains_p(cadr(e),p)) return 1;
+	    e = caddr(e);
+	    continue;
+	} else if (TARNARY_ARGS(car(e))) {
+        /* tarary operators */
+	    if (contains_p(cadr(e), p)) return 1;
+	    if (contains_p(caddr(e),p)) return 1;
+	    e = cadddr(e);
+	    continue;
+	} else if (NULLARY_ARGS(car(e))) {
+        /* nullary operators */
+	    return 0;
+	} else {
+	    fprintf(stderr,"Unknown Tree ID %d\n",car(e));
+	    error(-1);
+	    return 0;
+	}
+    }
+    return 0;
+}
+
 /* end */
--- a/mc-codegen.h	Mon Apr 26 08:58:34 2004 +0900
+++ b/mc-codegen.h	Mon Apr 26 11:01:43 2004 +0900
@@ -58,6 +58,8 @@
 
 extern int contains(int e,int type);
 extern int contains_in_list(int e,int type);
+extern int contains_p(int e,int (*p)(int));
+extern int contains_in_list_p(int e,int (*p)(int));
 
 
 /* end */
--- a/mc-parse.c	Mon Apr 26 08:58:34 2004 +0900
+++ b/mc-parse.c	Mon Apr 26 11:01:43 2004 +0900
@@ -1940,7 +1940,7 @@
     if (t==FNAME) {
 	nptr0 = (NMTBL *)cadr(e1);
 	t = nptr0->sc;
-	if (t==EMPTY) {
+	if (t==EMPTY||t==EXTRN1||t==EXTRN) {
 	    nptr0->sc = FLABEL;
 	    jmp(nptr0->dsp = fwdlabel());
 	} else if (t==FLABEL||t==BLABEL) {
@@ -3529,7 +3529,7 @@
 	/* this is recognized by called function declaration */
 	/* but I don't know this sequence is compatible with gcc */
 
-	append3(arglist,list2(ADDRESS,e),list2(POINTER,type));
+	arglist = append3(arglist,list2(ADDRESS,e),list2(POINTER,type));
     }
     return list4(FUNCTION,e1,arglist,ftype);
 }
--- a/test/code-gen.c	Mon Apr 26 08:58:34 2004 +0900
+++ b/test/code-gen.c	Mon Apr 26 11:01:43 2004 +0900
@@ -227,7 +227,7 @@
 
 struct aa { char a[100]; } a0;
 struct aa
- code_return_struct0()
+ code_return_struct0(/*int j*/)
 {
     a0.a[55]=3;
     return a0;
@@ -236,7 +236,9 @@
 void
 code_return_struct1()
 {
-    int i = code_return_struct0().a[55];
+    int i = code_return_struct0(/*1*/).a[55];
+    // int i;
+    // i = code_return_struct0(i).a[55];
     printf("code_return_struct %d\n", i);
 }