Mercurial > hg > CbC > old > device
changeset 353:41ed77cb9c67 nametbl-done
name table reogranization, extendable cheap done.
author | kono |
---|---|
date | Sat, 03 Jul 2004 13:53:37 +0900 |
parents | 48aeb7379759 |
children | 32cd53208b79 |
files | Changes Makefile mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-code.h mc-codegen.c mc-parse.c mc.h rsyncs stdio.h test/cext.c |
diffstat | 12 files changed, 282 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Sat Jul 03 02:13:11 2004 +0900 +++ b/Changes Sat Jul 03 13:53:37 2004 +0900 @@ -5400,3 +5400,24 @@ Fri Jul 2 23:38:14 JST 2004 あと、もう少し.. + +セルフコンパイルのバグがとれないよ。 + +もしかすると、void fuga(b,d,e,f) { return hoge(a,b,c,e) ; } +っていうプログラムで完全に、tail recursion するなら、 +CbC と、おんなじなんじゃない? (条件は?) + +その方が簡単か? いや、関数呼び出しと互換性を維持しないといけない +ので、やっぱり、こっちの方が難しい。レジスタのセーブとかあるし。 + +そうか、I2C, I2S, U2UC, U2US が必要なみたいだね。それに応じて、 + code_i2c + code_i2s + code_u2uc + code_u2us +がいるのか。 + +endian 特有の問題なのか。じゃぁ、hash のバグとは関係ないのね。 + +K&R argument が redefined 扱いで、新しい変数になって +しまう。
--- a/Makefile Sat Jul 03 02:13:11 2004 +0900 +++ b/Makefile Sat Jul 03 13:53:37 2004 +0900 @@ -79,6 +79,7 @@ make check TARGET=test/code-gen-all make check TARGET=test/bitfield make check TARGET=test/bitfield1 + make check TARGET=test/cext #MK =-make MK= check-all-code:
--- a/mc-code-ia32.c Sat Jul 03 02:13:11 2004 +0900 +++ b/mc-code-ia32.c Sat Jul 03 13:53:37 2004 +0900 @@ -507,6 +507,7 @@ /* process in reverse order */ n = (NMTBL*)caddr(args); type = n->ty; +printf("# %s %d %d\n",n->nm,n->dsp,n->ty); if (scalar(type)) { if ((reg = get_input_register_var(reg_var,n,is_code0))) { n->sc = REGISTER; @@ -780,6 +781,41 @@ regv[creg]=1; } +extern void +code_i2c(int reg) +{ + use_int(reg); + use_data_reg(reg,1); + printf("\t%s %s,%s\n",cload(1,1), + register_name(reg,1),register_name(reg,0)); +} + +extern void +code_i2s(int reg) +{ + use_int(reg); + use_data_reg(reg,1); + printf("\t%s %s,%s\n",cload(1,SIZE_OF_SHORT), + register_name(reg,2),register_name(reg,0)); +} + +extern void +code_u2uc(int reg) +{ + use_int(reg); + use_data_reg(reg,1); + printf("\t%s %s,%s\n",cload(0,1), + register_name(reg,1),register_name(reg,0)); +} + +extern void +code_u2us(int reg) +{ + use_int(reg); + use_data_reg(reg,1); + printf("\t%s %s,%s\n",cload(0,SIZE_OF_SHORT), + register_name(reg,2),register_name(reg,0)); +} void code_crlvar(int e2,int reg,int sign,int sz) {
--- a/mc-code-mips.c Sat Jul 03 02:13:11 2004 +0900 +++ b/mc-code-mips.c Sat Jul 03 13:53:37 2004 +0900 @@ -1206,6 +1206,42 @@ lvar(e2); } +extern void +code_i2c(int reg) +{ + int reg1; + use_int(reg); + reg1 = get_register(); + printf("sll %s,%s,24\n",register_name(reg1),register_name(reg)); + printf("sra %s,%s,24\n",register_name(reg),register_name(reg1)); + free_register(reg1); +} + +extern void +code_i2s(int reg) +{ + int reg1; + use_int(reg); + reg1 = get_register(); + printf("sll %s,%s,16\n",register_name(reg1),register_name(reg)); + printf("sra %s,%s,16\n",register_name(reg),register_name(reg1)); + free_register(reg1); +} + +extern void +code_u2uc(int reg) +{ + use_int(reg); + printf("andi %s,%s,0xff\n",register_name(reg),register_name(reg)); +} + +extern void +code_u2us(int reg) +{ + use_int(reg); + printf("andi %s,%s,0xffff\n",register_name(reg),register_name(reg)); +} + void code_crlvar(int e2,int reg,int sign,int sz) { use_int(reg);
--- a/mc-code-powerpc.c Sat Jul 03 02:13:11 2004 +0900 +++ b/mc-code-powerpc.c Sat Jul 03 13:53:37 2004 +0900 @@ -1144,6 +1144,33 @@ printf("\tmr %s,%s\n",register_name(reg),register_name(e2)); } +extern void +code_i2c(int reg) +{ + use_int(reg); + cext(1,1,reg); +} + +extern void +code_i2s(int reg) +{ + use_int(reg); + cext(1,SIZE_OF_SHORT,reg); +} + +extern void +code_u2uc(int reg) +{ + use_int(reg); + cext(0,1,reg); +} + +extern void +code_u2us(int reg) +{ + use_int(reg); + cext(0,SIZE_OF_SHORT,reg); +} void code_rlvar(int e2,int reg) {
--- a/mc-code.h Sat Jul 03 02:13:11 2004 +0900 +++ b/mc-code.h Sat Jul 03 13:53:37 2004 +0900 @@ -136,6 +136,10 @@ extern int emit_string_label(); extern void ascii(char *s); +extern void code_i2c(int reg); +extern void code_i2s(int reg); +extern void code_u2uc(int reg); +extern void code_u2us(int reg); #if FLOAT_CODE /* floating point part */
--- a/mc-codegen.c Sat Jul 03 02:13:11 2004 +0900 +++ b/mc-codegen.c Sat Jul 03 13:53:37 2004 +0900 @@ -294,6 +294,10 @@ case CONV: g_expr0(e2); switch(caddr(e1)) { + case I2C: code_i2c(USE_CREG); return INT; + case I2S: code_i2s(USE_CREG); return INT; + case U2UC: code_u2uc(USE_CREG); return UNSIGNED; + case U2US: code_u2us(USE_CREG); return UNSIGNED; #if FLOAT_CODE case I2D: code_i2d(USE_CREG); return DOUBLE; case D2I: code_d2i(USE_CREG); return INT; @@ -1718,6 +1722,24 @@ } static int +char_value(int e2) +{ + if (type!=CHAR) { + e2 = list3(CONV,int_value(rvalue(e2)),I2C); type = INT; + } + return e2; +} + +static int +short_value(int e2) +{ + if (type!=SHORT) { + e2 = list3(CONV,int_value(rvalue(e2)),I2S); type = INT; + } + return e2; +} + +static int unsigned_value(int e2) { if (type>0&&car(type)==BIT_FIELD) e2=rvalue(e2); @@ -1744,6 +1766,24 @@ return e2; } +static int +uchar_value(int e2) +{ + if (type!=UCHAR) { + e2 = list3(CONV,unsigned_value(rvalue(e2)),U2UC); type = UNSIGNED; + } + return e2; +} + +static int +ushort_value(int e2) +{ + if (type!=USHORT) { + e2 = list3(CONV,unsigned_value(rvalue(e2)),U2US); type = UNSIGNED; + } + return e2; +} + /* assign statement */ /* keep type */ @@ -2600,6 +2640,7 @@ emit_data_closing(n); } +#define ARG_REORDER_DEBUG 0 extern int arg_reorder(int arg,int new_arg) @@ -2609,14 +2650,15 @@ int dsp = 0; NMTBL *n,*n1; - /* f(a,b,c) { int c; short a; char* b;} case */ - -// fprintf(stderr,"arg_reorder old:\n"); -// for(j=new_arg;j;j=cadr(j)) { -// n=(NMTBL *)caddr(j); -// fprintf(stderr,"dsp %d %s sz %d type %d\n",n->dsp,n->nm,cadddr(j),car(j)); -// } -// fprintf(stderr,"arg_reorder new:\n"); + /* f(a,b,c) int c; short a; char* b; { } case */ +#if ARG_REORDER_DEBUG + fprintf(stderr,"arg_reorder old:\n"); + for(j=new_arg;j;j=cadr(j)) { + n=(NMTBL *)caddr(j); + fprintf(stderr,"dsp %d %s sz %d type %d\n",n->dsp,n->nm,cadddr(j),car(j)); + } + fprintf(stderr,"arg_reorder new:\n"); +#endif for(j=arg;j;j=cadr(j)) { n=(NMTBL *)caddr(j); for(i=new_arg;i;i=cadr(i)) { @@ -2624,21 +2666,29 @@ if (!neqname(n1->nm,n->nm)) break; // if (n1==n) break; } -// fprintf(stderr,"dsp %d %s %s sz %d type %d\n",dsp,n->nm,n1->nm,cadddr(i),car(i)); +#if ARG_REORDER_DEBUG + fprintf(stderr,"dsp %d %s %s sz %d type %d\n",dsp,n->nm,n1->nm,cadddr(i),car(i)); +#endif if (!i) { - /* f(a,b,c) { int c; } case (what?!) */ + /* f(a,b,c) int c; { } case (what?!) */ i = j; + n1 = n; } if(n->sc==LVAR) { n->dsp = dsp; car(j)=car(i); caddr(j)=caddr(i); + n1->dsp = n->dsp; + n->ty = n1->ty; + n->sc = n1->sc; cadddr(j)=sz= cadddr(i); if (sz==1||sz==size_of_short) sz = size_of_int; dsp += sz; } } -// fprintf(stderr,"arg_reorder end:\n"); +#if ARG_REORDER_DEBUG + fprintf(stderr,"arg_reorder end:\n"); +#endif return arg; } @@ -3155,7 +3205,7 @@ binop(int op, int e1, int e2, int t1, int t2) { int e=0; - int us = (t1==UNSIGNED&&t2==UNSIGNED); + int us = 0; 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; } @@ -3169,6 +3219,13 @@ else if(t1==LONGLONG||t2==LONGLONG||t1==ULONGLONG||t2==ULONGLONG) return lbinop(op,e1,e2,t1,t2); #endif + if (t1==UNSIGNED) { + if (t2==UNSIGNED || (car(e2)==CONST && cadr(e2)>0)) us = 1; + } + if (t2==UNSIGNED) { + if (t1==UNSIGNED || (car(e1)==CONST && cadr(e1)>0)) us = 1; + } + if(car(e1)==CONST&&car(e2)==CONST) { e1=cadr(e1); e2=cadr(e2); @@ -3323,7 +3380,11 @@ 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); + else if (t==UNSIGNED) e = unsigned_value(e); + else if (t==CHAR) { e = char_value(e); t = INT; } + else if (t==UCHAR) { e = uchar_value(e); t = UNSIGNED; } + else if (t==SHORT) { e = short_value(e); t = INT; } + else if (t==USHORT) { e = ushort_value(e); t = UNSIGNED; } else if (integral(t)) e = int_value(e); #if FLOAT_CODE else if (t==FLOAT) e = float_value(e);
--- a/mc-parse.c Sat Jul 03 02:13:11 2004 +0900 +++ b/mc-parse.c Sat Jul 03 13:53:37 2004 +0900 @@ -71,7 +71,7 @@ struct {int fd,ln;char *name0;int inc;FILE *fcb;} *filep,filestack[FILES]; -static NMTBL *decl0(void),*decl1(void),*lsearch(char *name,int sc); +static NMTBL *decl0(void),*decl1(void),*l_top_search(char *name,int sc); static int append3(int p,int a1,int a2); static int expr0(void); static int expr1(void); @@ -131,6 +131,7 @@ extern NMTBL * get_name_from_chptr(); static NMTBL * hash_search(char *name,struct cheap *scheap,int len,unsigned int hash,int mode); static NMTBL * make_local_scope(NMTBL *nlist,NMTBL *nptr1,int sc); +static NMTBL * make_top_scope(NMTBL *nlist,NMTBL *nptr1,int sc); static void enter_scope(); static void leave_scope(); static void extrn_use(NMTBL *nptr); @@ -1936,7 +1937,7 @@ t = nptr0->sc; if (t==EMPTY||t==EXTRN1||t==EXTRN) { nptr0->sc=EMPTY; - nptr0=lsearch(nptr0->nm,0); + nptr0=l_top_search(nptr0->nm,0); nptr0->sc = FLABEL; gen_jmp(nptr0->dsp = fwdlabel()); } else if (t==FLABEL||t==BLABEL) { @@ -1988,7 +1989,7 @@ else if(nptr->sc != EMPTY && nptr->sc != EXTRN1) error(TYERR); nptr->sc=EMPTY; - nptr1=lsearch(nptr->nm,0); + nptr1=l_top_search(nptr->nm,0); nptr1->sc = BLABEL; nptr1->dsp = backdef(); conv->label_(); @@ -2978,9 +2979,9 @@ get_name(char *name,int *len,int mode) { /* no name copy */ - int ch,i = 0; + unsigned int ch,i = 0; unsigned int hash0 = 0; - char *n = name; + unsigned char *n = name; struct cheap scheap; save_cheap(&scheap,cheap); @@ -3444,12 +3445,12 @@ } static NMTBL * -lsearch(char *name,int sc) +l_top_search(char *name,int sc) { NMTBL *nlist,*nptr1; nptr1 = name_space_search( nlist = name_space_search(get_name(name,0,DEF),LDECL),sc); - return make_local_scope(nlist,nptr1,sc); + return make_top_scope(nlist,nptr1,sc); } static NMTBL * @@ -3467,6 +3468,28 @@ return nptr1; } +static NMTBL * +make_top_scope(NMTBL *nlist,NMTBL *nptr1,int sc) +{ + int ns; + int *scope; + if (saved_scope) { + for(ns=saved_scope;cadr(ns);ns=cadr(ns)); + scope = &car(ns); + } else { + scope = ¤t_scope; + } + for(ns=nlist->dsp;ns;ns=cadr(ns)) { + if (car(ns)==sc /* && nptr1->sc!=EMPTY */) { + *scope = glist3((int)&(caddr(ns)),*scope, + (int)nptr1); + caddr(ns) = (int)(nptr1 = get_nptr()); + nptr1->nm = nlist->nm; nptr1->sc=EMPTY; nptr1->dsp = 0; + } + } + return nptr1; +} + static void enter_scope() {
--- a/mc.h Sat Jul 03 02:13:11 2004 +0900 +++ b/mc.h Sat Jul 03 13:53:37 2004 +0900 @@ -324,19 +324,36 @@ /* not appeared as tags */ -#define I2I 78 -#define I2U 79 -#define I2D 80 -#define I2F 81 -#define I2LL 82 -#define I2ULL 83 +#define LPAR 78 +#define RPAR 79 +#define LBRA 80 +#define RBRA 81 +#define LC 82 +#define RC 83 +#define COLON 84 +#define SM 85 +#define PERIOD 86 +#define ARROW 87 +#define CNAME 88 -#define U2I 84 -#define U2U 85 -#define U2D 86 -#define U2F 87 -#define U2LL 88 -#define U2ULL 89 +#define I2C 89 +#define I2S 90 +#define I2I 91 +#define I2U 92 +#define I2D 93 +#define I2F 94 +#define I2LL 95 +#define I2ULL 96 + +#define U2UC 97 +#define U2US 98 +#define U2I 99 +#define U2U 100 +#define U2D 101 +#define U2F 102 +#define U2LL 103 +#define U2ULL 104 + #define D2I (DOP+I2I) #define D2U (DOP+I2U) @@ -366,18 +383,6 @@ #define ULL2LL (LOP+U2LL) #define ULL2ULL (LOP+U2ULL) -#define LPAR 90 -#define RPAR 91 -#define LBRA 92 -#define RBRA 93 -#define LC 94 -#define RC 95 -#define COLON 96 -#define SM 97 -#define PERIOD 98 -#define ARROW 99 -#define CNAME 100 - /* tree node tags end */ /* error number start */
--- a/rsyncs Sat Jul 03 02:13:11 2004 +0900 +++ b/rsyncs Sat Jul 03 13:53:37 2004 +0900 @@ -4,11 +4,10 @@ --exclude mc-ia32 --exclude mc-powerpc --exclude CVS \ --exclude '*.bak' --exclude '*.out' \ kono@"$1":~/src/device $HOME -# touch Makefile *.c conv_* *.h */*.[hc] -# make clean +touch * */* +make clean cp .gdbinit.ia32 .gdbinit rm -f mc-ia32 -touch Makefile *.pl *.[hc] conv/*.[hc] test/*.[hc] make depend rm b*.s make diff ARCH=ia32
--- a/stdio.h Sat Jul 03 02:13:11 2004 +0900 +++ b/stdio.h Sat Jul 03 13:53:37 2004 +0900 @@ -1,4 +1,4 @@ -#ifndef __micro_c__aaa +#ifndef __micro_c__ #include "/usr/include/stdio.h" long long strtoll(const char *, char **, int); char *malloc(int);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/cext.c Sat Jul 03 13:53:37 2004 +0900 @@ -0,0 +1,21 @@ + +unsigned int u; + +main() +{ + int i,k; unsigned uk; + + for(i=-3;i<4;i++) { + k = (char) i; + uk = (unsigned char) i; + printf("%d %u\n",k,uk); + k = (short) i; + uk = (unsigned short) i; + printf("%d %u\n",k,uk); + } + u = (unsigned) -23432; + + printf("%d\n",u/(8048+5)); + return 0; +} +