changeset 40:060d1e549fec

*** empty log message ***
author kono
date Wed, 12 Feb 2003 04:45:53 +0900
parents c63c4fdeb9a7
children 886ca1f2cf15
files mc-nop-386.c mc-parse.c test/tmp10.c
diffstat 3 files changed, 79 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/mc-nop-386.c	Tue Feb 11 22:36:51 2003 +0900
+++ b/mc-nop-386.c	Wed Feb 12 04:45:53 2003 +0900
@@ -133,6 +133,7 @@
     rname[dreg]   spare real register
 
     regs[]        virtual register usage
+    regv[]        value in virtual register flag
 
     reg_name[rname[creg]]
  */
@@ -141,6 +142,7 @@
 static int rname[MAX_MAX];
 static int regs[MAX_MAX];       /* 使われているレジスタを示すフラグ */
 static int reg_stack[MAX_MAX];  /* 実際のレジスタの領域 */
+static int regv[MAX_MAX];       /* 値が入っているかどうか */
 
 void
 code_init(void)
@@ -203,7 +205,7 @@
 
 void 
 free_register(int i) {    /* いらなくなったレジスタを開放 */
-    regs[i]=0;
+    regv[i]=regs[i]=0;
 }
 
 int
@@ -230,6 +232,28 @@
     return count;    
 }
 
+void
+use_register_var(int i) {
+    regv[i]=1;
+}
+
+static int creg_regvar = -1;
+static int creg_regvar_back;
+static int creg_back;
+
+void
+creg_destroy() {
+    creg_back = creg; creg_regvar_back = creg_regvar;
+    if (creg_regvar>=0)
+	creg = creg_regvar;
+    creg_regvar=-1;
+}
+
+void
+creg_un_destroy() {
+    creg = creg_back; creg_regvar = creg_regvar_back;
+}
+
 
 void 
 gexpr_init(void)
@@ -239,16 +263,17 @@
     }
     text_mode();
     use_register(creg,REG_EAX,0);
+    /* use_register(dreg,REG_EDX,0); */
+    creg_regvar = -1;
 }
 
 void 
 emit_init(void)
 {
     int i;
-    for(i=0;i<REAL_MAX_REGISTER;i++) regs[i]=0;
-    for(i=0;i<REAL_MAX_REGISTER;i++) rname[i]=i;
-    creg = get_register();
-    dreg = get_register();
+    for(i=0;i<REAL_MAX_REGISTER;i++) { regs[i]=0; regv[i]=0;rname[i]=i;}
+    creg = get_register(); /* must be EAX */
+    dreg = get_register(); /* must be EBX */
     reg_sp = 0;
     text_mode();
 }
@@ -799,6 +824,13 @@
     if(length%size_of_int) {
 	length += size_of_int - (length%size_of_int);
     }
+    if (length==4) {
+	printf("\tpushl (%s)\n",register_name(creg,0)); return 1;
+    }
+    if (length==8) {
+	printf("\tpushl 4(%s)\n",register_name(creg,0));
+	printf("\tpushl (%s)\n",register_name(creg,0)); return 2;
+    }
     /* I think, after g_expr, at least two registers are free */
     printf("\tsubl $%d,%%esp\n",length);
     if (register_full()) {
--- a/mc-parse.c	Tue Feb 11 22:36:51 2003 +0900
+++ b/mc-parse.c	Wed Feb 12 04:45:53 2003 +0900
@@ -107,6 +107,7 @@
 extern void gexpr(int e1);
 extern void g_expr(int e1);
 extern int get_register_var(void);
+extern void use_register_var(int);
 extern void bexpr(int e1, char cond, int l1);
 extern int fwdlabel(void);
 extern void fwddef(int l);
@@ -582,6 +583,7 @@
 		nptr->sc = REGISTER;
 		if ((nptr->dsp = get_register_var())<0)
 		    error(-1);
+		use_register_var(nptr->dsp); /* it has now value in it */
 		reg_var++;
 	    } else {
 		nptr->ty = INT;
@@ -745,6 +747,7 @@
 		if ((n->dsp = get_register_var())<0) {
 		    error(-1);
 		} 
+		use_register_var(nptr->dsp); /* it has now value in it */
 	    } 
 	    return n;
 	}
@@ -2026,19 +2029,27 @@
     if (integral(type)||(car(type)!=STRUCT && car(type)!=UNION))
 	e=rvalue(e);
     type = nptr->ty;
-    switch(car(e)) {
-    case GVAR:
-	e=list2(INDIRECT,list3(ADD,e,list2(CONST,nptr->dsp)));
-	break; 
-    case LVAR:
-	e=list2(car(e),cadr(e) + nptr->dsp);
-	break;
-    case INDIRECT:
-	if(!nptr->dsp) break;
-	e=list2(INDIRECT,list3(ADD,cadr(e),list2(CONST,nptr->dsp)));
-	break;
-    default:
-	e=list2(INDIRECT,list3(ADD,e,list2(CONST,nptr->dsp)));
+    if(nptr->dsp) {
+	switch(car(e)) {
+	case GVAR:
+	    e=list2(INDIRECT,list3(ADD,e,list2(CONST,nptr->dsp)));
+	    break; 
+	case LVAR:
+	    e=list2(car(e),cadr(e) + nptr->dsp);
+	    break;
+	case INDIRECT:
+	    e=list2(INDIRECT,list3(ADD,cadr(e),list2(CONST,nptr->dsp)));
+	    break;
+	default:
+	    e=list2(INDIRECT,list3(ADD,e,list2(CONST,nptr->dsp)));
+	}
+    } else {
+	switch(car(e)) {
+	case GVAR: case LVAR: case INDIRECT:
+	    break;
+	default:
+	    e=list2(INDIRECT,e);
+	}
     }
     getsym();
     return e;
@@ -2116,6 +2127,8 @@
 	if(car(t1)!=POINTER||!integral(t2)) error(TYERR);
 	e=binop(MUL,e2,list2(CONST,size(cadr(t1))),t2,INT);
 	type=t1;
+	if (car(e)==CONST && cadr(e)==0)
+	    return(e1);
 	if(car(e1)==ADDRESS&&car(e)==CONST&&car(cadr(e1))!=GVAR)
 	    return(list2(ADDRESS,list2(car(cadr(e1)),
 		cadr(cadr(e1))+cadr(e))));
@@ -3166,13 +3179,13 @@
     fprintf(stderr,"nptr->nm %s\n",n->nm); 
 }
 
-void c0(int d)  { fprintf(stderr,"heap[%d]=%d\n",d,car(d)); }
-void c1(int d)  { fprintf(stderr,"heap[%d]=%d\n",d,cadr(d)); }
-void c2(int d)  { fprintf(stderr,"heap[%d]=%d\n",d,caddr(d)); }
-void c3(int d)  { fprintf(stderr,"heap[%d]=%d\n",d,cadddr(d)); }
-void cc0(int d) { fprintf(stderr,"heap[%d]=%s\n",d,(char *)car(d)); }
-void cc1(int d) { fprintf(stderr,"heap[%d]=%s\n",d,(char *)cadr(d)); }
-void cc2(int d) { fprintf(stderr,"heap[%d]=%s\n",d,(char *)caddr(d)); }
-void cc3(int d) { fprintf(stderr,"heap[%d]=%s\n",d,(char *)cadddr(d)); }
+int c0(int d)  { fprintf(stderr,"heap[%d]=",d);return car(d); }
+int c1(int d)  { fprintf(stderr,"heap[%d]=",d);return cadr(d); }
+int c2(int d)  { fprintf(stderr,"heap[%d]=",d);return caddr(d); }
+int c3(int d)  { fprintf(stderr,"heap[%d]=",d);return cadddr(d); }
+char *cc0(int d) { fprintf(stderr,"heap[%d]=",d);return (char *)car(d); }
+char *cc1(int d) { fprintf(stderr,"heap[%d]=",d);return (char *)cadr(d); }
+char *cc2(int d) { fprintf(stderr,"heap[%d]=",d);return (char *)caddr(d); }
+char *cc3(int d) { fprintf(stderr,"heap[%d]=",d);return (char *)cadddr(d); }
 
 /* end */
--- a/test/tmp10.c	Tue Feb 11 22:36:51 2003 +0900
+++ b/test/tmp10.c	Wed Feb 12 04:45:53 2003 +0900
@@ -1,6 +1,14 @@
 int chptrsave;
+int p[3];
+struct {int  a[100];} bbb;
 
 main()
 {
+     int q[3];
+     struct {int  a[100];} ccc;
      int i = chptrsave;
+     i=q[0];
+     i=p[0];
+     bbb.a[55]=1;
+     ccc.a[55]=1;
 }