changeset 431:800a5e3e6a17

*** empty log message ***
author kono
date Sun, 31 Oct 2004 11:54:17 +0900
parents ba5faa547607
children f8ebd7e1c644
files mc-code-arm.c mc-code-mips.c mc-code-powerpc.c
diffstat 3 files changed, 65 insertions(+), 79 deletions(-) [+]
line wrap: on
line diff
--- a/mc-code-arm.c	Sun Oct 31 00:49:51 2004 +0900
+++ b/mc-code-arm.c	Sun Oct 31 11:54:17 2004 +0900
@@ -565,7 +565,7 @@
 void
 code_gexpr(int e){
      if (is_int_reg(creg) && creg!=ireg) error(-1);
-//  register_usage("code_gexpr");
+  register_usage("code_gexpr");
 }
 
 
@@ -5911,6 +5911,8 @@
         this is architecture depenedent
  */
 
+#define NON_ALIGNED_BFD 1
+
 extern int
 code_bit_field_disp(int type,int *poffset,int *bfd,int *sz)
 {
@@ -5929,16 +5931,23 @@
 	/* previous field is bit field and spaces may remain */
 	/* calc previsous offset */
 	offset-=(bitpos+7)/8;
-#if 1
+
+#ifdef NON_ALIGNED_BFD
 	/* code for non-aligned non-hole bit-field */
+
+	/* remove extra previous offset from bitpos */
 	while(bitpos>align*8) {
 	    i = ((offset+(align))&~(align-1))-offset;
 	    offset+=i; bitpos-=i*8;
 	}
 	if (bitpos+bitsize > bitsz) {
 	    int stype;
+
+	    /* rewind extra previous offset */
 	    bitpos = *bfd; offset=*poffset;
 	    offset-=(bitpos+7)/8;
+
+	    /* extend store type to allow |---===|===---| */
 	    switch(car(caddr(type))) { 
 	    case INT:	case UNSIGNED:	
 		stype=ULONGLONG; align=4; break;
@@ -5947,18 +5956,22 @@
 	    case SHORT:   case USHORT:      	
 		stype=UNSIGNED; align=4; break;
 	    case ULONGLONG: case LONGLONG:   	
+		/* dummy struct type. fields are never used */
 		stype=list4(STRUCT,12,0,0);align=4;break;
 	    default: error(-1);
 	    }
+	    /* remove extra previous offset from bitpos again */
 	    while(bitpos>align*8) {
 		i = ((offset+(align))&~(align-1))-offset;
 		offset+=i; bitpos-=i*8;
 	    }
 	    bitsz = size(stype)*8;
+	    /* fix store type */
 	    car(caddr(type)) = stype;
 	}
 #endif
 
+	/* previous remaining bit space can contain this type? */
 	i= offset;
 	for(l = bitpos;l>0;l -= 8,i++) {
 	    if ((i & (align-1))==0 && l+bitsize <= bitsz) {
@@ -5967,13 +5980,15 @@
 		i = l+bitsize;
 		*bfd = (i==bitsz)?0:i;
 	        *sz = (i+7)/8;
- printf("# %d: bitpos=%d bitsize=%d bitsz=%d offset=%d\n",lineno,bitpos,bitsize,bitsz,*poffset);
+#ifdef BITPOS_DEBUG
+    printf("# %d: bitpos=%d bitsize=%d bitsz=%d offset=%d\n",lineno,bitpos,bitsize,bitsz,*poffset);
+#endif
 		return l;
 	    } 
 	}
     }
 
-    /* first bit-field */
+    /* first bit-field or no remaining bits */
 
     if ((i=(offset & (align-1)))) {
 	*poffset = (offset += (align-i));
@@ -5981,8 +5996,9 @@
     bitpos = 0;
     *bfd = (bitsize==bitsz)?0:bitsize;
     *sz = (bitsize+7)/8;
-
- printf("# %d: bitpos=%d bitsize=%d bitsz=%d offset=%d\n",lineno,bitpos,bitsize,bitsz,*poffset);
+#ifdef BITPOS_DEBUG
+    printf("# %d: bitpos=%d bitsize=%d bitsz=%d offset=%d\n",lineno,bitpos,bitsize,bitsz,*poffset);
+#endif
     return bitpos;
 }
 
@@ -6000,7 +6016,7 @@
 // printf("# %d: bitpos=%d bitsize=%d bitsz=%d\n",lineno,bitpos,bitsize,bitsz);
     /* this implementation returns -1 for int i:1; */
     if (l==1) {
-	use_int(adr);
+	// use_int(adr);
 	use_longlong(reg);
         lload(adr,reg,0);
 	/* shift left */
@@ -6009,8 +6025,8 @@
 	/* shift right */
 	if ((i=bitsz-bitsize)) 
 	    loprtc(sign?LRSHIFT:LURSHIFT,reg,list2(CONST,i));
-    } else if (l==2) {
-	use_int(adr);
+    } else if (l==2) {   /* three int container */
+	// use_int(adr);
 	use_longlong(reg);
 	lvalue = get_register(); 
 	code_register(adr,lvalue); adr = lvalue;
@@ -6051,7 +6067,7 @@
 	if (i<0||64<=i) error(-1);
 	free_register(adr);
     } else {
-	use_int(adr);
+	// use_int(adr);
 	use_int(reg);
 	code_ld(cload(0,0),reg,0,adr,cext_at(0,0));
 	/* shift left */
@@ -6094,7 +6110,7 @@
     size = bitsz/8;
 // printf("# %d: bitpos=%d bitsize=%d bitsz=%d\n",lineno,bitpos,bitsize,bitsz);
     if (l==1) {
-        use_int(adr);
+        // use_int(adr);
         lvalue = get_lregister();
 	tmp2 = get_register();
 	code_register(adr,tmp2); adr = tmp2;
@@ -6122,7 +6138,7 @@
 	free_register(lvalue);
 	free_register(adr);
     } else if (l==2) {
-        use_int(adr);
+        // use_int(adr);
 	use_longlong(value);
 	lvalue = get_register();
 	code_register(adr,lvalue); adr = lvalue;
@@ -6170,7 +6186,7 @@
 	free_lvar(tmpvar);
 	free_register(adr);
     } else {
-	use_int(adr);
+	// use_int(adr);
 	use_int(value);
         lvalue = get_register();
 	code_ld(cload(size,sign),lvalue,0,adr,cext_at(0,0));
@@ -6267,7 +6283,7 @@
         code_lassign(adr,lvalue);
 	free_register(adr);
         free_register(lvalue);
-    } else if (l==2) {
+    } else if (l==2) {  // three int container
 /*
                         hhhhhh  mmmmmmmmmmmm  lllllll
    lllll  00000000000  mmmmmmmmmmmm  0000000  hhhhhhh 
--- a/mc-code-mips.c	Sun Oct 31 00:49:51 2004 +0900
+++ b/mc-code-mips.c	Sun Oct 31 11:54:17 2004 +0900
@@ -1902,6 +1902,7 @@
 		    free_register(regv_h(lreg));
 		}
 		if (creg==lreg) creg = ireg;
+		free_register(lreg);
 		lreg = 0;
 	    } else if (regv_h(lreg)==reg) {
 		regs[lreg]=0;
@@ -1912,6 +1913,7 @@
 		    free_register(regv_l(lreg));
 		}
 		if (creg==lreg) creg = ireg;
+		free_register(lreg);
 		lreg = 0;
 	    }
 	}
--- a/mc-code-powerpc.c	Sun Oct 31 00:49:51 2004 +0900
+++ b/mc-code-powerpc.c	Sun Oct 31 11:54:17 2004 +0900
@@ -146,10 +146,15 @@
 #define lregister_name_low(i) reg_name[regv_l(i)]
 #define lregister_name_high(i) reg_name[regv_h(i)]
 
-char *r(i) { return register_name(i); }
-char *f(i) { return fregister_name(i); }
-char *ll(i) { return lregister_name_low(i); }
-char *lh(i) { return lregister_name_high(i); }
+#define DEBUG_REG 1
+#if DEBUG_REG
+char *rn(i) { return register_name(i); }
+char *fn(i) { return fregister_name(i); }
+char *lln(i) { return lregister_name_low(i); }
+char *lhn(i) { return lregister_name_high(i); }
+int ll(i) { return regv_l(i); }
+int lh(i) { return regv_h(i); }
+#endif
 
 #define is_int_reg(i)  (0<=i&&i<REAL_MAX_REGISTER)
 #define is_float_reg(i)  (REAL_MAX_REGISTER<=i&&i<REAL_MAX_FREGISTER+REAL_MAX_REGISTER)
@@ -246,6 +251,8 @@
 static void    set_freg(int,int);
 static void    set_lreg(int,int);
 static void jcond(int l, char cond);
+static void register_usage(char *s);
+
 
 static int max_func_args;
 static int my_func_args;
@@ -455,6 +462,7 @@
 void
 code_gexpr(int e){
 //     if (is_int_reg(creg) && creg!=ireg) error(-1);
+//    register_usage("code_gexpr");
 }
 
 
@@ -948,48 +956,6 @@
     printf("\n");
 }
 
-#if 0
-void
-register_usage(char *s)
-{
-#if 1
-    int i;
-#endif
-    if (chk) return;
-    if (!lsrc) return;
-    printf("# %d: %s:",lineno,s);
-    if (ireg) printf(" creg=%s",register_name(ireg));
-    if (freg) printf(" freg=%s",fregister_name(freg));
-    if (lreg) printf(" lreg=%s,%s",lregister_name_high(lreg),
-	lregister_name_low(lreg));
-#if 1
-    printf("\n# regs:");
-    for(i=0;i<MAX_REGISTER;i++) {  printf("%d",regs[i]); }
-    printf(" stack ");
-    for(i=reg_sp;i>0;i--) {
-	if(reg_stack[i-1]>=0)
-	    printf(" %s",register_name(reg_stack[i]));
-    }
-    printf("\n# freg:");
-    for(i=0;i<MAX_FREGISTER;i++) {  printf("%d",regs[i+FREG_OFFSET]); }
-    printf(" stack ");
-    for(i=freg_sp;i>0;i--) {
-	if(freg_stack[i-1]>=0)
-	    printf(" %s",fregister_name(freg_stack[i]));
-    }
-    printf("\n# lreg:");
-    for(i=0;i<REAL_MAX_LREGISTER;i++) {  printf("%d",regs[i+LREG_OFFSET]); }
-    printf(" stack ");
-    for(i=lreg_sp;i>0;i--) {
-	if(lreg_stack[i-1]>=0)
-	    printf(" %s",lregister_name_high(lreg_stack[i]));
-	    printf(",%s",lregister_name_low(lreg_stack[i]));
-    }
-#endif
-    printf("\n");
-}
-#endif
-
 void
 
 gexpr_init(void)
@@ -1855,6 +1821,7 @@
 		    free_register(regv_h(lreg));
 		}
 		if (creg==lreg) creg = 0;
+		free_register(lreg);
 		lreg = 0;
 	    } else if (regv_h(lreg)==reg) {
 		regs[lreg]=0;
@@ -1862,6 +1829,7 @@
 		    free_register(regv_l(lreg));
 		}
 		if (creg==lreg) creg = 0;
+		free_register(lreg);
 		lreg = 0;
 	    }
 	}
@@ -5303,7 +5271,7 @@
 // printf("# %d: bitpos=%d bitsize=%d bitsz=%d\n",lineno,bitpos,bitsize,bitsz);
     /* this implementation returns -1 for int i:1; */
     if (l==1) {
-	use_int(adr);
+	// use_int(adr);
 	use_longlong(reg);
 	lload(adr,reg,0);
 	/* shift left */
@@ -5313,7 +5281,7 @@
 	if ((i=bitsz-bitsize)) 
 	    loprtc(sign?LRSHIFT:LURSHIFT,reg,list2(CONST,i));
     } else {
-	use_int(adr);
+	// use_int(adr);
 	use_int(reg);
 	printf("\t%s %s,lo16(%d)(%s)\n",cload(size),
 		register_name(reg),0,register_name(adr));
@@ -5345,7 +5313,7 @@
 }
 
 extern void
-code_bit_replace(int reg,int value,int type)
+code_bit_replace(int adr,int value,int type)
 {
     int sign,bitsz,l,align;
     int bitsize,bitpos;
@@ -5359,9 +5327,9 @@
     size = bitsz/8;
 // printf("# %d: bitpos=%d bitsize=%d bitsz=%d\n",lineno,bitpos,bitsize,bitsz);
     if (l) {
-	use_int(reg);
+	// use_int(adr);
 	lvalue = get_lregister();
-	lload(reg,lvalue,0);
+	lload(adr,lvalue,0);
 	use_longlong(value);
 	crn = lregister_name_low(value);
 	lrn = lregister_name_low(lvalue);
@@ -5381,15 +5349,15 @@
 	    mask = make_mask(bitpos,bitpos+bitsize>=32?31:bitpos+bitsize-1);
 	    make_mask_and_or(mask,tmp,trn,crn,lrn);
 	}
-	code_lassign(reg,value);
+	code_lassign(adr,value);
 	free_register(lvalue);
-	// free_register(reg);
+	// free_register(adr);
     } else {
-	use_int(reg);
+	// use_int(adr);
 	use_int(value);
 	lvalue = get_register();
 	printf("\t%s %s,lo16(%d)(%s)\n",cload(size),
-		register_name(lvalue),0,register_name(reg));
+		register_name(lvalue),0,register_name(adr));
 	cext(sign,size,lvalue);
 	crn = register_name(value);
 	lrn = register_name(lvalue);
@@ -5401,11 +5369,11 @@
 	mask = make_mask(bitpos+(32-bitsz),bitpos+bitsize-1+(32-bitsz));
 	make_mask_and_or(mask,tmp,trn,crn,lrn);
 	free_register(lvalue);
-	code_assign(reg,size,value);
+	code_assign(adr,size,value);
     }
     if (tmp!=-1) free_register(tmp);
     if (use) {
-	code_bit_field(type,reg,USE_CREG);
+	code_bit_field(type,adr,USE_CREG);
     }
 }
 
@@ -5437,7 +5405,7 @@
 }
 
 extern void
-code_bit_replace_const(int value,int reg,int type)
+code_bit_replace_const(int value,int adr,int type)
 {
     int sign,bitsz,l,align;
     int bitsize,bitpos,size;
@@ -5454,9 +5422,9 @@
 // printf("# %d: bitpos=%d bitsize=%d bitsz=%d\n",lineno,bitpos,bitsize,bitsz);
     if (l) {
 #if LONGLONG_CODE
-	use_int(reg);
+	use_int(adr);
 	lvalue = get_lregister();
-	lload(reg,lvalue,0);
+	lload(adr,lvalue,0);
 	crn = lregister_name_low(lvalue);
 	/* shift left */
 	lc = lcadr(value);
@@ -5473,14 +5441,14 @@
 	    mask = make_mask(bitpos,bitpos+bitsize>=32?31:bitpos+bitsize-1);
 	    make_mask_and_or_const(mask,crn,(int)(lc>>32));
 	}
-	code_lassign(reg,lvalue);
+	code_lassign(adr,lvalue);
 	free_register(lvalue);
 #endif
     } else {
-	use_int(reg);
+	use_int(adr);
 	lvalue = get_register();
 	printf("\t%s %s,lo16(%d)(%s)\n",cload(size),
-		register_name(lvalue),0,register_name(reg));
+		register_name(lvalue),0,register_name(adr));
 	cext(sign,size,lvalue);
 	crn = register_name(lvalue);
 	/* shift left */
@@ -5490,11 +5458,11 @@
 	/* make and-mask */
 	mask = make_mask(bitpos+(32-bitsz),bitpos+bitsize-1+(32-bitsz));
 	make_mask_and_or_const(mask,crn,c);
-	code_assign(reg,size,lvalue);
+	code_assign(adr,size,lvalue);
 	free_register(lvalue);
     }
     if (use) {
-	code_bit_field(type,reg,USE_CREG);
+	code_bit_field(type,adr,USE_CREG);
     }
 }