Mercurial > hg > CbC > old > device
diff conv/cbc2c.c @ 599:df04bc5fd5fe
*** empty log message ***
author | kono |
---|---|
date | Thu, 26 Jan 2006 15:19:55 +0900 |
parents | 0b068058dd67 |
children | e055df7c1082 |
line wrap: on
line diff
--- a/conv/cbc2c.c Tue Jan 24 10:55:00 2006 +0900 +++ b/conv/cbc2c.c Thu Jan 26 15:19:55 2006 +0900 @@ -1,50 +1,447 @@ #define EXTERN /**/ +#include <stdio.h> #include "mc.h" - -static void open(char *); -static void print(char *); -static void close(); -static void comment(char *s); +#include "mc-parse.h" +#include "mc-codegen.h" -Converter cbc2c_converter = { - &open, - &print, - &close, - &comment, -}; +#include "conv/conv.h" +#include "conv/convdef.h" +#include "conv/cbc2c.h" -static FILE *vout; +extern void type_print(int type,NMTBL *nptr,FILE *out); +extern void type_print1(int type,NMTBL *nptr,FILE *out,int cont); +extern void sym_print(int type,FILE *out); + +static FILE *vout,*svout; +static FILE *null; +static FILE *hout; static void -comment(char *s) +comment_(int c) { + fprintf(vout,"%c",c); } static void -open(char *s) +open_(char *s) { - char *p=cheapp; - while((*cheapp++ = *s++)) { - if (*s=='.') { - *cheapp++=*s++; *cheapp++='c'; - *cheapp++='c'; *cheapp++=0; - break; - } - } + char *p; + p = make_filename_with_extension(s,"cbc.c"); +#if 1 vout = fopen(p,"w"); - if(!vout) error(-1); +#else + vout = stderr;p=p; +#endif + p = make_filename_with_extension(s,"cbc.h"); + hout = fopen(p,"w"); + null=fopen("/dev/null","w"); + if (!vout) error(-1); } static void -print(char *s) +conv_() +{ + vout=svout; +} + +static void +noconv_(int c) +{ + svout=vout; + vout=c?null:vout; +} + +static void +print_(char *s) { fprintf(vout,"c: %s\n",s); } static void -close() +close_() { fclose(vout); } +void +case_begin_(int cases,int def){ + fprintf(vout,"case "); +} + +void +case_(int cases,int def){ + if (def) + fprintf(vout,"default:"); + else + fprintf(vout,"%d:",car(cases)); +} + +void +code_(NMTBL *n){ + int args; + args=n->dsp; + fprintf(vout,"code %s(",n->nm); + while(args) { + n=(NMTBL *)caddr(args); + type_print(n->ty,n,vout); + args=cadr(args); + if(args) fprintf(vout,","); + } + fprintf(vout,")"); +} + +void +code_end_(){ + fprintf(vout,"}"); +} + +void +comma_(){ + fprintf(vout,","); +} + +void +cond_(){ + +} + +void +cond1_(){ + fprintf(vout,"?"); +} + +void +cond2_(){ + fprintf(vout,":"); +} + +void +cond_end_(){ + +} + +void +decl_data_begin_(){ + +} + +void +decl_data_end_(){ + +} + +void +def_(NMTBL *n){ +} + +void +dowhile_(){ + fprintf(vout,"do"); +} + +void +dowhile_cond_(){ + fprintf(vout,"while("); +} + +void +dowhile_end_(){ + fprintf(vout,");"); +} + +int +error_(int n){ + return 0; +} + +void +extern_(){ + fprintf(vout,"extern "); +} + +void +for_(){ + fprintf(vout,"for("); +} + +void +for1_(){ + fprintf(vout,";"); +} + +void +for2_(){ + fprintf(vout,";"); +} + +void +for_body_(){ + fprintf(vout,")"); +} + +void +for_end_(){ + +} + +void +funcall_(int type){ + fprintf(vout,"("); +} + +void +funcall_args_(){ + fprintf(vout,")"); +} + +void +function_(NMTBL *n,int cont){ + int args; + type_print1(cadr(n->ty),0,vout,cont); + fprintf(vout,"%s(",n->nm); + args=n->dsp; + while(args) { + n=(NMTBL *)caddr(args); + if (n==&str_ret) { + args=cadr(args); continue; + } + type_print(n->ty,n,vout); + args=cadr(args); + if(args) { + /* if(caddr(args)==(int)&str_ret) break; */ + fprintf(vout,","); + } + } + fprintf(vout,")"); +} + +void +function_end_(){ + +} + +void +goto_(){ + fprintf(vout,"goto "); +} + +void +goto_label_(){ + +} + +void +id_(int sym,NMTBL *nptr){ + char *p = nptr->nm; + for(;*p && *p!='.';p++) fputc(*p,vout); +} + +void +string_(char *s,int len){ + int c; + fprintf(vout,"\""); + while((c=*s++)) { + if(c=='\n') fprintf(vout,"\\n"); + else if(c=='\r') fprintf(vout,"\\r"); + else if(c=='\t') fprintf(vout,"\\t"); + else if(c=='\e') fprintf(vout,"\\e"); + else if(c=='"') fprintf(vout,"\\\""); + else if(c=='\\') fprintf(vout,"\\\\"); + else if(!(' '<=c&&c<=0x7f)) fprintf(vout,"\\%03o",c); + else fprintf(vout,"%c",c); + } + fprintf(vout,"\""); +} + +void +const_(int symval){ + fprintf(vout,"%d",symval); +} + +void +return_f_(){ + fprintf(vout,"return"); +} + +void +defined_(char *s){ + fprintf(vout,"defined(%s)",s); +} + +void +environment_(){ + fprintf(vout,"environment"); +} + +void +if_(){ + fprintf(vout,"if ("); +} + +void +if_else_(){ + fprintf(vout," else "); +} + +void +if_endif_(){ +} + +void +if_then_(){ + fprintf(vout,")"); +} + +void +jump_(int env){ + +} + +void +label_(){ + fprintf(vout,"%s:",nptr->nm); +} + +void +lpar_(){ + fprintf(vout,"("); +} + +void +rpar_(){ + fprintf(vout,")"); +} + +void +lbra_(int sym){ + fprintf(vout,"["); +} + +void +rbra_(int sym){ + fprintf(vout,"]"); +} + +void +lc_(){ + fprintf(vout,"{"); +} + +void +rc_(){ + fprintf(vout,"}"); +} + +void +localvar_end_(){ + +} + +void +op_(int sym){ + sym_print(sym,vout); +} + +void +postfix_(int sym){ + sym_print(sym,vout); +} + +void +prefix_(int sym){ + sym_print(sym,vout); +} + +void +register_(){ + fprintf(vout,"register "); +} + +void +return_(){ + fprintf(vout,"return "); +} + +void +return_end_(){ + fprintf(vout,";"); +} + +void +return_type_(int t,NMTBL *nptr,int cont){ + type_print1(t,nptr,vout,cont); +} + +void +sm_(){ + fprintf(vout,";"); +} + +void +static_(){ + fprintf(vout,"static "); +} + +void +switch_(){ + fprintf(vout,"switch ("); +} + +void +switch_body_(){ + fprintf(vout,")"); +} + +void +switch_end_(){ +} + +void +typedef_(){ + fprintf(vout,"typedef "); +} + +void +type_(int t){ + type_print(t,0,vout); +} + +void +sdecl_(int s) +{ + fprintf(vout,s==UNION?"union ":"struct "); +} + +void +while_(){ + fprintf(vout,"while ("); +} + +void +while_body_(){ + fprintf(vout,")"); +} + +void +while_end_(){ +} + +void +decl_data_() +{ +} + +void +break_() +{ + fprintf(vout,"break;"); +} + +void +continue_() +{ + fprintf(vout,"continue;"); +} + +/* end */