diff mc-code-ia32.c @ 711:35e6841ba01a

pointer fixes (partial)
author kono
date Sat, 27 Oct 2007 13:30:38 +0900
parents 8b54c40081de
children bf94c295d763
line wrap: on
line diff
--- a/mc-code-ia32.c	Thu Oct 25 13:58:42 2007 +0900
+++ b/mc-code-ia32.c	Sat Oct 27 13:30:38 2007 +0900
@@ -854,7 +854,7 @@
 	if (i>=MAX_CODE_INPUT_REGISTER_VAR) return 0;
 	i += REG_ESI;
 	regs[i]=INPUT_REG;
-	return list3(REGISTER,i,(int)nptr);
+	return list3n(REGISTER,i,nptr);
     } else {
 	return 0;
     }
@@ -897,7 +897,7 @@
 	reg_var=2; 
 	return list2(LREGISTER,REG_L);
     }
-    return list3(LVAR,new_lvar(SIZE_OF_LONGLONG),0);
+    return list3n(LVAR,new_lvar(SIZE_OF_LONGLONG),0);
 }
 
 int 
@@ -991,7 +991,7 @@
 
     while (args) {
         /* process in reverse order */
-        n = (NMTBL*)caddr(args);
+        n = ncaddr(args);
         type = n->ty;
 	// n->dsp = offset;
 // printf("###  %s %d %d\n",n->nm,n->dsp,n->ty);
@@ -1066,16 +1066,16 @@
     for(i=REG_ESI;i<REG_EBP;i++) {
 	if (! regs[i]) {    /* 使われていないなら */
 	    regs[i]=REG_VAR;      /* そのレジスタを使うことを宣言し */
-	    return list3(REGISTER,i,(int)nptr); /* その場所を表す番号を返す */
+	    return list3n(REGISTER,i,nptr); /* その場所を表す番号を返す */
 	}
     }
-    return list3(LVAR,new_lvar(SIZE_OF_INT),0);
+    return list3n(LVAR,new_lvar(SIZE_OF_INT),0);
 }
 
 int
 get_dregister_var(NMTBL *nptr,int d)
 {
-    return list3(LVAR,new_lvar(d?SIZE_OF_DOUBLE:SIZE_OF_FLOAT),0);
+    return list3n(LVAR,new_lvar(d?SIZE_OF_DOUBLE:SIZE_OF_FLOAT),0);
 }
 
 
@@ -1120,7 +1120,7 @@
 code_gvar(int e1,int creg) {
     use_int(creg);
 #ifdef __APPLE__
-    int r = get_ptr_cache((NMTBL*)caddr(e1));
+    int r = get_ptr_cache(ncaddr(e1));
     if (cadr(e1)) {
 	printf("\tleal %d(%s),%s\n", cadr(e1),register_name(r,0),
 		register_name(creg,0));
@@ -1129,10 +1129,10 @@
     }
 #else
     if (cadr(e1)) {
-	printf("\tmovl $%s+%d,%s\n",((NMTBL*)caddr(e1))->nm,cadr(e1),
+	printf("\tmovl $%s+%d,%s\n",(ncaddr(e1))->nm,cadr(e1),
 		register_name(creg,0));
     } else {
-	printf("\tmovl $%s,%s\n",((NMTBL*)caddr(e1))->nm,register_name(creg,0));
+	printf("\tmovl $%s,%s\n",(ncaddr(e1))->nm,register_name(creg,0));
     }
 #endif
 
@@ -1142,7 +1142,7 @@
 code_rgvar(int e1,int creg) {
     use_int(creg);
 #ifdef __APPLE__
-    int r = get_ptr_cache((NMTBL*)caddr(e1));
+    int r = get_ptr_cache(ncaddr(e1));
     if (cadr(e1)) {
         printf("\tmovl %d(%s),%s\n", cadr(e1),register_name(r,0),
                 register_name(creg,0));
@@ -1151,10 +1151,10 @@
     }
 #else
     if (cadr(e1)) {
-	printf("\tmovl %s+%d,%s\n",((NMTBL*)caddr(e1))->nm,cadr(e1),
+	printf("\tmovl %s+%d,%s\n",(ncaddr(e1))->nm,cadr(e1),
 		register_name(creg,0));
     } else
-	printf("\tmovl %s,%s\n",((NMTBL*)caddr(e1))->nm,register_name(creg,0));
+	printf("\tmovl %s,%s\n",(ncaddr(e1))->nm,register_name(creg,0));
 #endif
 
 }
@@ -1169,7 +1169,7 @@
 code_crgvar(int e1,int creg,int sign,int sz){
     use_int(creg);
 #ifdef __APPLE__
-    int r = get_ptr_cache((NMTBL*)caddr(e1));
+    int r = get_ptr_cache(ncaddr(e1));
     if (cadr(e1)) {
         printf("\t%s %d(%s),%s\n", cload(sign,sz),cadr(e1),register_name(r,0),
                 register_name(creg,0));
@@ -1180,10 +1180,10 @@
 #else
     if (cadr(e1)) {
 	printf("\t%s %s+%d,%s\n",cload(sign,sz),
-		((NMTBL*)caddr(e1))->nm,cadr(e1),register_name(creg,0));
+		(ncaddr(e1))->nm,cadr(e1),register_name(creg,0));
     } else
 	printf("\t%s %s,%s\n",cload(sign,sz),
-		((NMTBL*)caddr(e1))->nm,register_name(creg,0));
+		(ncaddr(e1))->nm,register_name(creg,0));
 #endif
 
 }
@@ -1422,7 +1422,7 @@
 code_cmp_crgvar(int e1,int reg,int sz,int label,int cond) {
     use_int(reg);
 #ifdef __APPLE__
-    int r = get_ptr_cache((NMTBL*)caddr(e1));
+    int r = get_ptr_cache(ncaddr(e1));
     if (cadr(e1)) {
 	if (sz==1)
 	    printf("\tcmpb $0,%d(%s)\n",cadr(e1),register_name(r,0));
@@ -1437,14 +1437,14 @@
 #else
     if (cadr(e1)) {
 	if (sz==1)
-	    printf("\tcmpb $0,%s+%d\n",((NMTBL*)caddr(e1))->nm,cadr(e1));
+	    printf("\tcmpb $0,%s+%d\n",(ncaddr(e1))->nm,cadr(e1));
 	else if (sz==SIZE_OF_SHORT)
-	    printf("\tcmpw $0,%s+%d\n",((NMTBL*)caddr(e1))->nm,cadr(e1));
+	    printf("\tcmpw $0,%s+%d\n",(ncaddr(e1))->nm,cadr(e1));
     } else {
 	if (sz==1)
-	    printf("\tcmpb $0,%s\n",((NMTBL*)caddr(e1))->nm);
+	    printf("\tcmpb $0,%s\n",(ncaddr(e1))->nm);
 	else if (sz==SIZE_OF_SHORT)
-	    printf("\tcmpw $0,%s\n",((NMTBL*)caddr(e1))->nm);
+	    printf("\tcmpw $0,%s\n",(ncaddr(e1))->nm);
     }
 #endif
     jcond(label,cond);
@@ -1467,16 +1467,16 @@
 code_cmp_rgvar(int e1,int reg,int label,int cond) {
     use_int(reg);
 #ifdef __APPLE__
-    int r = get_ptr_cache((NMTBL*)caddr(e1));
+    int r = get_ptr_cache(ncaddr(e1));
     if (cadr(e1))
 	printf("\tcmpl $0,%d(%s)\n",cadr(e1),register_name(r,0));
     else
 	printf("\tcmpl $0,(%s)\n",register_name(r,0));
 #else
     if (cadr(e1))
-	printf("\tcmpl $0,%s+%d\n",((NMTBL*)caddr(e1))->nm,cadr(e1));
+	printf("\tcmpl $0,%s+%d\n",(ncaddr(e1))->nm,cadr(e1));
     else
-	printf("\tcmpl $0,%s\n",((NMTBL*)caddr(e1))->nm);
+	printf("\tcmpl $0,%s\n",(ncaddr(e1))->nm);
 #endif
     jcond(label,cond);
 }
@@ -1503,7 +1503,7 @@
 {
     char *s;
     int lb;
-    NMTBL *n = (NMTBL *)cadr(e1);
+    NMTBL *n = ncaddr(e1);
     if ((lb=attr_value(n,LABEL))) {
         // already defined
         return code_label_value(lb,creg) ;
@@ -1729,37 +1729,37 @@
 {
     if(scalar(t)) {
         if (mode==AS_SAVE) {
-	    return list3(LVAR,new_lvar(size(t)),0);
+	    return list3n(LVAR,new_lvar(size(t)),0);
             // return get_register_var(0);
         } else 
-            return list3(LVAR,caller_arg_offset_v(nargs),0);
+            return list3n(LVAR,caller_arg_offset_v(nargs),0);
     } else if (t==LONGLONG||t==ULONGLONG) {
         if (mode==AS_SAVE) {
-	    return list3(LVAR,new_lvar(size(t)),0);
+	    return list3n(LVAR,new_lvar(size(t)),0);
             // return get_lregister_var(0);
         } else 
-            return list3(LVAR,caller_arg_offset_v(nargs),0);
+            return list3n(LVAR,caller_arg_offset_v(nargs),0);
     } else if (t==FLOAT) {
         if (mode==AS_SAVE) {
-	    return list3(LVAR,new_lvar(size(t)),0);
+	    return list3n(LVAR,new_lvar(size(t)),0);
             // return get_dregister_var(0,0);
         } else
-            return list3(LVAR,caller_arg_offset_v(nargs),0);
+            return list3n(LVAR,caller_arg_offset_v(nargs),0);
     } else if (t==DOUBLE) {
         if (mode==AS_SAVE) {
-	    return list3(LVAR,new_lvar(size(t)),0);
+	    return list3n(LVAR,new_lvar(size(t)),0);
             // return get_dregister_var(0,1);
         } else
-            return list3(LVAR,caller_arg_offset_v(nargs),0);
+            return list3n(LVAR,caller_arg_offset_v(nargs),0);
     } else if (t>=0&&(car(t)==STRUCT||car(t)==UNION)) {
         if (mode==AS_SAVE) {
-	    return list3(LVAR,new_lvar(size(t)),0);
+	    return list3n(LVAR,new_lvar(size(t)),0);
             // return get_register_var(0);
         } else
-            return list3(LVAR,caller_arg_offset_v(nargs),0);
+            return list3n(LVAR,caller_arg_offset_v(nargs),0);
     } else {
         error(-1);
-	return list3(LVAR,new_lvar(size(t)),0);
+	return list3n(LVAR,new_lvar(size(t)),0);
         // return get_register_var(0);
     }
 }
@@ -1807,7 +1807,7 @@
     arg_assign = 0;
     e2 = cadr(e1);
     if (car(e2) == FNAME) {     
-        fn=(NMTBL *)cadr(e2);
+        fn=ncaddr(e2);
     } else {    
         if (car(e2)==INDIRECT) e2=cadr(e2); // (*func)(i) case
         jmp = list3(REGISTER,REG_EAX,0);
@@ -2086,7 +2086,7 @@
     if (byte) { use_data_reg(creg,1); 
     } else { use_int(creg); }
 #ifdef __APPLE__
-    int r = get_ptr_cache((NMTBL*)caddr(e2));
+    int r = get_ptr_cache(ncaddr(e2));
     if (cadr(e2)) 
 	printf("\t%s %s,%d(%s)\n",move(byte),register_name(creg,byte),
 	    cadr(e2),register_name(r,0));
@@ -2095,9 +2095,9 @@
 	    register_name(r,0));
 #else
     if (cadr(e2)) 
-	printf("\t%s %s,%s+%d\n",move(byte),register_name(creg,byte),((NMTBL*)caddr(e2))->nm,cadr(e2));
+	printf("\t%s %s,%s+%d\n",move(byte),register_name(creg,byte),(ncaddr(e2))->nm,cadr(e2));
     else
-	printf("\t%s %s,%s\n",move(byte),register_name(creg,byte),((NMTBL*)caddr(e2))->nm);
+	printf("\t%s %s,%s\n",move(byte),register_name(creg,byte),(ncaddr(e2))->nm);
 #endif
 }
 
@@ -3044,16 +3044,16 @@
 void code_dassign_gvar(int e2,int freg,int d)
 { 
 #ifdef __APPLE__
-    int r = get_ptr_cache((NMTBL*)caddr(e2));
+    int r = get_ptr_cache(ncaddr(e2));
     if (cadr(e2)) 
 	printf("\t%s %d(%s)\n",fstore(d),cadr(e2),register_name(r,0));
     else
 	printf("\t%s (%s)\n",fstore(d),register_name(r,0));
 #else
     if (cadr(e2)) 
-	printf("\t%s %s+%d\n",fstore(d),((NMTBL*)caddr(e2))->nm,cadr(e2));
+	printf("\t%s %s+%d\n",fstore(d),(ncaddr(e2))->nm,cadr(e2));
     else
-	printf("\t%s %s\n",fstore(d),((NMTBL*)caddr(e2))->nm);
+	printf("\t%s %s\n",fstore(d),(ncaddr(e2))->nm);
 #endif
 }
 
@@ -3199,16 +3199,16 @@
 void code_drgvar(int e2,int d,int freg)
 { 
 #ifdef __APPLE__
-    int r = get_ptr_cache((NMTBL*)caddr(e2));
+    int r = get_ptr_cache(ncaddr(e2));
     if (cadr(e2))
 	printf("\t%s %d(%s)\n",fload(d),cadr(e2),register_name(r,0));
     else
 	printf("\t%s (%s)\n",fload(d),register_name(r,0));
 #else
     if (cadr(e2))
-	printf("\t%s %s+%d\n",fload(d),((NMTBL*)caddr(e2))->nm,cadr(e2));
+	printf("\t%s %s+%d\n",fload(d),(ncaddr(e2))->nm,cadr(e2));
     else
-	printf("\t%s %s\n",fload(d),((NMTBL*)caddr(e2))->nm);
+	printf("\t%s %s\n",fload(d),(ncaddr(e2))->nm);
 #endif
 }
 
@@ -3221,16 +3221,16 @@
 void code_cmp_drgvar(int e2,int reg,int d,int label,int cond)
 { 
 #ifdef __APPLE__
-    int r = get_ptr_cache((NMTBL*)caddr(e2));
+    int r = get_ptr_cache(ncaddr(e2));
     if (cadr(e2))
 	printf("\tfcomp %d(%s)\n",cadr(e2),register_name(r,0));
     else
 	printf("\tfcomp (%s)\n",register_name(r,0));
 #else
     if (cadr(e2))
-	printf("\tfcomp %s+%d\n",((NMTBL*)caddr(e2))->nm,cadr(e2));
+	printf("\tfcomp %s+%d\n",(ncaddr(e2))->nm,cadr(e2));
     else
-	printf("\tfcomp %s\n",((NMTBL*)caddr(e2))->nm);
+	printf("\tfcomp %s\n",(ncaddr(e2))->nm);
 #endif
     jcond(label,cond);
 }
@@ -3596,7 +3596,7 @@
     use_int(e2);
     crn = register_name(e2,0);
 #ifdef __APPLE__
-    int r = get_ptr_cache((NMTBL*)caddr(e1));
+    int r = get_ptr_cache(ncaddr(e1));
     n = register_name(r,0);
     if (cadr(e1)) {
 	printf("\tmovl %d(%s),%s\n",cadr(e1),n,crn);
@@ -3606,7 +3606,7 @@
 	printf("\torl  4(%s),%s\n",n,crn);
     }
 #else
-    n = ((NMTBL*)caddr(e1))->nm;
+    n = (ncaddr(e1))->nm;
     if (cadr(e1)) {
 	printf("\tmovl %s+%d,%s\n",n,cadr(e1),crn);
 	printf("\torl  %s+%d,%s\n",n,cadr(e1)+4,crn);
@@ -3648,7 +3648,7 @@
     use_longlong(e2);
 #if ENDIAN_L==0
 #ifdef __APPLE__
-    int r = get_ptr_cache((NMTBL*)caddr(e1));
+    int r = get_ptr_cache(ncaddr(e1));
     n = register_name(r,0);
     if (cadr(e1)) {
 	printf("\tmovl %s,%d(%s)\n",l_eax(e2),cadr(e1),n);
@@ -3658,7 +3658,7 @@
 	printf("\tmovl %s,4(%s)\n",l_edx(e2),n);
     }
 #else
-    n = ((NMTBL*)caddr(e1))->nm;
+    n = (ncaddr(e1))->nm;
     if (cadr(e1)) {
 	printf("\tmovl %s,%s+%d\n",l_eax(e2),n,cadr(e1));
 	printf("\tmovl %s,%s+%d\n",l_edx(e2),n,cadr(e1)+4);
@@ -3713,7 +3713,7 @@
     use_longlong(e2);
 #if ENDIAN_L==0
 #ifdef __APPLE__
-    int r = get_ptr_cache((NMTBL*)caddr(e1));
+    int r = get_ptr_cache(ncaddr(e1));
     n = register_name(r,0);
     if (cadr(e1)) {
 	printf("\tmovl %d(%s),%s\n",cadr(e1),n,l_eax(e2));
@@ -3723,7 +3723,7 @@
 	printf("\tmovl 4(%s),%s\n",n,l_edx(e2));
     }
 #else
-    n = ((NMTBL*)caddr(e1))->nm;
+    n = (ncaddr(e1))->nm;
     if (cadr(e1)) {
 	printf("\tmovl %s+%d,%s\n",n,cadr(e1),l_eax(e2));
 	printf("\tmovl %s+%d,%s\n",n,cadr(e1)+4,l_edx(e2));
@@ -4330,11 +4330,11 @@
 	printf("%d",cadr(rstr));
     } else if (car(rstr)==FNAME) {
 #ifdef __APPLE__
-	printf("_%s-_%d",(char*)cadr(rstr),goffset_label);
+	printf("_%s-_%d",ncaddr(rstr)->nm,goffset_label);
 #else
-	printf("%s",(char*)cadr(rstr));
+	printf("%s",ncaddr(rstr)->nm);
 #endif
-    } else if (car(rstr)==STRING) {
+    } else if (car(rstr)==LABEL) {
 #ifdef __APPLE__
 	printf("_%d-_%d",cadr(rstr),goffset_label);
 #else
@@ -4398,13 +4398,13 @@
 	repl = list3(list2(0,0),repl,clobber);
     } else if (c=='i') {
 	if (car(e1)==GVAR) {
-	    e1=list3(FNAME,(int)(((NMTBL *)caddr(e1))->nm),0);
+	    e1=list3n(FNAME,0,ncaddr(e1));
 	} else if (car(e1)==FNAME) {
-	    e1=list3(FNAME,(int)(((NMTBL *)cadr(e1))->nm),0);
+	    e1=list3n(FNAME,0,ncaddr(e1));
 	} else if (car(e1)==STRING) {
 	    val = emit_string_label();
-	    ascii((char*)cadr(e1));
-	    e1=list3(STRING,val,0);
+	    ascii(ncaddr(e1)->nm);
+	    e1=list2(LABEL,val);
 	} else if (car(e1)==CONST) {
 	} else error(-1);
 	repl = list3(e1,repl,clobber);