Mercurial > hg > CbC > old > device
changeset 350:43099915f4c2
name table reconfigure continue...
author | kono |
---|---|
date | Fri, 02 Jul 2004 18:28:19 +0900 |
parents | b74b580c10f6 |
children | 000c509b663d |
files | mc-code-powerpc.c mc-codegen.c mc-macro.c mc-parse.c mc-parse.h |
diffstat | 5 files changed, 54 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/mc-code-powerpc.c Fri Jul 02 14:14:24 2004 +0900 +++ b/mc-code-powerpc.c Fri Jul 02 18:28:19 2004 +0900 @@ -3010,7 +3010,7 @@ NMTBL *n; int init; char *extrn; init=0; - for(n = global_list;n;n = n->next) { + for(n = global_list;n!=&null_nptr;n = n->next) { if ((n->sc == GVAR) && n->dsp != -1) { /* n->dsp = -1 means initialized global */ if (init==0) { @@ -3027,7 +3027,7 @@ printf(".lcomm _%s,%d\n",n->nm,size(n->ty)); } } - for(n = global_list;n;n = n->next) { + for(n = global_list;n!=&null_nptr;n = n->next) { if (is_code(n)||is_function(n)) { extrn = n->nm; if (n->sc==EXTRN1) { @@ -3059,7 +3059,7 @@ } } init=0; - for(n = global_list;n;n = n->next) { + for(n = global_list;n!=&null_nptr;n = n->next) { if (n->sc == GVAR) { if (init==0) { printf(".data\n"); @@ -3069,7 +3069,7 @@ } } init = 0; - for(n = global_list;n;n = n->next) { + for(n = global_list;n!=&null_nptr;n = n->next) { if (is_code(n)||is_function(n)) continue; if (n->sc==EXTRN1) { if(init==0) { @@ -3091,7 +3091,7 @@ int init; init=0; /* static local variables */ - for(n = local_static_list;n;n = n->next) { + for(n = local_static_list;n!=&null_nptr;n = n->next) { if (n->sc == GVAR) { if (init==0) { data_mode(0);
--- a/mc-codegen.c Fri Jul 02 14:14:24 2004 +0900 +++ b/mc-codegen.c Fri Jul 02 18:28:19 2004 +0900 @@ -2319,7 +2319,6 @@ n->ty = type; /* must be in global table/heap */ if(type>0&&(car(type)==FUNCTION || car(type)==CODE)) { if ((mode==GDECL)) { - n->next = global_list; global_list = n; fcheck(n); return n; /* function and code segment are defined using fdecl/code_decl */ @@ -2373,9 +2372,13 @@ n->sc = nsc; if (stmode==LDECL) { n = new_static_name(n->nm,'.'); - n->next = local_static_list; local_static_list = n; + if (!n->next) { + n->next = local_static_list; local_static_list = n; + } } else { - n->next = global_list; global_list = n; + if (!n->next) { + n->next = global_list; global_list = n; + } } gpc +=sz; return n;
--- a/mc-macro.c Fri Jul 02 14:14:24 2004 +0900 +++ b/mc-macro.c Fri Jul 02 18:28:19 2004 +0900 @@ -609,8 +609,7 @@ static int macro_eval(int macrop,char *body0,int history) { - int c/*,len*/; - int sch; char *schptr; + int c,len; int in_quote = 0; int in_wquote = 0; char *macro; @@ -642,17 +641,16 @@ // name concatenation. skip ## and re-eval macro line. mconcat = 1; body++; continue; } else if (alpha(c)) { -#if 0 body--; // ungetc - nptrm = get_name(body,&len); + nptrm = get_name(body,&len,NONDEF); + if (!nptrm) { + while((*cheap->ptr = *body++) && len--) + cheap = increment_cheap(cheap,expand); + body--; + continue; + } + body += len; c = *body; -#else - sch = ch; schptr = chptr; ch = c; chptr = body; - nptrm = get_name_from_chptr(); - body = chptr; c = ch; - body--; // ungetc - ch = sch; chptr = schptr; -#endif nptrm = name_space_search(nptrm,MACRO); macro = (char *)car(nptrm->dsp); switch(nptrm->sc) { @@ -706,7 +704,7 @@ p = (char *)car(lists); for(;(*cheap->ptr=*p++);cheap = increment_cheap(cheap,0)) { // in_quote + \n case ? should be \n. - if (p[-1]=='\n') cheap->ptr[-1]=' '; + if (p[-1]=='\n') cheap->ptr[0]=' '; } } cheap = increment_cheap(cheap,0);
--- a/mc-parse.c Fri Jul 02 14:14:24 2004 +0900 +++ b/mc-parse.c Fri Jul 02 18:28:19 2004 +0900 @@ -129,9 +129,10 @@ static int typeid(int s); static int typename(void); extern NMTBL * get_name_from_chptr(); -static NMTBL * hash_search(char *name,struct cheap *scheap,int len,unsigned int hash); +static NMTBL * hash_search(char *name,struct cheap *scheap,int len,unsigned int hash,int mode); static void enter_scope(); static void leave_scope(); +static void extrn_use(NMTBL *nptr); static struct cheap * new_cheap(); @@ -336,6 +337,7 @@ struct cheap *p; + global_list = &null_nptr; cheap=cheap0; for(p=cheap;p;p=p->next) p->ptr=p->first; @@ -517,7 +519,7 @@ NMTBL *nptr; - (nptr = name_space_search(get_name(s,0),d?0:MACRO))->sc = RESERVE; + (nptr = name_space_search(get_name(s,0,DEF),d?0:MACRO))->sc = RESERVE; if (d==0) { nptr->sc = MACRO; nptr->dsp = (int)""; nptr->ty=0; @@ -1016,7 +1018,7 @@ *cheap->ptr = 0; increment_cheap(cheap,&p); return name_space_search( - name_space_search(hash_search(p,&scheap,len,hash),LDECL),0); + name_space_search(hash_search(p,&scheap,len,hash,DEF),LDECL),0); } @@ -1331,7 +1333,8 @@ int t,arglist; if(!chk) gen_code_enter(n->nm); - local_static_list = 0; + extrn_use(n); + local_static_list = &null_nptr; fnptr=n; n->sc = CODE; n->ty = type; @@ -1414,7 +1417,8 @@ int sd = stypedecl; int arglist; if(!chk) gen_enter(n->nm); - local_static_list = 0; + extrn_use(nptr); + local_static_list = &null_nptr; fnptr=n; retlabel=fwdlabel(); retcont = 0; @@ -2492,7 +2496,12 @@ extrn_use(NMTBL *nptr) { /* EXTRN1 means that defined extern is used in this source */ - if(nptr->sc==EXTRN) nptr->sc=EXTRN1; + if(nptr->sc==EXTRN) { + nptr->sc=EXTRN1; + } + if (!nptr->next) { + nptr->next = global_list; global_list = nptr; + } } static int @@ -2927,7 +2936,7 @@ } static NMTBL * -hash_search(char *name,struct cheap *scheap,int len,unsigned int hash) +hash_search(char *name,struct cheap *scheap,int len,unsigned int hash,int mode) { NMTBL *hptr,**iptr,**eptr; @@ -2938,6 +2947,7 @@ if (eptr==iptr) error(GSERR); } if (!hptr) { + if (mode==NONDEF) return 0; hptr = get_nptr(); hptr->nm = name; /* name should be in the safe place (cheap) */ } @@ -2951,7 +2961,7 @@ } extern NMTBL * -get_name(char *name,int *len) +get_name(char *name,int *len,int mode) { /* no name copy */ int ch,i = 0; @@ -2966,7 +2976,7 @@ ch = *n++; } if (len) *len = i; - return hash_search(name,&scheap,i,hash0); + return hash_search(name,&scheap,i,hash0,mode); } extern NMTBL * @@ -2985,7 +2995,7 @@ } *cheap->ptr = 0; cheap = increment_cheap(cheap,&name); - return hash_search(name,&scheap,i,hash0); + return hash_search(name,&scheap,i,hash0,DEF); } static void @@ -3014,7 +3024,7 @@ *cheap->ptr = 0; cheap = increment_cheap(cheap,&name); i++; - nptr = name_space_search(hash_search(name,&scheap,i,hash),STRING); + nptr = name_space_search(hash_search(name,&scheap,i,hash,DEF),STRING); symval = i; } @@ -3209,6 +3219,10 @@ if (mode==STAT) { /* can be undeclared global variable */ if (nptr1->sc == EMPTY) return sym; + else { + nptr=nptr1; + return sym; + } } /* define case */ for(ns=nlist->dsp;ns;ns=cadr(ns)) { @@ -3399,7 +3413,7 @@ extern NMTBL * msearch0(char *name) { - return name_space_search(get_name(name,0),MACRO); + return name_space_search(get_name(name,0,DEF),MACRO); } extern NMTBL * @@ -3427,7 +3441,7 @@ lsearch(char *name,int sc) { return - name_space_search(name_space_search(get_name(name,0),LDECL),sc); + name_space_search(name_space_search(get_name(name,0,DEF),LDECL),sc); } static void @@ -3457,7 +3471,7 @@ { NMTBL *nptr0; - (nptr0 = name_space_search(get_name(s,0),0))->sc = EXTRN; + (nptr0 = name_space_search(get_name(s,0,DEF),0))->sc = EXTRN; nptr0->dsp = d; nptr0->ty=type; if (use) extrn_use(nptr0); }
--- a/mc-parse.h Fri Jul 02 14:14:24 2004 +0900 +++ b/mc-parse.h Fri Jul 02 18:28:19 2004 +0900 @@ -104,7 +104,11 @@ /* used in mc-macro.c */ extern struct cheap *cheap; -extern NMTBL *get_name(char *name,int *i); + +extern NMTBL *get_name(char *name,int *i,int mode); +#define DEF 1 +#define NONDEF 2 + extern NMTBL * get_name_from_chptr(); extern NMTBL *name_space_search(NMTBL *ns,int sc);