changeset 264:7de200d88747

MIPS first binary run (inomplete)
author kono
date Mon, 17 May 2004 00:36:31 +0900
parents c922bade771d
children b47a106a9bce
files mc-code-mips.c mc-codegen.c
diffstat 2 files changed, 104 insertions(+), 86 deletions(-) [+]
line wrap: on
line diff
--- a/mc-code-mips.c	Sun May 16 20:11:48 2004 +0900
+++ b/mc-code-mips.c	Mon May 17 00:36:31 2004 +0900
@@ -108,9 +108,9 @@
 int MAX_CODE_INPUT_DREGISTER_VAR = 14-MIN_TMP_FREG;
 int MAX_CODE_INPUT_FREGISTER_VAR = 14-MIN_TMP_FREG;
 
+#define LREG_V 3    /* for virtual long long/double register */
 static int mips_regs[REAL_MAX_REGISTER+REAL_MAX_FREGISTER+
-   REAL_MAX_LREGISTER];
-#define LREG_V 3    /* for virtual long long/double register */
+   REAL_MAX_LREGISTER+LREG_V];
 static int regv_h0[REAL_MAX_LREGISTER+LREG_V];
 static int regv_l0[REAL_MAX_LREGISTER+LREG_V];
 #define regv_h(i)  regv_h0[(i)-LREG_OFFSET]
@@ -165,7 +165,6 @@
 #define fregister_name(i) reg_name[i]
 #define lregister_name_low(i) reg_name[regv_l(i)]
 #define lregister_name_high(i) reg_name[regv_h(i)]
-static int emit_dpop_regvar(int d);
 
 char *r(i) { return register_name(i); }
 char *f(i) { return fregister_name(i); }
@@ -920,7 +919,7 @@
         i = get_lregister_var(n);
 	if (car(i)==LREGISTER) {
 	    car(i) = DREGISTER;
-	    regs[i] = USING_DREG;
+	    regs[cadr(i)] = USING_DREG;
 	} 
 	return i;
     }
@@ -2607,13 +2606,13 @@
     else
 	printf("\t.align 3\n");
     if (stmode!=STATIC)
-	printf(".globl _%s\n",name);
+	printf(".globl %s\n",name);
 #ifdef DOT_SIZE
     printf("\t.type\t%s,@function\n",name);
 #endif
 
     printf("%s:\n",name);
-    printf("\t.frame $fp,%d,$31\n",0);
+    printf("\t.frame $fp,$L_%d,$31\n",0);
     printf("\t.mask  0x%x,%d\n",code_mask(),0);
     printf("\t.fmask 0x%x,%d\n",code_fmask(),0);
 
@@ -2662,9 +2661,10 @@
 
     lvar_offset_label = fwdlabel();
 
+    printf("\t.globl\t%s\n",name);
     printf(".ent %s\n",name);
     printf("%s:\n",name);
-    printf("\t.frame $fp,$L_%d,$31\t",r1_offset_label);
+    printf("\t.frame $fp,$L_%d,$31\t",r1_offset_label=fwdlabel());
     printf("\t.mask  0x%x,%d\n",mask_label=fwdlabel(),
 	mask_offset_label=fwdlabel());
     printf("\t.fmask  0x%x,%d\n",fmask_label=fwdlabel(),
@@ -2672,7 +2672,7 @@
     printf("\t.set noreorder\n");
     printf("\t.cpload $25\n");
     printf("\t.set reorder\n");
-    printf("\tsubu $sp,$sp,$L_%d\n",r1_offset_label=fwdlabel());
+    printf("\tsubu $sp,$sp,$L_%d\n",r1_offset_label);
     printf("\t.cprestore $L_%d\n",cprestore_label=fwdlabel());
     printf("\tj $L_%d\n",register_save_label=fwdlabel());
     register_save_return_label = backdef();
@@ -2771,7 +2771,7 @@
 	fprintf(asi,"$L_%d=$L_%d\n",
 		register_save_label,register_save_return_label);
     } else {
-	code_label(register_save_return_label);
+	code_label(register_save_label);
 	code_register_save(disp);
 	jmp(register_save_return_label);
     }
@@ -2820,7 +2820,7 @@
 {
     /*
     if (stmode!=STATIC)
-	printf(".globl _%s\n",n); 
+	printf(".globl %s\n",n); 
      */
 }
 
@@ -2854,10 +2854,10 @@
     if (chk) return;
     if (n->dsp != -1) {
 	n->dsp = -1;   /* initiallized flag */
-	printf(".globl\t_%s\n",name);
+	printf(".globl\t%s\n",name);
 	data_mode(name);
 	align(t);
-	printf("_%s:\n",name); 
+	printf("%s:\n",name); 
     } else {
 	data_mode(0);
     }
@@ -2891,11 +2891,11 @@
     } else if(t!=CHAR) {       
 	gpc += SIZE_OF_INT;
 	if(car(e)==ADDRESS&&car(cadr(e))==GVAR) {
-	    printf("\t.long _%s\n",((NMTBL *)cadr(cadr(e)))->nm);
+	    printf("\t.long %s\n",((NMTBL *)cadr(cadr(e)))->nm);
 	} else if(car(e)==FNAME) {
-	    printf("\t.long _%s\n",((NMTBL *)cadr(e))->nm);
+	    printf("\t.long %s\n",((NMTBL *)cadr(e))->nm);
 	} else if(car(e)==GVAR) {
-	    printf("\t.long _%s\n",((NMTBL *)cadr(e))->nm);
+	    printf("\t.long %s\n",((NMTBL *)cadr(e))->nm);
 	} else if(car(e)==STRING) {       
 	    if (car(n->ty)!=ARRAY || cadr(n->ty)!=CHAR) {
 		l = fwdlabel();
@@ -2939,14 +2939,15 @@
 		data_mode(0);
 		init=1;
 	    }
-	    printf(".comm _%s,%d\n",n->nm,size(n->ty));
+	    printf(".comm %s,%d\n",n->nm,size(n->ty));
 	} else if ((n->sc==STATIC) && n->dsp != -1) {
 	    /* n->dsp = -1 means initialized global */
 	    if (init==0) {
 		data_mode(0);
 		init=1;
 	    }
-	    printf(".lcomm _%s,%d\n",n->nm,size(n->ty));
+	    printf(".local %s\n",n->nm);
+	    printf(".comm %s,%d\n",n->nm,size(n->ty));
 	}
     }
 }
@@ -2964,8 +2965,10 @@
 		data_mode(0);
 		init=1;
 	    }
-	    if (n->dsp != -1) /* initialized static */
-		printf(".lcomm _%s,%d\n",n->nm,size(n->ty));
+	    if (n->dsp != -1) { /* initialized static */
+		printf(".local %s\n",n->nm);
+		printf(".comm %s,%d\n",n->nm,size(n->ty));
+	    }
 	}
     }
 }
@@ -3014,6 +3017,8 @@
 {
     char *grn,*frn;
     int greg;
+    use_float(d,e2);
+
     if (d) {
         code_save_stacks();
 	clear_ptr_cache();
@@ -3138,9 +3143,11 @@
     if (d) {
         code_save_stacks();
 	clear_ptr_cache();
-	set_dreg(RET_DREGISTER,1);
+	set_lreg(LREGISTER_OPERAND_1,1);
+        printf("\tmove $4,$0\n"); 
+        printf("\tmove $5,$0\n"); 
 	/// set_dreg_operand(oreg,1);
-        extern_conv("dpneg");
+        extern_conv("dpsub");
 	return;
     }
     frn = fregister_name(freg);
@@ -3189,7 +3196,7 @@
     set_ireg(RET_REGISTER,1);
     code_save_stacks();
     clear_ptr_cache();
-    extern_conv("ultodp");
+    extern_conv("litodp");
     set_dreg(RET_DREGISTER,0);
     use_float(1,reg);
     return;
@@ -3416,35 +3423,39 @@
 
     d=(op<FOP);
     use_float(d,reg);
-    switch(op) {
-    case FADD: opn="add.s"; break;
-    case DADD: opc="dpadd"; break;
-    case FSUB: opn="sub.s"; break;
-    case DSUB: opc="dpsub"; break;
-    case FDIV: opc="div.s"; break;
-    case DDIV: opn="dpdiv"; break;
-    case FMUL: opc="mul.s"; break;
-    case DMUL: opn="dpmul"; break;
-    case FCMP: opn="c.lt.s"; cmp=1; break;
-    case DCMPGE:
-    case DCMP:  opc="dpcmp"; break;
-    case FCMPGE: opn="c.le.s"; cmp=1; break;
-    case FCMPEQ: opn="c.eq.s"; cmp=1; break;
-    default:
-	error(-1); return;
+    if (d) {
+	switch(op) {
+	case DADD: opc="dpadd"; break;
+	case DSUB: opc="dpsub"; break;
+	case DDIV: opc="dpdiv"; break;
+	case DMUL: opc="dpmul"; break;
+	case DCMPGE:
+	case DCMP:  opc="dpcmp"; break;
+	default:
+	    error(-1); return;
+	}
+      double_lib(opc,reg,e1);
+    } else {
+	switch(op) {
+	case FADD: opn="add.s"; break;
+	case FSUB: opn="sub.s"; break;
+	case FDIV: opn="div.s"; break;
+	case FMUL: opn="mul.s"; break;
+	case FCMP: opn="c.lt.s"; cmp=1; break;
+	case FCMPGE: opn="c.le.s"; cmp=1; break;
+	case FCMPEQ: opn="c.eq.s"; cmp=1; break;
+	default:
+	    error(-1); return;
+	}
+        grn = fregister_name(e1);
+        frn = fregister_name(reg);
+        if (cmp) {
+	  cmpreg=CMP_C1T;
+	  printf("\t%s %s,%s\n",opn,frn,grn);
+        } else {
+	  printf("\t%s %s,%s,%s\n",opn,frn,frn,grn);
+        }
     }
-    if (opn && !d) {
-      grn = fregister_name(e1);
-      frn = fregister_name(reg);
-      if (cmp) {
-	cmpreg=CMP_C1T;
-	printf("\t%s %s,%s\n",opn,frn,grn);
-      } else {
-	printf("\t%s %s,%s,%s\n",opn,frn,frn,grn);
-      }
-    } else if (opc && d) {
-      double_lib(opc,reg,e1);
-    } else error(-1);
 }
 
 void
@@ -3572,7 +3583,7 @@
       code_save_stacks();
       clear_ptr_cache();
       set_dreg(RET_DREGISTER,0);
-      xreg = emit_dpop_regvar(0);
+      xreg = emit_pop(1);
       xrn = register_name(xreg);
       printf("\tlw $4,%d(%s)\n",SIZE_OF_INT,xrn);
       printf("\tlw $5,0(%s)\n",xrn);
@@ -3597,29 +3608,29 @@
     int dir=caddr(e1);
 
     if (!d) {
-    if (car(e2)==FREGISTER) {
-	crn=register_name(cadr(e2));
-    } else {
-	g_expr(e2);
-	if (!is_int_reg(creg)) error(-1);
-	crn=register_name(creg);
-    }
-
-    use_float(d,reg);
-
-    frn=fregister_name(reg);
-    grn=fregister_name(g=get_dregister(d));
-    printf("\tli.s %s,1.0\n",grn);
-
-    if (car(e2)==FREGISTER) {
-	printf("\t%s %s,%s,%s\n",(dir>0)?"add.s":"sub.s",frn,crn,grn);
-	printf("\tmov.s %s,%s\n",frn,crn);
-    } else {
-	printf("\tl.s %s,0(%s)\n",frn,crn);
-	printf("\t%s %s,%s,%s\n",(dir>0)?"add.s":"sub.s",grn,frn,grn);
-	printf("\ts.s %s,0(%s)\n",grn,crn);
-    }
-    free_register(g);
+	if (car(e2)==FREGISTER) {
+	    crn=register_name(cadr(e2));
+	} else {
+	    g_expr(e2);
+	    if (!is_int_reg(creg)) error(-1);
+	    crn=register_name(creg);
+	}
+
+	use_float(d,reg);
+
+	frn=fregister_name(reg);
+	grn=fregister_name(g=get_dregister(d));
+	printf("\tli.s %s,1.0\n",grn);
+
+	if (car(e2)==FREGISTER) {
+	    printf("\t%s %s,%s,%s\n",(dir>0)?"add.s":"sub.s",frn,crn,grn);
+	    printf("\tmov.s %s,%s\n",frn,crn);
+	} else {
+	    printf("\tl.s %s,0(%s)\n",frn,crn);
+	    printf("\t%s %s,%s,%s\n",(dir>0)?"add.s":"sub.s",grn,frn,grn);
+	    printf("\ts.s %s,0(%s)\n",grn,crn);
+	}
+	free_register(g);
     } else {
       if (car(e2)==DREGISTER) {
 	use_float(d,reg);
@@ -3641,7 +3652,7 @@
       code_save_stacks();
       clear_ptr_cache();
       set_dreg(RET_LREGISTER,0);
-      xreg = emit_dpop_regvar(0);
+      xreg = emit_pop(0);
       xrn = register_name(xreg);
       printf("\tlw $4,%d(%s)\n",SIZE_OF_INT,xrn);
       printf("\tlw $5,0(%s)\n",xrn);
@@ -3650,6 +3661,7 @@
       printf("\tsw $3,0(%s)\n",xrn);
       emit_pop_free(xreg);
       if (use) {
+        use_float(d,reg);
 	printf("\tlw %s,%d(%s)\n",lregister_name_high(reg),SIZE_OF_INT,xrn);
 	printf("\tlw %s,0(%s)\n",lregister_name_low(reg),xrn);
       }
@@ -3719,6 +3731,7 @@
     return xreg;
 }
 
+#if 0
 static int emit_lpop_regvar();
 
 static
@@ -3726,7 +3739,9 @@
 { 
     int xreg,reg;
     if (d) {
-	return emit_lpop_regvar();
+	reg =  emit_lpop_regvar();
+	regs[reg] = USING_DREG;
+	return  reg;
     }
     xreg=pop_fregister();
     reg = cadr(get_dregister_var(0,d));
@@ -3739,6 +3754,7 @@
     }
     return xreg;
 }
+#endif
 
 void
 emit_dpop_free(int e1,int d)
@@ -3788,7 +3804,7 @@
 static void
 pcond(int op,char *s,int l1)
 {
-    if (op==EQ||op==NEQ) {
+    if (op==LOP+EQ||op==LOP+NEQ) {
 	 printf(",$L_%d\n",l1);
     } else {
 	 printf("\tb%s %s,$0,$L_%d\n",s,register_name(cmpreg),l1);
@@ -3798,10 +3814,10 @@
 static int
 lcmp(int op,int cond)
 {
-    if (op==EQ||op==NEQ) {
-	 if (!cond) { op=(op==EQ)?CMPNEQ:CMPEQ; }
+    if (op==LOP+EQ||op==LOP+NEQ) {
+	 op=((op==LOP+EQ)^cond)?CMPNEQ:CMPEQ;
     } else {
-	 op = (op==UGT||op==UGE)?UCMP:CMP;
+	 op = (op==LOP+UGT||op==LOP+UGE)?UCMP:CMP;
     }
     return op;
 }
@@ -3863,6 +3879,7 @@
     emit_lpop_free(e3);
 }
 
+#if 0
 static
 int emit_lpop_regvar()
 { 
@@ -3878,6 +3895,7 @@
     }
     return xreg;
 }
+#endif
 
 int
 emit_lpop()
@@ -3910,7 +3928,7 @@
 		lregister_name_low(reg),
 		lregister_name_low(reg),
 		lregister_name_high(reg));
-    printf("\tbeq %s,$0\n",lregister_name_low(reg));
+    code_cmp_register(regv_l(reg));
 }
 
 void
@@ -4637,11 +4655,11 @@
     }
     xreg = emit_pop(0);
     xrn = register_name(xreg);
-    printf("\tlz %s,%d(%s)\n",drn_l,SIZE_OF_INT,xrn);
-    printf("\tlz %s,0(%s)\n",drn_h,xrn);
+    printf("\tlw %s,%d(%s)\n",drn_l,SIZE_OF_INT,xrn);
+    printf("\tlw %s,0(%s)\n",drn_h,xrn);
     ladd(dreg,dir);
-    printf("\tst %s,%d(%s)\n",drn_l,SIZE_OF_INT,xrn);
-    printf("\tst %s,0(%s)\n",drn_h,xrn);
+    printf("\tsw %s,%d(%s)\n",drn_l,SIZE_OF_INT,xrn);
+    printf("\tsw %s,0(%s)\n",drn_h,xrn);
     emit_pop_free(xreg);
     if (dreg!=-1) free_register(dreg);
 }
--- a/mc-codegen.c	Sun May 16 20:11:48 2004 +0900
+++ b/mc-codegen.c	Mon May 17 00:36:31 2004 +0900
@@ -1278,7 +1278,7 @@
     case FRLVAR:
     case DRLVAR: code_drlvar(cadr(e4),d,reg); return;
     case FCONST:
-    case DCONST: code_dconst(e4,reg,1); return;
+    case DCONST: code_dconst(e4,reg,d); return;
     default:
 	    error(-1);
     }