Mercurial > hg > CbC > old > device
changeset 699:0bc5f2ff86cc
code segement argument offset in parse mode.
author | kono |
---|---|
date | Mon, 22 Oct 2007 01:09:46 +0900 |
parents | c6567d33cf21 |
children | 22e0330a6d5b |
files | mc-inline.c mc-parse.c |
diffstat | 2 files changed, 48 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/mc-inline.c Mon Oct 22 00:06:31 2007 +0900 +++ b/mc-inline.c Mon Oct 22 01:09:46 2007 +0900 @@ -1523,8 +1523,7 @@ if (!fargtype) { goto no_args; // wrong number of arguments } - if (is_code(n) && toplevel) { - } + for (e3 = e5 = reverse0(caddr(e)); e3; e3 = cadr(e3)) { anptr = (NMTBL*)caddr(fargtype); if (!anptr) break; // should not happen?
--- a/mc-parse.c Mon Oct 22 00:06:31 2007 +0900 +++ b/mc-parse.c Mon Oct 22 01:09:46 2007 +0900 @@ -2217,6 +2217,42 @@ } } +/* copy function argment for inline function */ +/* calcurate argument offset here */ + +static int +copy_arg(int arg) +{ + NMTBL *a,*n1; + int offset=0; + int nargs; + + for(nargs=0;arg;arg=cadr(arg)) { + int t; + int sz ; + + n1 = get_nptr(); + a = (NMTBL*)caddr(arg); + n1->ty = a->ty; + n1->nm = a->nm; + n1->sc = a->sc==IVAR?LVAR:a->sc; + n1->attr = a->attr; + + t = type_value(n1->ty); + sz = size(t); + + n1->dsp = offset; + offset+= (scalar(t))?size_of_int: + (t>0&&(car(t)==UNION||car(t)==STRUCT))? + ((sz+(size_of_int-1))&~(size_of_int-1)): + sz; + + nargs=list4(car(arg),nargs,(int)n1,cadddr(arg)); + } + args = offset; + return nargs; +} + /* generate function from parse tree */ /* some inline functions are external or indirectly called */ /* even if it is a static. Generate these in closing(); */ @@ -2227,8 +2263,7 @@ { int e; int args,nargs,cargs; - int offset=0; - NMTBL *a,*n1; + NMTBL *a; if (has_attr(n,GENERATED)) return; set_attr(n,GENERATED,0); @@ -2255,28 +2290,8 @@ fnptr->next=0; // make copied called function argment - for(args=n->dsp,nargs=0;args;args=cadr(args)) { - int t; - int sz ; - - n1 = get_nptr(); - a = (NMTBL*)caddr(args); - n1->ty = a->ty; - n1->nm = a->nm; - n1->sc = a->sc==IVAR?LVAR:a->sc; - n1->attr = a->attr; - - t = type_value(n1->ty); - sz = size(t); - - n1->dsp = offset; - offset+= (scalar(t))?size_of_int: - (t>0&&(car(t)==UNION||car(t)==STRUCT))? - ((sz+(size_of_int-1))&~(size_of_int-1)): - sz; - - nargs=list4(car(args),nargs,(int)n1,cadddr(args)); - } + nargs = copy_arg(n->dsp); + // fdecl_struct(fnptr->ty); already done by fdecl before fnptr->dsp=reverse0(nargs); @@ -2317,8 +2332,7 @@ pcode_decl(NMTBL *n) { int e; - int args,nargs,cargs,t; - int offset=0; + int arg,nargs,cargs,t; NMTBL *a,*n1; if (has_attr(n,GENERATED)) return; @@ -2346,25 +2360,14 @@ fnptr->next=0; // make copied called function argment - for(args=n->dsp,nargs=0;args;args=cadr(args)) { - n1 = get_nptr(); - a = (NMTBL*)caddr(args); - n1->ty = a->ty; - n1->nm = a->nm; - n1->sc = a->sc==IVAR?LVAR:a->sc; - n1->attr = a->attr; - - n1->dsp = offset; - offset+= (scalar(n1->ty))?size_of_int:size(n1->ty); - - nargs=list4(car(args),nargs,(int)n1,cadddr(args)); - } + nargs = copy_arg(n->dsp); + // fdecl_struct(fnptr->ty); already done by fdecl before fnptr->dsp=reverse0(nargs); /* reverse all argument offset (with size) */ - args = fnptr->dsp; - for(t=args;t;t=cadr(t)) { + arg = fnptr->dsp; + for(t=arg;t;t=cadr(t)) { n1=(NMTBL *)caddr(t); if(n1->sc==LVAR) n1->dsp = -n1->dsp-cadddr(t); @@ -2373,12 +2376,12 @@ retcont = 0; tmp_struct = 0; - disp=0; + disp = -args; arg_register(fnptr); // should fix n1->dsp // make calling argments - for(args=fnptr->dsp,cargs=0;args;args=cadr(args)) { - a = (NMTBL*)caddr(args); + for(arg=fnptr->dsp,cargs=0;arg;arg=cadr(arg)) { + a = (NMTBL*)caddr(arg); // make call function argment for gen_inline e=list3(a->sc==IVAR?LVAR:a->sc,a->dsp,(int)a); cargs = list3(e,cargs,a->ty);