Mercurial > hg > CbC > old > device
changeset 173:3b33c7daae95
*** empty log message ***
author | kono |
---|---|
date | Wed, 26 Nov 2003 18:55:37 +0900 |
parents | 096559f07a70 |
children | 8b0ffe9b933d |
files | Changes mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-code.h mc-parse.c mc.h |
diffstat | 7 files changed, 166 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Tue Nov 25 11:47:41 2003 +0900 +++ b/Changes Wed Nov 26 18:55:37 2003 +0900 @@ -3526,3 +3526,45 @@ rename されちゃえばあんまり関係ないのかも知れないけど。 二つのレジスタを交互に使うとかだと、まぁ、誤差ですね。 + +Wed Nov 26 13:27:00 JST 2003 + +include path は内蔵のものと、外部のものと二ついるわけね。 + +predefined が結構無いといけないみたい。 + +にゃ〜 inline は必須なの? macro で実装するのは難しいんじゃないかなぁ。 +inline には、結構、いろんな変な部分があるんだよな。一旦はコンパイル +しないといけないはずだし。 + inline int f(int a,int b) { + int c; + c = a+b; + return c; + } +だよね。 + f(3,4) +があった時には、 + int _c,int _a,int _b; をlocal変数に付け加える + _a = 3; + _b = 4; + _c = _a+_b; +をコンパイル。 + current register = _c +とする。かなぁ。 + +むしろ、 + c = { decl; statements* return value; } +を実装して、#define を拡張する +方が簡単じゃない? そのためには nest したdecl を扱わないと +だめだけど... + +いや、やっぱり、中間木をなんとかするのかなぁ。 + +とりあえず、無視。 + +やっぱり、long long はいるのね〜 + +やっぱり、enum もいるよね〜 + +なんか、知らないけど、やっぱり全部実装しないとだめなのね。 +
--- a/mc-code-ia32.c Tue Nov 25 11:47:41 2003 +0900 +++ b/mc-code-ia32.c Wed Nov 26 18:55:37 2003 +0900 @@ -6,6 +6,12 @@ #include "mc-codegen.h" #include "mc-code.h" +char *l_include_path[] = { + "/usr/include/", + 0 +}; + + #define SAVE_STACKS 1 #define TEXT_EMIT_MODE 0 @@ -150,6 +156,8 @@ void code_init(void) { + macro_define("__i386__ 1\n"); + arg_offset = 8; func_disp_offset = -12; disp_offset = -12;
--- a/mc-code-mips.c Tue Nov 25 11:47:41 2003 +0900 +++ b/mc-code-mips.c Wed Nov 26 18:55:37 2003 +0900 @@ -6,6 +6,11 @@ #include "mc-code.h" #include "mc-codegen.h" +char *l_include_path[] = { + "/usr/include/", + 0 +}; + #define TEXT_EMIT_MODE 0 #define DATA_EMIT_MODE 1 #define RODATA_EMIT_MODE 2
--- a/mc-code-powerpc.c Tue Nov 25 11:47:41 2003 +0900 +++ b/mc-code-powerpc.c Wed Nov 26 18:55:37 2003 +0900 @@ -6,6 +6,11 @@ #include "mc-code.h" #include "mc-codegen.h" +char *l_include_path[] = { + "/usr/include/", + 0 +}; + #define TEXT_EMIT_MODE 0 #define DATA_EMIT_MODE 1 #define RODATA_EMIT_MODE 2 @@ -295,6 +300,8 @@ void code_init(void) { + macro_define("__ppc__ 1\n"); + init_ptr_cache(); }
--- a/mc-code.h Tue Nov 25 11:47:41 2003 +0900 +++ b/mc-code.h Wed Nov 26 18:55:37 2003 +0900 @@ -2,10 +2,13 @@ mc-code-*.c have to provied these */ + #define MAX_MAX 50 #define INPUT_REG 2 /* input register ( can be reused ) */ #define USING_REG 1 /* unreusable register usage */ +extern char *l_include_path[]; + extern int size_of_int; extern int size_of_short; extern int size_of_float;
--- a/mc-parse.c Tue Nov 25 11:47:41 2003 +0900 +++ b/mc-parse.c Wed Nov 26 18:55:37 2003 +0900 @@ -80,7 +80,6 @@ static void lcheck(int e); static void local_define(); static void local_undef(); -static void macro_define(); static void macro_define0(); static void macro_processing(); static void newfile(void); @@ -102,6 +101,11 @@ static char *ccout = 0; +#define MAX_INCLUDE_PATH_COUNT 10 +static char *include_path[MAX_INCLUDE_PATH_COUNT]; +int include_path_count; +extern char *l_include_path[]; + int main(int argc, char **argv) { @@ -131,6 +135,10 @@ chk = 1; ccout=0; break; + case 'I': + include_path[include_path_count++] = av[ac2]+2; + if (include_path_count<MAX_INCLUDE_PATH_COUNT) + break; default: error(OPTION); exit(1); @@ -279,6 +287,7 @@ reserve("environment",ENVIRONMENT); reserve("float",FLOAT); reserve("double",DOUBLE); + reserve("inline",INLINE); gpc=glineno=0; gfree=ilabel=1; @@ -310,6 +319,7 @@ if ( (filep->fcb = fopen(av[ac2++],"r")) == NULL ) error(FILERR); s = av[ac2-1]; filep->name0 = cheapp; + filep->inc = 0; while((*cheapp++ = *s++)); if(!ccout) { ccout=s=cheapp; s= filep->name0; @@ -458,6 +468,9 @@ while (sym==KONST) { getsym(); } + if (sym==INLINE) { + getsym(); + } switch(sym) { case VOID: case INT: @@ -477,7 +490,17 @@ if(getsym()==INT) getsym(); else if (sym==CHAR) { getsym(); t = UCHAR; } else if (sym==SHORT) { getsym(); t = USHORT; } - else if (sym==LONGLONG) {getsym(); t = ULONGLONG; } + else if (sym==LONG) { + getsym(); t = ULONG; + if(sym==LONG) { + getsym(); + // t=ULONGLONG; + t=UNSIGNED; + } else if(sym==INT) { + getsym(); + t=UNSIGNED; + } + } break; case SHORT: t=SHORT; @@ -488,9 +511,9 @@ getsym(); if(sym==LONG) { getsym(); - t=LONGLONG; - } - if(sym==INT) getsym(); + // t=LONGLONG; + t=INT; + } else if(sym==INT) getsym(); break; default: if(sym==IDENT) { @@ -719,6 +742,7 @@ if(t==FLOAT) return size_of_float; if(t==DOUBLE) return size_of_double; if(t==LONGLONG) return size_of_longlong; + if(t==ULONGLONG) return size_of_longlong; error(DCERR); } if(car(t)==STRUCT||car(t)==UNION) { @@ -3509,23 +3533,53 @@ return c; } +static char * +expand_file_name(char *path,char *name,int pos,int lbufsize) +{ + char *p = name+pos; + int i,j; + j = 0; + for(i=0;path[i];i++,j++); for(i=0;name[i];i++,j++); + if (pos+j+1>lbufsize) { error(FILERR); return ""; } + while((name[pos++] = *path++)); + pos--; + if (name[pos]!='/') name[pos]='/'; + for(i = 0; ((name[pos++] = name[i++]));); + return p; +} + static FILE * getfname(void) { - int i; - char *s,name[LBUFSIZE]; + int i,end='"',err=0; + char *s,*p,**pp,name[LBUFSIZE]; FILE *fp; getch(); - if(skipspc()!='"') error(INCERR); - for(i=0;(getch()!='"' && ch!='\n');) { + if(skipspc()=='"') { end = '"'; + } else if (ch=='<') { end = '>'; + } else { error(INCERR); err=1; + } + for(i=0;(getch()!=end && ch!='\n');) { if(i<LBUFSIZE-1) name[i++]=ch; } if(ch=='\n') error(INCERR); + if (err) return filep->fcb; name[i]=0; fp = fopen(name,"r") ; - s = name; + if (fp) { + p = name; + } else { + for(pp=(end=='>'||filep->inc=='>') + ?l_include_path:include_path;*pp;pp++) { + p = expand_file_name(*pp,name,i+1,LBUFSIZE); + if ((fp = fopen(p,"r"))) break ; + } + } + if(!fp) { error(FILERR); return filep->fcb; } + s = p; (filep+1)->name0 = cheapp; + (filep+1)->inc = end; while((*cheapp++ = *s++)); return ( (filep+1)->fcb = fp ); } @@ -3568,6 +3622,7 @@ int mode_save; ++chptr; + while (*chptr==' '||*chptr=='\t') ++chptr; if (macroeq("ifdef") || macroeq("ifndef")) { c = (chptr[-4]=='n'); macro_if_current++; @@ -3587,7 +3642,10 @@ chptr[c] = ';'; /* this can't happen in macro expression */ ch= *chptr; getsym(); - i=cexpr(expr(1)); + /* i=cexpr(expr(1)); #if allow undefined symbols.. */ + i=expr(1); + if (car(i)==CONST) i=cadr(i); + else i=0; if (ch) { if (chptr[-1]==ch) { /* we are fall into getch(), which lost the last ch */ @@ -3607,6 +3665,20 @@ if (macro_if_current == macro_if_depth) macro_if_skip = !macro_if_skip; return; + } else if (macroeq("elif")) { + if (macro_if_current==0) { + error(MCERR); /* extra #else */ + return; + } + if (macro_if_current == macro_if_depth) { + if (macro_if_skip) { + mode_save = mode; mode = IFDEF; + ch= *chptr; + i = getsym(); + mode = mode_save; + macro_if_skip = (!i)^c; + } + } } else if (macroeq("endif")) { if (macro_if_current == macro_if_depth) { macro_if_skip = 0; @@ -3687,7 +3759,7 @@ if (use) extrn_use(nptr0); } -static void +void macro_define(char *macro) { char *chptr_save;
--- a/mc.h Tue Nov 25 11:47:41 2003 +0900 +++ b/mc.h Wed Nov 26 18:55:37 2003 +0900 @@ -53,21 +53,22 @@ #define EXTRN (-37) #define EXTRN1 (-38) #define VOID (-39) -#define REGISTER (-40) -#define FREGISTER (-41) -#define DREGISTER (-42) -#define CODE (-43) -#define ENVIRONMENT (-44) -#define DEFINED (-45) -#define KONST (-46) -#define FMACRO (-47) -#define LMACRO (-48) -#define DOTS (-49) +#define INLINE (-40) +#define REGISTER (-41) +#define FREGISTER (-42) +#define DREGISTER (-43) +#define CODE (-44) +#define ENVIRONMENT (-45) +#define DEFINED (-46) +#define KONST (-47) +#define FMACRO (-48) +#define LMACRO (-49) +#define DOTS (-50) -#define FLOAT (-50) -#define DOUBLE (-51) -#define LONGLONG (-52) -#define ULONGLONG (-53) +#define FLOAT (-51) +#define DOUBLE (-52) +#define LONGLONG (-53) +#define ULONGLONG (-54) /* reserved word end */ @@ -374,10 +375,11 @@ EXTERN NMTBL null_nptr; EXTERN int typedefed,gtypedefed; -EXTERN struct {int fd,ln;char *name0;FILE *fcb;} *filep,filestack[FILES]; +EXTERN struct {int fd,ln;char *name0;int inc;FILE *fcb;} *filep,filestack[FILES]; EXTERN char cheap[CHEAPSIZE]; EXTERN char *macropp,macro_buf[MACROSIZE]; +extern void macro_define(char *n); extern void error(int n); extern int size(int t); extern int scalar(int t);