Mercurial > hg > CbC > old > device
changeset 625:4b4c6b1ea69a
*** empty log message ***
author | kono |
---|---|
date | Sat, 07 Oct 2006 20:24:41 +0900 |
parents | 4d28634e46e4 |
children | 5bd74f52df62 |
files | Changes mc-inline.c mc-macro.c mc-parse.c |
diffstat | 4 files changed, 149 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Wed Sep 27 13:57:55 2006 +0900 +++ b/Changes Sat Oct 07 20:24:41 2006 +0900 @@ -8493,7 +8493,7 @@ Tue Jan 17 10:56:08 JST 2006 -一応、ia32 から ranme と dreg は落しましたが.... +一応、ia32 から rname と dreg は落しましたが.... get_register が必ず成功するようにする register_var をセーブするような手法が必要かも? @@ -8870,3 +8870,37 @@ これは、なんかあったな。ARM は、そういう仕組みになっていて 対処しているみたいだね。なんでだろう? +あ、そうか。Intel Mac の対応があるんだった... しくしく。 + +filep の overflow をチェックしてない。(こういうの多そう...) + +Sat Oct 7 13:41:13 JST 2006 + +inline のswitchの展開ぐらいいれた方がいいが... + +0x19d9c <__i686.get_pc_thunk.bx>: mov (%esp),%ebx +0x19d9f <__i686.get_pc_thunk.bx+3>: ret + +ですか。 + +string は、ebx でPC相対で取って来るわけね。(ださ〜) ということは、 +やっぱり、一つレジスタを潰さないとだめか。 + +しかも、EBX なわけ?! + +大域変数は、 + leal L_uc1$non_lazy_ptr-"L00000000006$pb"(%ebx), %eax + movl (%eax), %eax + movb $-56, (%eax) +だから、やっぱり、レジスタ一つ EBX とは別に潰すことになる。 + +ということは、デフォルトでレジスタが二つ潰れるわけね。 + +そして、浮動小数点の計算は、すべて mmx(sse2) らしい。ぶぅ。 +mmx は 8 個レジスタがあるわけね。 + + + + + +
--- a/mc-inline.c Wed Sep 27 13:57:55 2006 +0900 +++ b/mc-inline.c Sat Oct 07 20:24:41 2006 +0900 @@ -20,6 +20,29 @@ ** You don't have to ask before copying, redistribution or publishing. ** THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE. ***********************************************************************/ + +/* + + Inline handler + + inline code is stored as parse tree + expr already has parse tree + statement part is handled here + + st_hoge() code generator (called from gexpr()) + p_hoge() partial evaluator called in gen_inline() + after p_hoge(), it contains no ST_* node. + + PVAR has an offset for pvartable, it can be + constant, local variable or global variable + other complex expression is evaluated before the code expansion + + We always perform inline expansion. + Non static inline function can be referenced from other. Real + function body is generated by pfdecl() in mc-parse.c. + + */ + #include <stdio.h> #include "mc.h" #include "mc-parse.h" @@ -753,6 +776,7 @@ int p1=pexpr(cadr(e1)); int p2=pexpr(caddr(e1)); int p3=pexpr(cadddr(e1)); + // unfolding for constant case? return list3(ST_FOR,pexpr(cadr(e)), list4(p0,p1,p2,p3)); } @@ -761,6 +785,8 @@ { int e2 = pexpr(caddr(e)); int e3 = pexpr(cadddr(e)); + // if cadr(e) is a constant, we have to prune case statement. + // here? return list4(ST_SWITCH,pexpr(cadr(e)),e2,e3); } @@ -796,7 +822,7 @@ static int p_default(int e) { - // should be removed if constant case value + // should be removed if case value is a constant return list2(ST_DEFAULT,pexpr(cadr(e))); } @@ -1179,11 +1205,16 @@ return VOID; } +/* + Prepare pvariable table + */ + static int replace_inline_parameter(NMTBL *anptr,int t,int e4,int narg,int evals) { int arg; if (has_attr(anptr,KONST) && !has_attr(anptr,HAS_ADDRESS)) { + // replacable const variable if (is_memory(e4)) { heap[pdisp+narg]=reference(e4); return evals; @@ -1192,6 +1223,7 @@ return evals; } } + // we need real local variable for this inline arg = heap[pdisp+narg]=list3(LVAR,new_lvar(size(t)),0); inline_lvars = glist2(arg,inline_lvars); evals=list2(assign_expr0(arg,e4,anptr->ty,t),evals); @@ -1262,6 +1294,8 @@ n->next = local_static_list; local_static_list = local_statics; cadddr(e1) = 0; // prevent duplicate initialize } + + // free used local variables or registers while(inline_lvars) { int e; int l = car(inline_lvars);
--- a/mc-macro.c Wed Sep 27 13:57:55 2006 +0900 +++ b/mc-macro.c Sat Oct 07 20:24:41 2006 +0900 @@ -71,11 +71,15 @@ save_cheap(&scheap,cheap); + // call macro evaluation interpreter if (nptrm->sc == FMACRO) { macrop=macro_function(macrop,&chptr,nptrm,0); } else { macrop=macro_eval(macrop,(char *)car(nptrm->dsp),0); } + + // copy output from resulted listed string + cheap = reset_cheap(&scheap); macropp = cheap->ptr; // append result override, working cheap, but it's OK. @@ -86,14 +90,17 @@ t = cheap->ptr-2; cheap->ptr[0] =0; cheap = increment_cheap(cheap,¯opp); + + // if we have ## (concatenation), + // remove \s**##\s* + // it is difficult to remove former space on the fly, + // so multi path loop is required + while (mconcat) { // ## re-eval macro // if (lsrc) printf("## before %s",macropp); mconcat = 0; macrop = 0; - // remove \s**##\s* - // it is difficult to remove previous space on the fly, - // so multi path loop is required for(s=t=macropp;*s;) { if ((c=*s++)=='#'&&*s=='#') { if (t>s-3) t=s-2; else t--; @@ -105,7 +112,7 @@ } *t++=0; // evaluate generated result again -if (lsrc) { +if (0 && lsrc) { printf("### %s\n",macropp); if (t[-2]!='\n') putchar('\n'); } @@ -128,7 +135,7 @@ if (t[-2]!='\n') putchar('\n'); } // push previous chptr, and change it to the generate macro - chptrsave = glist2((int)chptr,chptrsave); + chptrsave = glist2((int)chptr,chptrsave); // push old one into the stack chsave = glist2(ch,chsave); chptr = macropp; ch = *chptr++; @@ -158,6 +165,34 @@ } /* + internal string compare routine + nameeq in mc-parse.c relies on + global name variable + */ + +static int +nameeq(char *p, char *q) +{ + if (!p) + return 0; + while(*p) + if(*p++ != *q++) return 0; + return (*q==0); +} + +/* + file name expansion + + Get file name from input stream. + Result is store in filep structure. + included file is put on the filep stack + return filep + + filename is copied into cheap + + possibly expanded by search path (including current + directory ). + get file name <name> => name current_file_name_dir / name @@ -169,15 +204,6 @@ next flag ignores the first occurence. */ -static int -nameeq(char *p, char *q) -{ - if (!p) - return 0; - while(*p) - if(*p++ != *q++) return 0; - return (*q==0); -} static FILE * getfname(int next) @@ -246,6 +272,7 @@ *cheap->ptr = 0; cheap = increment_cheap(cheap,&name); } + // should check filep over flow (sigh...) (filep+1)->inc = end; (filep+1)->name0 = name; return ( (filep+1)->fcb = fp ); @@ -311,7 +338,7 @@ { int i; int c; - char num[10]; + char num[10]; // for 32bit char *p; if (next_eof) { @@ -320,6 +347,7 @@ } do { if (chinput) { + // some another input source ( init string ) if (! *chinput) { chinput=0; continue; @@ -330,6 +358,7 @@ if (++i > LBUFSIZE-2) error(LNERR); } } else { + // get the line from input stream lineno++; glineno++; chptr=linebuf; @@ -353,11 +382,15 @@ } } } + *chptr = '\0'; if (lsrc && !asmf && !macro_if_skip && linebuf[0]) { - gen_comment(linebuf); + gen_comment(linebuf); // #if ed line will not be commented if (inmode) { // inline mode + + // generate inlined line in assembler output + int i=0; int c; // should be done in some init @@ -389,6 +422,7 @@ } p = chptr = linebuf; while(*p==' '||*p=='\t') p++; if (*p == '#' && !in_comment && !in_quote) { + // macro directive chptr = p; if (macro_processing()) return; } @@ -446,6 +480,13 @@ type=stype; } +/* + Macro directive + + implemented in simple hash + + */ + static int macro_processing() { @@ -626,7 +667,13 @@ ch = chsave; } -/* macro define from chptr */ +/* macro define from chptr + + body will be copied and stored in nptr->dsp + list2( string, list of argments (if any)) + We don't expand macro here, it just copied. + + */ static void macro_define0() @@ -693,6 +740,8 @@ // create function macro argument list // return list2((char*)arg,next) +// it can be sepearted by \ or comments +// no expansion static int macro_args(char **pchptr) @@ -788,7 +837,11 @@ return reverse0(args); } -/* output macro expansion result into macrobuf (macropp) */ +/* output macro expansion + + This is a recursive interpreter. + + result into macrobuf (macropp) */ static int macro_function(int macrop,char **pchptr,NMTBL *nptr,int history) @@ -828,6 +881,10 @@ return macrop; } +/* + define name in the local scope + */ + static void local_define(char *macro,char *value) { @@ -840,6 +897,9 @@ /* Evaluate macro string. + + This is a recursive interpreter. + reuslt: list2("replaced string",next) history is necessary to avoid recursion */
--- a/mc-parse.c Wed Sep 27 13:57:55 2006 +0900 +++ b/mc-parse.c Sat Oct 07 20:24:41 2006 +0900 @@ -2100,6 +2100,7 @@ e=list3(a->sc==IVAR?LVAR:a->sc,a->dsp,(int)a); cargs = list3(e,cargs,a->ty); } + // build inline function call e = list4(INLINE,list2(FNAME,(int)n),cargs, list3(car(fnptr->ty),cadr(fnptr->ty),caddr(fnptr->ty)));