diff mc-code-ia32.c @ 83:f3f75911d62c

*** empty log message ***
author kono
date Wed, 05 Mar 2003 03:41:08 +0900
parents 25654dc29ecc
children 1a723130a2c7
line wrap: on
line diff
--- a/mc-code-ia32.c	Wed Mar 05 00:39:39 2003 +0900
+++ b/mc-code-ia32.c	Wed Mar 05 03:41:08 2003 +0900
@@ -43,16 +43,12 @@
 int size_of_double = 8;
 int size_of_longlong = 8;
 int endian = 0;
-int MAX_REGISTER=6;         /* intel386のレジスタを4つまで使う*/
+int MAX_REGISTER=6;         /* intel386のレジスタを6つまで使う*/
 int REAL_MAX_REGISTER=8;    /* intel386のレジスタが8つということ*/
 int MAX_DATA_REG=4;    
 int MAX_POINTER=3;    
 int MAX_REGISTGER_VAR=2;    
-
-EXTERN int  creg;     /* current register */
-EXTERN int  dreg;     /* temporary register */
-EXTERN int  freg;     /* current floating point register */
-EXTERN int  reg_sp;   /* REGister Stack-Pointer */
+int MAX_FREGISTER=1;
 
 
 #define REG_EAX   0
@@ -71,17 +67,6 @@
 static char *reg_name_l[4];
 static char *reg_name_w[4];
 
-extern int  creg;     /* current register */
-extern int  dreg;     /* temporary register */
-extern int  reg_sp;   /* REGister Stack-Pointer */
-
-#define MAX_MAX 10
-int rname[MAX_MAX];
-int regs[MAX_MAX];       /* 使われているレジスタを示すフラグ */
-int reg_stack[MAX_MAX];  /* 実際のレジスタの領域 */
-int regv[MAX_MAX];       /* 値が入っているかどうか */
-
-
 void use_register(int virt, int real, int move);
 void code_preinc(int e1,int e2) ;
 void code_cmp_register(int e2) ;
@@ -167,13 +152,10 @@
     }
 }
 
-extern int creg_regvar;
-
 void
 gexpr_code_init(void){
     use_register(creg,REG_EAX,0);
     regv[dreg]=0;
-    creg_regvar = -1;
 }
 
 int
@@ -250,6 +232,7 @@
     int new_reg;
     new_reg = get_register();
     if(new_reg<0) {                     /* もうレジスタがない */
+	if (reg_sp>=MAX_MAX) error(-1);
 	reg_stack[reg_sp++] =  -1;
 	printf("\tpushl %s\n",register_name(creg,0));
 	/* creg is used soon, don't regv[creg]=0 */
@@ -734,13 +717,13 @@
 	} else if (t==DOUBLE) {
 	    g_expr(e4);
 	    printf("\tleal\t-8(%%esp),%%esp\n\tfstpl\t(%%esp)\n");
-	    regv[freg]=0;
+	    fregv[freg]=0;
 	    nargs += size_of_double/size_of_int;
 	    continue;
 	} else if (t==FLOAT) {
 	    g_expr(e4);
 	    printf("\tleal\t-4(%%esp),%%esp\n\tfstps\t(%%esp)\n");
-	    regv[freg]=0;
+	    fregv[freg]=0;
 	    nargs += size_of_float/size_of_int;
 	    continue;
 	} else if (car(t)==STRUCT||car(t)==UNION) {
@@ -781,7 +764,7 @@
     }
     regv[save]=0;
     regv[creg]=1;
-    regv[freg]=1; /* return type はどこ? fnptr にはあるけど... */
+    fregv[freg]=1; /* return type はどこ? fnptr にはあるけど... */
 }
 
 void
@@ -1174,7 +1157,7 @@
     fwddef(retlabel);
     /* use_register(creg,REG_EAX,0); too late */
     /* if(disp) printf("\taddl $%d,%%esp\n",-disp);  */
-    disp&= -size_of_int;
+    disp &= -size_of_int;
 
     printf("\tlea %d(%%ebp),%%esp\n",disp_offset);
     printf("\tpopl %%edi\n");
@@ -1363,6 +1346,15 @@
 char *
 fstore(int d)
 {
+    return use?
+	(d?"fstl":"fsts"):
+	(d?"fstpl":"fstps")
+    ;
+}
+
+char *
+fstore_u(int d)
+{
     return d?"fstpl":"fstps";
 }
 
@@ -1490,6 +1482,42 @@
     }
 }
 
+void
+code_dassop(int op,int d) {
+    /* we have lvalue in creg, applied floating value is in %st(0) */
+    printf("\t%s (%s)\n",fload(d),register_name(creg,0));
+    dtosop(op,0);
+    printf("\t%s (%s)\n",fstore(d),register_name(creg,0));
+}
+
+void
+code_dpreinc(int e1,int e2,int d) {
+    g_expr(e2);
+    printf("\t%s (%s)\n",fload(d),register_name(creg,0));
+    printf("\tfld1\n");
+    if (e2>0)
+	printf("\tfaddp %%st,%%st(1)\n");
+    else
+	printf("\tfsubrp %%st,%%st(1)\n");
+    printf("\t%s (%s)\n",fstore(d),register_name(creg,0));
+}
+
+void
+code_dpostinc(int e1,int e2,int d) {
+    g_expr(e2);
+    printf("\t%s (%s)\n",fload(d),register_name(creg,0));
+    if (use)
+	/* dup */;
+    printf("\tfld1\n");
+    if (e2>0)
+	printf("\tfaddp %%st,%%st(1)\n");
+    else
+	printf("\tfsubrp %%st,%%st(1)\n");
+    printf("\t%s (%s)\n",fstore_u(d),register_name(creg,0));
+    if (use)
+	/* pop */;
+}
+
 int dpop_register()
 { 
     return 1;