Mercurial > hg > CbC > old > device
changeset 182:e1e9ec8c96a7
some fix
author | kono |
---|---|
date | Sun, 30 Nov 2003 21:15:24 +0900 |
parents | 4beb7f079055 |
children | 1d80ad165831 |
files | mc-code-ia32.c mc-code-powerpc.c mc-parse.c mc.h |
diffstat | 4 files changed, 88 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/mc-code-ia32.c Sun Nov 30 18:38:43 2003 +0900 +++ b/mc-code-ia32.c Sun Nov 30 21:15:24 2003 +0900 @@ -8,6 +8,7 @@ char *l_include_path[] = { "/usr/include/", + "/usr/include/linux/", 0 }; @@ -157,6 +158,11 @@ code_init(void) { macro_define("__i386__ 1\n"); + macro_define("__LITTLE_ENDIAN__ 1\n"); + macro_define("__STDC__ 1\n"); + macro_define("size_t int\n"); + macro_define("__externsion__\n"); + macro_define("__flexarr\n"); arg_offset = 8; func_disp_offset = -12; @@ -1403,6 +1409,7 @@ void enter1() { + text_mode(); func_disp_label=fwdlabel(); printf("\tlea _%d(%%ebp),%%esp\n",func_disp_label); /* if(disp) printf("\tsubl $%d,%%esp\n",-disp); */
--- a/mc-code-powerpc.c Sun Nov 30 18:38:43 2003 +0900 +++ b/mc-code-powerpc.c Sun Nov 30 21:15:24 2003 +0900 @@ -302,7 +302,7 @@ { macro_define("__ppc__ 1\n"); macro_define("__BIG_ENDIAN__ 1\n"); - macro_define("_BSD_CT_RUNE_T_ int\n"); +// macro_define("_BSD_CT_RUNE_T_ int\n"); init_ptr_cache(); } @@ -1878,6 +1878,7 @@ void enter1() { + text_mode(); set_creg(CREG_REGISTER,0); set_freg(FREG_FREGISTER,0); }
--- a/mc-parse.c Sun Nov 30 18:38:43 2003 +0900 +++ b/mc-parse.c Sun Nov 30 21:15:24 2003 +0900 @@ -84,6 +84,7 @@ static void local_undef(); static void macro_define0(); static void macro_processing(); +static void check_macro_eof(); static void newfile(void); static void replace_return_struct(int func,int left); static void reserve(char *s, int d); @@ -267,6 +268,7 @@ reserve("struct",STRUCT); reserve("union",UNION); reserve("unsigned",UNSIGNED); + reserve("signed",SIGNED); reserve("static",STATIC); reserve("goto",GOTO); reserve("return",RETURN); @@ -522,18 +524,38 @@ case UNION: t=sdecl(sym); break; + case SIGNED: + t = INT; + if(getsym(0)==INT) getsym(0); + else if (sym==CHAR) { getsym(0); t = CHAR; } + else if (sym==SHORT) { + t = SHORT; + if(getsym(0)==INT) getsym(0); + } else if (sym==LONG) { + getsym(0); + t = INT; + if(sym==LONG) { + getsym(0); + t=LONGLONG; + } else if(sym==INT) { + getsym(0); + t=INT; + } + } + break; case UNSIGNED: t = UNSIGNED; if(getsym(0)==INT) getsym(0); else if (sym==CHAR) { getsym(0); t = UCHAR; } - else if (sym==SHORT) { getsym(0); t = USHORT; } - else if (sym==LONG) { + else if (sym==SHORT) { + t = USHORT; + if(getsym(0)==INT) getsym(0); + } else if (sym==LONG) { getsym(0); t = UNSIGNED; if(sym==LONG) { getsym(0); t=ULONGLONG; - // t=UNSIGNED; } else if(sym==INT) { getsym(0); t=UNSIGNED; @@ -944,7 +966,7 @@ return n; case GTDECL: nsc = TYPE; - if (gnptr!=n) error(-1); + // if (gnptr!=n) error(-1); gtypedefed=glist2((int)gnptr,gtypedefed); break; case LTDECL: @@ -1188,7 +1210,7 @@ if (getsym(0) == LC) { if (sdecl_f) conv->lc_(); if(nptr0->sc == EMPTY) nptr0=gnptr0; - if (nptr0->sc != EMPTY) error(DCERR); + if (nptr0->sc!=TAG && nptr0->sc != EMPTY) error(DCERR); nptr0->sc = TAG; nptr0->ty = list4(s,-1,0,(int)nptr0); sdecl_field(); @@ -2467,7 +2489,7 @@ static int expr14(void) { - int e1=0,t; + int e1=0,t,t1; switch(sym) { case IDENT: @@ -2507,15 +2529,16 @@ break; case EMPTY: if(getsym(0)==LPAR) { - nptr->sc = EXTRN1; type= glist3(FUNCTION,INT,0); nptr->ty= type; e1=expr15(list2(FNAME,(int)nptr)); break; + } else if (in_macro_if) { + type = INT; + e1= list2(CONST,0); + break; } else { - if (!in_macro_if) { - nptr->sc = EXTRN1; - } + nptr->sc = EXTRN1; nptr->ty= glist3(FUNCTION,INT,0); e1=list2(FNAME,(int)nptr); type=list3(nptr->sc,nptr->ty,nptr->dsp); @@ -2552,15 +2575,16 @@ getsym(0); break; case DEFINED: + t = mode; mode = IFDEF; getsym(0); - t = mode; mode = IFDEF; - checksym(LPAR); + if (sym==LPAR) { t1 = 1; getsym(0); } else t1 = 0; conv-> defined_(name); mode = t; type= INT; e1=list2(CONST,symval); getsym(0); - checksym(RPAR); + if (t1) + checksym(RPAR); break; case ENVIRONMENT: conv-> environment_(); @@ -3212,7 +3236,7 @@ return (symval=0); } } - if (nptrm->sc!=EMPTY&&(nptrm->sc!=FMACRO||ch=='(')) { + if (nptrm->sc!=EMPTY&&(nptrm->sc!=FMACRO||skipspc()=='(')) { i = mode; mode = STAT; macrop = 0; @@ -3286,7 +3310,7 @@ else break; } return sym=CONST; - } else if (ch!='.') { + } else if (ch!='.'&&ch!='L') { while (digit(ch)) { symval=symval*8+ch-'0';getch(); } @@ -3299,11 +3323,18 @@ *cheapp++ = ch; symval=symval*10+ch-'0';getch(); } - if (!(ch=='.'||ch=='e')) { + if (!(ch=='.'||ch=='e'||ch=='L')) { cheapp=scheapp; return sym=CONST; } } + if (!d && ch=='L') { + getch(); + if (ch=='L') { + getch(); /*LONGLONG*/ + } + return sym=CONST; + } while(digit(ch)|| ch=='.'||ch=='e') { *cheapp++ = ch; getch(); @@ -3401,6 +3432,8 @@ return getsym(0); case 0: case '\n': + case '\f': + case '\\': return getsym(0); default: error(CHERR); @@ -3569,12 +3602,10 @@ symval++; } -static int topspc = 0; - static int skipspc(void) { - /* static int topspc = 0; */ + static int topspc = 0; while(ch=='\t'||ch=='\n'||ch==' '||ch=='\r') { if (ch=='\n'||ch=='\r') topspc=1; @@ -3599,6 +3630,7 @@ return ch; } getline(); + if (in_macro_if) check_macro_eof(); return getch(); } @@ -3724,15 +3756,31 @@ } static void +check_macro_eof() +{ + int c; + for(c=0;c<LBUFSIZE-3&&chptr[c];c++); + if (c>0&&chptr[c-1]=='\\') { + return; + } else if (c>0&&chptr[c-1]=='\n') { + if (c>0&&chptr[c-2]=='\\') { + return; + } else { + c--; + } + } + chptr[c] = ';'; + chptr[c+1] = '\n'; + chptr[c+2] = 0; +} + +static void macro_if() { - int c,i; - for(c=0;chptr[c];c++); - chptr[c] = ';'; /* this can't happen in macro expression */ - chptr[c+1] = '\n'; - chptr[c+2] = 0; + int i; ch= *chptr; in_macro_if = 1; + check_macro_eof(); getsym(0); /* i=cexpr(expr(1)); #if allow undefined symbols.. */ i=expr(1);
--- a/mc.h Sun Nov 30 18:38:43 2003 +0900 +++ b/mc.h Sun Nov 30 21:15:24 2003 +0900 @@ -63,13 +63,14 @@ #define KONST (-47) #define FMACRO (-48) #define LMACRO (-49) -#define DOTS (-50) +#define SIGNED (-50) +#define DOTS (-51) -#define FLOAT (-51) -#define DOUBLE (-52) -#define LONGLONG (-53) -#define ULONGLONG (-54) -#define VOLATILE (-55) +#define FLOAT (-52) +#define DOUBLE (-53) +#define LONGLONG (-54) +#define ULONGLONG (-55) +#define VOLATILE (-56) /* reserved word end */