Mercurial > hg > CbC > old > device
changeset 574:aad312f61654 inmode-fix
remove too much inmode.
author | kono |
---|---|
date | Fri, 13 Jan 2006 18:37:05 +0900 |
parents | 3de2ae36c7e5 |
children | a4445cb1aa91 |
files | .gdbinit Changes mc-codegen.c mc-inline.c mc-parse.c mc-parse.h mc.h test/basic.c test/func_conv_err.c test/scope.c test/tmp7.c |
diffstat | 11 files changed, 109 insertions(+), 53 deletions(-) [+] |
line wrap: on
line diff
--- a/.gdbinit Fri Jan 13 01:55:33 2006 +0900 +++ b/.gdbinit Fri Jan 13 18:37:05 2006 +0900 @@ -48,8 +48,10 @@ # run -s test/strinit.c # run -DINLINE=inline test/scope.c # run -DINLINE=inline test/code-gen-all.c -# run -DINLINE=inline test/bitfield1.c +# run -DINLINE=inline test/bitfield1.c # run -s test/linux_kernel.c.--- # run -s test/stralign.c # run -s test/putenemy.c -run -s test/func_conv_err.c +# run -s test/func_conv_err.c +# run -DINLINE=inline test/tmp7.c +run -DINLINE=inline test/code-gen-all.c
--- a/Changes Fri Jan 13 01:55:33 2006 +0900 +++ b/Changes Fri Jan 13 18:37:05 2006 +0900 @@ -8279,4 +8279,17 @@ から、構文解析レベルではチェックできないな。 mode を変えないと。stmode? - +codegen level では構文エラーを出さない方針が良いらしい。 + +Fri Jan 13 09:34:10 JST 2006 + +inmode を fdecl の最後でクリアすると、fargtype が +変になるらしい。local heap 上に取られてしまうから +なんだろうけど。でも、fdecl でinmode をクリアしないのは +おかしい。 + +local struct の型情報は local heap に取られるけど、 +global_table で参照される可能性がある。global に +置いてもいいんじゃないの? + +
--- a/mc-codegen.c Fri Jan 13 01:55:33 2006 +0900 +++ b/mc-codegen.c Fri Jan 13 18:37:05 2006 +0900 @@ -258,7 +258,7 @@ t = function(e1); return t; case CODE: - if (car(e2)==FNAME&&is_code((NMTBL*)cadr(e2))) { + if (car(e2)==FNAME&&is_function((NMTBL*)cadr(e2))) { // error(GTERR); return function(e1); } @@ -553,6 +553,7 @@ case ST_LABEL: st_label(e1); break; case ST_COMMENT: st_comment(e1); break; case IVAR: error(-1); break; + case 0: break; // empty case default: code_bool(e1,USE_CREG); /* type? */ return INT;
--- a/mc-inline.c Fri Jan 13 01:55:33 2006 +0900 +++ b/mc-inline.c Fri Jan 13 18:37:05 2006 +0900 @@ -411,6 +411,7 @@ extern void st_comment(int e1){ + glineno++; gen_comment((char *)caddr(e1)); } @@ -437,6 +438,8 @@ int d = cadr(e1); int d1,e; if ((d1=(heap[pdisp+d]))) return d1; +fprintf(stderr,"## undeclared ivar %d\n",d); + // error(-1); e = heap[pdisp+d]=list3(LVAR,new_lvar(sz),0); inline_lvars = glist2(e,inline_lvars); return e; @@ -642,6 +645,8 @@ // is used or not. if (ctmode) { mode = car(ctmode); stmode = cadr(ctmode); ctmode = caddr(ctmode); + } else { + mode = LDECL; stmode = 0; ctmode = 0; } switch(stmode) { case EXTRN: case EXTRN1: case STATIC: @@ -677,7 +682,10 @@ } if (n->sc!=FLABEL) inline_lvars = glist2(v,inline_lvars); - if (heap[pdisp+dsp]) error(-1); + if (heap[pdisp+dsp]) { + fprintf(stderr,"## double p_decl %s %s\n",((NMTBL*)(caddr(heap[pdisp+dsp])))->nm,n->nm); + error(-1); + } heap[pdisp+dsp]=v; stmode = sstmode; mode = smode; @@ -860,6 +868,7 @@ static int p_comment(int e) { + glineno++; return list3(ST_COMMENT,pexpr(cadr(e)),caddr(e)); } @@ -914,7 +923,8 @@ case FUNCTION: return pfunction(e1); case CODE: - return list2(car(e1),pexpr(e2)); + e2=pexpr(e2); + return list3(car(e1),e2,pexpr(cadddr(e1))); case INLINE: return p_inline(e1); case INDIRECT:
--- a/mc-parse.c Fri Jan 13 01:55:33 2006 +0900 +++ b/mc-parse.c Fri Jan 13 18:37:05 2006 +0900 @@ -364,10 +364,11 @@ case CODE_ERR: // "goto is necessary" : case ILERR: // "inline error" : case SIERR: // "non brace in struct init error" : - case GTERR: - case FNERR: - case UCERR: - case UFERR: + case GTERR: // "cannot goto to a function" : + case FNERR: // "calling a code segement, use goto" : + case UCERR: // "already used as code segement" : + case UFERR: // "already used as function" : + case ENERR: // function has return value but reached to the end return 0; } return 1; @@ -434,6 +435,7 @@ (n==FNERR) ? "calling a code segement, use goto" : (n==UCERR) ? "already used as code segement" : (n==UFERR) ? "already used as function" : + (n==ENERR) ? "function has return value but reached to the end" : (n==CSERR) ? "no excutable code in switch" : "Bug of compiler"); errmsg(); @@ -1745,13 +1747,13 @@ disp = cadr(nptr0->ty); } conv->comment_(' '); - type0 = list4(s,disp,fields,(int)nptr0); + type0 = glist4(s,disp,fields,(int)nptr0); } } else if(sym==LC) { /* no tag name */ if (sdecl_f) conv->lc_(); sdecl_field(smode); - type0 = list4(s,disp,fields,0); + type0 = glist4(s,disp,fields,0); // mode is now previous mode } else error(DCERR); @@ -1857,7 +1859,7 @@ emit_init_vars(); while(sym!=RC) statement(0); if(control) - error(STERR); + error(CODE_ERR); control=0; conv->code_end_(); if(!chk) gen_code_leave(fnptr->nm); @@ -1957,7 +1959,14 @@ list4(reverse0(parse),arg_disp,disp,(int)local_static_list)); parse = 0; inline_funcs = list2((int)n,inline_funcs); + inmode = 0; } else { +#if 1 + if (type_value(cadr(fnptr->ty))!=VOID) { + if (control && !retpending && !pending_jmp) + error(ENERR); // function has return value but reached to the end + } +#endif if(!chk) gen_leave(control,n->nm); } retpending = 0; @@ -2820,7 +2829,7 @@ checkret(); conv->goto_(); - stmode=CODE; + stmode=GOTO; getsym(0); e1 = expr(0); stmode=sstmode; @@ -3586,7 +3595,7 @@ break; case EMPTY: if(getsym(0)==LPAR) { - type= glist3(stmode==CODE?CODE:FUNCTION,INT,0); + type= glist3(stmode==GOTO?CODE:FUNCTION,INT,0); nptr->sc = EXTRN1; nptr->ty= type; extrn_use(nptr); @@ -3597,7 +3606,7 @@ e1= list2(CONST,0); break; } else { - if (stmode!=CODE) // goto statement + if (stmode!=GOTO) // undefined on goto statement is OK error(UDERR); nptr->sc = EXTRN1; type = nptr->ty= glist3(FUNCTION,INT,0); @@ -3832,7 +3841,7 @@ tmp_struct = def(0,0); if (inmode) { set_attr(tmp_struct,HAS_ADDRESS,1); - parse = list4(ST_DECL,parse,(int)tmp_struct,0); + parse = list4(ST_DECL,parse,(int)tmp_struct,list3(LDECL,0,0)); } } return tmp_struct; @@ -3898,11 +3907,12 @@ checksym(RPAR); conv->funcall_args_(); if(t==CODE) { - if (stmode!=CODE) error(FNERR); + if (stmode!=GOTO) error(FNERR); // code segment has no return type type = ftype; return list4(CODE,e1,arglist,ftype); // should be CODE? - } else if (stmode==CODE) { + } else if (stmode==GOTO) { + // symbol is undefined at this time // error(GTERR); } @@ -3932,7 +3942,7 @@ return list4(INLINE,e1,arglist,ftype); } } - return list4(stmode==CODE?CODE:FUNCTION,e1,arglist,ftype); + return list4(stmode==GOTO?CODE:FUNCTION,e1,arglist,ftype); } static int @@ -4732,7 +4742,10 @@ scope = car(current_scope); while(scope) { ns = (NMTBL *)caddr(car(scope)); - if (ns->sc != GVAR && ns->sc != STATIC && !inmode) free_nptr(ns); + switch(ns->sc) { + case GVAR: case STATIC: case IVAR: break; + default: if (!inmode) free_nptr(ns); + } caddr(car(scope)) = caddr(scope); next = cadr(scope); free_glist2(scope); // will destroy cadr @@ -4979,17 +4992,18 @@ extern int glist2(int e1,int e2) { - int smode,ret; + int ret; if (free_glist2_list) { ret = free_glist2_list; free_glist2_list = cadr(free_glist2_list); car(ret)=e1; cadr(ret)=e2; return ret; } - smode = mode; - mode = GDECL; - ret = list2(e1,e2); - mode = smode; + ret = gfree; + gfree+=2 ; + heap[ret]=e1; + heap[ret+1]=e2; + if(lfree<gfree) error(HPERR); return ret; } @@ -5008,17 +5022,33 @@ extern int glist3(int e1,int e2,int e3) { - int smode,ret; + int ret; if (free_glist3_list) { ret = free_glist3_list; free_glist3_list = cadr(free_glist3_list); car(ret)=e1; cadr(ret)=e2; caddr(ret)=e3; return ret; } - smode = mode; - mode = GDECL; - ret = list3(e1,e2,e3); - mode = smode; + ret = gfree; + gfree+=3 ; + heap[ret]=e1; + heap[ret+1]=e2; + heap[ret+2]=e3; + if(lfree<gfree) error(HPERR); + return ret; +} + +extern int +glist4(int e1,int e2,int e3,int e4) +{ + int ret; + ret = gfree; + gfree+=4 ; + heap[ret]=e1; + heap[ret+1]=e2; + heap[ret+2]=e3; + heap[ret+3]=e4; + if(lfree<gfree) error(HPERR); return ret; } @@ -5035,7 +5065,7 @@ } extern void -free_glist3_a(int e1) +free_glist3_a(int e1) // free chain of glist3 { int next; while(e1) {
--- a/mc-parse.h Fri Jan 13 01:55:33 2006 +0900 +++ b/mc-parse.h Fri Jan 13 18:37:05 2006 +0900 @@ -106,6 +106,7 @@ extern void error(int n); extern int glist2(int e1,int e2); extern int glist3(int e1,int e2,int e3); +extern int glist4(int e1,int e2,int e3,int e4); extern int insert_ascend(int p,int e,int eq()); extern int length(int list);
--- a/mc.h Fri Jan 13 01:55:33 2006 +0900 +++ b/mc.h Fri Jan 13 18:37:05 2006 +0900 @@ -473,7 +473,8 @@ #define FNERR 33 #define UCERR 34 #define UFERR 35 -#define SIERR 36 +#define ENERR 36 +#define SIERR 37 /* error number end */
--- a/test/basic.c Fri Jan 13 01:55:33 2006 +0900 +++ b/test/basic.c Fri Jan 13 18:37:05 2006 +0900 @@ -119,7 +119,7 @@ int h( int a0,int a1,int a2,int a3,int a4,int a5,int a6,int a7,int a8) { -g( a0,a1,a2,a3,a4,a5,a6,a7,a8); +return g( a0,a1,a2,a3,a4,a5,a6,a7,a8); }
--- a/test/func_conv_err.c Fri Jan 13 01:55:33 2006 +0900 +++ b/test/func_conv_err.c Fri Jan 13 18:37:05 2006 +0900 @@ -16,21 +16,19 @@ h(); // ok h() is a function if (i) goto f(); // bad - else + else if(i-1) goto g(i); // ok g() is a code segement -} +} // need goto bad int -g(int i) -{ // g is already used as code bad +g(int i) { // g is already used as code bad k(); if (i) goto h(); // bad // should complain.... no return value } -code k() -{ // bad k is already used as function +code k() { // bad k is already used as function goto hoge(); // ok } @@ -38,5 +36,6 @@ main() { hoge(); // bad + return 0; }
--- a/test/scope.c Fri Jan 13 01:55:33 2006 +0900 +++ b/test/scope.c Fri Jan 13 18:37:05 2006 +0900 @@ -90,5 +90,5 @@ int main() { - main0(); + return main0(); }
--- a/test/tmp7.c Fri Jan 13 01:55:33 2006 +0900 +++ b/test/tmp7.c Fri Jan 13 18:37:05 2006 +0900 @@ -1,17 +1,16 @@ int printf(const char *format, ...); - - +#ifndef INLINE +#define INLINE +#endif int k=3; - struct aa { int a[100]; } aaa,bbb; struct bb { int b[2]; } aaa1,bbb1; +INLINE void tmp(void); -void tmp(void); - -struct aa +INLINE struct aa main0(int); -struct aa +INLINE struct aa main0(int k) { int i; @@ -22,14 +21,14 @@ return ccc; } -struct aa +INLINE struct aa main3(struct aa arg) { int j=++arg.a[55]; return main0(j); } -void +INLINE void main2(struct aa a1) { /* main2 a1.a[99] 0 */ @@ -40,7 +39,7 @@ printf("#0039:main2 a1.a[55] %d\n",a1.a[55]); } -struct bb +INLINE struct bb main5(struct aa a1,struct bb a2) { printf("#0045:main5 a1.a[99] %d\n",a1.a[99]); @@ -53,7 +52,7 @@ } -void +INLINE void main1(struct aa a1) { /* main1 a1.a[0] 0 */ @@ -126,7 +125,7 @@ return 0; } -void +INLINE void tmp() { }