changeset 136:069960078249

remove redundant funcall argument for prototyped code in PowerPC case.
author kono
date Sun, 04 May 2003 15:10:41 +0900
parents 4cfd24d1b929
children 9fb09db54436
files Changes mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-parse.c
diffstat 5 files changed, 128 insertions(+), 66 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Sun May 04 10:30:52 2003 +0900
+++ b/Changes	Sun May 04 15:10:41 2003 +0900
@@ -2896,7 +2896,11 @@
 した方がいいんじゃない? register full だと、
 
      register にload (emit_push)
-     register full でそれを局所変数に代入
+     register full でそれを局所変数に代入 (*)
      演算時にregisterに再代入
 
-なんかr10までなのか。何故奇数個? 整数はr8までなの?
+まぁねぇ。それだと、mc-code-386.c の時代に戻るわけ
+だけど。まぁ、その方がいいのかな。もっとも、(*)
+が起こらなければ、特に問題はないんだけどね。
+
+局所変数、大域変数、定数の足し算とかは処理した方がいいのかなぁ。
--- a/mc-code-ia32.c	Sun May 04 10:30:52 2003 +0900
+++ b/mc-code-ia32.c	Sun May 04 15:10:41 2003 +0900
@@ -937,7 +937,9 @@
     int e2,e3,e4,nargs,t,ret_type;
     NMTBL *n=0;
     int save,saved;
-    ret_type = cadddr(e1);
+    ret_type = cadr(cadddr(e1));
+    if (ret_type==CHAR) ret_type=INT;
+
 #ifdef SAVE_STACKS
     code_save_stacks();
 #endif
--- a/mc-code-mips.c	Sun May 04 10:30:52 2003 +0900
+++ b/mc-code-mips.c	Sun May 04 15:10:41 2003 +0900
@@ -15,12 +15,14 @@
 static void local_table(void);
 static void shift(char *op, int reg);
 static int struct_push(int e4,int t,int arg);
+static int code_d1(double d);
+static int code_d2(double d);
+
 
 static int output_mode = TEXT_EMIT_MODE;
 static int data_alignment = 0;
 
 static int code_disp_label;
-static int code_setup;
 static int r1_offset_label;
 static int lvar_offset_label;
 
@@ -98,20 +100,18 @@
 #define register_name(i)  reg_name[i]
 #define fregister_name(i) freg_name[i]
 
-static
-NMTBL float_zero = {"_float_zero",STATIC,FLOAT,0};
-static
-NMTBL float_one = {"_float_one",STATIC,FLOAT,0};
-
 
 static char * fload(int d);
-static int code_d1(double d);
-static int code_d2(double d);
 static void code_save_stacks();
 static void code_save_input_registers();
 static void    set_creg(int,int);
 static void    set_freg(int,int);
 
+static int    mask_label;
+static int    mask1_label;
+static int    fmask_label;
+static int    fmask1_label;
+
 static FILE *asi;
 int max_func_args;
 int my_func_args;
@@ -536,8 +536,6 @@
     return xreg;
 }
 
-static int code_base;
-
 void
 code_label(int labelno)
 {
@@ -546,19 +544,19 @@
 
 void
 code_gvar(int e1,int creg) {
-    printf("\tla %s,%s\n",register_name(creg),(NMTBL*)cadr(e1));
+    printf("\tla %s,%s\n",register_name(creg),((NMTBL*)cadr(e1))->nm);
     regv[creg]=1;
 }
 
 void
 code_rgvar(int e1,int creg) {
-    printf("\tlw %s,%s\n",register_name(creg),(NMTBL*)cadr(e1));
+    printf("\tlw %s,%s\n",register_name(creg),((NMTBL*)cadr(e1))->nm);
     regv[creg]=1;
 }
 
 void
 code_crgvar(int e1,int creg){
-    printf("\tlb %s,%s\n",register_name(creg),(NMTBL*)cadr(e1));
+    printf("\tlb %s,%s\n",register_name(creg),((NMTBL*)cadr(e1))->nm);
     regv[creg]=1;
 }
 
@@ -589,8 +587,7 @@
 
 void
 code_fname(NMTBL *n,int creg) {
-    if(r!=creg)
-	printf("\tla %s,%s\n",register_name(creg),n->nm);
+    printf("\tla %s,%s\n",register_name(creg),n->nm);
     regv[creg]=1;
     return;
 }
@@ -887,7 +884,7 @@
 void
 code_cmp_rlvar(int e2) {
     if (dreg==-1) dreg = get_register();
-    code_rlvar(e1,dreg);
+    code_rlvar(e2,dreg);
     regv[dreg]=1;
 }
 
@@ -1353,15 +1350,14 @@
 
 void
 code_assign_gvar(int e2,int creg,int byte) {
-    int r;
-    char *crn,*rrn;
-    r = get_ptr_cache((NMTBL*)cadr(e2));
-    rrn=register_name(r);
+    char *crn,*nm;
+
+    nm = ((NMTBL*)cadr(e2))->nm;
     crn=register_name(creg);
     if (byte) {
-	printf("\tsb %s,0(%s)\n",crn,rrn);
+	printf("\tsb %s,%s\n",crn,nm);
     } else {
-	printf("\tsw %s,0(%s)\n",crn,rrn);
+	printf("\tsw %s,%s\n",crn,nm);
     }
 }
 
@@ -1434,7 +1430,7 @@
 tosop(int op,int oreg)
 {
     int dx;
-    char *orn,*crn,*drn;
+    char *orn,*crn;
 
     if(oreg==-1) {
 	error(-1);
@@ -1538,12 +1534,12 @@
 }
 
 void
-code_opening(char *filename)
+code_opening(char *s)
 {
     /* this is called once per month */
     char *p=cheapp;
 
-    printf("\t.file \"%s\"\n",filename);
+    printf("\t.file \"%s\"\n",s);
     /* printf("\t.version\t\"01.01\"\n"); */
     /* printf("gcc2_compiled.:\n"); */
     printf("\t.abicalls\n");
@@ -1561,7 +1557,7 @@
         }
     }
     asi = fopen(p,"w");
-    printf("\.include \"%s\"\n",p);
+    printf(".include \"%s\"\n",p);
     if (!asi) error(-1);
 }
 
@@ -1598,7 +1594,7 @@
 {
     if (chk) return;
     if (dreg==-1) error(-1);
-    printf("\tb%s %s,%s,L_%d\n",register_name(creg),regiser_name(dreg),
+    printf("\tb%s %s,%s,L_%d\n",register_name(creg),register_name(dreg),
 	cond?"ne":"eq",l);
     if (regv[dreg]==1) {
 	free_register(dreg); dreg = -1;
@@ -1979,8 +1975,9 @@
 code_cmp_fregister(int e2)
 {
     /* not tested.. */
-    char *frn,*rrn,*grn;
-    int greg,r;
+    char *frn,*grn;
+    int greg;
+
     grn =  register_name(greg = get_fregister());
     frn = register_name(e2);
     printf("\tli.s %s,%g\n",grn,0.0);
@@ -1999,7 +1996,6 @@
 
 void code_dassign_gvar(int e2,int freg,int d)
 { 
-    int r;
     NMTBL *n = (NMTBL*)cadr(e2);
     printf("\t%s %s,0(%s)\n",fstore(d),fregister_name(freg),n->nm);
     fregv[freg]=1;
@@ -2024,28 +2020,71 @@
 	printf("\tmov.s %s,%s\n",fregister_name(e2),fregister_name(freg));
 }
 
-void code_dconst(int e2,int freg)
+static double d0 = 1.0;
+
+int
+code_d1(double d)
+{
+    int *i = (int *)&d0; int *j = (int *)&d;
+    return (i[1] == 0x3ff00000)?j[0]:j[1];
+}
+
+int
+code_d2(double d)
+{
+    int *i = (int *)&d0; int *j = (int *)&d;
+    return (i[1] == 0x3ff00000)?j[1]:j[0];
+}
+
+int
+code_f(double d)
+{
+    float f = d;
+    int *j = (int *)&f;
+    return *j;
+}
+
+void code_dconst1(int e2,int freg,int db)
 { 
     double d = dcadr(e2);
     char *frn = fregister_name(freg);
     printf("\tli.s %s,%g\n",frn,d);
-    free_register(r);
     fregv[freg]=1;
 }
 
+void code_fconst(int e2,int freg)
+{
+    code_dconst1(e2,freg,0);
+}
+
+void code_dconst(int e2,int freg)
+{
+    code_dconst1(e2,freg,1);
+}
+
+
 void code_dneg(int freg)
 { 
     char *frn = fregister_name(freg);
     printf("\tfneg %s,%s\n",frn,frn);
 }
 
+void code_fneg(int freg)
+{ 
+    char *frn = fregister_name(freg);
+    printf("\tfneg %s,%s\n",frn,frn);
+}
+
+
 void code_d2i(int freg,int creg)
 { 
     char *frn = fregister_name(freg);
     char *crn = register_name(creg);
     int e2 = new_lvar(size_of_double);
     free_lvar(e2);
-    printf("\tjal dptoli\n",frn,frn);
+    code_save_stacks();
+    /* setup arguments */
+    printf("\tjal dptoli\n");
     printf("\tstfd  %s,",frn); lvar(e2);
     printf("\tlwz %s,",crn); lvar(e2+size_of_double-size_of_int);
     fregs[freg]=0;
@@ -2054,11 +2093,9 @@
 
 void code_i2d(int creg,int freg)
 { 
-    i2d_lib_used = 1;
-    clear_ptr_cache();
     code_save_stacks();
     set_creg(RET_REGISTER,1);
-    printf("\tjal litodp\n",frn,frn);
+    printf("\tjal litodp\n");
     set_freg(RET_FREGISTER,0);
     fregs[freg]=1;
     regs[creg]=0;
@@ -2068,8 +2105,6 @@
 void code_d2u(int freg,int creg)
 { 
     code_save_stacks();
-    clear_ptr_cache();
-    d2u_lib_used=1;
     set_freg(RET_FREGISTER,1);
     printf("\tjal dptoul\n");
     set_creg(RET_REGISTER,0);
@@ -2081,9 +2116,7 @@
 { 
     char *frn;
     char *crn;
-    u2d_lib_used = 1;
     code_save_stacks();
-    clear_ptr_cache();
     frn = fregister_name(freg);
     crn = register_name(creg);
 
@@ -2094,11 +2127,18 @@
     regs[creg]=0;
 }
 
+void code_d2f(int freg) {}
+void code_f2d(int freg) {}
+void code_f2i(int freg,int creg) {}
+void code_f2u(int freg,int creg) {}
+void code_i2f(int creg,int freg) {}
+void code_u2f(int creg,int freg) {}
+
+
 void code_drgvar(int e2,int d,int freg)
 { 
-    int r;
-    r = get_ptr_cache((NMTBL*)cadr(e2));
-    printf("\t%s %s,0(%s)\n",fload(d),fregister_name(freg),register_name(r));
+    char *nm = ((NMTBL*)cadr(e2))->nm;
+    printf("\t%s %s,%s\n",fload(d),fregister_name(freg),nm);
     fregv[freg]=1;
 }
 
@@ -2111,12 +2151,11 @@
 
 void code_cmp_drgvar(int e2)
 { 
-    int r;
     char *frn=fregister_name(freg);
     int g=get_fregister();
     char *grn=fregister_name(g);
-    r = get_ptr_cache((NMTBL*)cadr(e2));
-    printf("\t%s %s,0(%s)\n",fload(1),grn,register_name(r));
+    char *nm = ((NMTBL*)cadr(e2))->nm;
+    printf("\t%s %s,%s\n",fload(1),grn,nm);
     printf("\tfcmpu cr0,%s,%s\n",frn,grn);
     free_fregister(g);
     fregv[freg]=0;
@@ -2141,18 +2180,26 @@
     char *grn=fregister_name(e1);
     fregv[freg]=1;
     switch(op) {
+    case FADD:
     case DADD: opn="fadd"; break;
+    case FSUB:
     case DSUB: opn="fsub"; break;
+    case FDIV:
     case DDIV: opn="fdiv"; break;
+    case FMUL:
     case DMUL: opn="fmul"; break;
+    case FCMP:
     case DCMP: 
 	printf("\tfcmpu cr0,%s,%s\n",frn,grn);
 	free_fregister(e1);
 	return;
+    case FCMPGE: 
     case DCMPGE: 
 	printf("\tfcmpu cr7,%s,%s\n",frn,grn);
 	free_fregister(e1);
 	return;
+    default:
+	error(-1); return;
     }
     printf("\t%s %s,%s,%s\n",opn,frn,frn,grn);
     free_fregister(e1);
@@ -2180,8 +2227,6 @@
     int  g;
     char *grn,*drn;
     int r;
-    r = get_ptr_cache(&float_one);
-    float_one_lib_used=1;
 
     g_expr(e2);
 
@@ -2207,15 +2252,11 @@
     char *crn;
     int  g;
     char *grn,*drn;
-    int r;
-    r = get_ptr_cache(&float_one);
-    float_one_lib_used=1;
 
     g_expr(e2);
 
     crn=register_name(creg);
     frn=fregister_name(freg);
-    drn=register_name(r);
     grn=fregister_name(g=get_fregister());
 
     printf("\t%s %s,0(%s)\n",fload(d),frn,crn);
@@ -2235,16 +2276,20 @@
     g_expr(list3(((op==DOP+GE)?DCMPGE:DCMP),e1,e2));
     switch(op) {
 	case DOP+GE:
+	case FOP+GE:
 	    printf("\tcror 2,29,30\n");
 	    printf("\tbne\tcr0,L_%d\n",l1);
 	    break;
 	case DOP+GT:
+	case FOP+GT:
 	    printf("\tble\tcr0,L_%d\n",l1);
 	    break;
 	case DOP+EQ:
+	case FOP+EQ:
 	    printf("\tbne\tcr0,L_%d\n",l1);
 	    break;
 	case DOP+NEQ:
+	case FOP+NEQ:
 	    printf("\tbeq\tcr0,L_%d\n",l1);
 	    break;
     }
@@ -2311,7 +2356,7 @@
 {
     global_table();
     /* printf("\t.ident \"Micro-C compiled\"\n"); */
-    fclose(ais);
+    fclose(asi);
 }
 
 /* end */
--- a/mc-code-powerpc.c	Sun May 04 10:30:52 2003 +0900
+++ b/mc-code-powerpc.c	Sun May 04 15:10:41 2003 +0900
@@ -322,7 +322,7 @@
         }
     }
     /* 空いている場所がないなら、エラー (いったい誰が使ってるの?) */
-    error(-1); return creg;
+    error(HPERR); return creg;
 }
 
 int
@@ -1315,13 +1315,25 @@
 {
     int e2,e3,e4,e5,nargs,t,r0,r1;
     int arg,reg_arg,freg_arg,arg_assign;
+    int dots;
     int reg_arg_list=0,ret_type,special_lvar;
     NMTBL *fn = 0;
     int jmp = 0;
     char *jrn;
 
     special_lvar = -1;
-    ret_type = cadddr(e1);
+    ret_type = cadr(cadddr(e1));
+    if (ret_type==CHAR) ret_type=INT;
+
+    /* check argments type is DOTS? */
+    t = caddr(cadddr(e1));
+    if (t==0 || t==DOTS) dots = 1;
+    else {
+	dots = 0;
+	for(t = caddr(cadddr(e1));t;t = cadr(t)) {
+	    if (car(t)==DOTS) dots = 1;
+	}
+    }
 
     e2 = cadr(e1);
     if (car(e2) == FNAME) {	
@@ -1361,7 +1373,7 @@
 	    nargs ++ ; reg_arg++;
 	    continue;
 	} else if (t==DOUBLE||t==FLOAT) {
-	    if (reg_arg<MAX_INPUT_REGISTER_VAR) {
+	    if (dots && reg_arg<MAX_INPUT_REGISTER_VAR) {
 		/* sigh... 
                    printf requies floating value in integer registers
                  */
@@ -1392,7 +1404,7 @@
 			INT,INT), arg_assign);
 		reg_arg += 2;
 	    }
-	    if (freg_arg>=4 && freg_arg<MAX_INPUT_DREGISTER_VAR) { 
+	    if (dots && freg_arg>=4 && freg_arg<MAX_INPUT_DREGISTER_VAR) { 
 		/* oh my god! 
                    it requies integer register and floating register and
                    stack value. You are crazy.
--- a/mc-parse.c	Sun May 04 10:30:52 2003 +0900
+++ b/mc-parse.c	Sun May 04 15:10:41 2003 +0900
@@ -2802,7 +2802,7 @@
 static int
 expr15(int e1)
 {
-    int t,arglist,e,sz,argtypes,at;
+    int t,arglist,e,sz,argtypes,at,ftype;
 
     /* function call */
     if(car(type)==POINTER) {
@@ -2814,6 +2814,7 @@
     if(integral(type)|| ((car(type)!=FUNCTION)&&(car(type)!=CODE))) {
 	error(TYERR);
     }
+    ftype = type;
     conv->funcall_(type);
     argtypes = caddr(type);
     if (!integral(t=cadr(type))&&(car(t)==STRUCT||car(t)==UNION)) {
@@ -2821,7 +2822,6 @@
 	if (argtypes==0) error(-1);
 	argtypes = cadr(argtypes);
     }
-    t=type;
     arglist=0;
     getsym();
     while(sym!=RPAR) {
@@ -2838,9 +2838,8 @@
     checksym(RPAR);
     conv->funcall_args_();
     if(car(t)==CODE)
-	return list4(FUNCTION,e1,arglist,0);
-    type=t;
-    type = cadr(type); /* return type */
+	return list4(FUNCTION,e1,arglist,ftype);
+    type = cadr(ftype); /* return type */
     if(type==CHAR) type=INT;
     else if(car(type)==STRUCT||car(type)==UNION) {
 	/* make temporaly struct for return value */
@@ -2867,7 +2866,7 @@
 
 	append3(arglist,list2(ADDRESS,e),list2(POINTER,type));
     }
-    return list4(FUNCTION,e1,arglist,type);
+    return list4(FUNCTION,e1,arglist,ftype);
 }
 
 static int