Mercurial > hg > CbC > old > device
changeset 65:8ad746efa4f8
*** empty log message ***
author | kono |
---|---|
date | Thu, 20 Feb 2003 08:56:29 +0900 |
parents | 262c8059e5df |
children | 0b068058dd67 |
files | Makefile conv/c.c conv/c2cbc.c conv/cbc2c.c conv/null.c mc-parse.c mc.h |
diffstat | 7 files changed, 291 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile Thu Feb 20 05:58:01 2003 +0900 +++ b/Makefile Thu Feb 20 08:56:29 2003 +0900 @@ -26,17 +26,13 @@ mc1 : b00.s b01.s mc-codegen.o mc-tree.o $CONVERTER $(CC) -g -o $@ $(PRINTF) b00.s b01.s mc-codegen.o mc-tree.o $CONVERTER b00.s : mc-parse.c mc - ./mc -s mc-parse.c - mv mcout.s $@ + ./mc -s -ob00.s mc-parse.c b01.s : mc-code-ia32.c mc - ./mc -s mc-code-ia32.c - mv mcout.s $@ + ./mc -s -ob01.s mc-code-ia32.c b10.s : mc-parse.c mc1 - ./mc1 -s mc-parse.c - mv mcout.s $@ + ./mc1 -s -ob10.s mc-parse.c b11.s : mc-code-ia32.c $(PRINTF) mc1 - ./mc1 -s mc-code-ia32.c - mv mcout.s $@ + ./mc1 -s -ob11.s mc-code-ia32.c diff : b00.s b01.s b10.s b11.s -diff b00.s b10.s
--- a/conv/c.c Thu Feb 20 05:58:01 2003 +0900 +++ b/conv/c.c Thu Feb 20 08:56:29 2003 +0900 @@ -2,16 +2,41 @@ #include "mc.h" +static void open(char *); static void print(char *); +static void close(); Converter c_converter = { - &print + &open, + &print, + &close, }; static FILE *vout; static void +open(char *s) +{ + char *p=cheapp; + while((*cheapp++ = *s++)) { + if (*s=='.') { + *cheapp++=*s++; *cheapp++='c'; + *cheapp++='c'; *cheapp++=0; + break; + } + } + vout = fopen(p,"w"); + if(!vout) error(-1); +} + +static void print(char *s) { fprintf(vout,"c: %s\n",s); } + +static void +close() +{ + fclose(vout); +}
--- a/conv/c2cbc.c Thu Feb 20 05:58:01 2003 +0900 +++ b/conv/c2cbc.c Thu Feb 20 08:56:29 2003 +0900 @@ -2,17 +2,214 @@ #include "mc.h" +static void open(char *); static void print(char *); +static void close(); Converter c2cbc_converter = { - &print + &open, + &print, + &close, }; -static -FILE *vout; +static void cbcstruct_init(void); +static void init(void); +static void unlist(int e1); +static int unsym(int e1); + +static FILE *vout; +static FILE *cbc_fp1; + +static int while_count=0; +static int for_count=0; +static int while_sign=0; +static int for_sign=0; + +#define SPSTACK_MAX 300 +int cbc_spstack[SPSTACK_MAX]; +static int sp_free=0; + +#define FUNBUF_MAX 1000 +char *cbc_funstack[FUNBUF_MAX]; +static int fun_free=0; + +static void +open(char *s) +{ + char *p=cheapp; + while((*cheapp++ = *s++)) { + if (*s=='.') { + *cheapp++=*s++; *cheapp++='c'; + *cheapp++='b'; *cheapp++='c'; + *cheapp++=0; + break; + } + } + vout = fopen(p,"w"); + if(!vout) error(-1); + + cheapp=p; + while((*cheapp++ = *s++)) { + if (*s=='.') { + *cheapp++='-'; *cheapp++='s'; + *cheapp++=*s++; *cheapp++='h'; + *cheapp++=0; + break; + } + } + cbc_fp1 = fopen(p,"w"); + if(!cbc_fp1) error(-1); + + cbcstruct_init(); + init(); + fprintf(vout,"#include \"%s\"\n",p); + cheapp=p; +} static void print(char *s) { fprintf(vout,"c: %s\n",s); } + +static void +close() +{ + fclose(vout); +} + +static void +cbcstruct_init(void) +{ + fprintf(cbc_fp1,"typedef char *stack;\n"); + fprintf(cbc_fp1,"EXTERN stack sp;\n"); + fprintf(cbc_fp1,"struct cont_save {\n"); + fprintf(cbc_fp1," code (*ret)();\n"); + fprintf(cbc_fp1,"};\n"); +} + +static void +init(void) +{ + while_count=0; + for_count=0; + while_sign=0; + for_sign=0; + sp_free=0; + fun_free=0; + cbc_funstack[fun_free++]="main"; +} + +static void +unlist(int e1) +{ + int e2,e3; + e2=cadr(e1); + e3=caddr(e1); + switch(car(e1)){ + case GT: + unlist(e2); + printf(">"); + unlist(e3); + return; + case LT: + unlist(e2); + unsym(LT); + unlist(e3); + return; + case RLVAR: case LVAR: case GVAR: + fprintf(vout,"%s",(char *)e3); + return; + case CONST: + fprintf(vout,"%d",e2); + return; + case POSTINC: + if(e3==1){ + unlist(e2); + fprintf(vout,"++"); + return; + } + else return; + case CPOSTINC: + unlist(e2); + fprintf(vout,"++"); + return; + default: + return; + } +} + +static int +unsym(int t) /*タイプをプリントする*/ +{ + char *symbuf; + switch(t){ + case -1: symbuf="int"; break; + case -2: symbuf="char"; break; + case -3: symbuf="unsigned"; break; + case -4: symbuf="*"; break; + case -6: symbuf="struct"; break; + case -10: symbuf="static"; break; + case -34: symbuf="long"; break; + case -35: symbuf="short"; break; + case -36: symbuf="extern"; break; + case -37: symbuf="void"; break; + case CODE: symbuf="code"; break; + case MUL: symbuf="*"; break; + case MUL+AS: symbuf="*="; break; + case BAND: symbuf="&"; break; + case BAND+AS: symbuf="&="; break; + case LAND: symbuf="&&"; break; + case SUB: symbuf="-"; break; + case SUB+AS: symbuf="-="; break; + case DEC: symbuf="--"; break; + case ARROW: symbuf="->"; break; + case LNOT: symbuf="!"; break; + case NEQ: symbuf="!="; break; + case BNOT: symbuf="~"; break; + case ADD: symbuf="+"; break; + case ADD+AS: symbuf="+="; break; + case INC: symbuf="++"; break; + case MOD: symbuf="%"; break; + case MOD+AS: symbuf="%="; break; + case EOR: symbuf="^"; break; + case EOR+AS: symbuf="^="; break; + case BOR: symbuf="|"; break; + case BOR+AS: symbuf="||"; break; + case ASS: symbuf="="; break; + case EQ: symbuf="=="; break; + case RSHIFT: symbuf=">>"; break; + case RSHIFT+AS: symbuf=">>="; break; + case GT: symbuf=">"; break; + case GE: symbuf=">="; break; + case LSHIFT: symbuf="<<"; break; + case LSHIFT+AS: symbuf="<<="; break; + case LT: symbuf="<"; break; + case LE: symbuf="<="; break; + case LPAR: symbuf="("; break; + case RPAR: symbuf=")"; break; + case LBRA: symbuf="["; break; + case RBRA: symbuf="]"; break; + case LC: symbuf="{"; break; + case RC: symbuf="}"; break; + case COMMA: symbuf=","; break; + case COLON: symbuf=":"; break; + case COND: symbuf="?"; break; + case DOTS: symbuf="..."; break; + case PERIOD: symbuf="."; break; + case DIV: symbuf="/"; break; + case DIV+AS: symbuf="/="; break; + default: + return sym; + } + if((mode==GDECL)&&((t==INT)||(t==CHAR))) + fprintf(vout,"code "); + else + fprintf(vout,"%s",symbuf); + if((mode!=GDECL)&&((t==INT)||(t==CHAR)||(t==-3)||(t==-4))) + fprintf(cbc_fp1," %s",symbuf); + return sym; +} + + +/* end */
--- a/conv/cbc2c.c Thu Feb 20 05:58:01 2003 +0900 +++ b/conv/cbc2c.c Thu Feb 20 08:56:29 2003 +0900 @@ -2,16 +2,42 @@ #include "mc.h" +static void open(char *); static void print(char *); +static void close(); Converter cbc2c_converter = { - &print + &open, + &print, + &close, }; static FILE *vout; static void +open(char *s) +{ + char *p=cheapp; + while((*cheapp++ = *s++)) { + if (*s=='.') { + *cheapp++=*s++; *cheapp++='c'; + *cheapp++='c'; *cheapp++=0; + break; + } + } + vout = fopen(p,"w"); + if(!vout) error(-1); +} + +static void print(char *s) { fprintf(vout,"c: %s\n",s); } + +static void +close() +{ + fclose(vout); +} +
--- a/conv/null.c Thu Feb 20 05:58:01 2003 +0900 +++ b/conv/null.c Thu Feb 20 08:56:29 2003 +0900 @@ -2,16 +2,28 @@ #include "mc.h" +static void open(char *); static void print(char *); +static void close(); Converter null_converter = { - &print + &open, + &print, + &close, }; -static FILE *vout; +static void +open(char *s) +{ +} static void print(char *s) { - fprintf(vout,"null: %s\n",s); } + +static void +close() +{ +} +
--- a/mc-parse.c Thu Feb 20 05:58:01 2003 +0900 +++ b/mc-parse.c Thu Feb 20 08:56:29 2003 +0900 @@ -96,16 +96,16 @@ Converter *conv = &null_converter; +static char *ccout = 0; + int main(int argc, char **argv) { NMTBL *nptr; int i; - char *ccout; if(argc==1) exit(1); lsrc = chk = asmf = 0; - ccout = OUTPUT_FILE_NAME; ac=argc; av=argv; for (ac2=1; (ac2 < ac) && (*av[ac2] == '-'); ++ac2) { @@ -130,7 +130,7 @@ exit(1); } } - if (!chk) + if (!chk && ccout) if ( (freopen(ccout,"w",stdout)) == NULL ) error(FILERR); init(); while(1) { @@ -288,13 +288,26 @@ newfile(void) { char *s; + lineno=0; /* fprintf(stderr,"%s:\n",av[ac2]); */ - opening(av[ac2]); if ( (filep->fcb = fopen(av[ac2++],"r")) == NULL ) error(FILERR); s = av[ac2-1]; filep->name0 = cheapp; while((*cheapp++ = *s++)); + if(!ccout) { + ccout=s=cheapp; s= filep->name0; + while((*cheapp++ = *s++)) { + if(s[0]=='.'&&s[1]=='c') { + *cheapp++=*s++; *cheapp++=*s++; + cheapp[-1]='s'; + } + } + if ( (freopen(ccout,"w",stdout)) == NULL ) error(FILERR); + cheapp=ccout; + ccout=0; + } + opening(filep->name0); } static void