changeset 95:185d2cc6a3a9

*** empty log message ***
author kono
date Thu, 13 Mar 2003 14:41:48 +0900
parents 1ad7045741a7
children 7d8de41390d8
files mc-code-ia32.c mc-code-powerpc.c mc-code.h mc-codegen.c mc-codegen.h mc-parse.c mc.h
diffstat 7 files changed, 227 insertions(+), 155 deletions(-) [+]
line wrap: on
line diff
--- a/mc-code-ia32.c	Wed Mar 12 15:28:44 2003 +0900
+++ b/mc-code-ia32.c	Thu Mar 13 14:41:48 2003 +0900
@@ -46,13 +46,46 @@
 int size_of_double = 8;
 int size_of_longlong = 8;
 int endian = 0;
-int MAX_REGISTER=6;         /* intel386のレジスタを6つまで使う*/
-int REAL_MAX_REGISTER=8;    /* intel386のレジスタが8つということ*/
+int MAX_REGISTER=6;            /* intel386のレジスタを6つまで使う*/
+#define REAL_MAX_REGISTER 8    /* intel386のレジスタが8つということ*/
 int MAX_DATA_REG=4;    
 int MAX_POINTER=3;    
 int MAX_REGISTGER_VAR=2;    
 int MAX_FREGISTER=1;
 
+/*
+    creg   currrent virtual register
+    dreg   spare virtual register
+
+    rname[creg]   currrent real register
+    rname[dreg]   spare real register
+
+    regs[]        virtual register usage
+    regv[]        value in virtual register flag
+
+    reg_name[rname[creg]]
+
+    freg    current floating point register
+    fregv   calue in floating point register
+ */
+
+static int dreg; /* general temporal register */
+
+int ia32regs[REAL_MAX_REGISTER];
+int ia32regv[REAL_MAX_REGISTER];
+int ia32rname[REAL_MAX_REGISTER];
+
+int *regv  = ia32regv;
+int *regs  = ia32regs;
+static int *rname = ia32rname;
+
+int ia32fregs[1];
+int ia32fregv[1];
+
+int freg;
+int *fregv = ia32fregv;
+int *fregs = ia32fregs;
+
 
 #define REG_EAX   0
 #define REG_EBX   1
@@ -142,8 +175,6 @@
     return virtual(r+REG_ESI);
 }
 
-
-
 int 
 get_register(void)
 {    /* 使われていないレジスタを調べる */
@@ -995,6 +1026,7 @@
 
 void
 code_assign(int e2,int byte) {
+    if (byte) use_data_reg(creg,1);
     printf("\t%s %s,(%s)\n",move(byte),register_name(creg,byte),register_name(e2,0));
 }
 
@@ -1160,17 +1192,25 @@
 
     op = byte ? "movsbl" : "movl";
     if (n) 
-	    printf("\t%s %d(%s),%s\n",op,n,register_name(xreg,0),register_name(creg,byte));
+	    printf("\t%s %d(%s),%s\n",op,n,
+		register_name(xreg,0),register_name(creg,byte));
     else
-	    printf("\t%s (%s),%s\n",op,register_name(xreg,0),register_name(creg,byte));
+	    printf("\t%s (%s),%s\n",op,
+		register_name(xreg,0),register_name(creg,byte));
+}
+
+int
+code_csvalue()
+{
+    return creg; /* for switch value */
 }
 
 void
-cmpdimm(int e, int csreg)
+code_cmpdimm(int e, int csreg)
 {
     /* used in dosiwtch() */
     if(chk) return;
-    use_register(creg,csreg,0);
+    use_register(creg,rname[csreg],0);
     printf("\tcmpl $%d,%s\n",e,register_name(creg,0));
 }
 
--- a/mc-code-powerpc.c	Wed Mar 12 15:28:44 2003 +0900
+++ b/mc-code-powerpc.c	Thu Mar 13 14:41:48 2003 +0900
@@ -15,7 +15,6 @@
 static void ld_indexx(int byte, int n, int xreg);
 static void local_table(void);
 static void shift(char *op, int reg);
-static void use_register(int virt, int real, int move);
 static void use_register_var(int i);
 
 static int output_mode = TEXT_EMIT_MODE;
@@ -56,8 +55,9 @@
 int size_of_double = 8;
 int size_of_longlong = 8;
 int endian = 0;
-int MAX_REGISTER=30;         /* PowerPCのレジスタを10個まで使う*/
-int REAL_MAX_REGISTER=32;    /* PowerPCのレジスタが32ということ*/
+int MAX_REGISTER=30;             /* PowerPCのレジスタを10個まで使う*/
+#define  REAL_MAX_REGISTER 32    /* PowerPCのレジスタが32ということ*/
+#define  REAL_MAX_FREGISTER 32    /* PowerPCのレジスタが32ということ*/
 int MAX_REGISTGER_VAR=30-10;    
 int MAX_FREGISTER=30;
 
@@ -69,7 +69,17 @@
 #define FREG_ARG_BASE 1 
 #define FREG_ARG_MAX  13 
 
-int reg_sp=REG_sp;
+int powerpc_regs[REAL_MAX_REGISTER];
+int powerpc_regv[REAL_MAX_REGISTER];
+
+int *regv  = powerpc_regv;
+int *regs  = powerpc_regs;
+
+int powerpc_fregs[REAL_MAX_FREGISTER];
+int powerpc_fregv[REAL_MAX_FREGISTER];
+
+int *fregv = powerpc_fregv;
+int *fregs = powerpc_fregs;
 
 static char *reg_name[] = {
     "r0","r1","r2","r3","r4","r5","r6","r7","r8","r9",
@@ -89,6 +99,13 @@
     "cr0","cr1","cr2","cr3","cr4","cr5","cr6","cr7"
 }; 
 
+char * fload(int d);
+int code_d1(double d);
+int code_d2(double d);
+void code_save_registers();
+void code_save_stacks();
+void regist_extern_function();
+
 void
 code_init(void)
 {
@@ -106,12 +123,6 @@
     regv[creg]=0;
 }
 
-int virtual(int real);
-char * fload(int d);
-int code_d1(double d);
-int code_d2(double d);
-
-
 int 
 get_register(void)
 {    /* 使われていないレジスタを調べる */
@@ -139,11 +150,7 @@
 void
 emit_pop_free(int xreg)
 {
-    if (xreg==dreg) {
-        regv[dreg]=0;
-    } else if (xreg!=-1) {
-        free_register(xreg);
-    }
+    free_register(xreg);
 }
 
 void 
@@ -182,7 +189,7 @@
 	regs[i]=regv[i]=0;
     }
     creg = get_register();
-    dreg = get_register();
+    freg = get_register();
     return;
 }
 
@@ -219,7 +226,7 @@
     int i;
     if (chk) return;
     printf("# %d: %s:",lineno,s);
-    printf(" creg=%s dreg=%s ",register_name(creg),register_name(dreg));
+    printf(" creg=%s ",register_name(creg));
     for(i=0;i<MAX_REGISTER;i++) {
 	printf("%d",regs[i]);
     }
@@ -253,7 +260,7 @@
 emit_init(void)
 {
     int i;
-    for(i=0;i<MAX_REGISTER;i++) { regs[i]=0; regv[i]=0;rname[i]=i;}
+    for(i=0;i<MAX_REGISTER;i++) { regs[i]=0; regv[i]=0; }
     free_all_register();
     init_ptr_cache();
     reg_sp = 0;
@@ -262,7 +269,7 @@
 
 int
 register_var(int r) {
-    return virtual(REG_VAR_BASE-r);
+    return REG_VAR_BASE-r;
 }
 
 int
@@ -329,7 +336,7 @@
     }
 }
 
-int
+void
 clear_ptr_cache()
 {
     int ptcptr=ptr_cache;
@@ -348,10 +355,9 @@
 {
     int r;
     int ptcptr=ptr_cache;
-    int cache;
-    int i = 0;
     int g = (int)name;
     int p,p1;
+    char *rrn;
 
     while(ptcptr) {
 	if(car(ptcptr)==g) return caddr(ptcptr);
@@ -406,7 +412,7 @@
 
 void
 code_lvar(int e2) {
-    printf("\tla %s,%d(r1),%s\n",register_name(creg),e2);
+    printf("\tla %s,%d(r1)\n",register_name(creg),e2);
 }
 
 
@@ -418,15 +424,15 @@
 
 
 void
-code_rlvar(int e2) {
-    printf("\tlwz %s,%d(r1),%s\n",register_name(creg),e2);
+code_rlvar(int e2,int reg) {
+    printf("\tlwz %s,%d(r1)\n",register_name(reg),e2);
 }
 
 
 void
-code_crlvar(int e2) {
-    printf("\tlbz %s,%d(r1),%s\n",register_name(creg),e2);
-    printf("\textsb %s,%s\n",register_name(creg),register_name(creg));
+code_crlvar(int e2,int reg) {
+    printf("\tlbz %s,%d(r1)\n",register_name(reg),e2);
+    printf("\textsb %s,%s\n",register_name(reg),register_name(reg));
 }
 
 
@@ -435,7 +441,7 @@
     int r;
     r = get_ptr_cache(e2);
     if(r!=creg)
-	printf("\tmr %s,%s\n",register_name(creg),register_name(e2));
+	printf("\tmr %s,%s\n",register_name(creg),register_name(r));
     return;
 }
 
@@ -476,7 +482,8 @@
     char *xrn,*drn;
     int i,dreg;
     if (car(e2)==REGISTER) {
-	printf("\taddi %s,%s,%d\n", register_name(cadr(e2)));
+	printf("\taddi %s,%s,%d\n", 
+		register_name(cadr(e2)),register_name(cadr(e2)), caddr(e1));
 	printf("\tmr %s,%s\n",register_name(cadr(creg)),register_name(e2));
 	return;
     } 
@@ -496,11 +503,11 @@
 void
 code_postinc(int e1,int e2) {
     char *xrn,*crn,*nrn;
-    int dreg,nreg;
+    int dreg,nreg,i;
     if (car(e2)==REGISTER) {
 	printf("\tmr %s,%s\n",register_name(creg),register_name(cadr(e2)));
 	printf("\taddi %s,%s,%d\n", 
-	    register_name(cadr(e2)),register_name(cadr(e2)));
+	    register_name(cadr(e2)),register_name(cadr(e2)),caddr(e1));
 	return;
     } 
     g_expr(e2);
@@ -520,7 +527,7 @@
 
 void
 code_cpostinc(int e1,int e2) {
-    char *xrn,*crn;
+    char *xrn,*crn,*nrn;
     int i,nreg,dreg;
     if (car(e2)==REGISTER) {
 	printf("\tlbz %s,(%s)\n",register_name(creg),register_name(cadr(e2)));
@@ -538,7 +545,7 @@
     printf("\tlwz %s,(%s)\n",xrn,crn);
     printf("\tlbz %s,(%s)\n",nrn,xrn);
     printf("\textsb %s,%s\n",nrn,nrn);
-    printf("\taddi %s,%s,%d\n", xrn,xrn);
+    printf("\taddi %s,%s,%d\n", xrn,xrn,caddr(e1));
     printf("\tstw %s,(%s)\n",xrn,crn);
     i=creg;creg=nreg;nreg=i; 
     free_register(nreg);
@@ -549,7 +556,7 @@
 
 void
 code_cpreinc(int e1,int e2) {
-    char *xrn,*crn;
+    char *xrn,*crn,*nrn;
     int i,nreg,dreg;
     if (car(e2)==REGISTER) {
 	printf("\tlbzu %s,%d(%s)\n",register_name(creg),caddr(e1),register_name(cadr(e2)));
@@ -575,7 +582,7 @@
 
 void
 code_cpostdec(int e1,int e2) {
-    char *xrn,*crn;
+    char *xrn,*crn,*nrn;
     int i,nreg,dreg;
     if (car(e2)==REGISTER) {
 	crn=register_name(creg);
@@ -605,7 +612,7 @@
 
 void
 code_cpredec(int e1,int e2) {
-    char *xrn,*crn;
+    char *xrn,*crn,*nrn;
     int i,nreg,dreg;
     if (car(e2)==REGISTER) {
 	crn=register_name(creg);
@@ -633,7 +640,7 @@
 
 void
 code_return() {
-    int r;
+    char *crn = register_name(creg);
     printf("\taddis %s,r31,ha16(_%d-%s)\n",crn,retcont,code_base);
     printf("\tla %s,lo16(_%d-%s)(%s)\n",crn,retcont,code_base,crn);
 }
@@ -746,8 +753,9 @@
 void
 string(int e1)
 {
-    char *s;
-    int i,lb;
+    char *s,*crn;
+    int lb;
+    crn=register_name(creg);
 
     s=(char *)cadr(e1);
     printf(".data\t.cstring\n\t.align 2\n");
@@ -773,7 +781,7 @@
     char *drn;
     int fix = 0;
     char *bcopy = "bcopy";
-    int dreg = get_regiter(); if (!dreg) error(-1);
+    int dreg = get_register(); if (!dreg) error(-1);
     drn	 = register_name(dreg);
 
     /* length <0 means upward direction copy */
@@ -835,14 +843,14 @@
 int
 struct_push(int e4,int t) 
 {
-    int length,save,count;
+    int length,count;
     int dreg; char *drn,*crn,*srn;
     g_expr(e4);
     length=size(t); 
     if(length%size_of_int) {
 	length += size_of_int - (length%size_of_int);
     }
-    dreg = get_regiter(); if (!dreg) error(-1);
+    dreg = get_register(); if (!dreg) error(-1);
     drn = register_name(dreg);
     crn = register_name(dreg);
     srn = register_name(reg_sp);
@@ -866,16 +874,22 @@
 }
 
 int
-arg_offset(int arg)
+arg_offset_v(int arg)
 {
+    return arg;
 }
 
-void
+int
 function(int e1)
 {
     int e2,e3,e4,e5,nargs,t;
     int reg_arg,freg_arg;
     NMTBL *n;
+    int jmp;
+    char *jrn,*crn;
+
+    code_save_stacks();
+    code_save_registers();
     e2 = cadr(e1);
     nargs = 0;
     reg_arg = REG_ARG_BASE;
@@ -890,25 +904,22 @@
                                 register_name(creg));
 	    else {
 		printf("\tstw %s,%d(r1)\n",register_name(creg),
-                                arg_offset(nargs));
+                                arg_offset_v(nargs));
 	    }
 	    nargs ++ ; reg_arg++;
 	} else if (t==DOUBLE||t==FLOAT) {
 	    g_expr(e4);
 	    nargs += size_of_double/size_of_int;
-	    if (fregv[freg_arg])
-		save_freg(freg_arg);
-	    fregv[freg_arg]=1;
 	    if (freg_arg<FREG_ARG_MAX)
 		printf("\tmr %s,%s\n",register_name(reg_arg++),
                                 register_name(freg));
 	    else if(t==DOUBLE) {
 		printf("\tstfd %s,%d(r1)\n",register_name(freg),
-                                arg_offset(nargs));
+                                arg_offset_v(nargs));
 		nargs+=size_of_double/size_of_int; 
 	    } else {
 		printf("\tstfs %s,%d(r1)\n",register_name(freg),
-                                arg_offset(nargs));
+                                arg_offset_v(nargs));
 		nargs+=size_of_float/size_of_int; 
 	    }
 	    freg_arg++;
@@ -932,8 +943,9 @@
     if (car(e2) == FNAME) {	
 	printf("\tbl\tL_%s$stub\n",n->nm);
     } else {
-	jmp=get_tmp_register();
+	jmp=get_register();
         jrn = register_name(jmp);
+	crn = register_name(creg);
 	printf("\tmr %s,%s\n",jrn,crn);
         printf("\tmtctr %s\n",jrn);
         printf("\tbctrl\n");
@@ -941,6 +953,7 @@
     }
     regv[creg]=1;
     clear_ptr_cache();
+    return fnptr->ty;
 }
 
 void
@@ -966,11 +979,11 @@
     printf("\tbctr\n");
 }
 
-void
+int
 rindirect(int e1)   /* *(p +5 ) */
 {
-    char *op,*crn;
-    int e2,e3,byte;
+    char *crn;
+    int e2,e3;
     e3 = cadr(e2 = cadr(e1));
     g_expr(e2);
     crn=register_name(creg);
@@ -979,15 +992,16 @@
 	printf("\t%s %s,(%s)\n",fload(car(e1)==DRINDIRECT),
 	    register_name(freg),crn);
 	regv[creg]=0; regv[freg]=1;
-	break;
+	return DOUBLE;
     case CRINDIRECT: 
 	printf("\tlbz %s,(%s)\n",crn,crn);
 	printf("\textsb %s,%s\n",crn,crn);
-	break;
+	return CHAR;
     case RINDIRECT:
 	printf("\tlwz %s,(%s)\n",crn,crn);
-	break;
+	return INT;
     }
+    error(-1); return INT;
 }
 
 void
@@ -1022,7 +1036,9 @@
 
 void
 code_assign(int e2,int byte) {
-    char *drn=register_name(dreg);
+    char *drn=register_name(e2);
+    char *crn=register_name(creg);
+
     if (byte) {
 	printf("\tstb %s,(%s)\n",crn,drn);
     } else {
@@ -1069,7 +1085,7 @@
 tosop(int op,int oreg)
 {
     int dx;
-    char *orn,*crn;
+    char *orn,*crn,*drn;
 
     switch(op) {
     case LSHIFT:
@@ -1103,34 +1119,34 @@
 	break;
     case MUL:
     case UMUL:
-	printf("\t%mullw %s,%s,%s\n",crn,orn,crn);
+	printf("\tmullw %s,%s,%s\n",crn,orn,crn);
 	break;
     case DIV:
-	printf("\t%divw %s,%s,%s\n",crn,orn,crn);
+	printf("\tdivw %s,%s,%s\n",crn,orn,crn);
 	break;
     case UDIV:
-	printf("\t%divwu %s,%s,%s\n",crn,orn,crn);
+	printf("\tdivwu %s,%s,%s\n",crn,orn,crn);
 	break;
     case MOD:
 	dx=get_register();
-	drn = register_name(drn);
-	printf("\t%divwu %s,%s,%s\n",drn,orn,crn);
-	printf("\t%mullw %s,%s,%s\n",drn,drn,crn);
-	printf("\t%subf %s,%s,%s\n",drn,drn,orn);
+	drn = register_name(dx);
+	printf("\tdivwu %s,%s,%s\n",drn,orn,crn);
+	printf("\tmullw %s,%s,%s\n",drn,drn,crn);
+	printf("\tsubf %s,%s,%s\n",drn,drn,orn);
 	free_register(creg);
 	creg=dx;
 	break;
     case UMOD:
 	dx=get_register();
-	drn = register_name(drn);
-	printf("\t%divwu %s,%s,%s\n",drn,orn,crn);
-	printf("\t%mullw %s,%s,%s\n",drn,drn,crn);
-	printf("\t%subf %s,%s,%s\n",drn,drn,orn);
+	drn = register_name(dx);
+	printf("\tdivwu %s,%s,%s\n",drn,orn,crn);
+	printf("\tmullw %s,%s,%s\n",drn,drn,crn);
+	printf("\tsubf %s,%s,%s\n",drn,drn,orn);
 	free_register(creg);
 	creg=dx;
 	break;
     }
-    if(oreg!=cre) free_register(oreg);
+    if(oreg!=creg) free_register(oreg);
 }
 
 
@@ -1145,19 +1161,24 @@
 void
 ld_indexx(int byte, int n, int xreg)
 {	
-    char *op;
-
+    char *crn = register_name(creg);
     if (byte) {
-	printf("\tlbz %s,%d(%s),%s\n",register_name(creg),n,
+	printf("\tlbz %s,%d(%s)\n",register_name(creg),n,
 	    register_name(xreg));
 	printf("\textsb %s,%s\n",crn,crn);
     } else 
-	printf("\tlwz %s,%d(%s),%s\n",register_name(creg),n,
+	printf("\tlwz %s,%d(%s)\n",register_name(creg),n,
 	    register_name(xreg));
 }
 
+int
+code_csvalue()
+{
+    return creg;
+}
+
 void
-cmpdimm(int e, int csreg)
+code_cmpdimm(int e, int csreg)
 {
     /* used in dosiwtch() */
     if(chk) return;
@@ -1181,7 +1202,7 @@
 }
 
 void
-rexpr(int e1, int l1, char *s)
+rexpr(int e1, int l1, char *s,int t)
 {       
     g_expr(list3(CMP,cadr(e1),caddr(e1)));
     printf("\tb%s cr0,_%d\n",s,l1);
@@ -1269,19 +1290,12 @@
 void
 leave(int control, char *name)
 {
-    if (control)
-	use_register(creg,REG_EAX,1);
     if (retcont) {
 	if (control)
 	    jmp(retlabel);
 	fwddef(retcont);
-	use_register(creg,REG_EAX,0);
-	printf("\tmovl %s,%s\n",reg_name[REG_ESI],register_name(creg));
-	/* printf("\tleave\n"); */
     }
     fwddef(retlabel);
-    /* use_register(creg,REG_EAX,0); too late */
-    /* if(disp) printf("\taddl $%d,%%esp\n",-disp);  */
     disp &= -size_of_int;
 
     printf("\tlea %d(%%ebp),%%esp\n",disp_offset);
@@ -1480,10 +1494,20 @@
     return d?"lfd":"lfs";
 }
 
+void
+code_cmp_dregister(int e2)
+{
+}
+
+void
+code_dregister(int e2)
+{
+}
+
 void code_dassign_gvar(int e2,int d)
 { 
     int r;
-    r = get_ptr_cache((char*)caddr(e1));
+    r = get_ptr_cache((char*)caddr(e2));
     printf("\t%s %s,(%s)\n",fstore(d),register_name(freg),register_name(r));
 }
 
@@ -1538,22 +1562,23 @@
     }
     printf("\taddis %s,r31,ha16(_%d-%s)\n",rrn,lb,code_base);
     printf("\tla %s,lo16(_%d-%s)(%s)\n",rrn,lb,code_base,rrn);
-    printf("\tlfd %s,%(s)\n",register_name(freg),rrn);
+    printf("\tlfd %s,(%s)\n",register_name(freg),rrn);
     free_register(r);
 }
 
 void code_dneg()
 { 
     char *frn = register_name(freg);
-    printf("\tfneg %s,%s\n",freg);
+    printf("\tfneg %s,%s\n",frn,frn);
 }
 
 void code_d2i()
 { 
     char *frn = register_name(freg);
+    char *crn = register_name(creg);
     disp-=size_of_double;
     printf("\tfctiwz  %s,%s\n",frn,frn);
-    printf("\tstfd  %s,%d(r1)\n",disp);
+    printf("\tstfd  %s,%d(r1)\n",frn,disp);
     printf("\tlwz  %s,%d(r1)\n",crn,disp+size_of_double-size_of_int);
     fregs[freg]=0;
     regs[creg]=1;
@@ -1589,7 +1614,7 @@
 
 void code_i2d()
 { 
-    d2u_lib_used=1;
+    i2d_lib_used = 1;
     char *frn = register_name(freg);
     char *crn = register_name(creg);
     printf("\tmr r3,%s\n",crn);
@@ -1676,7 +1701,7 @@
 
 void code_u2d()
 { 
-    u2d_lib_used=1;
+    u2d_lib_used = 1;
     char *frn = register_name(freg);
     char *crn = register_name(creg);
     printf("\tmr r3,%s\n",crn);
@@ -1689,7 +1714,7 @@
 void code_drgvar(int e2,int d)
 { 
     int r;
-    r = get_ptr_cache((char*)caddr(e1));
+    r = get_ptr_cache((char*)caddr(e2));
     printf("\t%s %s,(%s)\n",fload(d),register_name(freg),register_name(r));
 }
 
@@ -1703,23 +1728,23 @@
 { 
     int r;
     char *frn=register_name(freg);
-    int g=get_fregister();
+    int g=get_register();
     char *grn=register_name(g);
-    r = get_ptr_cache((char*)caddr(e1));
-    printf("\t%s,(%s)\n",fload(d),grn,register_name(r));
+    r = get_ptr_cache((char*)caddr(e2));
+    printf("\t%s %s,(%s)\n",fload(1),grn,register_name(r));
     printf("\tfcmpu cr0,%s,%s\n",frn,grn);
-    free_fregister(g);
+    free_register(g);
 }
 
 void code_cmp_drlvar(int e2)
 { 
     printf("\tfcmpu %d(%%ebp)\n",e2);
     char *frn=register_name(freg);
-    int g=get_fregister();
+    int g=get_register();
     char *grn=register_name(g);
-    printf("\t%s,%d(r1)\n",fload(d),grn,e2);
+    printf("\t%s %s,%d(r1)\n",fload(1),grn,e2);
     printf("\tfcmpu cr0,%s,%s\n",frn,grn);
-    free_fregister(g);
+    free_register(g);
 }
 
 void dtosop(int op,int e1)
@@ -1733,23 +1758,23 @@
     case DDIV: opn="fadd"; break;
     case DMUL: opn="fadd"; break;
     case DCMP: 
-	printf("\tfcompu cr0,%s,%s\n",opn,frn,grn);
-	fgree_register(e1);
+	printf("\tfcompu cr0,%s,%s\n",frn,grn);
+	free_register(e1);
 	break;
     case DCMPGE: 
-	printf("\tfcompu cr7,%s,%s\n",opn,frn,grn);
-	fgree_register(e1);
+	printf("\tfcompu cr7,%s,%s\n",frn,grn);
+	free_register(e1);
 	break;
     }
     printf("\t%s %s,%s,%s\n",opn,frn,frn,grn);
-    fgree_register(e1);
+    free_register(e1);
 }
 
 void
 code_dassop(int op,int d) {
     /* we have lvalue in creg, applied floating value is in freg */
     char *frn=register_name(freg);
-    int  e1=get_fregister();
+    int  e1=get_register();
     char *grn=register_name(e1);
     char *crn=register_name(creg);
 
@@ -1851,5 +1876,20 @@
 { 
 }
 
+void
+code_save_registers()
+{
+}
+
+void
+code_save_stacks()
+{
+}
+
+void
+regist_extern_function(bcopy)
+{
+}
+
 /* end */
 
--- a/mc-code.h	Wed Mar 12 15:28:44 2003 +0900
+++ b/mc-code.h	Thu Mar 13 14:41:48 2003 +0900
@@ -16,11 +16,12 @@
 extern void gexpr_code_init(void);
 extern int register_var(int r);
 extern int get_register_var(void);
-extern void use_data_reg(int virt, int move);
 extern void emit_push(void);
 extern void emit_push_x(int xreg);
 extern int emit_pop(int type);
 extern void gexpr_code_init();
+extern int  code_csvalue();
+extern void code_cmpdimm(int e, int csreg);
 extern void code_gvar(int e1);
 extern void code_rgvar(int e1);
 extern void code_crgvar(int e1);
--- a/mc-codegen.c	Wed Mar 12 15:28:44 2003 +0900
+++ b/mc-codegen.c	Thu Mar 13 14:41:48 2003 +0900
@@ -7,39 +7,21 @@
 #include "mc-code.h"
 
 int  creg;     /* current register */
-int  dreg;     /* temporary register */
 int  reg_sp;   /* REGister Stack-Pointer */
-
-int rname[MAX_MAX];
-int regs[MAX_MAX];       /* 使われているレジスタを示すフラグ */
 int reg_stack[MAX_MAX];  /* 実際のレジスタの領域 */
-int regv[MAX_MAX];       /* 値が入っているかどうか */
 
 /* floating point registers */
 
 int  freg;     /* current floating point register */
-int  greg;     /* current floating point register */
 int  freg_sp;  /* floating point REGister Stack-Pointer */
-
-int frname[MAX_MAX];
-int fregs[MAX_MAX];      /* 使われているレジスタを示すフラグ */
 int freg_stack[MAX_MAX]; /* 実際のレジスタの領域 */
-int fregv[MAX_MAX];      /* 値が入っているかどうか */
 
 int use;       /* generated value will be used */
 
 /*
     creg   currrent virtual register
-    dreg   spare virtual register
-
-    rname[creg]   currrent real register
-    rname[dreg]   spare real register
-
     regs[]        virtual register usage
     regv[]        value in virtual register flag
-
-    reg_name[rname[creg]]
-
     freg    current floating point register
     fregv   calue in floating point register
  */
@@ -69,12 +51,6 @@
 }
 
 int
-csvalue()
-{
-    return rname[creg]; /* for switch value */
-}
-
-int
 g_expr_u(int e1)
 {
     int t;
@@ -120,14 +96,12 @@
 	return ADDRESS;
     case REGISTER:
 	/* this is of course redundant... */
-	/* we can use rname for this? */
 	/* or why not creg=e2? */
 	code_register(e2);
 	regv[creg]=1;
 	return INT;
     case DREGISTER:
 	/* this is of course redundant... */
-	/* we can use rname for this? */
 	/* or why not creg=e2? */
 	code_dregister(e2);
 	fregv[freg]=1;
@@ -258,7 +232,6 @@
 	b_expr(cadr(e1),0,e2,0);
 	code_set_fixed_creg(0);
 	g_expr0(caddr(e1));
-	/* e4 = rname[creg]; this is a bad idea */
 	code_set_fixed_creg(1);
 	jmp(e3=fwdlabel());
 	fwddef(e2);
@@ -854,9 +827,7 @@
     }
     g_expr(e2);
     emit_push();
-    use_data_reg(creg,0);
     g_expr(e4);
-    if (byte) use_data_reg(creg,1);
     e2 = emit_pop(0);
     code_assign(e2,byte);
     emit_pop_free(e2);
@@ -938,6 +909,19 @@
     return;
 }
 
+void 
+cmpdimm(int e, int csreg)
+{
+    code_cmpdimm(e, csreg);
+}
+
+int 
+csvalue()
+{
+    return code_csvalue();
+}
+
+
 int
 fwdlabel(void)
 {       
--- a/mc-codegen.h	Wed Mar 12 15:28:44 2003 +0900
+++ b/mc-codegen.h	Thu Mar 13 14:41:48 2003 +0900
@@ -3,32 +3,27 @@
 #define MAX_MAX 10
 
 extern int  creg;     /* current register */
-extern int  dreg;     /* temporary register */
 extern int  reg_sp;   /* REGister Stack-Pointer */
 
-extern int rname[MAX_MAX];
-extern int regs[MAX_MAX];       /* 使われているレジスタを示すフラグ */
+extern int *regs;       /* 使われているレジスタを示すフラグ */
+extern int *regv;       /* 値が入っているかどうか */
 extern int reg_stack[MAX_MAX];  /* 実際のレジスタの領域 */
-extern int regv[MAX_MAX];       /* 値が入っているかどうか */
 
 /* floating point registers */
 
-extern int  freg;     /* current floating point register */
-extern int  greg;     /* current floating point register */
-extern int  freg_sp;  /* floating point REGister Stack-Pointer */
+extern int  freg;       /* current floating point register */
+extern int  freg_sp;    /* floating point REGister Stack-Pointer */
 
-extern int frname[MAX_MAX];
-extern int fregs[MAX_MAX];      /* 使われているレジスタを示すフラグ */
+extern int *fregs;      /* 使われているレジスタを示すフラグ */
+extern int *fregv;      /* 値が入っているかどうか */
 extern int freg_stack[MAX_MAX]; /* 実際のレジスタの領域 */
-extern int fregv[MAX_MAX];      /* 値が入っているかどうか */
 
-extern int use;                 /* generated value will be used */
+extern int use;                 /* generated value will be used in gexpr */
 
 /* function provided by mc-codegen.c */
 
 extern void def_label(int cslabel, int dlabel);
 extern int backdef(void);
-extern int csvalue();
 extern int free_register_count(void);
 extern int fwdlabel(void);
 extern void b_expr(int e1, char cond, int l1,int err);
--- a/mc-parse.c	Wed Mar 12 15:28:44 2003 +0900
+++ b/mc-parse.c	Thu Mar 13 14:41:48 2003 +0900
@@ -3699,6 +3699,17 @@
 }
 
 int
+glist3(int e1,int e2,int e3)
+{
+    int smode,ret;
+    smode = mode;
+    mode = GDECL;
+    ret = list3(e1,e2,e3);
+    mode = smode;
+    return ret;
+}
+
+int
 rplacad(int e, int n)
 {
     heap[e+1]=n;
--- a/mc.h	Wed Mar 12 15:28:44 2003 +0900
+++ b/mc.h	Thu Mar 13 14:41:48 2003 +0900
@@ -305,6 +305,7 @@
 EXTERN int fwdlabel(void);
 EXTERN int get_register_var(void);
 EXTERN int glist2(int e1,int e2);
+EXTERN int glist3(int e1,int e2,int e3);
 EXTERN int integral(int t);
 EXTERN int list2(int e1, int e2);
 EXTERN int list3(int e1, int e2, int e3);