Mercurial > hg > CbC > old > device
changeset 334:dc81596066df
type fix done.
author | kono |
---|---|
date | Thu, 24 Jun 2004 20:50:17 +0900 |
parents | bd3e6eff7d41 |
children | 4f98dc4b5fd8 |
files | mc-code-powerpc.c mc-codegen.c |
diffstat | 2 files changed, 138 insertions(+), 127 deletions(-) [+] |
line wrap: on
line diff
--- a/mc-code-powerpc.c Thu Jun 24 18:14:37 2004 +0900 +++ b/mc-code-powerpc.c Thu Jun 24 20:50:17 2004 +0900 @@ -2970,7 +2970,7 @@ printf("\t.short %d\n",cadr(e)); if (data_alignment>0) data_alignment++; gpc += SIZE_OF_SHORT; - } else if (t==INT||t==UNSIGNED||(t>0&&car(t)==POINTER)) { + } else if (t==INT||t==UNSIGNED||t==ENUM||(t>0&&car(t)==POINTER)) { printf("\t.long %d\n",cadr(e)); gpc += SIZE_OF_INT; } else {
--- a/mc-codegen.c Thu Jun 24 18:14:37 2004 +0900 +++ b/mc-codegen.c Thu Jun 24 20:50:17 2004 +0900 @@ -1535,127 +1535,149 @@ /* numerical type conversion */ static int -double_value(int e2,int type) +double_value(int e2) { - if (type>0&&car(type)==BIT_FIELD) e2=rvalue_t(e2,cadr(type)); + if (type>0&&car(type)==BIT_FIELD) e2=rvalue(e2); + if (0) ; #if FLOAT_CODE - if (car(e2)==CONST) return dlist2(DCONST,(double)cadr(e2)); - if (car(e2)==FCONST) return dlist2(DCONST,dcadr(e2)); - if(type==DOUBLE) return e2; - if(type==FLOAT) return list3(CONV,rvalue_t(e2,type),F2D); - if(type==UNSIGNED) return list3(CONV,rvalue_t(e2,type),U2D); - if(integral(type)) return list3(CONV,rvalue_t(e2,type),I2D); - if(type==LONGLONG) return list3(CONV,rvalue_t(e2,type),LL2D); - if(type==ULONGLONG) return list3(CONV,rvalue_t(e2,type),ULL2D); - error(TYERR); return dlist2(DCONST,1.0); +#if LONGLONG_CODE + else if (car(e2)==LCONST) e2 = dlist2(DCONST,(double)lcadr(e2)); +#endif + else if (car(e2)==CONST) e2 = dlist2(DCONST,(double)cadr(e2)); + else if (car(e2)==FCONST) e2 = dlist2(DCONST,dcadr(e2)); + else if(type==DOUBLE) ; + else if(type==FLOAT) e2 = list3(CONV,rvalue(e2),F2D); + else if(type==UNSIGNED) e2 = list3(CONV,rvalue(e2),U2D); + else if(integral(type)) e2 = list3(CONV,rvalue(e2),I2D); + else if(type==LONGLONG) e2 = list3(CONV,rvalue(e2),LL2D); + else if(type==ULONGLONG) e2 = list3(CONV,rvalue(e2),ULL2D); + else { error(TYERR); e2 = dlist2(DCONST,1.0); } #else - error(TYERR); return list2(CONST,0); + else { error(TYERR); type = DOUBLE; return list2(CONST,0); } #endif + type = DOUBLE; + return e2; } static int -float_value(int e2,int type) +float_value(int e2) { - if (type>0&&car(type)==BIT_FIELD) e2=rvalue_t(e2,cadr(type)); + if (type>0&&car(type)==BIT_FIELD) e2=rvalue(e2); + if (0) ; #if FLOAT_CODE #if LONGLONG_CODE - if (car(e2)==LCONST) return dlist2(FCONST,(double)lcadr(e2)); - if(type==LONGLONG) return list3(CONV,rvalue_t(e2,type),LL2F); - if(type==ULONGLONG) return list3(CONV,rvalue_t(e2,type),ULL2F); + else if (car(e2)==LCONST) e2 = dlist2(FCONST,(double)lcadr(e2)); #endif - if (car(e2)==CONST) return dlist2(FCONST,(double)cadr(e2)); - if (car(e2)==DCONST) return dlist2(FCONST,dcadr(e2)); - if(type==FLOAT) return e2; - if(type==DOUBLE) return list3(CONV,rvalue_t(e2,type),D2F); - if(type==UNSIGNED) return list3(CONV,rvalue_t(e2,type),U2F); - if(integral(type)) return list3(CONV,rvalue_t(e2,type),I2F); - error(TYERR); return dlist2(DCONST,1.0); + else if(type==LONGLONG) e2 = list3(CONV,rvalue(e2),LL2F); + else if(type==ULONGLONG) e2 = list3(CONV,rvalue(e2),ULL2F); + else if (car(e2)==CONST) e2 = dlist2(FCONST,(double)cadr(e2)); + else if (car(e2)==DCONST) e2 = dlist2(FCONST,dcadr(e2)); + else if(type==FLOAT) ; + else if(type==DOUBLE) e2 = list3(CONV,rvalue(e2),D2F); + else if(type==UNSIGNED) e2 = list3(CONV,rvalue(e2),U2F); + else if(integral(type)) e2 = list3(CONV,rvalue(e2),I2F); + else { error(TYERR); e2 = dlist2(DCONST,1.0); } #else - error(TYERR); return list2(CONST,0); + else { error(TYERR); e2 = list2(CONST,0); } #endif + type = FLOAT; + return e2; } static int -longlong_value(int e2,int type) +longlong_value(int e2) { - if (type>0&&car(type)==BIT_FIELD) e2=rvalue_t(e2,cadr(type)); + if (type>0&&car(type)==BIT_FIELD) e2=rvalue(e2); + if (0) ; #if LONGLONG_CODE - if (car(e2)==CONST) return llist2(LCONST,(long long)cadr(e2)); - if (car(e2)==LCONST) return e2; + else if (car(e2)==CONST) e2 = llist2(LCONST,(long long)cadr(e2)); + else if (car(e2)==LCONST) ; #if FLOAT_CODE - if (car(e2)==DCONST||car(e2)==FCONST) - return llist2(LCONST,(long long)dcadr(e2)); - if(type==FLOAT) return list3(CONV,rvalue_t(e2,type),F2LL); - if(type==DOUBLE) return list3(CONV,rvalue_t(e2,type),D2LL); + else if (car(e2)==DCONST||car(e2)==FCONST) + e2 = llist2(LCONST,(long long)dcadr(e2)); + else if(type==FLOAT) e2 = list3(CONV,rvalue(e2),F2LL); + else if(type==DOUBLE) e2 = list3(CONV,rvalue(e2),D2LL); #endif - if(type==UNSIGNED) return list3(CONV,rvalue_t(e2,type),U2LL); - if(type==LONGLONG) return e2; - if(type==ULONGLONG) return e2; - if(integral(type)) return list3(CONV,rvalue_t(e2,type),I2LL); - error(TYERR); return llist2(LCONST,0LL); + else if(type==UNSIGNED) e2 = list3(CONV,rvalue(e2),U2LL); + else if(type==LONGLONG) e2 = e2; + else if(type==ULONGLONG) e2 = e2; + else if(integral(type)) e2 = list3(CONV,rvalue(e2),I2LL); + else { error(TYERR); e2 = llist2(LCONST,0LL); } #else - return int_value(e2,type); + else { error(TYERR); e2 = list2(CONST,0); } #endif + type = LONGLONG; + return e2; } static int -ulonglong_value(int e2,int type) +ulonglong_value(int e2) { - if (type>0&&car(type)==BIT_FIELD) e2=rvalue_t(e2,cadr(type)); + if (type>0&&car(type)==BIT_FIELD) e2=rvalue(e2); + if (0); #if LONGLONG_CODE - if (car(e2)==CONST) return llist2(LCONST,(unsigned long long)cadr(e2)); - if (car(e2)==LCONST) return e2; + else if (car(e2)==CONST) e2 = llist2(LCONST,(unsigned long long)cadr(e2)); + else if (car(e2)==LCONST) ; #if FLOAT_CODE - if (car(e2)==DCONST||car(e2)==FCONST) - return llist2(LCONST,(unsigned long long)dcadr(e2)); - if(type==FLOAT) return list3(CONV,rvalue_t(e2,type),F2ULL); - if(type==DOUBLE) return list3(CONV,rvalue_t(e2,type),D2ULL); + else if (car(e2)==DCONST||car(e2)==FCONST) + e2 = llist2(LCONST,(unsigned long long)dcadr(e2)); + else if(type==FLOAT) e2 = list3(CONV,rvalue(e2),F2ULL); + else if(type==DOUBLE) e2 = list3(CONV,rvalue(e2),D2ULL); #endif - if(type==UNSIGNED) return list3(CONV,rvalue_t(e2,type),U2ULL); - if(type==LONGLONG) return e2; - if(type==ULONGLONG) return e2; - if(integral(type)) return list3(CONV,rvalue_t(e2,type),I2ULL); - error(TYERR); return llist2(LCONST,0LL); + else if(type==UNSIGNED) e2 = list3(CONV,rvalue(e2),U2ULL); + else if(type==LONGLONG) ; + else if(type==ULONGLONG) ; + else if(integral(type)) e2 = list3(CONV,rvalue(e2),I2ULL); + else { error(TYERR); e2 = llist2(LCONST,0LL); } #else - unsigned_value(e2,type); + else unsigned_value(e2); #endif + type = ULONGLONG; + return e2; } static int -int_value(int e2,int type) +int_value(int e2) { - if (type>0&&car(type)==BIT_FIELD) e2=rvalue_t(e2,cadr(type)); - if(scalar(type)) return e2; + if (type>0&&car(type)==BIT_FIELD) e2=rvalue(e2); + if (0); + else if(scalar(type)) return e2; #if FLOAT_CODE - if (car(e2)==DCONST||car(e2)==FCONST) return list2(CONST,(int)dcadr(e2)); - if(type==FLOAT) return list3(CONV,rvalue_t(e2,type),F2I); - if(type==DOUBLE) return list3(CONV,rvalue_t(e2,type),D2I); + else if (car(e2)==DCONST||car(e2)==FCONST) e2 = list2(CONST,(int)dcadr(e2)); + else if(type==FLOAT) e2 = list3(CONV,rvalue(e2),F2I); + else if(type==DOUBLE) e2 = list3(CONV,rvalue(e2),D2I); #endif #if LONGLONG_CODE - if (car(e2)==LCONST) return list2(CONST,(int)lcadr(e2)); - if(type==LONGLONG) return list3(CONV,rvalue_t(e2,type),LL2I); - if(type==ULONGLONG) return list3(CONV,rvalue_t(e2,type),ULL2I); + else if (car(e2)==LCONST) e2 = list2(CONST,(int)lcadr(e2)); + else if(type==LONGLONG) e2 = list3(CONV,rvalue(e2),LL2I); + else if(type==ULONGLONG) e2 = list3(CONV,rvalue(e2),ULL2I); #endif - if(car(type)==ARRAY) return e2; - error(TYERR); return list2(CONST,1); + else if(car(type)==ARRAY) return e2; + else { error(TYERR); e2 = list2(CONST,1); } + type = INT; + return e2; } static int -unsigned_value(int e2,int type) +unsigned_value(int e2) { - if (type>0&&car(type)==BIT_FIELD) e2=rvalue_t(e2,cadr(type)); - if(scalar(type)) return e2; + if (type>0&&car(type)==BIT_FIELD) e2=rvalue(e2); + if (0); + else if(scalar(type)) return e2; #if FLOAT_CODE - // if (car(e2)==DCONST||car(e2)==FCONST) return list2(CONST,(unsigned)dcadr(e2)); - if (car(e2)==DCONST||car(e2)==FCONST) return list2(CONST,(int)dcadr(e2)); - if(type==FLOAT) return list3(CONV,rvalue_t(e2,type),F2U); - if(type==DOUBLE) return list3(CONV,rvalue_t(e2,type),D2U); + // else if (car(e2)==DCONST||car(e2)==FCONST) e2 = list2(CONST,(unsigned)dcadr(e2)); + else if (car(e2)==DCONST||car(e2)==FCONST) e2 = list2(CONST,(int)dcadr(e2)); + else if(type==FLOAT) e2 = list3(CONV,rvalue(e2),F2U); + else if(type==DOUBLE) e2 = list3(CONV,rvalue(e2),D2U); #endif #if LONGLONG_CODE - if(type==LONGLONG) return list3(CONV,rvalue_t(e2,type),LL2U); - if(type==ULONGLONG) return list3(CONV,rvalue_t(e2,type),ULL2U); + else if(type==LONGLONG) e2 = list3(CONV,rvalue(e2),LL2U); + else if(type==ULONGLONG) e2 = list3(CONV,rvalue(e2),ULL2U); #endif - error(TYERR); return e2; + else if(car(type)==ARRAY) return e2; + else error(TYERR); + type = UNSIGNED; + return e2; } /* assign statement */ @@ -1682,32 +1704,29 @@ if(t==VOID) error(TYERR); if(t==CHAR||t==UCHAR) { - e2=(t==UCHAR)?unsigned_value(e2,type):int_value(e2,type); - if (!integral(type)) error(TYERR); - type= t==CHAR?INT:UNSIGNED;return(list3(CASS,e1,e2)); + e2=(t==UCHAR)?unsigned_value(e2):int_value(e2); + return(list3(CASS,e1,e2)); } else if(t==SHORT||t==USHORT) { - e2=(t==USHORT)?unsigned_value(e2,type):int_value(e2,type); - if (!integral(type)) error(TYERR); - type= t==SHORT?INT:UNSIGNED; return(list3(SASS,e1,e2)); + e2=(t==USHORT)?unsigned_value(e2):int_value(e2); + return(list3(SASS,e1,e2)); #if FLOAT_CODE } else if(t==DOUBLE) { - e2=double_value(e2,type); - type= t;return(list3(DASS,e1,e2)); + e2=double_value(e2); + return(list3(DASS,e1,e2)); } else if(t==FLOAT) { - e2=float_value(e2,type); - type= t;return(list3(FASS,e1,e2)); + e2=float_value(e2); + return(list3(FASS,e1,e2)); #endif #if LONGLONG_CODE } else if(t==LONGLONG) { - e2=longlong_value(e2,type); - type= t;return(list3(LASS,e1,e2)); + e2=longlong_value(e2); + return(list3(LASS,e1,e2)); } else if(t==ULONGLONG) { - e2=ulonglong_value(e2,type); - type= t;return(list3(LASS,e1,e2)); + e2=ulonglong_value(e2); + return(list3(LASS,e1,e2)); #endif } else if(scalar(t)) { - e2=(t==UNSIGNED)?unsigned_value(e2,type):int_value(e2,type); - type=t; + e2=(t==UNSIGNED)?unsigned_value(e2):int_value(e2); return(list3(ASS,e1,e2)); } else if (car(t)==BIT_FIELD) { e2 = correct_type(e2,cadr(t)); @@ -1734,29 +1753,25 @@ } #if FLOAT_CODE if(type==DOUBLE||t==DOUBLE) { - e2=double_value(e2,t); - e3=double_value(e3,type); - t=type=DOUBLE; + e3=double_value(e3); + type = t; e2=double_value(e2); return(list4(DCOND,e1,e2,e3)); } if(type==FLOAT||t==FLOAT) { - e2=float_value(e2,t); - e3=float_value(e3,type); - t=type=FLOAT; + e3=float_value(e3); + type = t; e2=float_value(e2); return(list4(FCOND,e1,e2,e3)); } #endif #if LONGLONG_CODE if(type==LONGLONG||t==LONGLONG) { - e2=longlong_value(e2,t); - e3=longlong_value(e3,type); - t=type=LONGLONG; + e3=longlong_value(e3); + type = t; e2=longlong_value(e2); return(list4(LCOND,e1,e2,e3)); } if(type==ULONGLONG||t==ULONGLONG) { - e2=ulonglong_value(e2,t); - e3=ulonglong_value(e3,type); - t=type=ULONGLONG; + e3=ulonglong_value(e3); + type = t; e2=ulonglong_value(e2); return(list4(LCOND,e1,e2,e3)); } #endif @@ -1775,20 +1790,20 @@ #if FLOAT_CODE if (t==FLOAT) { if (no_float) error(TYERR); - e2=float_value(e2,type); type=t; + e2=float_value(e2); return(list4(FASSOP,e1,e2,op+FOP)); } else if (t==DOUBLE) { if (no_float) error(TYERR); - e2=double_value(e2,type); type=t; + e2=double_value(e2); return(list4(DASSOP,e1,e2,op+DOP)); } #endif #if LONGLONG_CODE if (t==LONGLONG) { - e2=longlong_value(e2,type); type=t; + e2=longlong_value(e2); return(list4(LASSOP,e1,e2,op+LOP)); } else if (t==ULONGLONG) { - e2=ulonglong_value(e2,type); type=t; + e2=ulonglong_value(e2); return(list4(LASSOP,e1,e2,op+LOP+((op==MUL+AS||op==DIV+AS)?US:0))); } #endif @@ -2782,15 +2797,13 @@ double d1,d2,d; int b=0; - type= DTYPE(dop); if (dop==DOP) { - e1=double_value(e1,t1); - e2=double_value(e2,t2); + type=t1; e1=double_value(e1); + type=t2; e2=double_value(e2); } else { - e1=float_value(e1,t1); - e2=float_value(e2,t2); + type=t1; e1=float_value(e1); + type=t2; e2=float_value(e2); } - t1=t2=DTYPE(dop); if(car(e1)==dop+CONST&&car(e2)==dop+CONST) { d1=dcadr(e1); d2=dcadr(e2); @@ -2890,13 +2903,11 @@ int us = (t1==ULONGLONG&&t2==ULONGLONG); if (us||(t1==ULONGLONG&&(op==LSHIFT||op==RSHIFT))) { - e1=ulonglong_value(e1,t1); - e2=ulonglong_value(e2,t2); - type = ULONGLONG; + type=t1; e1=ulonglong_value(e1); + type=t2; e2=ulonglong_value(e2); } else { - e1=longlong_value(e1,t1); - e2=longlong_value(e2,t2); - type = LONGLONG; + type=t1; e1=longlong_value(e1); + type=t2; e2=longlong_value(e2); } if(car(e1)==LCONST&&car(e2)==LCONST) { le1=lcadr(e1); @@ -2985,8 +2996,8 @@ int e=0; int us = (t1==UNSIGNED&&t2==UNSIGNED); - if(t1>0&&car(t1)==POINTER) { e2= int_value(e2,t2); t2=INT; } - else if(t2>0&&car(t2)==POINTER) { e1= int_value(e1,t1); t1=INT; } + if(t1>0&&car(t1)==POINTER) { type = t2; e2= int_value(e2); t2=INT; } + else if(t2>0&&car(t2)==POINTER) { type = t1; e1= int_value(e1); t1=INT; } #if FLOAT_CODE else if(t1==DOUBLE||t2==DOUBLE) return dbinop(op,e1,e2,t1,t2); @@ -3151,15 +3162,15 @@ if (type==FLOAT && t==DOTS) { t=DOUBLE;} // fall thru if (type==CHAR && t==DOTS) { t=INT;} // fall thru if (t==DOTS) return e; - if (t==UNSIGNED) e = unsigned_value(e,type); - else if (integral(t)) e = int_value(e,type); + if (t==UNSIGNED) e = unsigned_value(e); + else if (integral(t)) e = int_value(e); #if FLOAT_CODE - else if (t==FLOAT) e = float_value(e,type); - else if (t==DOUBLE) e = double_value(e,type); + else if (t==FLOAT) e = float_value(e); + else if (t==DOUBLE) e = double_value(e); #endif #if LONGLONG_CODE - else if (t==LONGLONG) e = longlong_value(e,type); - else if (t==ULONGLONG) e = ulonglong_value(e,type); + else if (t==LONGLONG) e = longlong_value(e); + else if (t==ULONGLONG) e = ulonglong_value(e); #endif else if ((t1=car(t))==STRUCT||t1==UNION) { if(size(t)!=size(type)) error(TYERR);