Mercurial > hg > CbC > old > device
changeset 571:d78f78ff50d1
*** empty log message ***
author | kono |
---|---|
date | Thu, 12 Jan 2006 13:56:44 +0900 |
parents | 266ded1a8fef |
children | 388baa7d4bee |
files | Changes Makefile mc-codegen.c |
diffstat | 3 files changed, 33 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Thu Jan 12 09:22:26 2006 +0900 +++ b/Changes Thu Jan 12 13:56:44 2006 +0900 @@ -8233,3 +8233,16 @@ -O99 の初期化してないっていうエラーメッセージに対処するために いろいろ初期化を入れちゃったけど、本当は必要ない。 +Thu Jan 12 13:03:12 JST 2006 + +あぁ、そうか。 + binop(...) { + int e = binop0(...); + if (inmode) return list3(op...); + else return e; + } +とすれば良かったわけね。まぁ、pexpr でひっかかりまくる +可能性はあるが.... + + +
--- a/Makefile Thu Jan 12 09:22:26 2006 +0900 +++ b/Makefile Thu Jan 12 13:56:44 2006 +0900 @@ -1,4 +1,5 @@ -CC = gcc -std=c99 -O2 +CC = gcc -std=c99 +# -O2 # -O99 CFLAGS = -g -Wall -I. # CFLAGS = -g -Wall -I. -pg -fprofile-arcs -ftest-coverage
--- a/mc-codegen.c Thu Jan 12 09:22:26 2006 +0900 +++ b/mc-codegen.c Thu Jan 12 13:56:44 2006 +0900 @@ -3750,16 +3750,13 @@ car(e2)==DRLVAR || car(e2)==DRGVAR || car(e2)==FRLVAR || car(e2)==FRGVAR )) { - if (inmode) return list3(ST_OP,op,list4(e2,e1,type,type)); return(list3(op+dop,e2,e1)); } if(op==ADD||op==SUB||op==MUL||op==DIV) { - if (inmode) return list3(ST_OP,op,list4(e1,e2,type,type)); return(list3(op+dop,e1,e2)); } t = type; type=INT; - if (inmode) return list3(ST_OP,op,list4(e1,e2,t,t)); if(op==LT) { return(list3(GT+dop,e2,e1)); } else if(op==LE) { @@ -3862,7 +3859,7 @@ return llist2(LCONST,le); } if(op==SUB) { us = 0; type=LONGLONG; } - if(op==SUB&&car(e2)==LCONST) { op=ADD; lcadr(e2)=-lcadr(e2); } + if(op==SUB&&car(e2)==LCONST) { op=ADD; e2=llist2(LCONST,-lcadr(e2)); } if((op==ADD||op==MUL||op==BOR||op==EOR||op==BAND)&& (car(e1)!=LCONST) && ( car(e2)==LRGVAR||car(e2)==LRLVAR|| @@ -3872,7 +3869,6 @@ } if((op==MUL||op==DIV)&&car(e2)==LCONST&&lcadr(e2)==1) return e1; if(op==BOR||op==EOR||op==BAND||op==ADD||op==SUB) { - if (inmode) return list3(ST_OP,op,list4(e1,e2,t1,t2)); return(list3(op+LOP,e1,e2)); } if(op==LSHIFT && car(e2)==LCONST) { @@ -3883,16 +3879,13 @@ if (lcadr(e2)==0) return e1; } if(op==LSHIFT||op==RSHIFT) { - if (inmode) return list3(ST_OP,op,list4(e1,e2,t1,t2)); return(list3(op+LOP+(t1==ULONGLONG),e1,e2)); } if (op==DIV||op==MUL||op==ADD||op==SUB||op==MOD) { - if (inmode) return list3(ST_OP,op,list4(e1,e2,t1,t2)); return(list3(op+LOP,e1,e2)); } type = INT; - if (inmode) return list3(ST_OP,op,list4(e1,e2,t1,t2)); if(op==LT) { return(list3(GT+LOP+us,e2,e1)); } else if(op==LE) { @@ -3909,12 +3902,14 @@ /* binary integer computation */ -extern int -binop(int op, int e1, int e2, int t1, int t2) +static int +binop0(int op, int e1, int e2, int t1, int t2) { int e=0; int us = 0; + // for inmode, destructive modification e1,e2,t1,t2 is not allowed + if(t1>0&&car(t1)==POINTER) { if(!(op==SUB && t2>0&&car(t2)==POINTER)) { type = t2; e2= int_value(e2); t2=INT; @@ -4014,13 +4009,11 @@ return list2(CONST,e); } if(op==GT||op==GE||op==LT||op==LE) { - if (inmode) return list3(ST_OP,op,list4(e1,e2,t1,t2)); return(car(e1)==CONST?list3(rop_dual(op)+us,e2,e1):list3(op+us,e1,e2)); } else if(op==EQ||op==NEQ) { - if (inmode) return list3(ST_OP,op,list4(e1,e2,t1,t2)); return(car(e1)==CONST?list3(op,e2,e1):list3(op,e1,e2)); } - if(op==SUB&&car(e2)==CONST) { op=ADD; cadr(e2)=-cadr(e2); } + if(op==SUB&&car(e2)==CONST) { op=ADD; e2=list2(CONST,-cadr(e2)); } if((op==ADD||op==MUL||op==BOR||op==EOR||op==BAND)&& (car(e1)!=CONST)) { switch(car(e2)) { case RGVAR: case RLVAR: @@ -4037,24 +4030,15 @@ if(integral(t2)) { // if(t1==INT) type=t2;else type=t1; if (us) type=UNSIGNED; else type=INT; - if (inmode) return list3(ST_OP,op,list4(e1,e2,t1,t2)); return(list3(ADD,e1,e2)); } if(car(t2)!=POINTER) error(TYERR); - if (inmode) { - type=t2; - return list3(ST_OP,op,list4(e1,e2,t1,t2)); - } - e=binop(MUL,e1,list2(CONST,size(cadr(t2))),t1,INT); + e=binop0(MUL,e1,list2(CONST,size(cadr(t2))),t1,INT); type=t2; return(list3(ADD,e,e2)); } if(car(t1)!=POINTER||!integral(t2)) error(TYERR); - if (inmode) { - type=t1; - return list3(ST_OP,op,list4(e1,e2,t1,t2)); - } - e=binop(MUL,e2,list2(CONST,size(cadr(t1))),t2,INT); + e=binop0(MUL,e2,list2(CONST,size(cadr(t1))),t2,INT); type=t1; if (car(e)==CONST && cadr(e)==0) return(e1); @@ -4084,16 +4068,11 @@ if(!integral(t2)) error(TYERR); if(t1==INT) type=t2;else type=t1; if (type==UNSIGNED) type=INT; - if (inmode) return list3(ST_OP,op,list4(e1,e2,t1,t2)); return(list3(SUB,e1,e2)); } if(car(t1)!=POINTER) error(TYERR); if(integral(t2)) { - if (inmode) { - type=t1; - return list3(ST_OP,op,list4(e1,e2,t1,t2)); - } - e=binop(MUL,e2,list2(CONST,size(cadr(t1))),t2,INT); + e=binop0(MUL,e2,list2(CONST,size(cadr(t1))),t2,INT); type=t1; if (car(e)==CONST) error(-1); return(list3(SUB,e1,e)); @@ -4101,19 +4080,14 @@ if(car(t2)!=POINTER) error(TYERR); compatible(t1,t2); - if (inmode) { - type= INT; - return list3(ST_OP,op,list4(e1,e2,t1,t2)); - } e=list3(SUB,e1,e2); - e=binop(DIV,e,list2(CONST,size(cadr(t1))),INT,INT); + e=binop0(DIV,e,list2(CONST,size(cadr(t1))),INT,INT); type= INT; return e; } if(!integral(t1)||!integral(t2)) error(TYERR); // if(t1==INT) type=t2; else type=t1; /* ??? */ if (us) type=UNSIGNED; else type=INT; - if (inmode) return list3(ST_OP,op,list4(e1,e2,t1,t2)); if((op==MUL||op==DIV)&&car(e2)==CONST&&cadr(e2)==1) return e1; if(op==BOR||op==EOR||op==BAND) return(list3(op,e1,e2)); if(op==LSHIFT||op==RSHIFT) return(list3(op+(t1==UNSIGNED?US:0),e1,e2)); @@ -4121,6 +4095,14 @@ return(list3(op+us,e1,e2)); } +extern int +binop(int op, int e1, int e2, int t1, int t2) +{ + int e = binop0(op,e1,e2,t1,t2); + if (inmode) return list3(ST_OP,op,list4(e1,e2,t1,t2)); + else return e; +} + /* arugment type of binary operator */