Mercurial > hg > CbC > old > device
changeset 23:e605560e6146
Fix breaking edx,ecx on function call
author | kono |
---|---|
date | Tue, 04 Feb 2003 12:17:26 +0900 |
parents | 3fa41d00f658 |
children | 1df0bf7eb5da |
files | Idea mc-nop-386.c mc-parse.c |
diffstat | 3 files changed, 90 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/Idea Mon Feb 03 23:43:12 2003 +0900 +++ b/Idea Tue Feb 04 12:17:26 2003 +0900 @@ -1234,3 +1234,34 @@ Fri Jan 31 20:30:36 JST 2003 なんか #ifdef / #if がないとだめだな。実装する? + +Tue Feb 4 01:04:12 JST 2003 + +## while ((*chptr++ = c = getc(filep->fcb)) != '\n') { +_1120: + movl $10,%eax + movl $8,%ecx + movl filep,%edx + addl %ecx,%edx + movl (%edx),%edx + pushl %edx + xchg %edx,%eax .... edx に$10が入る (なんでxchg?) + call getc + addl $4,%esp + movl %eax,-20(%ebp) c に代入 + movl $chptr,%ecx + pushl %ecx + popl %ebx + movl (%ebx),%ecx ecx にchptrの中身 + addl $1,(%ebx) + movb %al,(%ecx) + subl %edx,%eax eax-edx ($10) + je _1119 + +が壊れる理由なんだけど... + +edx,ecx が破壊されちゃうみたいね。 + +Tue Feb 4 12:17:07 JST 2003 + +ようやっと直したよ...
--- a/mc-nop-386.c Mon Feb 03 23:43:12 2003 +0900 +++ b/mc-nop-386.c Tue Feb 04 12:17:26 2003 +0900 @@ -225,6 +225,19 @@ return 1; } +static +int +free_register_count(void) +{ + int i,count; + count = 0; + for(i=0;i<MAX_REGISTER;i++) { + if (! regs[i]) count++; + } + return count; +} + + void gexpr_init(void) { @@ -257,8 +270,8 @@ break; } } - if (real_v == -1) - error(-1); + /* if (real_v == -1) + error(-1); */ return real_v; } @@ -801,7 +814,15 @@ { int e2,e3,e4,e5,nargs,t; NMTBL *n; - + int save,saved; + if (free_register_count()<1) { + for(save = 0;save==dreg||save==creg;save++); + printf("\tpushl %s\n",register_name(save,0)); + saved = 1; + } else { + save = get_register(); + saved = 0; + } e2 = cadr(e1); nargs = 0; for (e3 = caddr(e1); e3; e3 = cadr(e3)) { @@ -831,14 +852,26 @@ } if (car(e2) == FNAME) { n=(NMTBL *)cadr(e2); - use_register(creg,REG_EAX,0); + } else { + use_register(creg,REG_ECX,0); + g_expr(e2); + } + + use_register(creg,REG_EAX,0); + use_register(dreg,REG_EDX,0); /* will be destroyed */ + use_register(save,REG_ECX,0); /* will be destroyed */ + + if (car(e2) == FNAME) { printf("\tcall\t%s\n",n->nm); - } else { - g_expr(e2); - use_register(creg,REG_EAX,0); + } else { printf("\tcall\t*%s\n",register_name(creg,0)); } if (nargs) printf("\taddl $%d,%%esp\n",size_of_int*nargs); + if (saved) { + printf("\tpopl %s\n",register_name(save,0)); + } else { + free_register(save); + } } int @@ -1110,19 +1143,16 @@ case REGISTER: g_expr(e4); if (creg!=cadr(e2)) - printf("\t%s %s,%s\n",op,register_name(creg,byte),register_name(cadr(e2),0)); + printf("\tmovl %s,%s\n",register_name(creg,0),register_name(cadr(e2),0)); return; } - g_expr(e4); + g_expr(e2); emit_push(); - g_expr(e2); - e2 = emit_pop(0); + use_data_reg(creg,0); + g_expr(e4); if (byte) use_data_reg(creg,1); - printf("\t%s %s,(%s)\n",op,register_name(e2,byte),register_name(creg,0)); - free_register(creg); - creg = e2; - regs[creg]=1; - /* printf("\tmovl %s,%s\n",register_name(e2,0),register_name(creg,0)); */ + e2 = emit_pop(0); + printf("\t%s %s,(%s)\n",op,register_name(creg,byte),register_name(e2,0)); return; } @@ -1466,8 +1496,8 @@ printf("\tpushl %%ebp\n"); printf("\tmovl %%esp,%%ebp\n"); printf("\tpushl %%ebx\n"); - printf("\tpushl %%ecx\n"); - printf("\tpushl %%edx\n"); + printf("\tpushl %%ecx\n"); /* we don't need this now */ + printf("\tpushl %%edx\n"); /* we don't need this now */ if (REGISTERS6) { printf("\tpushl %%edi\n"); printf("\tpushl %%esi\n");
--- a/mc-parse.c Mon Feb 03 23:43:12 2003 +0900 +++ b/mc-parse.c Tue Feb 04 12:17:26 2003 +0900 @@ -2510,11 +2510,15 @@ glineno++; chptr=linebuf; i=0; - /* while ((*chptr++ = c = getc(filep->fcb)) != '\n') { } - we cannot handle unsaved register in library call +#if 1 + while ((*chptr++ = c = getc(filep->fcb)) != '\n') { +#else + while ((c=getc(filep->fcb)),(*chptr++=c)!='\n') { +#endif + /* we cannot handle unsaved register in library call so make it easy for the compiler + \ line continuation? */ - while ((c=getc(filep->fcb)),(*chptr++=c)!='\n') { if (++i > LBUFSIZE-2) error(LNERR); if (c==EOF) { error(EOFERR); @@ -2522,11 +2526,11 @@ } } *chptr = '\0'; - if (lsrc && !asmf) gen_comment(linebuf); + if (lsrc && !asmf && !macro_if_skip) gen_comment(linebuf); if (*(chptr = linebuf) == '#' && !in_comment) { macro_processing(); } - } while(macro_if_skip); + } while(macro_if_skip || linebuf[0] == '#'); } void @@ -2552,6 +2556,8 @@ } else if (macroeq("if")) { macro_if_current++; if (!macro_if_skip) { + for(c=0;chptr[c];c++); + chptr[c] = ';'; ch= *chptr; getsym(); i=cexpr(expr());