changeset 114:e6cb1e293b35

float/int passed.
author kono
date Thu, 20 Mar 2003 12:32:03 +0900
parents a9261154cde9
children ebac635814dc
files Changes mc-code-powerpc.c mc-parse.c test/int.c
diffstat 4 files changed, 54 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Wed Mar 19 23:03:50 2003 +0900
+++ b/Changes	Thu Mar 20 12:32:03 2003 +0900
@@ -2352,3 +2352,14 @@
 まぁ、一時変数を良く使うのでfree listを作った方が良いかもね。
 
 その前に整数演算のチェックが必要だな。
+
+Thu Mar 20 12:06:27 JST 2003
+
+まだ、save したレジスタを破壊しているな。
+    set L_98,244
+    stw r15,lo16(-44+L_98)(r1)
+ぐらいで、もう壊れちゃうみたい。ってことは、L_98 がもっと
+大きくないとダメなのか。
+
+ 
+
--- a/mc-code-powerpc.c	Wed Mar 19 23:03:50 2003 +0900
+++ b/mc-code-powerpc.c	Thu Mar 20 12:32:03 2003 +0900
@@ -52,7 +52,7 @@
      f24-f31 saved register variable
  */
 int arg_offset = 40;
-int disp_offset = -32;
+int disp_offset = -48;
 int func_disp_offset = -40;
 int code_disp_offset = 0;
 int jump_offset = 0;
@@ -1436,50 +1436,48 @@
     crn = register_name(creg);
     switch(op) {
     case ADD:
-	printf("\tadd %s,%s,%s\n",crn,orn,crn);
+	printf("\tadd %s,%s,%s\n",crn,crn,orn);
 	break;
     case SUB:
-	printf("\tsub %s,%s,%s\n",crn,orn,crn);
+	printf("\tsub %s,%s,%s\n",crn,crn,orn);
 	break;
     case CMP:
 	printf("\tcmpw cr0,%s,%s\n",crn,orn);
 	break;
     case BAND: 
-	printf("\tand %s,%s,%s\n",crn,orn,crn);
+	printf("\tand %s,%s,%s\n",crn,crn,orn);
 	break;
     case EOR: 
-	printf("\txor %s,%s,%s\n",crn,orn,crn);
+	printf("\txor %s,%s,%s\n",crn,crn,orn);
 	break;
     case BOR:
-	printf("\tor %s,%s,%s\n",crn,orn,crn);
+	printf("\tor %s,%s,%s\n",crn,crn,orn);
 	break;
     case MUL:
     case UMUL:
-	printf("\tmullw %s,%s,%s\n",crn,orn,crn);
+	printf("\tmullw %s,%s,%s\n",crn,crn,orn);
 	break;
     case DIV:
-	printf("\tdivw %s,%s,%s\n",crn,orn,crn);
+	printf("\tdivw %s,%s,%s\n",crn,crn,orn);
 	break;
     case UDIV:
-	printf("\tdivwu %s,%s,%s\n",crn,orn,crn);
+	printf("\tdivwu %s,%s,%s\n",crn,crn,orn);
 	break;
     case MOD:
 	dx=get_register();
 	drn = register_name(dx);
-	printf("\tdivwu %s,%s,%s\n",drn,orn,crn);
+	printf("\tdivwu %s,%s,%s\n",drn,crn,orn);
 	printf("\tmullw %s,%s,%s\n",drn,drn,crn);
-	printf("\tsubf %s,%s,%s\n",drn,drn,orn);
-	free_register(creg);
-	creg=dx;
+	printf("\tsubf %s,%s,%s\n",crn,drn,orn);
+	free_register(dx);
 	break;
     case UMOD:
 	dx=get_register();
 	drn = register_name(dx);
-	printf("\tdivwu %s,%s,%s\n",drn,orn,crn);
+	printf("\tdivwu %s,%s,%s\n",drn,crn,orn);
 	printf("\tmullw %s,%s,%s\n",drn,drn,crn);
-	printf("\tsubf %s,%s,%s\n",drn,drn,orn);
-	free_register(creg);
-	creg=dx;
+	printf("\tsubf %s,%s,%s\n",crn,drn,orn);
+	free_register(dx);
 	break;
     default:
 	error(-1);
@@ -2406,12 +2404,12 @@
 
 int emit_dpop(int e1)
 { 
-    int xreg;
+    int xreg,reg;
     xreg=pop_fregister();
     if (xreg<= -REG_LVAR_OFFSET) {
-	xreg = get_fregister();
-        code_drlvar(lvar(REG_LVAR_OFFSET+xreg),1,freg);
-	fregv[xreg]=1;
+	reg = get_fregister();
+        code_drlvar(lvar(REG_LVAR_OFFSET+xreg),1,reg);
+	fregv[reg]=1; xreg=reg;
     }
     return xreg;
 }
--- a/mc-parse.c	Wed Mar 19 23:03:50 2003 +0900
+++ b/mc-parse.c	Thu Mar 20 12:32:03 2003 +0900
@@ -89,6 +89,7 @@
 static void reverse(int t1);
 static void set_converter(char *s);
 static void statement(void);
+static int correct_type(int e,int t);
 
 
 static int struct_return  = 0;
@@ -552,6 +553,8 @@
 		getsym();
 	    n->dsp=0;
 	    if(stmode==EXTRN) n->sc=EXTRN;
+	    if(stmode==STATIC) n->sc=STATIC;
+	    else n->sc=EXTRN; /* this is odd... */
 	    if (type==CODE) {
 		n->ty=CODE;
 		if(sym==RPAR) {
@@ -622,7 +625,6 @@
 		break;
 	    }
 	    if(sym!=COMMA && sym!=RPAR) {
-		if(sym==RPAR) break;
 		type=t;
 		sargs = args;
 		arg=decl0();
@@ -632,8 +634,8 @@
 		    if (smode==GDECL)
 			def(arg);
 		}
-		argtypes=list2(type,argtypes);
 	    }
+	    argtypes=list2(type,argtypes);
 	    if(sym==RPAR) break;
 	}
 	if (sym!=COMMA) error(DCERR);
@@ -1568,7 +1570,7 @@
 	    error(TYERR); /* should check compatible */
 	}
     } else {
-	gexpr(expr(0),1);
+	gexpr(correct_type(expr(0),cadr(fnptr->ty)),1);
     }
     lfree=slfree;
     conv->return_end_();
@@ -2142,7 +2144,7 @@
 {
     int e1;
     e1=list2(FNAME,(int)nptr);
-    type=list3(car(nptr->ty),cadr(nptr->ty),nptr->dsp);
+    type=list3(car(nptr->ty),cadr(nptr->ty),caddr(nptr->ty));
     getsym();
     extrn_use(nptr);
     return expr16(e1);
@@ -2157,13 +2159,13 @@
     case IDENT:
 	conv->id_(sym,nptr);
 	switch(nptr->sc) {
-	case EXTRN: case EXTRN1:
+	case EXTRN: case EXTRN1: 
 	    extrn_use(nptr);
+	case STATIC:
 	    if(is_code(nptr)||is_function(nptr)) {
 		return fname(nptr);
 	    }
 	case GVAR:
-	case STATIC:
 	    e1=list2(GVAR,(int)nptr);
 	    type=nptr->ty;
 	    getsym();
@@ -2637,10 +2639,10 @@
 }
 
 int
-function_args(int e,int t)
+correct_type(int e,int t)
 {
     int t1;
-    e = rvalue(e);
+    /* e = rvalue(e); */
     if (type==FLOAT && t==DOTS) { type=DOUBLE;}
     if (type==CHAR  && t==DOTS) { type=INT;}
     if (t==DOTS) return e;
@@ -2684,7 +2686,7 @@
 	if(argtypes==0) at=DOTS;
 	else if(car(argtypes)==DOTS) at=DOTS;
         else { at=car(argtypes); argtypes=cadr(argtypes); }
-	e = function_args(e,at);
+	e = correct_type(e,at);
 	arglist=list3(e,arglist,type);
 	if(sym!=COMMA) break;
 	conv->comma_();
@@ -2927,6 +2929,8 @@
 	    getch();
 	    if (ch=='-' && cheapp[-1]=='e') {
 		*cheapp++ = ch; getch();
+	    } else if (ch=='+' && cheapp[-1]=='e') {
+		*cheapp++ = ch; getch();
 	    }
 	}
 	*cheapp++ = 0;
--- a/test/int.c	Wed Mar 19 23:03:50 2003 +0900
+++ b/test/int.c	Thu Mar 20 12:32:03 2003 +0900
@@ -1,5 +1,6 @@
 #include "stdio.h"
 
+double sin(double);
 void test1();
 void print(int d);
 
@@ -40,6 +41,9 @@
    unsigned u;
    unsigned d00 = ac?-30:ac;
 
+   printf("%d %f %d %f\n",1,0.1,1,0.1);
+   printf("%f %d %f %d\n",0.1,1,0.1,1);
+
    printf("%ud\n",d00);
 
    g = 1;
@@ -65,9 +69,9 @@
    d = i;
    i = f;
    f = i;
-   printf("\n%d %d %f",i,d,f);
+   printf("\n%d %d %d",i,d,f);
    f = g = d = d1 = d2 = f;
-   printf(" %d %d %f %d\n",i,d,f,g);
+   printf(" %d %d %d %d\n",i,d,f,g);
 
    d = 320967294; f=224967294;
    u = d;
@@ -176,7 +180,7 @@
     printf("\n");
     printf("simple calc ");
 
-    f=0.13; g=-0.56; f1=-0.13; g1=0.56;
+    f=3.13; g=-7.56; f1=-5.13; g1=7.56;
 
     g = f+f;
     printf("%d:%d\t",n++,g);
@@ -236,7 +240,7 @@
     printf("%d:%d\t",n++, (*pf1)-- - --(*pf));
     printf("\n");
 
-    *pf=0.13; *pg=-0.56; *pf1=-0.13; *pg1=0.56;
+    *pf=3.13; *pg=-7.56; *pf1=-5.13; *pg1=7.56;
 
     *pg = *pf+*pf;
     printf("%d:%d\t",n++,*pg);
@@ -310,10 +314,10 @@
     int g,h;
   
     if (i<=0) return f;
-#if 0
+#if 1
     printf("rec: %d %d\n",i,f);
 #endif
     g =  f*2;
-    h =  f-0.5;
-    return h/3-(3.0-(g+3)*test2(f*0.5,i-1)/(h-1));
+    h =  f-3.5;
+    return h/3-(3.0-(g+3)*test2(f*1.5,i-1)/(h-1));
 }