changeset 415:bdf900926f32

fix cpmd register
author kono
date Sat, 23 Oct 2004 23:26:33 +0900
parents 0a4416b34d4a
children a6ed0575d731
files mc-code-arm.c mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-codegen.c
diffstat 5 files changed, 60 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/mc-code-arm.c	Fri Oct 22 22:52:01 2004 +0900
+++ b/mc-code-arm.c	Sat Oct 23 23:26:33 2004 +0900
@@ -1104,7 +1104,6 @@
     max_reg_var=0; max_freg_var=0;
     reg_sp = 0;
     freg_sp = 0;
-    text_mode(3);
 }
 
 #define reg_var_num(i) (REG_VAR_BASE+i)
@@ -3449,12 +3448,16 @@
 }
 
 void
-
 align(int t)
 {
-    if (t!=CHAR) {
-//	if (data_alignment & 1)
-	    printf("\t.align 2\n");
+    int d;
+    switch(t) {
+    case CHAR: case UCHAR: return;
+    case SHORT: case USHORT: d = data_alignment & 1; break;
+    default: d = data_alignment & 3;
+    }
+    if (d) {
+        printf("\t.align 2\n");
 	data_alignment = 0;
     }
 }
@@ -3479,7 +3482,7 @@
     printf("\\0%c\n",34);
 }
 
-extern int
+int
 emit_string_label() {
     int lb;
 
@@ -3492,7 +3495,7 @@
 }
 
 
-extern void
+void
 emit_global(char *name,int t)
 {
     printf("\t.globl\t%s\n",name);
@@ -3501,28 +3504,28 @@
     printf("%s:\n",name); 
 }
 
-extern void
+void
 emit_space(int sp)
 {
     data_mode(0);
     printf("\t.space\t%d\n",sp);
 }
 
-extern void
+void
 emit_char(int d)
 {
     data_mode(0);
     printf("\t.byte %d\n",d);
 }
 
-extern void
+void
 emit_short(int d)
 {
     data_mode(0);
     printf("\t.short %d\n",d);
 }
 
-extern void
+void
 emit_int(int d)
 {
     data_mode(0);
@@ -3530,7 +3533,7 @@
     printf("\t.word %d\n",d);
 }
 
-extern void
+void
 emit_longlong(int e)
 {
 #if LONGLONG_CODE
@@ -3544,7 +3547,7 @@
 #endif
 }
 
-extern void
+void
 emit_double(int e)
 {
 #if FLOAT_CODE
@@ -3558,7 +3561,7 @@
 #endif
 }
 
-extern void
+void
 emit_float(int e)
 {
 #if FLOAT_CODE
@@ -3568,7 +3571,7 @@
 #endif
 }
 
-extern void
+void
 emit_address(char *s,int offset)
 {
     data_mode(0);
@@ -3578,14 +3581,14 @@
 	printf("\t.word %s\n",s);
 }
 
-extern void
+void
 emit_label(int labelno)
 {
     data_mode(0);
     printf("\t.word .L%d\n",labelno);
 }
 
-extern void
+void
 emit_data_closing(NMTBL *n)
 {
 #ifdef DOT_SIZE
--- a/mc-code-ia32.c	Fri Oct 22 22:52:01 2004 +0900
+++ b/mc-code-ia32.c	Sat Oct 23 23:26:33 2004 +0900
@@ -556,7 +556,6 @@
     free_all_register();
     reg_sp = 0;
     freg_sp = 0;
-    text_mode();
 }
 
 int
@@ -1986,13 +1985,18 @@
     return lb;
 }
 
-void 
+void
 align(int t)
 {
-    if (t!=CHAR) {
-	if (data_alignment & 1)
-	    printf("\t.align 2\n");
-	data_alignment = 0;
+    int d;
+    switch(t) {
+    case CHAR: case UCHAR: return;
+    case SHORT: case USHORT: d = data_alignment & 1; break;
+    default: d = data_alignment & 3;
+    }
+    if (d) {
+        printf("\t.align 2\n");
+        data_alignment = 0;
     }
 }
 
--- a/mc-code-mips.c	Fri Oct 22 22:52:01 2004 +0900
+++ b/mc-code-mips.c	Sat Oct 23 23:26:33 2004 +0900
@@ -1062,7 +1062,6 @@
     max_reg_var=0; max_freg_var=0;
     reg_sp = 0;
     freg_sp = 0;
-    text_mode(3);
 }
 
 #define reg_var_num(i) (REG_VAR_BASE-i)
@@ -2694,13 +2693,15 @@
 code_cmpdimm(int e, int csreg,int label,int cond)
 {
     /* used in dosiwtch() */
-    int reg=-1;
+    int reg=-1,regsv;
     char *rn,*crn;
     if(chk) return;
     crn = register_name(csreg);
 
     if (e<-32767||32766<e) {
+	regsv=regs[csreg]; use_reg(csreg);
 	rn = register_name(reg= get_register());
+	regs[csreg]=regsv;
 	code_const(e,reg);
 	switch(cond) {
 	case 1:
@@ -2708,7 +2709,6 @@
 	case 0:
 	    printf("\tbeq\t%s,%s,$L_%d\n",crn,rn,label); break;
 	case LT:
-	    use_reg(csreg);
 	    printf("\tslt\t%s,%s,%s\n",rn,crn,rn);
 	    printf("\tbne\t%s,$0,$L_%d\n",rn,label); break;
 	default: error(-1);
@@ -2721,8 +2721,9 @@
     case 0:
 	printf("\tbeq\t%s,%d,$L_%d\n",crn,e,label); break;
     case LT:
-	use_reg(csreg);
+	regsv=regs[csreg]; use_reg(csreg);
 	rn = register_name(reg= get_register());
+	regs[csreg]=regsv;
 	printf("\tslt\t%s,%s,%d\n",rn,crn,e);
 	printf("\tbne\t%s,$0,$L_%d\n",rn,label); break;
     default: error(-1);
@@ -3208,13 +3209,17 @@
 }
 
 void
-
 align(int t)
 {
-    if (t!=CHAR) {
-	if (data_alignment & 1)
-	    printf("\t.align 2\n");
-	data_alignment = 0;
+    int d;
+    switch(t) {
+    case CHAR: case UCHAR: return;
+    case SHORT: case USHORT: d = data_alignment & 1; break;
+    default: d = data_alignment & 3;
+    }
+    if (d) {
+        printf("\t.align 2\n");
+        data_alignment = 0;
     }
 }
 
--- a/mc-code-powerpc.c	Fri Oct 22 22:52:01 2004 +0900
+++ b/mc-code-powerpc.c	Sat Oct 23 23:26:33 2004 +0900
@@ -1023,7 +1023,6 @@
     max_reg_var=-1; max_freg_var=-1;
     reg_sp = 0;
     freg_sp = 0;
-    text_mode();
 }
 
 
@@ -2639,7 +2638,7 @@
 void
 code_cmpdimm(int e, int csreg,int label,int cond)
 {
-    int reg;
+    int reg,regsv;
     /* used in dosiwtch() */
     if(chk) return;
     inc_cmpflag();
@@ -2647,7 +2646,9 @@
 	printf("\tcmpwi cr%d,%s,%d\n",cmpflag,register_name(csreg),e);
 	jcond(label,cond);
     } else {
+	regsv = regs[csreg]; regs[csreg]=USING_REG;
 	reg = get_register();
+	regs[csreg]= regsv;
 	code_const(e,reg);
 	printf("\tcmpw cr%d,%s,%s\n",cmpflag,register_name(csreg),register_name(reg));
 	jcond(label,cond);
@@ -2984,13 +2985,18 @@
     return lb;
 }
 
-extern void
+void
 align(int t)
 {
-    if (t!=CHAR) {
-	if (data_alignment & 1)
-	    printf("\t.align 2\n");
-	data_alignment = 0;
+    int d;
+    switch(t) {
+    case CHAR: case UCHAR: return;
+    case SHORT: case USHORT: d = data_alignment & 1; break;
+    default: d = data_alignment & 3;
+    }
+    if (d) {
+        printf("\t.align 2\n");
+        data_alignment = 0;
     }
 }
 
--- a/mc-codegen.c	Fri Oct 22 22:52:01 2004 +0900
+++ b/mc-codegen.c	Sat Oct 23 23:26:33 2004 +0900
@@ -2580,12 +2580,11 @@
 	return;
     case CHAR: case UCHAR:
 	emit_char(cadr(e));
-	if (data_alignment>0)
-	    data_alignment++;
+	data_alignment++;
 	return;
     case SHORT: case USHORT:
 	emit_short(cadr(e));
-	if (data_alignment>0) data_alignment++;
+	data_alignment++;
 	return;
     case INT: case UNSIGNED: case ENUM:
 	emit_int(cadr(e));
@@ -2598,6 +2597,7 @@
 	return;
     case FLOAT:
 	emit_float(e);
+	data_alignment++;
 	return;
     default:
 	if (t<0) error(-1);