Mercurial > hg > CbC > old > device
changeset 3:ca8e268dd7d4
tmp2
author | kono |
---|---|
date | Thu, 13 Jan 2000 10:54:33 +0900 |
parents | b3f259ac34a1 |
children | 535bf528d68f |
files | mc-nop-386.c mc-parse.c mc.h |
diffstat | 3 files changed, 72 insertions(+), 49 deletions(-) [+] |
line wrap: on
line diff
--- a/mc-nop-386.c Thu Jan 13 06:27:07 2000 +0900 +++ b/mc-nop-386.c Thu Jan 13 10:54:33 2000 +0900 @@ -86,10 +86,11 @@ see enter/enter1/leave */ int arg_offset = 8; -int disp_offset = -20; -int func_disp_offset = -20; -int code_disp_offset = 0; -int int_size = 4; +int code_arg_offset = -4; /* depends on number of args */ +int disp_offset = -12; +int func_disp_offset = -12; +int code_disp_offset = -4; +int size_of_int = 4; int endian = 0; int MAX_REGISTER=6; /* intel386のレジスタを4つまで使う*/ int REAL_MAX_REGISTER=8; /* intel386のレジスタが8つということ*/ @@ -147,7 +148,8 @@ if (REGISTERS6) { arg_offset = 8; func_disp_offset = -20; - int_size = 4; + disp_offset = -20; + size_of_int = 4; endian = 0; MAX_REGISTER=6; MAX_DATA_REG=4; @@ -155,7 +157,8 @@ } else { arg_offset = 8; func_disp_offset = -12; - int_size = 4; + disp_offset = -12; + size_of_int = 4; endian = 0; MAX_REGISTER=4; MAX_DATA_REG=4; @@ -764,7 +767,7 @@ } int -arg_size(int e3) +arg_size(int e3,int *nargs0) { int i,nargs,offset_list,e,t; @@ -772,14 +775,15 @@ /* we should use prototypes's type */ for (i = nargs = 0; e3;e3 =cadr(e3)) { e = car(e3); t = caddr(e3); - if (i++ < MAX_REGISTER_VAR && scalar(t)) { - offset_list = list3(REG_ESI+i,offset_list,e); + if (i < MAX_REGISTER_VAR && scalar(t)) { + offset_list = list3(REG_ESI+i++,offset_list,e); } else { - nargs += (car(e3)==CHAR?int_size:size(t)); offset_list = - list3(-nargs+disp_offset+int_size,offset_list,e); + list3(-nargs,offset_list,e); + nargs += (car(e3)==CHAR?size_of_int:size(t)); } } + *nargs0 = -nargs; return offset_list; } @@ -788,17 +792,16 @@ { int i,args,e2,e3,e4,e5,nargs,nargs0,regs; NMTBL *n,*code0; - int new_disp; + int new_disp,scode,scode_arg_offset; char *xrn; /* We need three passes. Compute Stack size, Compute Arg, Copy it. */ /* count number of args */ args = caddr(e1); - reverse0(args); - nargs = arg_size(args); - new_disp = car(nargs); - if (new_disp < disp) { - printf("\tlea %d(%%ebp),%%esp\n",new_disp+disp_offset); + args = reverse0(args); + nargs = arg_size(args,&new_disp); /* compute in normal order */ + if (new_disp-size_of_int < disp) { /* have to extend stack */ + printf("\taddl $%d,%%esp\n",new_disp-size_of_int-disp); } /* compute jump address */ e2 = cadr(e1); @@ -812,8 +815,9 @@ emit_push(); } /* compute arguments in reverse order */ +printf("# jump code_arg_offset=%d code_disp_offset=%d\n",code_arg_offset,code_disp_offset); regs = 0; - nargs; + i=0; for (e3=nargs; e3;e3 =cadr(e3)) { n=(NMTBL *)(e5=(cadr(e4 = caddr(e3)))); switch(car(e4)) { @@ -828,17 +832,19 @@ case RLVAR: case CRLVAR: if (env==0) { - if (e5<0 && e5+disp_offset==nargs) { + if (e5<0 && e5==car(e3)) { /* The same positioned local variable. No need to copy */ reg_stack[reg_sp++] = -2; } } + g_expr(e4); + emit_push(); + break; case REGISTER: - if (rname[e5]==REG_ESI+regs) { - /* Same register variable. No need to copy */ + if (i<MAX_REGISTER_VAR && rname[e5]==REG_ESI+i++) { + /* The same register variable. No need to copy */ reg_stack[reg_sp++] = e5; } - break; default: g_expr(e4); emit_push(); @@ -849,23 +855,32 @@ /* change the frame pointer */ g_expr(env); printf("\tmovl %s,%%ebp\n",crn); - } + } else if (fnptr->sc==FUNCTION) { + printf("\tlea %d(%%ebp),%%ebp\n",disp_offset); + } + /* force lvar offset mode to CODE */ + scode = fnptr->sc; fnptr->sc = CODE; + scode_arg_offset = code_arg_offset; + code_arg_offset = new_disp; +printf("# jump2 code_arg_offset=%d code_disp_offset=%d\n",code_arg_offset,code_disp_offset); /* copy arguments to destination environment if necessary */ - reverse0(args); - for (e3=args; e3;e3 =cadr(e3)) { + nargs = reverse0(nargs); /* pop in normal order */ + i=0; + for (e3=nargs; e3;e3 =cadr(e3)) { if ((e4=car(e3))>0) { /* register case */ if (reg_stack[--reg_sp]>=REG_ESI) { /* the same registger */ } else { if(reg_stack[reg_sp]<0) { - printf("\tpopl %s\n",reg_name[rname[e4]]); + printf("\tpopl %s\n",reg_name[rname[REG_ESI+i]]); } else { printf("\tmovl %s,%s\n", reg_name[rname[reg_stack[reg_sp]]], - reg_name[rname[e4]]); + reg_name[rname[REG_ESI+i]]); free_register(reg_stack[reg_sp]); } + i++; } } else { /* local variable case */ @@ -874,25 +889,24 @@ reg_sp--; } else { xrn=emit_pop(0); - printf("\tmovl %s,%d(%%ebp)\n",xrn, e4); + printf("\tmovl %s,%d(%%ebp)\n",xrn, lvar(e4)); } } } if (car(e2) != FNAME) { xrn=emit_pop(0); } - if (fnptr->sc==FUNCTION) { - printf("\tlea %d(%%ebp),%%ebp\n",disp_offset+int_size); - } - if (new_disp>disp) { + if (new_disp-size_of_int>disp) { /* shrink stack if necessary */ - printf("\tlea %d(%%ebp),%%esp\n",new_disp); + printf("\tlea %d(%%ebp),%%esp\n",new_disp-size_of_int); } if (car(e2) == FNAME) { printf("\tjmp %s\n",code0->nm); } else { printf("\tjmp *%s\n",xrn); } + fnptr->sc = scode; + code_arg_offset = scode_arg_offset; } @@ -1277,7 +1291,6 @@ void code_enter(char *name) { - disp_offset = code_disp_offset; printf("\t.align 4\n"); if (stmode!=STATIC) printf(".globl %s\n",name); @@ -1286,11 +1299,13 @@ } void -code_enter1(int disp) +code_enter1(int disp,int args) { if(disp) { printf("\tsubl $%d,%%esp\n",-disp); } + code_arg_offset = -args; +printf("# args %d code_arg_offset=%d code_disp_offset=%d\n",args,code_arg_offset,code_disp_offset); } void @@ -1305,7 +1320,6 @@ void enter(char *name) { - disp_offset = func_disp_offset; printf("\t.align 2\n"); if (stmode!=STATIC) printf(".globl %s\n",name); @@ -1411,10 +1425,10 @@ gpc += 1; } else { printf("\t.long %d\n",cadr(e)); - gpc += int_size; + gpc += size_of_int; } } else if(t!=CHAR) { - gpc += int_size; + gpc += size_of_int; if(car(e)==ADDRESS&&car(cadr(e))==GVAR) { printf("\t.long %s\n",caddr(cadr(e))); } else if(car(e)==FNAME) { @@ -1514,7 +1528,10 @@ else return l+disp_offset; } else { - return l+arg_offset; + if (fnptr->sc==CODE) + return l+code_arg_offset; + else + return l+arg_offset; } }
--- a/mc-parse.c Thu Jan 13 06:27:07 2000 +0900 +++ b/mc-parse.c Thu Jan 13 10:54:33 2000 +0900 @@ -537,7 +537,7 @@ nptr->ty = INT; nptr->sc = LVAR; nptr->dsp = args ; - args += int_size; + args += size_of_int; } getsym(); if(sym==RPAR) break; @@ -609,7 +609,7 @@ { if(t==CHAR) return 1; if(t==VOID) return 0; - if(scalar(t)) return int_size; + if(scalar(t)) return size_of_int; if(car(t)==STRUCT||car(t)==UNION) { if(cadr(t)==-1) error(DCERR); return(cadr(t)); @@ -701,9 +701,9 @@ if (nptr->dsp==0) { nptr->dsp = args; if (endian) - n->dsp += int_size-1; + n->dsp += size_of_int-1; } - args += int_size; + args += size_of_int; } else { if (nptr->dsp==0) nptr->dsp = args; @@ -907,29 +907,34 @@ void code_decl(NMTBL *n) { + int odisp; + if (n->sc==EMPTY) n->sc = CODE; code_enter(n->nm); fnptr=n; - args= 0; + disp = -args; + args = 0; reg_var=0; mode=ADECL; stmode=REGISTER; while (sym!=LC) { /* argument declaration !ANSI */ decl(); getsym(); } - disp=0; + if (args) disp = -args; + else args = -disp; init_vars=0; /* local variable declaration */ stmode=0; mode=STAT; init_vars=0; + odisp=disp; while (typeid(getsym()) || sym==STATIC || sym==EXTRN || sym==TYPEDEF) { mode=LDECL; decl(); mode=STAT; } control=1; - code_enter1(disp); + code_enter1(disp-odisp,args); emit_init_vars(); while(sym!=RC) statement(); if(control) @@ -2016,7 +2021,7 @@ int expr15(int e1) { - int t,arglist; + int t,arglist,e; t=type; if(integral(t)|| (car(t)!=FUNCTION && car(t)!=CODE)) @@ -2024,7 +2029,8 @@ getsym(); arglist=0; while(sym!=RPAR) { - arglist=list3(rvalue(expr1()),arglist,type); + e=rvalue(expr1()); + arglist=list3(e,arglist,type); if(sym!=COMMA) break; getsym(); }
--- a/mc.h Thu Jan 13 06:27:07 2000 +0900 +++ b/mc.h Thu Jan 13 10:54:33 2000 +0900 @@ -177,7 +177,7 @@ EXTERN char linebuf[LBUFSIZE],namebuf[LBUFSIZE],*chptr,*chptrsave; EXTERN char *name,*cheapp,**av,/*obuf[320],*/*sptr,escape(void); -EXTERN int arg_offset,stat_no,int_size,disp_offset,endian,csvalue,csvalue1; +EXTERN int arg_offset,stat_no,size_of_int,disp_offset,endian,csvalue,csvalue1; EXTERN int code_arg_offset; EXTERN int retlabel,retpending,retcont;