Mercurial > hg > CbC > old > device
changeset 76:fb3fb9e9a462
*** empty log message ***
author | kono |
---|---|
date | Mon, 24 Feb 2003 21:36:16 +0900 |
parents | 92dcf107a837 |
children | 2b8ba655e572 |
files | .gdbinit Changes conv/c.c mc-parse.c |
diffstat | 4 files changed, 64 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/.gdbinit Mon Feb 24 19:50:20 2003 +0900 +++ b/.gdbinit Mon Feb 24 21:36:16 2003 +0900 @@ -13,5 +13,5 @@ x/1i $eip end b errmsg -r -s -ob00.s -Cc mc-parse.c +r -Cc test/tmp2.c
--- a/Changes Mon Feb 24 19:50:20 2003 +0900 +++ b/Changes Mon Feb 24 21:36:16 2003 +0900 @@ -1764,3 +1764,7 @@ たぶん、buffer に出力するってのをいれればおそらくは 変換できるだろう。 +式の途中での呼び出しとかを考えると、やっぱり +構文式から生成しないとだめだろうね。 +(ってことは、まだ、かなりの作業があるってこと.... むぅ...) +tmp2.c は、通らないし...
--- a/conv/c.c Mon Feb 24 19:50:20 2003 +0900 +++ b/conv/c.c Mon Feb 24 21:36:16 2003 +0900 @@ -7,6 +7,7 @@ extern void type_print(int type,NMTBL *nptr,FILE *out); extern void type_print1(int type,NMTBL *nptr,FILE *out,int cont); extern void sym_print(int type,FILE *out); +extern NMTBL str_ret; static FILE *vout,*svout; static FILE *null; @@ -28,7 +29,7 @@ break; } } -#if 1 +#if 0 vout = fopen(p,"w"); #else vout = stderr;p=p; @@ -76,7 +77,7 @@ } void -code_(NMTBL *n,int arglist){ +code_(NMTBL *n,int args){ fprintf(vout,"code %s(",n->nm); while(args) { n=(NMTBL *)car(args); @@ -84,12 +85,12 @@ args=cadr(args); if(args) fprintf(vout,","); } - fprintf(vout,")"); + fprintf(vout,")\n{"); } void code_end_(){ - + fprintf(vout,"}"); } void @@ -200,7 +201,10 @@ n=(NMTBL *)car(args); type_print(n->ty,n,vout); args=cadr(args); - if(args) fprintf(vout,","); + if(args) { + if(car(args)==(int)&str_ret) break; + fprintf(vout,","); + } } fprintf(vout,")"); } @@ -212,7 +216,7 @@ void goto_(){ - fprintf(vout,"goto"); + fprintf(vout,"goto "); } void @@ -410,7 +414,6 @@ void decl_data_() { - fprintf(vout," = "); } void
--- a/mc-parse.c Mon Feb 24 19:50:20 2003 +0900 +++ b/mc-parse.c Mon Feb 24 21:36:16 2003 +0900 @@ -93,12 +93,13 @@ static int struct_return = 0; static int arglist = 0; +static int sdecl_f = 1; +static int stypedecl; /* Converter *conv = &null_converter; */ Converter *conv = &c_converter; static char *ccout = 0; -static int stypedecl; int main(int argc, char **argv) @@ -356,7 +357,7 @@ decl(void) { NMTBL *n; - int t; int sd; + int t,sd; if (mode==GDECL) typedefed=0; if(sym==STATIC) { @@ -398,7 +399,7 @@ conv->return_type_(t,0,stypedecl); conv->sm_(); return; } - type=t; sd=stypedecl; + type=t;sd=stypedecl; n=decl0(); reverse(t); if (n == &null_nptr) { @@ -406,7 +407,7 @@ return; } if(sym==LC || ( sym!=SM && sym!=COMMA && sym!=ASS )) { - stypedecl=sd; + stypedecl=sd; if (car(type)==CODE) { code_decl(n); return; } else if (car(type)==FUNCTION) { @@ -578,11 +579,13 @@ { NMTBL *arg,*sfnptr; int sreg_var,t; - int stype,smode; + int stype,smode,sd; stype=type; sfnptr=fnptr; fnptr=n; + sd = sdecl_f; + sdecl_f = 0; sreg_var=reg_var; reg_var=0; smode = mode; @@ -592,6 +595,7 @@ arglist = 0; for(;;) { if(sym==IDENT && nptr->sc!=TYPE) { + type=INT; /* naked argument, old K&R C */ def(nptr); getsym(); if(sym==RPAR) break; @@ -627,6 +631,7 @@ reg_var=sreg_var; fnptr=sfnptr; type=stype; + sdecl_f = sd; return; } @@ -665,6 +670,7 @@ { if(t==CHAR) return 1; if(t==VOID) return 0; + if(t==REGISTER) return size_of_int; /* could be float? */ if(scalar(t)) return size_of_int; if(car(t)==STRUCT||car(t)==UNION) { if(cadr(t)==-1) error(DCERR); @@ -727,6 +733,7 @@ *cheapp++ = 0; } if(sym==ASS) { + conv->op_(sym); decl_data(type,n,0); emit_data_closing(n); /* gpc is incremented by emit_data */ @@ -802,6 +809,7 @@ n->sc = nsc; n->dsp = ndsp; if(sym==ASS) { + conv->op_(sym); decl_data(type,n,0); } return n; @@ -924,19 +932,22 @@ } else error(DCERR); } else if (t1==STRUCT) { - conv->decl_data_begin_(); - mode = mode_save; - if(cadr(t)==-1) error(DCERR); - t1 = caddr(t); /* list of fields */ - while(t1) { - offset = decl_data(car(t1),n,offset); /* alignment? */ - t1 = cadr(t1); - if ( t1 && sym==COMMA) { conv->comma_(); continue; } - if (!t1 && sym!=RC) error(DCERR); - } - conv->decl_data_end_(); - getsym(); - return offset; + if (sym==LC) { + conv->lc_(); conv->decl_data_begin_(); + mode = mode_save; + if(cadr(t)==-1) error(DCERR); + t1 = caddr(t); /* list of fields */ + while(t1) { + offset = decl_data(car(t1),n,offset); /* alignment? */ + t1 = cadr(t1); + if ( t1 && sym==COMMA) { conv->comma_(); continue; } + if (!t1 && sym!=RC) error(DCERR); + } + conv->decl_data_end_(); conv->rc_(); + getsym(); + return offset; + } else + error(DCERR); } else { mode = mode_save; error(TYERR); /* should be initialization error */ @@ -958,13 +969,13 @@ mode=(s==STRUCT?LSDECL:LUDECL); sdisp=disp; disp=0; - conv->sdecl_(s); + if (sdecl_f) conv->sdecl_(s); if (getsym() == IDENT) { nptr0 = nptr; gnptr0 = gnptr; - conv->id_(sym,nptr); + if (sdecl_f) conv->id_(sym,nptr); if (getsym() == LC) { - conv->lc_(); + if (sdecl_f) conv->lc_(); if (nptr0->sc != EMPTY) error(DCERR); nptr0->sc = TAG; tags = 0; @@ -973,7 +984,7 @@ decl(); tags = list3(type,tags,(int)nptr); } - conv->rc_(); + if (sdecl_f) conv->rc_(); getsym(); tags=reverse0(tags); heap[nptr0->ty+2]=tags; @@ -985,16 +996,17 @@ if(nptr0->sc != TAG) error(TYERR); tags = caddr(nptr0->ty); disp = cadr(nptr0->ty); + conv->comment_(' '); } type0 = list4(s,disp,tags,(int)nptr0); } else if(sym==LC) { - conv->lc_(); + if (sdecl_f) conv->lc_(); tags = 0; while(getsym() != RC) { decl(); tags = list3(type,tags,(int)nptr); } - conv->rc_(); + if (sdecl_f) conv->rc_(); getsym(); tags=reverse0(tags); type0 = list4(s,disp,tags,0); @@ -1015,15 +1027,17 @@ if(!chk) code_enter(n->nm); fnptr=n; disp = -args; - reg_var=0; mode=ADECL; - args = 0; - stmode=REGISTER; - while (sym!=LC) { /* argument declaration !ANSI */ - decl(); getsym(); + if (sym!=LC) { + stmode=REGISTER; + reg_var=0; + args=0; arglist = 0; fnptr->dsp=0; + while (sym!=LC) { /* argument declaration !ANSI */ + decl(); getsym(); + } + fnptr->dsp=reverse0(fnptr->dsp); + disp = -args; } - if (args) disp = -args; - else args = -disp; /* reverse all argument offset (with size) */ for(t=arglist;t;t=cadr(t)) { n=(NMTBL *)car(t); @@ -1104,7 +1118,8 @@ arglist=0; } -static NMTBL str_ret; +extern NMTBL str_ret; +NMTBL str_ret; /* If function has structure return value, it has extra @@ -1572,6 +1587,7 @@ jmp(nptr0->dsp); } control=0; + conv->sm_(); checksym(SM); conv->goto_label_(nptr0); return; @@ -1592,6 +1608,7 @@ } gexpr(list3(CODE,e1,env)); control=0; + conv->sm_(); checksym(SM); return; }