Mercurial > hg > CbC > old > device
comparison mc-codegen.c @ 353:41ed77cb9c67 nametbl-done
name table reogranization, extendable cheap done.
author | kono |
---|---|
date | Sat, 03 Jul 2004 13:53:37 +0900 |
parents | 43099915f4c2 |
children | 6188f66c0c0b |
comparison
equal
deleted
inserted
replaced
352:48aeb7379759 | 353:41ed77cb9c67 |
---|---|
292 return FLOAT; | 292 return FLOAT; |
293 #endif | 293 #endif |
294 case CONV: | 294 case CONV: |
295 g_expr0(e2); | 295 g_expr0(e2); |
296 switch(caddr(e1)) { | 296 switch(caddr(e1)) { |
297 case I2C: code_i2c(USE_CREG); return INT; | |
298 case I2S: code_i2s(USE_CREG); return INT; | |
299 case U2UC: code_u2uc(USE_CREG); return UNSIGNED; | |
300 case U2US: code_u2us(USE_CREG); return UNSIGNED; | |
297 #if FLOAT_CODE | 301 #if FLOAT_CODE |
298 case I2D: code_i2d(USE_CREG); return DOUBLE; | 302 case I2D: code_i2d(USE_CREG); return DOUBLE; |
299 case D2I: code_d2i(USE_CREG); return INT; | 303 case D2I: code_d2i(USE_CREG); return INT; |
300 case U2D: code_u2d(USE_CREG); return DOUBLE; | 304 case U2D: code_u2d(USE_CREG); return DOUBLE; |
301 case F2U: code_f2u(USE_CREG); return UNSIGNED; | 305 case F2U: code_f2u(USE_CREG); return UNSIGNED; |
1716 type = INT; | 1720 type = INT; |
1717 return e2; | 1721 return e2; |
1718 } | 1722 } |
1719 | 1723 |
1720 static int | 1724 static int |
1725 char_value(int e2) | |
1726 { | |
1727 if (type!=CHAR) { | |
1728 e2 = list3(CONV,int_value(rvalue(e2)),I2C); type = INT; | |
1729 } | |
1730 return e2; | |
1731 } | |
1732 | |
1733 static int | |
1734 short_value(int e2) | |
1735 { | |
1736 if (type!=SHORT) { | |
1737 e2 = list3(CONV,int_value(rvalue(e2)),I2S); type = INT; | |
1738 } | |
1739 return e2; | |
1740 } | |
1741 | |
1742 static int | |
1721 unsigned_value(int e2) | 1743 unsigned_value(int e2) |
1722 { | 1744 { |
1723 if (type>0&&car(type)==BIT_FIELD) e2=rvalue(e2); | 1745 if (type>0&&car(type)==BIT_FIELD) e2=rvalue(e2); |
1724 else if(type>0&&car(type)==ARRAY) return e2; | 1746 else if(type>0&&car(type)==ARRAY) return e2; |
1725 if (0); | 1747 if (0); |
1739 default: | 1761 default: |
1740 error(TYERR); | 1762 error(TYERR); |
1741 } | 1763 } |
1742 } | 1764 } |
1743 type = UNSIGNED; | 1765 type = UNSIGNED; |
1766 return e2; | |
1767 } | |
1768 | |
1769 static int | |
1770 uchar_value(int e2) | |
1771 { | |
1772 if (type!=UCHAR) { | |
1773 e2 = list3(CONV,unsigned_value(rvalue(e2)),U2UC); type = UNSIGNED; | |
1774 } | |
1775 return e2; | |
1776 } | |
1777 | |
1778 static int | |
1779 ushort_value(int e2) | |
1780 { | |
1781 if (type!=USHORT) { | |
1782 e2 = list3(CONV,unsigned_value(rvalue(e2)),U2US); type = UNSIGNED; | |
1783 } | |
1744 return e2; | 1784 return e2; |
1745 } | 1785 } |
1746 | 1786 |
1747 /* assign statement */ | 1787 /* assign statement */ |
1748 | 1788 |
2598 data_closing(NMTBL *n) | 2638 data_closing(NMTBL *n) |
2599 { | 2639 { |
2600 emit_data_closing(n); | 2640 emit_data_closing(n); |
2601 } | 2641 } |
2602 | 2642 |
2643 #define ARG_REORDER_DEBUG 0 | |
2603 | 2644 |
2604 extern int | 2645 extern int |
2605 arg_reorder(int arg,int new_arg) | 2646 arg_reorder(int arg,int new_arg) |
2606 { | 2647 { |
2607 /* list4(type,fnptr->dsp,(int)n,size); */ | 2648 /* list4(type,fnptr->dsp,(int)n,size); */ |
2608 int i,j,sz; | 2649 int i,j,sz; |
2609 int dsp = 0; | 2650 int dsp = 0; |
2610 NMTBL *n,*n1; | 2651 NMTBL *n,*n1; |
2611 | 2652 |
2612 /* f(a,b,c) { int c; short a; char* b;} case */ | 2653 /* f(a,b,c) int c; short a; char* b; { } case */ |
2613 | 2654 #if ARG_REORDER_DEBUG |
2614 // fprintf(stderr,"arg_reorder old:\n"); | 2655 fprintf(stderr,"arg_reorder old:\n"); |
2615 // for(j=new_arg;j;j=cadr(j)) { | 2656 for(j=new_arg;j;j=cadr(j)) { |
2616 // n=(NMTBL *)caddr(j); | 2657 n=(NMTBL *)caddr(j); |
2617 // fprintf(stderr,"dsp %d %s sz %d type %d\n",n->dsp,n->nm,cadddr(j),car(j)); | 2658 fprintf(stderr,"dsp %d %s sz %d type %d\n",n->dsp,n->nm,cadddr(j),car(j)); |
2618 // } | 2659 } |
2619 // fprintf(stderr,"arg_reorder new:\n"); | 2660 fprintf(stderr,"arg_reorder new:\n"); |
2661 #endif | |
2620 for(j=arg;j;j=cadr(j)) { | 2662 for(j=arg;j;j=cadr(j)) { |
2621 n=(NMTBL *)caddr(j); | 2663 n=(NMTBL *)caddr(j); |
2622 for(i=new_arg;i;i=cadr(i)) { | 2664 for(i=new_arg;i;i=cadr(i)) { |
2623 n1=(NMTBL *)caddr(i); | 2665 n1=(NMTBL *)caddr(i); |
2624 if (!neqname(n1->nm,n->nm)) break; | 2666 if (!neqname(n1->nm,n->nm)) break; |
2625 // if (n1==n) break; | 2667 // if (n1==n) break; |
2626 } | 2668 } |
2627 // fprintf(stderr,"dsp %d %s %s sz %d type %d\n",dsp,n->nm,n1->nm,cadddr(i),car(i)); | 2669 #if ARG_REORDER_DEBUG |
2670 fprintf(stderr,"dsp %d %s %s sz %d type %d\n",dsp,n->nm,n1->nm,cadddr(i),car(i)); | |
2671 #endif | |
2628 if (!i) { | 2672 if (!i) { |
2629 /* f(a,b,c) { int c; } case (what?!) */ | 2673 /* f(a,b,c) int c; { } case (what?!) */ |
2630 i = j; | 2674 i = j; |
2675 n1 = n; | |
2631 } | 2676 } |
2632 if(n->sc==LVAR) { | 2677 if(n->sc==LVAR) { |
2633 n->dsp = dsp; | 2678 n->dsp = dsp; |
2634 car(j)=car(i); | 2679 car(j)=car(i); |
2635 caddr(j)=caddr(i); | 2680 caddr(j)=caddr(i); |
2681 n1->dsp = n->dsp; | |
2682 n->ty = n1->ty; | |
2683 n->sc = n1->sc; | |
2636 cadddr(j)=sz= cadddr(i); | 2684 cadddr(j)=sz= cadddr(i); |
2637 if (sz==1||sz==size_of_short) sz = size_of_int; | 2685 if (sz==1||sz==size_of_short) sz = size_of_int; |
2638 dsp += sz; | 2686 dsp += sz; |
2639 } | 2687 } |
2640 } | 2688 } |
2641 // fprintf(stderr,"arg_reorder end:\n"); | 2689 #if ARG_REORDER_DEBUG |
2690 fprintf(stderr,"arg_reorder end:\n"); | |
2691 #endif | |
2642 return arg; | 2692 return arg; |
2643 } | 2693 } |
2644 | 2694 |
2645 | 2695 |
2646 static NMTBL str_ret; | 2696 static NMTBL str_ret; |
3153 | 3203 |
3154 extern int | 3204 extern int |
3155 binop(int op, int e1, int e2, int t1, int t2) | 3205 binop(int op, int e1, int e2, int t1, int t2) |
3156 { | 3206 { |
3157 int e=0; | 3207 int e=0; |
3158 int us = (t1==UNSIGNED&&t2==UNSIGNED); | 3208 int us = 0; |
3159 | 3209 |
3160 if(t1>0&&car(t1)==POINTER) { type = t2; e2= int_value(e2); t2=INT; } | 3210 if(t1>0&&car(t1)==POINTER) { type = t2; e2= int_value(e2); t2=INT; } |
3161 else if(t2>0&&car(t2)==POINTER) { type = t1; e1= int_value(e1); t1=INT; } | 3211 else if(t2>0&&car(t2)==POINTER) { type = t1; e1= int_value(e1); t1=INT; } |
3162 #if FLOAT_CODE | 3212 #if FLOAT_CODE |
3163 else if(t1==DOUBLE||t2==DOUBLE) | 3213 else if(t1==DOUBLE||t2==DOUBLE) |
3167 #endif | 3217 #endif |
3168 #if LONGLONG_CODE | 3218 #if LONGLONG_CODE |
3169 else if(t1==LONGLONG||t2==LONGLONG||t1==ULONGLONG||t2==ULONGLONG) | 3219 else if(t1==LONGLONG||t2==LONGLONG||t1==ULONGLONG||t2==ULONGLONG) |
3170 return lbinop(op,e1,e2,t1,t2); | 3220 return lbinop(op,e1,e2,t1,t2); |
3171 #endif | 3221 #endif |
3222 if (t1==UNSIGNED) { | |
3223 if (t2==UNSIGNED || (car(e2)==CONST && cadr(e2)>0)) us = 1; | |
3224 } | |
3225 if (t2==UNSIGNED) { | |
3226 if (t1==UNSIGNED || (car(e1)==CONST && cadr(e1)>0)) us = 1; | |
3227 } | |
3228 | |
3172 if(car(e1)==CONST&&car(e2)==CONST) { | 3229 if(car(e1)==CONST&&car(e2)==CONST) { |
3173 e1=cadr(e1); | 3230 e1=cadr(e1); |
3174 e2=cadr(e2); | 3231 e2=cadr(e2); |
3175 type= INT; | 3232 type= INT; |
3176 switch(op) { | 3233 switch(op) { |
3321 if (type==BIT_FIELD) e = rvalue(e); | 3378 if (type==BIT_FIELD) e = rvalue(e); |
3322 #endif | 3379 #endif |
3323 if (type==FLOAT && t==DOTS) { t=DOUBLE;} // fall thru | 3380 if (type==FLOAT && t==DOTS) { t=DOUBLE;} // fall thru |
3324 if (type==CHAR && t==DOTS) { t=INT;} // fall thru | 3381 if (type==CHAR && t==DOTS) { t=INT;} // fall thru |
3325 if (t==DOTS) return e; | 3382 if (t==DOTS) return e; |
3326 if (t==UNSIGNED) e = unsigned_value(e); | 3383 else if (t==UNSIGNED) e = unsigned_value(e); |
3384 else if (t==CHAR) { e = char_value(e); t = INT; } | |
3385 else if (t==UCHAR) { e = uchar_value(e); t = UNSIGNED; } | |
3386 else if (t==SHORT) { e = short_value(e); t = INT; } | |
3387 else if (t==USHORT) { e = ushort_value(e); t = UNSIGNED; } | |
3327 else if (integral(t)) e = int_value(e); | 3388 else if (integral(t)) e = int_value(e); |
3328 #if FLOAT_CODE | 3389 #if FLOAT_CODE |
3329 else if (t==FLOAT) e = float_value(e); | 3390 else if (t==FLOAT) e = float_value(e); |
3330 else if (t==DOUBLE) e = double_value(e); | 3391 else if (t==DOUBLE) e = double_value(e); |
3331 #endif | 3392 #endif |