diff mc-codegen.c @ 105:7e3d59e56a53

save register ( incomplete )
author kono
date Tue, 18 Mar 2003 01:54:46 +0900
parents c21aeb12b78b
children 06f72222d6b5
line wrap: on
line diff
--- a/mc-codegen.c	Mon Mar 17 20:57:01 2003 +0900
+++ b/mc-codegen.c	Tue Mar 18 01:54:46 2003 +0900
@@ -26,15 +26,16 @@
     fregv   calue in floating point register
  */
 
-void remove0(int *parent,int e) ;
-void remove0_all(int *parent,int e) ;
-int is_same_type(int e1,int e2);
-void jump(int e1, int env);
-void machinop(int e1);
-void sassign(int e1);
-void assign(int e1);
-void assop(int e1);
-int g_expr0(int e1);
+static void remove0(int *parent,int e) ;
+/* static void remove0_all(int *parent,int e) ; */
+static int is_same_type(int e1,int e2);
+static void jump(int e1, int env);
+static void machinop(int e1);
+static void sassign(int e1);
+static void assign(int e1);
+static void assop(int e1);
+static int g_expr0(int e1);
+static int register_to_lvar(int e);
 
 void
 codegen_init()
@@ -165,7 +166,10 @@
     case DRINDIRECT: case FRINDIRECT:
 	return rindirect(e1);
     case ADDRESS:
-	return g_expr0(e2);
+	if (car(e2)==REGISTER||car(e2)==DREGISTER)
+	    return register_to_lvar(e2);
+	else
+	    return g_expr0(e2);
     case MINUS:  /* レジスタに対し、neglを実行すれば実現可能 */
 	g_expr0(e2); code_neg();
 	return INT;
@@ -469,26 +473,61 @@
         if (scalar(type)) {
             if(reg_var<max_input_register_var) {
                 n->sc = REGISTER;
-		n->dsp = cadr(get_input_register_var(reg_var));
-		regv[reg_var]= 1;
-		regs[reg_var]= INPUT_REG;
+		n->dsp = cadr(get_input_register_var(reg_var,n));
+		regv[n->dsp]= 1;
+		regs[n->dsp]= INPUT_REG;
                 reg_var++;
-                cadddr(fnptr->dsp)=size_of_int;
+                cadddr(args)=size_of_int; /* why we need this? */
             }
         } else if ((type==FLOAT||type==DOUBLE)&&stmode==REGISTER) {
             if(freg_var<max_input_fregister_var) {
                 n->sc = DREGISTER;
-		n->dsp = cadr(get_input_fregister_var(freg_var));
-		fregv[reg_var]= 1;
-		fregs[reg_var]= INPUT_REG;
+		n->dsp = cadr(get_input_fregister_var(freg_var,n));
+		fregv[n->dsp]= 1;
+		fregs[n->dsp]= INPUT_REG;
                 freg_var++;
-                cadddr(fnptr->dsp)=size_of_double;
+                cadddr(args)=size_of_double; /* why we need this? */
             }
         }
 	args = cadr(args);
     }
 }
 
+static int
+register_to_lvar(int e)
+{
+    error(REG_ERR);
+    return 0;
+#if 0
+    途中でレジスタからLVARに変更しても、間に合わない。
+
+    NMTBL *n = (NMTBL*)caddr(e);
+    int reg = cadr(e);
+    int tag = car(e);
+    int lvar;
+    int t;
+    if (!n||n==&null_nptr) error(REG_ERR);
+    if (tag==REGISTER) {
+	/* regs[reg]==INPUT_REG case should be considered */
+	n->dsp = new_lvar(size_of_int);
+        t = INT;
+    } else if (tag==DREGISTER) {
+	/* fregs[reg]==INPUT_REG case should be considered */
+	n->dsp = new_lvar(size_of_double);
+        t = DOUBLE;
+    } else error(-1);
+    n->sc  = LVAR;
+    lvar = list2(LVAR,n->dsp);
+    g_expr_u(assign_expr0(list2(LVAR,n->dsp),list3(tag,reg,(int)n),t,t));
+    if (tag==REGISTER) {
+	free_register(reg);
+    } else if (tag==DREGISTER) {
+	free_fregister(reg);
+    }
+    return g_expr0(lvar);
+#endif
+}
+
 /* goto arguments list                                      */
 /* target         list4(list2(tag,disp),cdr,ty,source_expr) */
 /*     source         expr=listn(tag,...)                   */
@@ -543,12 +582,12 @@
     int e1;
     /*新しいレジスタ(or スタック)を取得する*/
     if (sz==size_of_int && (e1=get_register())!=-1) {
-	e1=list2(REGISTER,e1);
+	e1=list3(REGISTER,e1,0);
 	*use=list3(t,*use,e1);
 	g_expr_u(assign_expr0(e1,s,ty,ty));
 	*target = append4(*target,t,ty,e1);
     } else if (sz==size_of_double && (e1=get_fregister())!=-1) {
-	e1=list2(DREGISTER,e1);
+	e1=list3(DREGISTER,e1,0);
 	*use=list3(t,*use,e1);
 	g_expr_u(assign_expr0(e1,s,ty,ty));
 	*target = append4(*target,t,ty,e1);
@@ -634,6 +673,7 @@
     }
 }
 
+/*
 void 
 remove0_all(int *parent,int e) 
 {
@@ -646,6 +686,7 @@
 	}
     }
 }
+ */
 
 int
 is_simple(int e1) 
@@ -715,11 +756,11 @@
 	e2 = car(e3); sz = size(ty=caddr(e3)); 
 	if (scalar(ty) && 
 		regs < MAX_CODE_INPUT_REGISTER_VAR) {
-	    target=list4(get_input_register_var(regs++), 
+	    target=list4(get_input_register_var(regs++,0), 
 		    target,ty,e2);
 	} else if ((ty==DOUBLE||ty==FLOAT) && 
 		fregs < MAX_CODE_INPUT_DREGISTER_VAR) {
-	    target=list4(get_input_fregister_var(fregs++), 
+	    target=list4(get_input_fregister_var(fregs++,0), 
 		    target,ty,e2);
 	} else {
 	    target=list4(list2(LVAR,0), target,ty,e2);