Mercurial > hg > CbC > old > device
changeset 560:d6ff45d719a5 string-shared
string sharing
author | kono |
---|---|
date | Sat, 07 Jan 2006 18:11:53 +0900 |
parents | c55b51d51f8f |
children | de0b0380c461 |
files | Changes mc-code-arm.c mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-codegen.c mc-macro.c mc-parse.c mc-parse.h test/inline.c |
diffstat | 10 files changed, 130 insertions(+), 48 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Sat Jan 07 13:09:45 2006 +0900 +++ b/Changes Sat Jan 07 18:11:53 2006 +0900 @@ -7984,6 +7984,15 @@ 被害が少ないが.... string の共有はやらないの? hash table にまで、いれたのに。 +set_attr が出来たので楽勝でした。 まぁ、でも、そろそろ封印だな。 +あぁ、そうか。ST_COMMENT がgetcでinrement_cheapと干渉するのは、ST_COMMENT +の方がまずいよ。でも、直せないな。負けた、string のところだけ? +わかった。ST_COMMENT が別な「cheap pointer」を使えばいいのか。 + +UTF-8 使えるようにする? ascii を拡張すれば良いだけだよね。 + + +
--- a/mc-code-arm.c Sat Jan 07 13:09:45 2006 +0900 +++ b/mc-code-arm.c Sat Jan 07 18:11:53 2006 +0900 @@ -1883,11 +1883,16 @@ { char *s,*crn; int lb,disp,label; + NMTBL *n = (NMTBL *)cadr(e1); + if ((lb=attr_value(n,LABEL))) { + // already defined + return code_label_value(lb,creg) ; + } use_int(creg); crn = register_name(creg); - s=(char *)cadr(e1); + s=n->nm; lb = emit_string_label(); ascii(s); text_mode(2); @@ -1895,6 +1900,7 @@ disp = search_const(LABEL,lb,&label); printf("\tldr\t%s, .L%d+%d\n",crn,label,disp); inc_inst(1); + set_attr(n,LABEL,lb); } #define MAX_COPY_LEN 20
--- a/mc-code-ia32.c Sat Jan 07 13:09:45 2006 +0900 +++ b/mc-code-ia32.c Sat Jan 07 18:11:53 2006 +0900 @@ -1078,9 +1078,14 @@ { char *s; int lb; + NMTBL *n = (NMTBL *)cadr(e1); + if ((lb=attr_value(n,LABEL))) { + // already defined + return code_label_value(lb,creg) ; + } use_int(creg); - s=(char *)cadr(e1); + s=n->nm; lb = emit_string_label(); ascii(s); if (output_mode==TEXT_EMIT_MODE) { @@ -1089,6 +1094,7 @@ text_mode(0); } printf("\tlea _%d,%s\n",lb,register_name(creg,0)); + set_attr(n,LABEL,lb); } #define MAX_COPY_LEN 20
--- a/mc-code-mips.c Sat Jan 07 13:09:45 2006 +0900 +++ b/mc-code-mips.c Sat Jan 07 18:11:53 2006 +0900 @@ -1522,15 +1522,21 @@ { char *s,*crn; int lb; + NMTBL *n = (NMTBL *)cadr(e1); + if ((lb=attr_value(n,LABEL))) { + // already defined + return code_label_value(lb,creg) ; + } use_int(creg); crn = register_name(creg); - s=(char *)cadr(e1); + s=n->nm; lb = emit_string_label(); ascii(s); text_mode(2); printf("\tla %s,$L_%d\n",crn,lb); + set_attr(n,LABEL,lb); } #define MAX_COPY_LEN 20
--- a/mc-code-powerpc.c Sat Jan 07 13:09:45 2006 +0900 +++ b/mc-code-powerpc.c Sat Jan 07 18:11:53 2006 +0900 @@ -1524,11 +1524,16 @@ { int lb; char *crn; + NMTBL *n = (NMTBL *)cadr(e1); + if ((lb=attr_value(n,LABEL))) { + // already defined + return code_label_value(lb,creg) ; + } use_int(creg); crn = register_name(creg); lb = emit_string_label(); - ascii((char *)cadr(e1)); + ascii(n->nm); if (output_mode==TEXT_EMIT_MODE) { printf(".text\n"); } else { @@ -1536,6 +1541,7 @@ } printf("\taddis %s,r31,ha16(L_%d-L_%d)\n",crn,lb,code_base); printf("\tla %s,lo16(L_%d-L_%d)(%s)\n",crn,lb,code_base,crn); + set_attr(n,LABEL,lb); } #define MAX_COPY_LEN 20 @@ -5274,7 +5280,7 @@ e1=list3(FNAME,(int)(((NMTBL *)cadr(e1))->nm),0); } else if (car(e1)==STRING) { val = emit_string_label(); - ascii((char*)cadr(e1)); + ascii(((NMTBL*)cadr(e1))->nm); e1=list3(STRING,val,0); } else if (car(e1)==CONST) { } else error(-1);
--- a/mc-codegen.c Sat Jan 07 13:09:45 2006 +0900 +++ b/mc-codegen.c Sat Jan 07 18:11:53 2006 +0900 @@ -3126,7 +3126,7 @@ emit_address(((NMTBL *)caddr(e))->nm,0); return; case STRING: - emit_string((char *)cadr(e),n->ty); + emit_string(((NMTBL *)cadr(e))->nm,n->ty); return; } // fprintf(stderr,"## type= %d\n",t);
--- a/mc-macro.c Sat Jan 07 13:09:45 2006 +0900 +++ b/mc-macro.c Sat Jan 07 18:11:53 2006 +0900 @@ -252,6 +252,9 @@ */ static int next_eof; +struct cheap *st_cheap, *cheap1; +// ST_COMMENT may interfere with other inrement_cheap, so we use +// another cheap area. extern void getline(void) @@ -295,24 +298,30 @@ if (inmode) { int i=0; int c; - char *p = cheap->ptr; + char *p; + // should be done in some init + if (!st_cheap) { + st_cheap = cheap1 = new_cheap(); + } + + p = st_cheap->ptr; sprintf(num,"%d: ",lineno); parse = list3(ST_COMMENT,parse,(int)p); // should contain file name c = 0; - while((*cheap->ptr = num[c++])) - cheap = increment_cheap(cheap,&p); - while((c = *cheap->ptr = linebuf[i++])) { - cheap = increment_cheap(cheap,&p); + while((*st_cheap->ptr = num[c++])) + st_cheap = increment_cheap(st_cheap,&p); + while((c = *st_cheap->ptr = linebuf[i++])) { + st_cheap = increment_cheap(st_cheap,&p); if (c=='\n') { - *cheap->ptr = 0; - cheap = increment_cheap(cheap,&p); - p = cheap->ptr; + *st_cheap->ptr = 0; + st_cheap = increment_cheap(st_cheap,&p); + p = st_cheap->ptr; // parse = list3(ST_COMMENT,parse,(int)p); sprintf(num,"%d: ",lineno); c = 0; while((*cheap->ptr = num[c++])) - cheap = increment_cheap(cheap,&p); + st_cheap = increment_cheap(st_cheap,&p); } } }
--- a/mc-parse.c Sat Jan 07 13:09:45 2006 +0900 +++ b/mc-parse.c Sat Jan 07 18:11:53 2006 +0900 @@ -50,7 +50,6 @@ char *chptr; int ch; // pre-read character int chptrsave,chsave; // linebuffer stack (for macro) -static struct cheap * new_cheap(); // increment cheap int chk; int args; // function argument list @@ -412,8 +411,8 @@ (s==COLON) ? "':'": "Identifier"; fprintf(stderr,"%d:%s expected.\n",lineno,p); errmsg(); - } else - getsym(0); + } + getsym(0); } /* @@ -457,6 +456,7 @@ global_list = &null_nptr; cheap=cheap0; + st_cheap = cheap1; for(p=cheap;p;p=p->next) p->ptr=p->first; nptr_pool = nptr_pool0; @@ -2790,7 +2790,7 @@ checksym(LPAR); // asm string if (sym!=STRING) error(DCERR); - asm0=list3(STRING,(int)nptr->nm,nptr->dsp); + asm0=list3(STRING,(int)nptr,nptr->dsp); getsym(0); if (sym!=COLON) error(DCERR); do { @@ -2798,7 +2798,7 @@ getsym(0); if (sym==COLON) break; if (sym!=STRING) error(DCERR); - out=list2(list3(STRING,(int)nptr->nm,nptr->dsp),out); + out=list2(list3(STRING,(int)nptr,nptr->dsp),out); getsym(0); e1=list2(e=expr1(),e1); lcheck(e); @@ -2809,7 +2809,7 @@ getsym(0); if (sym==COLON) break; if (sym!=STRING) error(DCERR); - input=list2(list3(STRING,(int)nptr->nm,nptr->dsp),input); + input=list2(list3(STRING,(int)nptr,nptr->dsp),input); getsym(0); e1=list2(expr1(),e1); } while(sym==COMMA); @@ -2819,7 +2819,7 @@ // option string getsym(0); if (sym!=STRING) error(DCERR); - opt=list2(list3(STRING,(int)nptr->nm,nptr->dsp),opt); + opt=list2(list3(STRING,(int)nptr,nptr->dsp),opt); getsym(0); } while(sym==COMMA); } @@ -3465,7 +3465,7 @@ break; case STRING: conv-> string_(nptr->nm,nptr->dsp); - e1=list3(STRING,(int)nptr->nm,nptr->dsp); + e1=list3(STRING,(int)nptr,nptr->dsp); type=list3(ARRAY,CHAR,nptr->dsp); getsym(0); break; @@ -3527,13 +3527,13 @@ case C_FILE: nptr=get_name(filep->name0,0,0); type=list3(ARRAY,CHAR,nptr->dsp); - e1=list3(STRING,(int)nptr->nm,nptr->dsp); + e1=list3(STRING,(int)nptr,nptr->dsp); getsym(0); break; case C_FUNCTION: nptr=get_name(fnptr->nm,0,0); type=list3(ARRAY,CHAR,nptr->dsp); - e1=list3(STRING,(int)nptr->nm,nptr->dsp); + e1=list3(STRING,(int)nptr,nptr->dsp); getsym(0); break; case C_LINE: @@ -3856,10 +3856,31 @@ } /* - string heap management + string cheap management + +compiler keeps string data (name, string etc.) + + new_cheap() increment cheap memory + + increment_cheap(cheap, &pointer_top) + before this + pointer_top = cheap->ptr + is necessary. + + increment cheap->ptr, if cheap is increased, + pointer_top is updated. + + Note. Inline comments use cheap during getc(). If getch() + cross the new line, continuous cheap is not assured. + + save_cheap(struct cheap *scheap,struct cheap *cheap) + saved point for reseting cheap. + reset_cheap(struct cheap *scheap) + abandone cheap to save_cheap point. + */ -static struct cheap * +extern struct cheap * new_cheap() { struct cheap *p = (struct cheap *)malloc(sizeof(struct cheap)); @@ -4017,15 +4038,14 @@ { char *name = cheap->ptr; int i= 0; - int str=0; unsigned int hash = 0; struct cheap scheap; + save_cheap(&scheap,cheap); do { - save_cheap(&scheap,cheap); while (ch == '"') { in_quote = 1; - getch(); + getch(); while (ch != '"') { if (i>STRSIZE) error(STRERR); hash_value(hash, *cheap->ptr = escape()); @@ -4034,26 +4054,14 @@ } in_quote = 0; getch(); - // skipspc is not allowed, becase it interfered with ST_COMMENT - // skipspc(); // "aaa" "bbb" case } - in_quote = 0; - *cheap->ptr = 0; - cheap = increment_cheap(cheap,&name); - i++; - nptr = name_space_search(hash_search(name,&scheap,i,hash,DEF),STRING); - // if we can reclaim space if we already have this skipspc(); - if (ch=='"') { - str = list2((int)nptr->nm,str); - } } while (ch=='"'); - if (str) { - save_cheap(&scheap,cheap); - mappend(str,&name); - for(i=0;name[i];i++); - nptr = name_space_search(hash_search(name,&scheap,i,hash,DEF),STRING); - } + *cheap->ptr = 0; + cheap = increment_cheap(cheap,&name); + i++; + nptr = name_space_search(hash_search(name,&scheap,i,hash,DEF),STRING); + // if we already have this, hash_search will reset cheap nptr->dsp = i; symval = i; }
--- a/mc-parse.h Sat Jan 07 13:09:45 2006 +0900 +++ b/mc-parse.h Sat Jan 07 18:11:53 2006 +0900 @@ -137,6 +137,7 @@ /* used in mc-macro.c */ extern struct cheap *cheap; +extern struct cheap *st_cheap, *cheap1; // for ST_COMMENT extern NMTBL *get_name(char *name,int *i,int mode); #define DEF 1 @@ -160,6 +161,7 @@ extern struct cheap * increment_cheap(struct cheap *cheap,char **save); extern void save_cheap(struct cheap *scheap,struct cheap *cheap); extern struct cheap * reset_cheap(struct cheap *scheap); +extern struct cheap * new_cheap(); extern void pfdecl(NMTBL *nptr); #if CASE_CODE extern int docase_eq();
--- a/test/inline.c Sat Jan 07 13:09:45 2006 +0900 +++ b/test/inline.c Sat Jan 07 18:11:53 2006 +0900 @@ -259,10 +259,28 @@ return 0; } +inline +void +main5() +{ + printf("test1 " " test2\n"); + printf("test3 " + " test4\n"); +#if 0 + // error + printf("test5 + test6\n"); +#endif + printf("test7 \ + test8\n"); +} int main(int ac,char *av[]) { + void (*f)() = main5; + const int i = 3; + fnp = ins1; printf("#0265:%d\n",(1,2,3,4,5)); order(1,2,3,4,5); @@ -276,7 +294,19 @@ inmain(ac,av); main2(ac,av); main3(ac,av); + + printf("test1 " " test2\n"); + + + switch(i) { + case 1: printf("1\n"); break; + default: + case 2: printf("2\n"); break; + case 3: printf("3\n"); break; + } + + main5(); + f(); return 0; } -