diff mc-codegen.c @ 711:35e6841ba01a

pointer fixes (partial)
author kono
date Sat, 27 Oct 2007 13:30:38 +0900
parents 0554b7f985ee
children bf94c295d763
line wrap: on
line diff
--- a/mc-codegen.c	Thu Oct 25 13:58:42 2007 +0900
+++ b/mc-codegen.c	Sat Oct 27 13:30:38 2007 +0900
@@ -249,7 +249,7 @@
 	return ULONGLONG;
 #endif
     case FNAME:
-	code_fname((NMTBL *)(e2),USE_CREG);
+	code_fname(ncaddr(e1),USE_CREG);
 	return ADDRESS;
     case LABEL:
 	if (car(e2)!=LVAR) error(-1);
@@ -275,7 +275,7 @@
 	code_string(e1,USE_CREG);
 	return ADDRESS;
     case FUNCTION:
-	if (car(e2)==FNAME&&is_code((NMTBL*)cadr(e2))) {
+	if (car(e2)==FNAME&&is_code(ncaddr(e2))) {
 	    // error(FNERR);
 	    jump(e1,0);
 	    return VOID;
@@ -283,7 +283,7 @@
 	t = function(e1);
 	return t;
     case JUMP:
-	if (car(e2)==FNAME&&is_function((NMTBL*)cadr(e2))) {
+	if (car(e2)==FNAME&&is_function(ncaddr(e2))) {
 	    // error(GTERR);
 	    return function(e1);
 	}
@@ -303,15 +303,15 @@
 	g_expr0(e1);
 	return t;
     case PERIOD:
-	nptr = (NMTBL*)caddr(e1);
-	type = cadddr(e1);
+	nptr = ncadddr(e1);
+	type = caddr(e1);
 	e1 = strop(e2,0); t = type;
 	if (chk) return t;
 	g_expr0(e1);
 	return t;
     case ARROW:
-	nptr = (NMTBL*)caddr(e1);
-	type = cadddr(e1);
+	nptr = ncadddr(e1);
+	type = caddr(e1);
 	e1 = strop(e2,1); t = type;
 	if (chk) return t;
 	g_expr0(e1);
@@ -958,8 +958,8 @@
 	error(-1);
     }
     n->sc  = LVAR;
-    lvar = list3(LVAR,n->dsp,(int)n);
-    g_expr_u(assign_expr0(list3(LVAR,n->dsp,(int)n),list3(tag,reg,(int)n),t,t));
+    lvar = list3n(LVAR,n->dsp,n);
+    g_expr_u(assign_expr0(list3n(LVAR,n->dsp,n),list3n(tag,reg,n),t,t));
     if (tag==REGISTER||tag==DREGISTER||tag==FREGISTER||tag==LREGISTER) {
 	free_register(reg);
     return g_expr0(lvar);
@@ -1127,7 +1127,7 @@
 if (lsrc) printf("## register overrap in save_target\n");
 #endif
 	}
-	g_expr_u(assign_expr0((e1=list3(LVAR,new_lvar(sz),0)),s,ty,ty));
+	g_expr_u(assign_expr0((e1=list3n(LVAR,new_lvar(sz),0)),s,ty,ty));
 	*target = append5(*target,t,ty,e1,list3(e1,0,sz));
 	*use=list3(t,*use,e1);
     }
@@ -1348,7 +1348,7 @@
     case RGVAR:
     case SRGVAR :
     case SURGVAR:
-	return list3(GVAR,cadr(e1),caddr(e1));
+	return list3n(GVAR,cadr(e1),ncaddr(e1));
     case LVAR :
     case CRLVAR  :
     case CURLVAR  :
@@ -1359,7 +1359,7 @@
     case RLVAR:
     case SRLVAR :
     case SURLVAR :
-	return list3(LVAR,cadr(e1),caddr(e1));
+	return list3n(LVAR,cadr(e1),ncaddr(e1));
     case FREGISTER :
     case REGISTER:
     case LREGISTER:
@@ -1496,7 +1496,7 @@
 		e2,ty,ty));
 	} else {
 	    while(car(e2)==RSTRUCT) e2=cadr(e2);
-	    target=list5(list3(LVAR,0,0), target,ty,e2,0);
+	    target=list5(list3n(LVAR,0,0), target,ty,e2,0);
 	}
         /* keep arg space for register variables */
         arg_size += sz;
@@ -1536,7 +1536,7 @@
 	if (contains_p(s0,not_simple_p)) {   /* } */
 #endif
 	    /* complex case */
-	    g_expr_u(assign_expr0((e4=list3(LVAR,new_lvar(sz),0)),s0,ty,ty));
+	    g_expr_u(assign_expr0((e4=list3n(LVAR,new_lvar(sz),0)),s0,ty,ty));
 	    use=list3(ty,use,e1);
 	    cadddr(e2)=e4;
 	    caddddr(e2)=list3(e4,0,sz);
@@ -1560,7 +1560,7 @@
 #endif
 		caddr(e2) = UNSIGNED;
 		caddddr(e2) = list3(
-			cadddr(e2)=list3(LVAR,cadr(s0),0),
+			cadddr(e2)=list3n(LVAR,cadr(s0),0),
 				0, size_of_int);
 #if DEBUG_PARALLEL_ASSIGN
 if (lsrc)printf("## div 0 source %d ty %d+%d sz %d\n",car(s0),ty,cadr(s0),size_of_int);
@@ -1575,9 +1575,9 @@
 		    default: caddr(e2) = UNSIGNED; r = size_of_int;
 		    }
 		    if (e4==size_of_int) e3=cadr(e2);
-		    car(e2) =  list3(LVAR,cadr(t0)+e4,0);
+		    car(e2) =  list3n(LVAR,cadr(t0)+e4,0);
 		    caddddr(e2) = list3(
-			cadddr(e2) = list3(LVAR,cadr(s0)+e4,0),0, r);
+			cadddr(e2) = list3n(LVAR,cadr(s0)+e4,0),0, r);
 		    e4 += r;
 #if DEBUG_PARALLEL_ASSIGN
 if (lsrc)printf("## div 1 source %d ty %d+%d sz %d\n",car(s0),ty,cadr(s0),r);
@@ -1599,7 +1599,7 @@
     /* compute jump address */
     e2 = cadr(e1);
     if (car(e2) == FNAME) {	
-	code0=(NMTBL *)cadr(e2);
+	code0=ncaddr(e2);
 	// if (!is_code(code0)) { error(TYERR); return; }
     } else {	/* indirect */
 	g_expr(e2);
@@ -1749,11 +1749,11 @@
 	switch (car(cadr(e1))) {
 	case GVAR:
 	    return(list2(ADDRESS,
-		list3(GVAR,cadr(cadr(e1))+cadr(e),caddr(cadr(e1)))));
+		list3n(GVAR,cadr(cadr(e1))+cadr(e),ncaddr(cadr(e1)))));
 	case LVAR:
 	    return(list2(ADDRESS,
-		list3(car(cadr(e1)),cadr(cadr(e1))+cadr(e),
-			caddr(cadr(e1)))));
+		list3n(LVAR,cadr(cadr(e1))+cadr(e),
+			ncaddr(cadr(e1)))));
 	case INDIRECT:
 	case PERIOD:
 	case ARROW:
@@ -1762,11 +1762,11 @@
 	    error(-1); // ?
 	}
     } else if(car(e1)==GVAR) {
-	return(list3(GVAR,cadr(e1)+cadr(e),caddr(e1)));
+	return(list3n(GVAR,cadr(e1)+cadr(e),ncaddr(e1)));
     } else if(car(e1)==LVAR) {
-	return(list3(LVAR,cadr(e1)+cadr(e),caddr(e1)));
+	return(list3n(LVAR,cadr(e1)+cadr(e),ncaddr(e1)));
 //    } else if(car(e1)==RLVAR) {  this is not correct
-//	return(list3(RLVAR,cadr(e1)+cadr(e),caddr(e1)));
+//	return(list3n(RLVAR,cadr(e1)+cadr(e),ncaddr(e1)));
     }
     return e0;
 }
@@ -1859,7 +1859,7 @@
 	if (car(cadr(e4))==STRING) code_string(cadr(e4),reg);
 	else code_gvar(cadr(e4),reg);   
 	return;
-    case FNAME:    code_fname((NMTBL*)cadr(e4),reg); return;
+    case FNAME:    code_fname(ncaddr(e4),reg); return;
     case STRING:   code_string(e4,reg); return;
     default: error(-1);
     }
@@ -2569,7 +2569,7 @@
 	// e2 が複雑な式でないと却ってだめなこともある
 	// register が取れれば常に有効か?
 	// たぶん、i386 の時には有効だったんだろうなぁ。
-	int n = list3(LVAR,new_lvar(size_of_int),0); // get register var?
+	int n = list3n(LVAR,new_lvar(size_of_int),0); // get register var?
 	g_expr_u(assign_expr0(n,list2(ADDRESS,e2),INT,INT));
 	g_expr0(assign_expr0(rvalue_t(n,INT),
 	    list3(op,rvalue_t(list2(INDIRECT,rvalue_t(n,INT)),t),e3),t,t));
@@ -2674,7 +2674,7 @@
 	if (!code_lassop_p) {
 	    /*  new = &e2 */
 	    /*  *new = *new op e3 */
-	    int n = list3(LVAR,new_lvar(size_of_int),0);
+	    int n = list3n(LVAR,new_lvar(size_of_int),0);
 	    g_expr_u(assign_expr0(n,list2(ADDRESS,e2),INT,INT));
 	    g_expr0(assign_expr0(rvalue_t(n,INT),
 		list3(op,rvalue_t(list2(INDIRECT,rvalue_t(n,INT)),t),e3),t,t));
@@ -3050,7 +3050,7 @@
 	    case FCONST: 
 	    case DCONST: e=dlist2(car(e),dcadr(e)); break;
 	    case LCONST: e=llist2(car(e),lcadr(e)); break;
-	    case STRING: e=list3(car(e),cadr(e),caddr(e)); break;
+	    case STRING: e=list3n(car(e),cadr(e),ncaddr(e)); break;
 	    case STRUCT:  // for udpcl
 		e=glist3(car(e),copy_expr(cadr(e)),copy_expr(caddr(e))); break;
 	    case ARRAY:
@@ -3098,9 +3098,11 @@
 		case LVAR: case RLVAR: case URLVAR:
 		case REGISTER: case FREGISTER:
 		case DREGISTER: case LREGISTER:
-		case STRING:
+		case FNAME:
 		case IVAR: case RIVAR:
-		    e = glist3(car(e),cadr(e),caddr(e)); break;
+		    e = glist3n(car(e),cadr(e),ncaddr(e)); break;
+		case STRING:
+		    e = glist3n(car(e),cadr(e),ncaddr(e)); break;
 		case CONST: 
 		    switch(car(e)) {
 		    case CONST:
@@ -3114,7 +3116,6 @@
 		    }
 		    break;
 		case LCALL:
-		case FNAME:
 		case LABEL:
 		    e = glist2(car(e),cadr(e)); break;
 		case DECL:
@@ -3475,7 +3476,7 @@
     if (n->attr) {
 	if ((e=attr_value(n,ASM))) {
 	    if (car(e)!=STRING) error(-1);
-	    str = (NMTBL*)caddr(e);
+	    str = ncaddr(e);
 	    return str->nm;
 	}
     }
@@ -3568,17 +3569,17 @@
 	    return;
 	case ADDRESS:
 	    if (car(cadr(e))==GVAR)
-		emit_address(((NMTBL *)caddr(cadr(e)))->nm,cadr(cadr(e)));
+		emit_address((ncaddr(cadr(e)))->nm,cadr(cadr(e)));
 	    else error(INERR);
 	    return;
 	case FNAME:
-	    emit_address(((NMTBL *)cadr(e))->nm,0);
+	    emit_address((ncaddr(e))->nm,0);
 	    return;
 	case GVAR:
-	    emit_address(((NMTBL *)caddr(e))->nm,0);
+	    emit_address((ncaddr(e))->nm,0);
 	    return;
 	case STRING:
-	    emit_string(((NMTBL *)cadr(e))->nm,n->ty);
+	    emit_string((ncaddr(e))->nm,n->ty);
 	    return;
 	}
     // if (lsrc)fprintf(stderr,"## type= %d\n",t);
@@ -3654,7 +3655,7 @@
         if (car(init)!=DECL_DATA_FIELD) {
                 error(-1);
         }
-        n = (NMTBL*)cadddr(init);
+        n = ncadddr(init);
         type1 = search_struct_type(type0,n->nm,&foffset);
         e = caddr(init);
         if (car(e)!=DECL_DATA) error(-1);
@@ -3741,9 +3742,9 @@
 	nptr0->attr = 0;
 	nptr0->ty = t;
 	nptr0->dsp = new_lvar_align(sz,16);
-	e1 = list3(RSTRUCT,list3(
-	    nptr0->sc,nptr0->dsp,(int)nptr0),sz);
-	v = list3(nptr0->sc,nptr0->dsp,(int)nptr0);
+	e1 = list3(RSTRUCT,list3n(
+	    nptr0->sc,nptr0->dsp,nptr0),sz);
+	v = list3n(nptr0->sc,nptr0->dsp,nptr0);
     } else {
 	e1 = 0;
     }
@@ -3999,8 +4000,8 @@
 	    def(&str_ret,0); 
 	    args = sargs + (inmode?1:size_of_int);
 	    struct_return = inmode
-		?list3(list3(IVAR,str_ret.dsp,0),sz,type)
-		:list3(list3(LVAR,str_ret.dsp,0),sz,type);
+		?list3(list3n(IVAR,str_ret.dsp,0),sz,type)
+		:list3(list3n(LVAR,str_ret.dsp,0),sz,type);
 	    caddr(fnptr->ty) = glist2(POINTER,caddr(fnptr->ty));
 	}
 	type = type_save;
@@ -4224,14 +4225,14 @@
 	    if (!has_attr(n,VOLATILE))
 	    return c;
 	}
-	return(list3(RGVAR+op,cadr(e),caddr(e)));
+	return(list3n(RGVAR+op,cadr(e),ncaddr(e)));
     case LVAR:
 	n = (NMTBL*)caddr(e);
 	if (cadr(e)==0 && n && (c=attr_value(n,KONST))) {
 	    if (!has_attr(n,VOLATILE))
 	    return c;
 	}
-	return(list3(RLVAR+op,cadr(e),caddr(e)));
+	return(list3n(RLVAR+op,cadr(e),ncaddr(e)));
     case INDIRECT:
 	return(indirect(RINDIRECT+op,cadr(e),type0));
     case IVAR: case ARRAY: case PERIOD: case ARROW:
@@ -4336,7 +4337,7 @@
     int e1 = 0;
 
     if (inmode || chk) {
-	e1 = list4(ind?ARROW:PERIOD,e,(int)nptr,type);
+	e1 = list4n(ind?ARROW:PERIOD,e,type,nptr);
     }
     if (ind) e = indop(rvalue(e));
     type0 = type_value(type);
@@ -4357,10 +4358,10 @@
 	switch(car(e)) {
 	case GVAR:
 	    // e=list2(INDIRECT,list3(ADD,e,list2(CONST,dsp)));
-	    e=list3(GVAR,cadr(e)+dsp,caddr(e));
+	    e=list3n(GVAR,cadr(e)+dsp,ncaddr(e));
 	    break;
 	case LVAR:
-	    e=list3(LVAR,cadr(e) + dsp,0);  /* may have attribute */
+	    e=list3n(LVAR,cadr(e) + dsp,ncaddr(e));  /* may have attribute */
 	    break;
 	case INDIRECT:
 	    e=list2(INDIRECT,list3(ADD,cadr(e),list2(CONST,dsp)));
@@ -4913,7 +4914,7 @@
 		// compatible(cadr(t),cadr(type));
 		// ではあかんの?
 		    if (car(e)==FNAME) {
-			NMTBL *n = (NMTBL*)cadr(e);
+			NMTBL *n = ncaddr(e);
 			int targ0 = caddr(cadr(t));
 			int targ1 = caddr(n->ty);
 			if (is_function(n)) {
@@ -5063,11 +5064,11 @@
     if (lo) {
 #if LONGLONG_CODE
 	if (post) {
-	    n1 = list3(LVAR,new_lvar(size_of_longlong),0);
+	    n1 = list3n(LVAR,new_lvar(size_of_longlong),0);
 	    code_lassign_lvar(cadr(n1),USE_CREG);
 	}
 	if (!code_lassop_p) {
-	    n2 = list3(LVAR,new_lvar(size_of_longlong),0);
+	    n2 = list3n(LVAR,new_lvar(size_of_longlong),0);
 	    code_lassign_lvar(cadr(n2),USE_CREG);
 	    lassign(list4(LASSOP,n2,e3,op+LOP));
 	} else {
@@ -5080,7 +5081,7 @@
 #endif
     } else {
 	if (post) {
-	    n1 = list3(LVAR,new_lvar(size_of_int),0);
+	    n1 = list3n(LVAR,new_lvar(size_of_int),0);
 	    code_assign_lvar(cadr(n1),USE_CREG,0);
 	}
 	emit_push();