Mercurial > hg > CbC > old > device
changeset 609:af6b9ae79583 udpcl
modificatioon for udpcl
author | kono |
---|---|
date | Thu, 16 Mar 2006 17:03:24 +0900 |
parents | c3ba27861c83 |
children | 3ce0fd61eeae |
files | Changes Makefile Makefile.powerpc conv/c.c conv/c.h conv/c2cbc.c conv/c2cbc.h conv/cbc2c.c conv/cbc2c.h conv/null.c conv/null.h conv_func.tbl mc-codegen.c mc-codegen.h mc-inline.c mc-macro.c mc-parse.c mc-parse.h mc-switch.c mc-tree.c mc.h |
diffstat | 21 files changed, 658 insertions(+), 230 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Sat Feb 18 21:33:43 2006 +0900 +++ b/Changes Thu Mar 16 17:03:24 2006 +0900 @@ -8683,4 +8683,9 @@ どうかを判断することは出来るんだけど... - +Sun Mar 5 20:05:41 JST 2006 + +やっぱり、print_expression とか、print_statement とか +作るじゃない? + +
--- a/Makefile Sat Feb 18 21:33:43 2006 +0900 +++ b/Makefile Thu Mar 16 17:03:24 2006 +0900 @@ -1,12 +1,12 @@ CC = gcc -std=c99 # -O2 # -O99 -CFLAGS = -g -Wall -I. +CFLAGS = -g -Wall -I. -DUSE_CODE_KEYWORD # CFLAGS = -g -Wall -I. -pg -fprofile-arcs -ftest-coverage # LDFLAGS = -pg # for Linux Zaurus # CFLAGS = -fsigned-char -pipe -g -I. -I/home/zaurus/develop/include -CFLAGS1 = -g -I. +CFLAGS1 = -g -I. -DUSE_CODE_KEYWORD BASE=0 STAGE=1 MFLAGS=$(MFALGS) BASE=$(BASE) STAGE=$(STAGE) @@ -14,7 +14,9 @@ MC=mc-$(ARCH) MLIB = -lm PRINTF= # printf.c -CONVERTER=conv/c.o conv/null.o conv/c2cbc.o conv/cbc2c.o +CONVERTER=conv/c.o conv/null.o conv/cbc2c.o conv/c2cbc.o + +# conv/c2cbc.o conv/cbc2c.o COMPLIB = mc-parse.o mc-codegen.o mc-switch.o mc-macro.o mc-tree.o mc-inline.o # CODE=mc-code-ia32.c CODE=mc-code-$(ARCH).c @@ -27,13 +29,16 @@ cp mc-$(ARCH) mc TAGS: - ctags mc-code-powerpc.c mc-code.h mc-codegen.c mc-codegen.h \ + ctags mc-code-null.c mc-code.h mc-codegen.c mc-codegen.h \ mc-macro.c \ mc-parse.c mc-tree.c mc-switch.c mc-switch.h \ mc.h conv/c.c conv/c.h \ mc-inline.h mc-inline.c \ conv/conv.h conv/convdef.h conv/null.c +mc-null : mc-code-null.o $(COMPLIB) $(CONVERTER) + $(CC) $(LDFLAGS) -g mc-code-null.o $(COMPLIB) $(CONVERTER) -o $@ + mc-powerpc : mc-code-powerpc.o $(COMPLIB) $(CONVERTER) $(CC) $(LDFLAGS) -g mc-code-powerpc.o $(COMPLIB) $(CONVERTER) -o $@ @@ -134,7 +139,7 @@ check: mc $(MC) $(TARGET).c -$(CC) $(CFLAGS1) $(STDFLAG) $(TARGET).c -o b.out $(MLIB) -./b.out > $(TARGET).gcc.out - -./$(MC) -s $(TARGET).c + -./$(MC) -s $(TARGET).c -$(CC) $(TARGET).s $(MLIB) -./a.out > $(TARGET).$(MC).out -diff $(TARGET).gcc.out $(TARGET).$(MC).out @@ -142,18 +147,18 @@ check-inline: mc $(MC) $(TARGET).c -$(CC) $(CFLAGS1) $(STDFLAG) $(TARGET).c -o b.out $(MLIB) -./b.out > $(TARGET).gcc.out - -./$(MC) -s -DINLINE=inline $(TARGET).c + -./$(MC) -s -DINLINE=inline $(TARGET).c -$(CC) $(TARGET).s $(MLIB) -./a.out > $(TARGET).$(MC).out -diff $(TARGET).gcc.out $(TARGET).$(MC).out check-code: mc $(MC) - -./$(MC) -s $(TARGET).c + -./$(MC) -s $(TARGET).c -$(CC) $(TARGET).s $(MLIB) -./a.out > $(TARGET).$(MC).out -diff $(TARGET).code-out $(TARGET).$(MC).out check-code-make: mc $(MC) - -./$(MC) -s $(TARGET).c + -./$(MC) -s $(TARGET).c -$(CC) $(TARGET).s $(MLIB) -./a.out > $(TARGET).code-out @@ -175,18 +180,20 @@ make clean tar cBf - . | gzip > ../comp.tgz -depend : +depend : conv/conv.h makedepend mc-code-ia32.c mc-code.h mc-codegen.c mc-codegen.h \ mc-parse.c mc-tree.c mc-switch.c mc-switch.h mc.h \ mc-macro.c mc-inline.c mc-macro.h mc-parse.h \ conv/c.c conv/c.h conv/c2cbc.c conv/c2cbc.h conv/cbc2c.c \ conv/cbc2c.h conv/conv.h conv/convdef.h conv/null.c conv/null.h \ + mc-code-null.c \ mc-code-powerpc.c \ mc-code-arm.c \ mc-code-mips.c clean : - -rm -f mc mc-ia32 mc-powerpc mc-mips mc-arm *.bak *.s *.o *.cc mc mc1 mc2 a.out *~ core* */*.o *.bak test/*.s test/*.cc test/*.o test/*.bak test/*~ conv/*.s conv/*.cc conv/*.o conv/*.bak conv/*~ *.out */*.out *.i */*.i *.cbc.? */*.cbc.? + -rm -f mc mc-null mc-ia32 mc-powerpc mc-mips mc-arm *.bak *.s *.o *.cc mc mc1 mc2 a.out *~ core* */*.o *.bak test/*.s test/*.cc test/*.o test/*.bak test/*~ conv/*.s conv/*.cc conv/*.o conv/*.bak conv/*~ *.out */*.out *.i */*.i *.cbc.? */*.cbc.? + -rm -f *.tsv ../test/*.tsv ../test/sample/*.tsv mc1 : b00.s b01.s mc-codegen.o mc-tree.o mc-switch.o mc-macro.o mc-inline.o $(CONVERTER) $(CC) -g -o $@ $(PRINTF) b00.s b01.s mc-codegen.o mc-tree.o mc-switch.o mc-macro.o mc-inline.o $(CONVERTER) @@ -252,6 +259,7 @@ mc-codegen.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h mc-codegen.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h mc-codegen.o: mc-parse.h mc-codegen.h mc-code.h mc-switch.h mc-inline.h +mc-codegen.o: conv/conv.h mc-parse.o: /usr/include/stdio.h /usr/include/_types.h mc-parse.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h mc-parse.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h @@ -289,6 +297,10 @@ conv/null.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h conv/null.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h conv/null.o: mc-parse.h conv/conv.h conv/convdef.h conv/null.h +mc-code-null.o: /usr/include/stdio.h /usr/include/_types.h +mc-code-null.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h +mc-code-null.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h +mc-code-null.o: mc-parse.h mc-code.h mc-codegen.h mc-code-powerpc.o: /usr/include/stdio.h /usr/include/_types.h mc-code-powerpc.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h mc-code-powerpc.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h
--- a/Makefile.powerpc Sat Feb 18 21:33:43 2006 +0900 +++ b/Makefile.powerpc Thu Mar 16 17:03:24 2006 +0900 @@ -14,7 +14,9 @@ MC=mc-$(ARCH) MLIB = -lm PRINTF= # printf.c -CONVERTER=conv/c.o conv/null.o conv/c2cbc.o conv/cbc2c.o +CONVERTER=conv/c.o conv/null.o conv/cbc2c.o conv/c2cbc.o + +# conv/c2cbc.o conv/cbc2c.o COMPLIB = mc-parse.o mc-codegen.o mc-switch.o mc-macro.o mc-tree.o mc-inline.o # CODE=mc-code-ia32.c CODE=mc-code-$(ARCH).c @@ -27,13 +29,16 @@ cp mc-$(ARCH) mc TAGS: - ctags mc-code-powerpc.c mc-code.h mc-codegen.c mc-codegen.h \ + ctags mc-code-null.c mc-code.h mc-codegen.c mc-codegen.h \ mc-macro.c \ mc-parse.c mc-tree.c mc-switch.c mc-switch.h \ mc.h conv/c.c conv/c.h \ mc-inline.h mc-inline.c \ conv/conv.h conv/convdef.h conv/null.c +mc-null : mc-code-null.o $(COMPLIB) $(CONVERTER) + $(CC) $(LDFLAGS) -g mc-code-null.o $(COMPLIB) $(CONVERTER) -o $@ + mc-powerpc : mc-code-powerpc.o $(COMPLIB) $(CONVERTER) $(CC) $(LDFLAGS) -g mc-code-powerpc.o $(COMPLIB) $(CONVERTER) -o $@ @@ -113,7 +118,6 @@ make check-code$(MK) TARGET=test/fact make check-code$(MK) TARGET=test/goto make check-code$(MK) TARGET=test/test1 - make check-code$(MK) TARGET=test/test2 make check-code$(MK) TARGET=test/tmpa make check-code$(MK) TARGET=test/tmp1 make check-code$(MK) TARGET=test/tmp2 @@ -121,6 +125,7 @@ make check-code$(MK) TARGET=test/tmp6 make check-code$(MK) TARGET=test/scope make check-code$(MK) TARGET=test/throw + make check-code$(MK) TARGET=test/test2 make check-code$(MK) TARGET=test/too-long-argument check-nkf: @@ -175,18 +180,20 @@ make clean tar cBf - . | gzip > ../comp.tgz -depend : +depend : conv/conv.h makedepend mc-code-ia32.c mc-code.h mc-codegen.c mc-codegen.h \ mc-parse.c mc-tree.c mc-switch.c mc-switch.h mc.h \ mc-macro.c mc-inline.c mc-macro.h mc-parse.h \ conv/c.c conv/c.h conv/c2cbc.c conv/c2cbc.h conv/cbc2c.c \ conv/cbc2c.h conv/conv.h conv/convdef.h conv/null.c conv/null.h \ + mc-code-null.c \ mc-code-powerpc.c \ mc-code-arm.c \ mc-code-mips.c clean : - -rm -f mc mc-ia32 mc-powerpc mc-mips mc-arm *.bak *.s *.o *.cc mc mc1 mc2 a.out *~ core* */*.o *.bak test/*.s test/*.cc test/*.o test/*.bak test/*~ conv/*.s conv/*.cc conv/*.o conv/*.bak conv/*~ *.out */*.out *.i */*.i *.cbc.? */*.cbc.? + -rm -f mc mc-null mc-ia32 mc-powerpc mc-mips mc-arm *.bak *.s *.o *.cc mc mc1 mc2 a.out *~ core* */*.o *.bak test/*.s test/*.cc test/*.o test/*.bak test/*~ conv/*.s conv/*.cc conv/*.o conv/*.bak conv/*~ *.out */*.out *.i */*.i *.cbc.? */*.cbc.? + -rm -f *.tsv ../test/*.tsv ../test/sample/*.tsv mc1 : b00.s b01.s mc-codegen.o mc-tree.o mc-switch.o mc-macro.o mc-inline.o $(CONVERTER) $(CC) -g -o $@ $(PRINTF) b00.s b01.s mc-codegen.o mc-tree.o mc-switch.o mc-macro.o mc-inline.o $(CONVERTER) @@ -252,6 +259,7 @@ mc-codegen.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h mc-codegen.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h mc-codegen.o: mc-parse.h mc-codegen.h mc-code.h mc-switch.h mc-inline.h +mc-codegen.o: conv/conv.h mc-parse.o: /usr/include/stdio.h /usr/include/_types.h mc-parse.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h mc-parse.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h @@ -289,6 +297,10 @@ conv/null.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h conv/null.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h conv/null.o: mc-parse.h conv/conv.h conv/convdef.h conv/null.h +mc-code-null.o: /usr/include/stdio.h /usr/include/_types.h +mc-code-null.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h +mc-code-null.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h mc.h +mc-code-null.o: mc-parse.h mc-code.h mc-codegen.h mc-code-powerpc.o: /usr/include/stdio.h /usr/include/_types.h mc-code-powerpc.o: /usr/include/sys/_types.h /usr/include/sys/cdefs.h mc-code-powerpc.o: /usr/include/machine/_types.h /usr/include/ppc/_types.h
--- a/conv/c.c Sat Feb 18 21:33:43 2006 +0900 +++ b/conv/c.c Thu Mar 16 17:03:24 2006 +0900 @@ -37,6 +37,11 @@ static FILE *null; static void +expr_(int c) +{ +} + +static void comment_(int c) { fprintf(vout,"%c",c); @@ -163,7 +168,7 @@ } void -dowhile_end_(){ +dowhile_end_(int cond){ fprintf(vout,");"); } @@ -188,17 +193,17 @@ } void -for2_(){ +for2_(int cond){ fprintf(vout,";"); } void -for_body_(){ +for_body_(int conti){ fprintf(vout,")"); } void -for_end_(){ +for_end_(int p0,int p1,int e){ } @@ -208,7 +213,7 @@ } void -funcall_args_(){ +funcall_args_(int f, int t, int arg){ fprintf(vout,")"); } @@ -304,7 +309,7 @@ } void -if_then_(){ +if_then_(int cond){ fprintf(vout,")"); } @@ -379,7 +384,7 @@ } void -return_end_(){ +return_end_(int e){ fprintf(vout,";"); } @@ -404,12 +409,12 @@ } void -switch_body_(){ +switch_body_(int v){ fprintf(vout,")"); } void -switch_end_(){ +switch_end_(int cases){ } void @@ -434,7 +439,7 @@ } void -while_body_(){ +while_body_(int cond){ fprintf(vout,")"); }
--- a/conv/c.h Sat Feb 18 21:33:43 2006 +0900 +++ b/conv/c.h Thu Mar 16 17:03:24 2006 +0900 @@ -5,6 +5,7 @@ Converter c_converter = { + &expr_, &conv_, &noconv_, &comment_,
--- a/conv/c2cbc.c Sat Feb 18 21:33:43 2006 +0900 +++ b/conv/c2cbc.c Thu Mar 16 17:03:24 2006 +0900 @@ -38,6 +38,11 @@ static FILE *hout; static void +expr_(int c) +{ +} + +static void comment_(int c) { fprintf(vout,"%c",c); @@ -166,7 +171,7 @@ } void -dowhile_end_(){ +dowhile_end_(int cond){ fprintf(vout,");"); } @@ -191,17 +196,18 @@ } void -for2_(){ +for2_(int cond){ fprintf(vout,";"); } void -for_body_(){ +for_body_(int conti){ fprintf(vout,")"); } void -for_end_(){ +for_end_(int p0,int p1,int e){ + } @@ -211,7 +217,7 @@ } void -funcall_args_(){ +funcall_args_(int f, int t, int args){ fprintf(vout,")"); } @@ -309,7 +315,7 @@ } void -if_then_(){ +if_then_(int cond){ fprintf(vout,")"); } @@ -384,7 +390,7 @@ } void -return_end_(){ +return_end_(int e){ fprintf(vout,";"); } @@ -409,12 +415,12 @@ } void -switch_body_(){ +switch_body_(int v){ fprintf(vout,")"); } void -switch_end_(){ +switch_end_(int cases){ } void @@ -439,7 +445,7 @@ } void -while_body_(){ +while_body_(int cond){ fprintf(vout,")"); } @@ -464,4 +470,5 @@ fprintf(vout,"continue;"); } + /* end */
--- a/conv/c2cbc.h Sat Feb 18 21:33:43 2006 +0900 +++ b/conv/c2cbc.h Thu Mar 16 17:03:24 2006 +0900 @@ -5,6 +5,7 @@ Converter c2cbc_converter = { + &expr_, &conv_, &noconv_, &comment_,
--- a/conv/cbc2c.c Sat Feb 18 21:33:43 2006 +0900 +++ b/conv/cbc2c.c Thu Mar 16 17:03:24 2006 +0900 @@ -38,6 +38,11 @@ static FILE *hout; static void +expr_(int c) +{ +} + +static void comment_(int c) { fprintf(vout,"%c",c); @@ -166,7 +171,7 @@ } void -dowhile_end_(){ +dowhile_end_(int cond){ fprintf(vout,");"); } @@ -191,17 +196,18 @@ } void -for2_(){ +for2_(int cond){ fprintf(vout,";"); } void -for_body_(){ +for_body_(int conti){ fprintf(vout,")"); } void -for_end_(){ +for_end_(int p0,int p1,int e){ + } @@ -211,7 +217,7 @@ } void -funcall_args_(){ +funcall_args_(int f, int t, int arg){ fprintf(vout,")"); } @@ -309,7 +315,7 @@ } void -if_then_(){ +if_then_(int cond){ fprintf(vout,")"); } @@ -384,7 +390,7 @@ } void -return_end_(){ +return_end_(int e){ fprintf(vout,";"); } @@ -409,12 +415,12 @@ } void -switch_body_(){ +switch_body_(int v){ fprintf(vout,")"); } void -switch_end_(){ +switch_end_(int cases){ } void @@ -439,7 +445,7 @@ } void -while_body_(){ +while_body_(int cond){ fprintf(vout,")"); } @@ -464,4 +470,5 @@ fprintf(vout,"continue;"); } + /* end */
--- a/conv/cbc2c.h Sat Feb 18 21:33:43 2006 +0900 +++ b/conv/cbc2c.h Thu Mar 16 17:03:24 2006 +0900 @@ -5,6 +5,7 @@ Converter cbc2c_converter = { + &expr_, &conv_, &noconv_, &comment_,
--- a/conv/null.c Sat Feb 18 21:33:43 2006 +0900 +++ b/conv/null.c Thu Mar 16 17:03:24 2006 +0900 @@ -7,6 +7,10 @@ #include "conv/convdef.h" #include "conv/null.h" static void +expr_(int e) +{ } + +static void conv_() { } @@ -87,7 +91,7 @@ { } static void -dowhile_end_() +dowhile_end_(int cond) { } static int @@ -107,15 +111,15 @@ { } static void -for2_() +for2_(int cond) { } static void -for_body_() +for_body_(int conti) { } static void -for_end_() +for_end_(int p0,int p1,int e) { } static void @@ -123,7 +127,7 @@ { } static void -funcall_args_() +funcall_args_(int f,int t, int args) { } static void @@ -179,7 +183,7 @@ { } static void -if_then_() +if_then_(int cond) { } static void @@ -235,7 +239,7 @@ { } static void -return_end_() +return_end_(int e) { } static void @@ -259,11 +263,11 @@ { } static void -switch_body_() +switch_body_(int v) { } static void -switch_end_() +switch_end_(int cslist) { } static void @@ -279,7 +283,7 @@ { } static void -while_body_() +while_body_(int cond) { } static void
--- a/conv/null.h Sat Feb 18 21:33:43 2006 +0900 +++ b/conv/null.h Thu Mar 16 17:03:24 2006 +0900 @@ -5,6 +5,7 @@ Converter null_converter = { + &expr_, &conv_, &noconv_, &comment_,
--- a/conv_func.tbl Sat Feb 18 21:33:43 2006 +0900 +++ b/conv_func.tbl Thu Mar 16 17:03:24 2006 +0900 @@ -1,3 +1,4 @@ +void expr_(int e) ; void conv_() ; void noconv_(int f) ; void comment_(int f) ; @@ -18,16 +19,16 @@ void def_(NMTBL *n); void dowhile_(); void dowhile_cond_(); -void dowhile_end_(); +void dowhile_end_(int cond); int error_(int n); void extern_(); void for_(); void for1_(); -void for2_(); -void for_body_(); -void for_end_(); +void for2_(int cond); +void for_body_(int conti); +void for_end_(int p0,int p1,int e); void funcall_(int type); -void funcall_args_(); +void funcall_args_(int f,int t, int args); void function_(NMTBL *n,int cont); void function_end_(); void goto_(); @@ -41,7 +42,7 @@ void if_(); void if_else_(); void if_endif_(); -void if_then_(); +void if_then_(int cond); void jump_(int env); void label_(); void lbra_(int sym); @@ -55,18 +56,18 @@ void rc_(); void register_(); void return_(); -void return_end_(); +void return_end_(int e); void return_type_(int t,NMTBL *n,int cont); void rpar_(); void sm_(); void static_(); void switch_(); -void switch_body_(); -void switch_end_(); +void switch_body_(int v); +void switch_end_(int cslist); void typedef_(); void type_(); void while_(); -void while_body_(); +void while_body_(int cond); void while_end_(); void decl_data_(); void break_();
--- a/mc-codegen.c Sat Feb 18 21:33:43 2006 +0900 +++ b/mc-codegen.c Thu Mar 16 17:03:24 2006 +0900 @@ -29,6 +29,9 @@ #include "mc-code.h" #include "mc-switch.h" #include "mc-inline.h" +#include "conv/conv.h" + +extern Converter *conv; int use; /* generated value will be used */ char *init_src; @@ -111,7 +114,7 @@ extern int gexpr(int e1,int use0) { - if (chk) return INT; + if (chk==1) return INT; gexpr_init(); use = use0; return g_expr0(e1); @@ -161,6 +164,7 @@ for(;e1;e1=e2) { code_gexpr(e1); + conv->expr_(e1); e2 = cadr(e1); switch (car(e1)){ @@ -278,7 +282,7 @@ } t = function(e1); return t; - case CODE: + case JUMP: if (car(e2)==FNAME&&is_function((NMTBL*)cadr(e2))) { // error(GTERR); return function(e1); @@ -294,12 +298,14 @@ nptr = (NMTBL*)caddr(e1); type = cadddr(e1); e1 = strop(e2,0); t = type; + if (chk) return t; g_expr0(e1); return t; case ARROW: nptr = (NMTBL*)caddr(e1); type = cadddr(e1); e1 = strop(e2,1); t = type; + if (chk) return t; g_expr0(e1); return t; case INLINE: @@ -600,7 +606,7 @@ return VOID; } -static int +extern int rop_dual(int op) { // x op y => y dual(op) x @@ -642,6 +648,7 @@ bexpr_u(int e1, char cond, int l1) { int op = car(e1); + conv->expr_(e1); if (chk) return l1; // gexpr_init(); switch(op) { @@ -1548,6 +1555,7 @@ g_expr(e2); emit_push(); } + if (chk) return; /* 並列代入を実行 */ parallel_assign(&target,&processing,&use); @@ -2692,6 +2700,7 @@ } if (!chk) code_closing(); + conv->close_(); } static int @@ -2722,7 +2731,7 @@ if (contains(cadr(e),type)) return 1; e = caddr(e); continue; - } else if (TARNARY_ARGS(car(e))) { + } else if (TERNARY_ARGS(car(e))) { /* tarary operators */ if (contains(cadr(e), type)) return 1; if (contains(caddr(e),type)) return 1; @@ -2770,7 +2779,7 @@ if (contains_p(cadr(e),p)) return 1; e = caddr(e); continue; - } else if (TARNARY_ARGS(car(e))) { + } else if (TERNARY_ARGS(car(e))) { /* tarary operators */ if (contains_p(cadr(e), p)) return 1; if (contains_p(caddr(e),p)) return 1; @@ -2819,7 +2828,7 @@ arg=contains_p1(arg,cadr(e),p); e = caddr(e); continue; - } else if (TARNARY_ARGS(car(e))) { + } else if (TERNARY_ARGS(car(e))) { /* tarary operators */ arg=contains_p1(arg,cadr(e), p); arg=contains_p1(arg,caddr(e),p); @@ -2840,6 +2849,169 @@ return arg; } +/* gahter accumurated list in all parse tree for all operator */ + +static int +contains_in_list_p2(int arg,int e,int (*p)(int,int)) +{ + while(e) { + arg=contains_p2(arg,car(e),p); + e = cadr(e); + } + return arg; +} + +extern int +contains_p2(int arg,int e,int (*p)(int,int)) +{ + while(e) { + if (!car(e)) return arg; + if (LIST_ARGS(car(e))){ + /* list arguments */ + arg=p(arg,e); + return contains_in_list_p2(arg,caddr(e),p); + } else if (UNARY_ARGS(car(e))) { + /* unary operators */ + arg=p(arg,e); + e = cadr(e); + continue; + } else if (BINARY_ARGS(car(e))) { + /* biary operators */ + arg=contains_p2(arg,cadr(e),p); + arg=p(arg,e); + e = caddr(e); + continue; + } else if (TERNARY_ARGS(car(e))) { + /* tarary operators */ + arg=contains_p2(arg,cadr(e), p); + arg=contains_p2(arg,caddr(e),p); + arg=p(arg,e); + e = cadddr(e); + continue; + } else if (NULLARY_ARGS(car(e))) { + /* nullary operators */ + arg=p(arg,e); + return arg; + } else if (IS_STATEMENT(car(e))) { + return arg; + } else { + // fprintf(stderr,"Unknown Tree ID %d\n",car(e)); + // error(-1); + return arg; + } + } + return arg; +} + +// +// globalize parse tree +// + +static int +copy_list(int e) +{ + int e1; + if (!e) return 0; + e1 = copy_expr(car(e)); + return glist2(e1,copy_list(cadr(e))); + return 0; +} + +extern int +copy_expr(int e) +{ + int smode = mode; + if (!car(e)) return 0; + if (car(e)<0) { + mode = GDECL; + switch (car(e)){ + case CONST: e=list2(car(e),cadr(e)); + case FCONST: + case DCONST: e=dlist2(car(e),dcadr(e)); + case LCONST: e=llist2(car(e),lcadr(e)); + case STRING: e=list3(car(e),cadr(e),caddr(e)); + case STRUCT: // for udpcl + e=glist3(car(e),copy_expr(cadr(e)),copy_expr(caddr(e))); + } + mode = smode; + return e; + } + switch (car(e)%SOP){ + // special cases + case ARROW: + case PERIOD: + return glist4(car(e),copy_expr(cadr(e)),caddr(e),cadddr(e)); + case ARRAY: + return glist5(car(e),copy_expr(cadr(e)),copy_expr(caddr(e)),cadddr(e),caddddr(e)); + case LVAR: case RLVAR: + case GVAR: case RGVAR: + return (e>=lfree)?glist3(car(e),cadr(e),caddr(e)):e; + case INDIRECT: case RINDIRECT: + return glist2(car(e),copy_expr(cadr(e))); + } + if (LIST_ARGS(car(e))){ + /* list arguments */ + return copy_list(caddr(e)); + } else if (UNARY_ARGS(car(e))) { + /* unary operators */ + e = glist2(car(e),copy_expr(cadr(e))); + return e; + } else if (BINARY_ARGS(car(e))) { + /* biary operators */ + e = glist3(car(e),copy_expr(cadr(e)),copy_expr(caddr(e))); + return e; + } else if (TERNARY_ARGS(car(e))||car(e)==STRUCT) { + /* ternary operators */ + e = glist4(car(e),copy_expr(cadr(e)), + copy_expr(caddr(e)), + copy_expr(cadddr(e))); + return e; + } else if (NULLARY_ARGS(car(e))) { + /* nullary operators */ + if (e>=lfree) { // local + int smode = mode; + switch(car(e)%SOP) { + case GVAR: case RGVAR: case URGVAR: + case LVAR: case RLVAR: case URLVAR: + case REGISTER: case FREGISTER: + case DREGISTER: case LREGISTER: + case STRING: + case IVAR: case RIVAR: + e = glist3(car(e),cadr(e),caddr(e)); break; + case CONST: + switch(car(e)) { + case CONST: + e = glist2(car(e),cadr(e)); break; + case DCONST: case FCONST: + mode=GDECL; + e = dlist2(car(e),dcadr(e)); mode = smode; break; + case LCONST: + mode=GDECL; + e = llist2(car(e),lcadr(e)); mode = smode; break; + } + break; + case LCALL: + case FNAME: + case LABEL: + e = glist2(car(e),cadr(e)); break; + case DECL: + case COMP: + // is this correct? + e = glist2(car(e),cadr(e)); break; + } + } + return e; + } else if (IS_STATEMENT(car(e))) { + // already in global heap + return e; // may contain anything + } else { + // fprintf(stderr,"Unknown Tree ID %d\n",car(e)); + error(-1); + return 0; + } + return 0; +} + #if ASM_CODE @@ -3787,7 +3959,7 @@ int type0; int e1; - if (inmode) { + if (inmode || chk) { e1 = list4(ind?ARROW:PERIOD,e,(int)nptr,type); } if (ind) e = indop(rvalue(e)); @@ -3802,7 +3974,7 @@ /* print_fields(caddr(type),"strop"); */ type = search_struct_type(type,nptr->nm,&dsp); if (!type) { error(TYERR); type=INT; return e; } - if (inmode) { + if (inmode || chk) { // bitfield will be checked after parse return e1; } else if(dsp) { @@ -4213,16 +4385,19 @@ return(e1); if (car(e)==CONST) { if(car(e1)==ADDRESS) { - if (car(cadr(e1))==GVAR) { + switch (car(cadr(e1))) { + case GVAR: return(list2(ADDRESS, list3(GVAR,cadr(cadr(e1))+cadr(e),caddr(cadr(e1))))); - } else if (car(cadr(e1))==LVAR) { + case LVAR: return(list2(ADDRESS, list3(car(cadr(e1)),cadr(cadr(e1))+cadr(e), caddr(cadr(e1))))); - } else if (car(cadr(e1))==INDIRECT) { + case INDIRECT: + case PERIOD: + case ARROW: return(list3(ADD,e1,e)); - } else { + default: error(-1); // ? } } else if(car(e1)==GVAR) {
--- a/mc-codegen.h Sat Feb 18 21:33:43 2006 +0900 +++ b/mc-codegen.h Thu Mar 16 17:03:24 2006 +0900 @@ -111,6 +111,7 @@ extern int b_expr(int e1, char cond, int l1,int err); extern int contains_p(int e,int (*p)(int)); extern int contains_p1(int arg,int e,int (*p)(int,int)); +extern int contains_p2(int arg,int e,int (*p)(int,int)); extern void fwddef(int l); extern int fwdlabel(void); extern int g_expr(int e1); @@ -137,4 +138,8 @@ extern NMTBL str_ret; +/* used by conv */ +extern int rop_dual(int op); +extern int copy_expr(int e); + /* end */
--- a/mc-inline.c Sat Feb 18 21:33:43 2006 +0900 +++ b/mc-inline.c Thu Mar 16 17:03:24 2006 +0900 @@ -399,7 +399,7 @@ if (nptr0->ty>0&&car(nptr0->ty)==FUNCTION) car(nptr0->ty)=CODE; } - gexpr(list3(CODE,e1,env),0); + gexpr(list3(JUMP,e1,env),0); control=0; // conv->sm_(); return ; @@ -815,7 +815,7 @@ switch(car(e1)) { case RINDIRECT: e1=pexpr(e1); break; case CODE: e2=pexpr(cadr(e1)); - e1=list3(CODE,e2,pexpr(caddr(e1))); break; + e1=list3(JUMP,e2,pexpr(caddr(e1))); break; case FLABEL: /* error(-1); */ break; case IVAR: lb = cadr(e1); @@ -943,7 +943,7 @@ return p_lvar(e1); case FUNCTION: return pfunction(e1); - case CODE: + case JUMP: e2 = pexpr(e2); return list3(car(e1),e2,pexpr(cadddr(e1))); case ARRAY:
--- a/mc-macro.c Sat Feb 18 21:33:43 2006 +0900 +++ b/mc-macro.c Thu Mar 16 17:03:24 2006 +0900 @@ -312,6 +312,7 @@ int i; int c; char num[10]; + char *p; if (next_eof) { next_eof=0; @@ -335,6 +336,16 @@ i=0; while ((*chptr++ = c = getc(filep->fcb)) != '\n') { if (++i > LBUFSIZE-2) error(LNERR); + if (c=='\r') { + c = getc(filep->fcb); + if (c == '\n') { + chptr[-1]='\n'; break; + } else { + // single cr equal to nl + ungetc(c,filep->fcb); + chptr[-1]=c='\n'; i--; break; + } + } if (c==EOF) { next_eof=1; --chptr; @@ -349,7 +360,6 @@ // inline mode int i=0; int c; - char *p; // should be done in some init if (!st_cheap) { st_cheap = cheap1 = new_cheap(); @@ -377,7 +387,9 @@ } } } - if (*(chptr = linebuf) == '#' && !in_comment && !in_quote) { + p = chptr = linebuf; while(*p==' '||*p=='\t') p++; + if (*p == '#' && !in_comment && !in_quote) { + chptr = p; if (macro_processing()) return; } } while(!in_quote && (macro_if_skip || linebuf[0] == '#')); @@ -549,10 +561,16 @@ return 0; } break; + case 'p': + if (macroeq("pragma")) { + getline(); + return 0; + } + break; #if ASM_CODE // deprecated, use asm function case 'a': - if (c=='a'&¯oeq("asm")) { + if (macroeq("asm")) { if (asmf) error(MCERR); asmf = 1; getline(); @@ -571,7 +589,7 @@ } break; #endif - case ' ': case '\t': + case ' ': case '\t': case '\n': case 0: getline(); return 0; } @@ -925,12 +943,12 @@ *result = cheap->ptr; for(;lists;lists = cadr(lists)) { p = (char *)car(lists); - for(;(*cheap->ptr=*p++);cheap = increment_cheap(cheap,0)) { + for(;(*cheap->ptr = *p++);cheap = increment_cheap(cheap,result)) { // in_quote + \n case ? should be \n. if (p[-1]=='\n') cheap->ptr[0]=' '; } } - cheap = increment_cheap(cheap,0); + cheap = increment_cheap(cheap,result); return *result; } @@ -942,12 +960,12 @@ *result = cheap->ptr; for(;lists;lists = cadr(lists)) { p = (char *)car(lists); - for(;(*cheap->ptr=*p++);cheap = increment_cheap(cheap,0)) { + for(;(*cheap->ptr=*p++);cheap = increment_cheap(cheap,result)) { // in_quote + \n case ? should be \n. // if (p[-1]=='\n') cheap->ptr[0]=' '; } } - cheap = increment_cheap(cheap,0); + cheap = increment_cheap(cheap,result); return *result; }
--- a/mc-parse.c Sat Feb 18 21:33:43 2006 +0900 +++ b/mc-parse.c Thu Mar 16 17:03:24 2006 +0900 @@ -33,6 +33,8 @@ #include "mc-inline.h" #include "conv/conv.h" +extern Converter *conv; + #define FILES 10 #define OUTPUT_FILE_NAME "mcout.s" @@ -205,7 +207,7 @@ static int sdecl_f = 1; // in struct defenition (for converter) static int stypedecl; // in type defenition (for converter) -static Converter *conv = &null_converter; +Converter *conv = &null_converter; /* Converter *conv = &c_converter; */ static char *ccout = 0; // output file name @@ -591,7 +593,10 @@ reserve("extern",EXTRN); reserve("defined",DEFINED); reserve("register",REGISTER); +#ifdef USE_CODE_KEYWORD reserve("code",CODE); +#endif + reserve("__code__",CODE); reserve("environment",ENVIRONMENT); reserve("float",FLOAT); reserve("double",DOUBLE); @@ -606,6 +611,7 @@ reserve("__builtin_constant_p",BUILTINP); reserve("__builtin_expect",BUILTIN_EXPECT); reserve("__attribute__",ATTRIBUTE); + reserve("__attribute",ATTRIBUTE); reserve("__label__",LABEL); reserve("__FILE__",C_FILE); reserve("__FUNCTION__",C_FUNCTION); @@ -730,13 +736,14 @@ while((*cheap->ptr = *s++)) cheap = increment_cheap(cheap,&filep->name0); *cheap->ptr = 0; cheap = increment_cheap(cheap,&filep->name0); - if(!ccout) { + conv->open_(filep->name0); + + if(!ccout && !chk) { ccout = make_filename_with_extension(filep->name0,"s"); if ( (freopen(ccout,"w",stdout)) == NULL ) error(FILERR); ccout=0; } opening(filep->name0); - conv->open_(filep->name0); if (init_src) { // before reading any file, perform initialization source @@ -868,6 +875,7 @@ conv->return_type_(t,0,stypedecl); conv->sm_(); return; } + storage_class(); type=t;sd=stypedecl; n=decl0(); reverse(t); @@ -2200,6 +2208,8 @@ doif(void) { int l1,l2=0,slfree,pparse=0; + int if0; + getsym(0); checksym(LPAR); conv->if_(); @@ -2207,12 +2217,12 @@ checkret(); if (inmode) { pparse = parse; parse = 0; - l1 = expr(0); + l1 = if0 = expr(0); } else { - l1 = bexpr(expr(0),0,fwdlabel()); + l1 = bexpr((if0 = expr(0)),0,fwdlabel()); } set_lfree(slfree); - conv->if_then_(); + conv->if_then_(if0); checksym(RPAR); statement(0); checkret(); @@ -2267,7 +2277,7 @@ slfree=lfree; e=expr(0); checksym(RPAR); - conv->while_body_(); + conv->while_body_(e); if(sym==SM) { if (inmode) { parse = list4(ST_WHILE,pparse,e,0); @@ -2332,11 +2342,11 @@ e = expr(0); parse = list4(ST_DO,pparse,e,l); } else { - bexpr(expr(0),1,l); + bexpr((e=expr(0)),1,l); } + conv->dowhile_end_(e); set_lfree(slfree); checksym(RPAR); - conv->dowhile_end_(); checksym(SM); if (!inmode) fwddef(blabel); @@ -2377,7 +2387,11 @@ decl(); mode=STAT; checkret(); - emit_init_vars(); + if (chk) { + p0 = list3(ST_COMP,reverse0(init_vars),0); + } else { + emit_init_vars(); + } if (inmode) { p0 = reverse0(parse); parse = 0; } @@ -2408,31 +2422,29 @@ if (inmode) { p1 = expr(0); } else { - bexpr(expr(0),0,blabel); + bexpr((p1=expr(0)),0,blabel); } checksym(SM); - conv->for2_(); + conv->for2_(p1); } else { - conv->for2_(); + conv->for2_(0); p1 = 0; getsym(0); } set_lfree(slfree); + e = 0; if(sym==RPAR) { // no continue expression clabel=l; - conv->for_body_(); + conv->for_body_(0); getsym(0); statement(0); checkret(); - if (inmode) { - e = 0; - } } else { // continue expression clabel=fwdlabel(); e=expr(0); - conv->for_body_(); + conv->for_body_(e); checksym(RPAR); statement(0); checkret(); @@ -2442,9 +2454,8 @@ } set_lfree(slfree); } - lfree_type_limit = slimit ; + conv->for_end_(p0,p1,e); if (dflag) leave_scope(); - conv->for_end_(); if (inmode) { parse = list3(ST_FOR,pparse,list4(p0,p1,e,reverse0(parse))); // parse = list3(ST_FOR,pparse,list4(p0,p1,e,parse)); @@ -2452,6 +2463,7 @@ gen_jmp(l); fwddef(blabel); } + lfree_type_limit = slimit ; clabel=scontinue; blabel=sbreak; init_vars=sinit_vars; @@ -2544,14 +2556,14 @@ csvalue1=cst ? glist2(CONST,cadr(v)): csvalue() ; set_lfree(slfree); checksym(RPAR); - conv->switch_body_(); + conv->switch_body_(v); if (cst) { gen_jmp( cslabel = fwdlabel()); } else { cslabel = control = 0; } } else { - conv->switch_body_(); + conv->switch_body_(v); checksym(RPAR); } /* next syntax should be a case statement but... @@ -2568,7 +2580,7 @@ Can be done in checkret(); */ statement(0); - conv->switch_end_(); + conv->switch_end_(cslist); checkret(); if (inmode) { parse = list4(ST_SWITCH,pparse,v,reverse0(parse)); @@ -2780,7 +2792,7 @@ if(getsym(0)==SM) { // should check fnptr have no return value conv->return_(); - conv->return_end_(); + conv->return_end_(0); getsym(0); if (inmode) parse = list3(ST_RETURN,parse,0); @@ -2822,12 +2834,12 @@ e = correct_type(expr(0),cadr(fnptr->ty)); parse = list3(ST_RETURN,parse,e); } else { - gexpr(correct_type(expr(0),cadr(fnptr->ty)),1); + gexpr(correct_type((e=expr(0)),cadr(fnptr->ty)),1); } } + conv->return_end_(e); set_lfree(slfree); - conv->return_end_(); checksym(SM); /* control = 0; still control continue until pending return emission */ retpending = 1; @@ -2851,9 +2863,9 @@ // car(nptr0->ty)=CODE; } if (inmode) { - parse = list3(ST_GOTO,parse,list3(CODE,e1,env)); + parse = list3(ST_GOTO,parse,list3(JUMP,e1,env)); } else { - gexpr(list3(CODE,e1,env),0); + gexpr(list3(JUMP,e1,env),0); } control=0; conv->sm_(); @@ -3346,6 +3358,9 @@ case REGISTER: case GVAR: case LVAR: + case ARRAY: + case ARROW: + case PERIOD: e=list2(ADDRESS,e); break; case IVAR: @@ -3833,7 +3848,7 @@ e2=rvalue(expr0()); checksym(RBRA); conv->rbra_(sym); - if (inmode) { + if (inmode || chk) { e1 = list5(ARRAY,e1,e2,t,type); if (car(t)!=POINTER) error(-1); @@ -3954,7 +3969,7 @@ error(AGERR); } checksym(RPAR); - conv->funcall_args_(); + conv->funcall_args_(e1,ftype,arglist); if(t==CODE) { if (stmode!=GOTO) error(FNERR); // code segment has no return type @@ -4481,6 +4496,10 @@ } if ((nptrm->sc==MACRO&&neqname((char *)car(nptrm->dsp),nptrm->nm)) || (nptrm->sc==FMACRO&&skipspc()=='(')) { + if (in_macro_if && *((char*)car(nptrm->dsp))==0) { + symval = 0; + return (sym=CONST); + } macro_expansion(nptrm); sc=0; goto retry; } @@ -4807,7 +4826,7 @@ car(current_scope) = 0; } -extern void +extern NMTBL * extern_define(char *s,int d,int type,int use) { NMTBL *nptr0; @@ -4815,6 +4834,7 @@ (nptr0 = name_space_search(get_name(s,0,DEF),0))->sc = EXTRN; nptr0->dsp = d; nptr0->ty=type; if (use) extrn_use(nptr0); + return nptr0; } /* @@ -5101,6 +5121,21 @@ return ret; } +extern int +glist5(int e1,int e2,int e3,int e4,int e5) +{ + int ret; + ret = gfree; + gfree+=4 ; + heap[ret]=e1; + heap[ret+1]=e2; + heap[ret+2]=e3; + heap[ret+3]=e4; + heap[ret+4]=e5; + if(lfree<gfree) error(HPERR); + return ret; +} + extern void free_glist3(int e1) {
--- a/mc-parse.h Sat Feb 18 21:33:43 2006 +0900 +++ b/mc-parse.h Thu Mar 16 17:03:24 2006 +0900 @@ -129,13 +129,14 @@ extern int glist2(int e1,int e2); extern int glist3(int e1,int e2,int e3); extern int glist4(int e1,int e2,int e3,int e4); +extern int glist5(int e1,int e2,int e3,int e4,int e5); extern int insert_ascend(int p,int e,int eq()); extern int length(int list); extern int list2(int e1, int e2); extern int list3(int e1, int e2, int e3); extern int list4(int e1, int e2, int e3, int e4); -extern void extern_define(char *s,int d,int type,int use); +extern NMTBL * extern_define(char *s,int d,int type,int use); extern void set_lfree(int save); extern int has_attr(NMTBL *n,int attr);
--- a/mc-switch.c Sat Feb 18 21:33:43 2006 +0900 +++ b/mc-switch.c Thu Mar 16 17:03:24 2006 +0900 @@ -188,10 +188,12 @@ int list; for(;count-->0;cslist=cadr(cslist)) { list = car(cslist); +#ifdef DEBUG_MERGE printf("## cascade cases delta=%d count=%d min=%d max=%d\n", caddr(cslist),car(cadddr(cslist)), cadr(cadddr(cslist)),caddr(cadddr(cslist)) ); +#endif for(;list; list=cadr(list)) { if (caddr(list)) cmpdimm(car(list),csvalue1,caddr(list),0); @@ -320,8 +322,10 @@ { control=1; for(;count-- !=0 && merge;merge=cadr(merge)) { +#ifdef DEBUG_MERGE printf("## merge count %d delta %d c_count %d\n", car(merge),caddr(merge),cadddr(merge)); +#endif if (cadddr(merge)>CASE_TABLE_COUNT) { chunks = table_jump(car(merge),caddr(merge),chunks); } else {
--- a/mc-tree.c Sat Feb 18 21:33:43 2006 +0900 +++ b/mc-tree.c Thu Mar 16 17:03:24 2006 +0900 @@ -53,12 +53,14 @@ {ENVIRONMENT,"environment",""}, {CODE,"code",""}, {REGISTER,"register",""}, + {ASM,"__asm__",""}, {VOID,"void",""}, {EXTRN,"extern",""}, {SHORT,"short",""}, {USHORT,"unsigned short",""}, {LONG,"long",""}, {TYPE,"type",""}, + {VOLATILE,"volatile",""}, {SIZEOF,"sizeof",""}, {TYPEDEF,"typedef",""}, {FLABEL,"flabel",""}, @@ -70,7 +72,7 @@ {TAG,"tag",""}, {RESERVE,"reserve",""}, {DEFAULT,"default",""}, - {ATTRIBUTE,"attribute",""}, + {ATTRIBUTE,"__attribute__",""}, {CASE,"case",""}, {SWITCH,"switch",""}, {WHILE,"while",""}, @@ -464,4 +466,129 @@ type_print1(type,n,out,0); } +/* + parse tree 医激 + + 罩c綣с篁≪眼冴筝... + 茯帥篏ゅャ綽荀 + */ + +void +print_expr(int e, FILE *vout) +{ + NMTBL *nptr,*n; + + switch (car(e)%SOP) { + case LVAR: + case RLVAR: + if ((nptr = (NMTBL*)caddr(e))) { + fprintf(vout,"%s",nptr->nm); + } else { + // anonymous variable + fprintf(vout,"_%d",caddr(e)); + } + break; + case GVAR: + case RGVAR: + if ((nptr = (NMTBL*)caddr(e))) { + fprintf(vout,"%s",nptr->nm); + } else { + // anonymous variable + fprintf(vout,"_%d",caddr(e)); + } + if (cadr(e)) { + // offset + // certainly this is wrong + fprintf(vout,"+%d",caddr(e)); + } + break; + case REGISTER: + if ((nptr = (NMTBL*)caddr(e))) { + fprintf(vout,"%s",nptr->nm); + } else { + // anonymous register variable + fprintf(vout,"_%d",caddr(e)); + } + break; + case IDENT: + nptr = (NMTBL*)cadr(e); + fprintf(vout,"%s",nptr->nm); break; + case CONST: + switch(car(e)) { + case CONST: + fprintf(vout,"%d",cadr(e)); break; +#if FLOAT_CODE + case FCONST: + fprintf(vout,"%g",dcadr(e)); break; + case DCONST: + fprintf(vout,"%g",dcadr(e)); break; +#endif +#if LONGLONG_CODE + case LCONST: + fprintf(vout,"%lld",lcadr(e)); break; +#endif + } + break; + case ADDRESS: + if (car(cadr(e))!=STRING) { + fprintf(vout,"&"); + print_expr(cadr(e),vout); + break; + } + case STRING: + { + nptr = (NMTBL*)cadr(e); + int c; char *s = nptr->nm; int i=nptr->dsp; + fprintf(vout,"\""); + while(--i>0) { + 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,"\""); + } + break; + case ARRAY: + print_expr(cadr(e),vout); + fprintf(vout,"["); + print_expr(caddr(e),vout); + fprintf(vout,"]"); + break; + case PERIOD: + print_expr(cadr(e),vout); + n = (NMTBL*)caddr(e); + fprintf(vout,".%s",n->nm); + break; + case ARROW: + print_expr(cadr(e),vout); + n = (NMTBL*)caddr(e); + fprintf(vout,"->%s",n->nm); + break; + case INDIRECT: + case RINDIRECT: + fprintf(vout,"*"); + print_expr(cadr(e),vout); + break; + case FNAME: + n = (NMTBL*)cadr(e); + fprintf(vout,"%s",n->nm); + break; + case ADD: + fprintf(vout,"("); + print_expr(cadr(e),vout); + fprintf(vout,"+"); + print_expr(caddr(e),vout); + fprintf(vout,")"); + break; + default: + error(-1); + } +} + /* end */
--- a/mc.h Sat Feb 18 21:33:43 2006 +0900 +++ b/mc.h Thu Mar 16 17:03:24 2006 +0900 @@ -68,46 +68,47 @@ #define FREGISTER (-29) #define DREGISTER (-30) #define LREGISTER (-31) +#define POSSIBLE_VALUES (-32) -#define DOTS (-32) +#define DOTS (-33) /* keyword */ -#define GOTO (-33) -#define RETURN (-34) -#define BREAK (-35) -#define CONTINUE (-36) -#define IF (-37) -#define ELSE (-38) -#define FOR (-39) -#define DO (-40) -#define WHILE (-41) -#define SWITCH (-42) -#define CASE (-43) -#define DEFAULT (-44) -#define RESERVE (-45) -#define TAG (-46) -#define FIELD (-47) -#define IDENT (-48) -#define MACRO (-49) -#define BLABEL (-50) -#define FLABEL (-51) -#define TYPEDEF (-52) -#define SIZEOF (-53) -#define TYPE (-54) -#define DEFINED (-55) +#define GOTO (-34) +#define RETURN (-35) +#define BREAK (-36) +#define CONTINUE (-37) +#define IF (-38) +#define ELSE (-39) +#define FOR (-40) +#define DO (-41) +#define WHILE (-42) +#define SWITCH (-43) +#define CASE (-44) +#define DEFAULT (-45) +#define RESERVE (-46) +#define TAG (-47) +#define FIELD (-48) +#define IDENT (-49) +#define MACRO (-50) +#define BLABEL (-51) +#define FLABEL (-52) +#define TYPEDEF (-53) +#define SIZEOF (-54) +#define TYPE (-55) +#define DEFINED (-56) -#define ENVIRONMENT (-56) +#define ENVIRONMENT (-57) -#define FMACRO (-57) -#define LMACRO (-58) +#define FMACRO (-58) +#define LMACRO (-59) -#define TYPEOF (-59) -#define ASM (-60) +#define TYPEOF (-60) +#define ASM (-61) -#define C_FILE (-61) -#define C_FUNCTION (-62) -#define C_LINE (-63) +#define C_FILE (-62) +#define C_FUNCTION (-63) +#define C_LINE (-64) /* reserved word end */ @@ -196,15 +197,17 @@ #define LNOT 19 #define BNOT 20 #define INC 21 -#define POSTINC 22 -#define UPOSTINC 23 -#define PREINC 24 -#define UPREINC 25 -#define POSTDEC 26 -#define UPOSTDEC 27 -#define PREDEC 28 -#define UPREDEC 29 -#define DEC 30 +#define PERIOD 22 +#define ARROW 23 +#define POSTINC 24 +#define UPOSTINC 25 +#define PREINC 26 +#define UPREINC 27 +#define POSTDEC 28 +#define UPOSTDEC 29 +#define PREDEC 30 +#define UPREDEC 31 +#define DEC 32 #define CPOSTINC (COP+POSTINC) #define CUPOSTINC (COP+UPOSTINC) #define CPREINC (COP+PREINC) @@ -229,9 +232,9 @@ #define LPREINC (LOP+PREINC) #define LUPOSTINC (LOP+UPOSTINC) #define LUPREINC (LOP+UPREINC) -#define INDIRECT 31 -#define RINDIRECT 32 -#define URINDIRECT 33 +#define INDIRECT 33 +#define RINDIRECT 34 +#define URINDIRECT 35 #define CRINDIRECT (COP+RINDIRECT) #define CURINDIRECT (COP+URINDIRECT) #define SRINDIRECT (SOP+RINDIRECT) @@ -240,17 +243,15 @@ #define DRINDIRECT (DOP+RINDIRECT) #define LRINDIRECT (LOP+RINDIRECT) #define LURINDIRECT (LOP+URINDIRECT) -#define RSTRUCT 34 -#define ALLOCA 35 -#define BUILTINP 36 -#define BUILTIN_EXPECT 37 -#define ATTRIBUTE 38 -#define BIT_FIELD 39 -#define RBIT_FIELD 40 -#define BPREINC 41 -#define BPOSTINC 42 -#define RPERIOD 43 -#define RARROW 44 +#define RSTRUCT 36 +#define ALLOCA 37 +#define BUILTINP 38 +#define BUILTIN_EXPECT 39 +#define ATTRIBUTE 40 +#define BIT_FIELD 41 +#define RBIT_FIELD 42 +#define BPREINC 43 +#define BPOSTINC 44 #define CONV 45 #define UNARY_ARGS(i) (ADDRESS<=(i%SOP)&&(i%SOP)<=CONV) @@ -356,15 +357,17 @@ #define BASSOP 86 #define BFD_REPL 87 -#define STASS 88 +#define JUMP 88 + +#define STASS 89 -#define BINARY_ARGS(i) (MUL<=(i%SOP)&&(i%SOP)<=STASS) +#define BINARY_ARGS(i) ((MUL<=(i%SOP)&&(i%SOP)<=STASS)) -/* tarnary argments */ +/* ternary argments */ -#define COND 89 -#define UCOND 90 +#define COND 90 +#define UCOND 91 #define SCOND (SOP+COND) #define SUCOND (SOP+UCOND) #define DCOND (DOP+COND) @@ -372,39 +375,37 @@ #define LCOND (LOP+COND) #define LUCOND (LOP+UCOND) -#define TARNARY_ARGS(i) (COND==(i%SOP)||UCOND==(i%SOP)) +#define TERNARY_ARGS(i) (COND==(i%SOP)||UCOND==(i%SOP)) /* not appeared as tags */ -#define LPAR 91 -#define RPAR 92 -#define LBRA 93 -#define RBRA 94 -#define LC 95 -#define RC 96 -#define COLON 97 -#define SM 98 -#define PERIOD 99 -#define ARROW 100 -#define CNAME 101 +#define LPAR 92 +#define RPAR 93 +#define LBRA 94 +#define RBRA 95 +#define LC 96 +#define RC 97 +#define COLON 98 +#define SM 99 +#define CNAME 100 -#define I2C 102 -#define I2S 103 -#define I2I 104 -#define I2U 105 -#define I2D 106 -#define I2F 107 -#define I2LL 108 -#define I2ULL 109 +#define I2C 101 +#define I2S 102 +#define I2I 103 +#define I2U 104 +#define I2D 105 +#define I2F 106 +#define I2LL 107 +#define I2ULL 108 -#define U2UC 110 -#define U2US 111 -#define U2I 112 -#define U2U 113 -#define U2D 114 -#define U2F 115 -#define U2LL 116 -#define U2ULL 117 +#define U2UC 109 +#define U2US 110 +#define U2I 111 +#define U2U 112 +#define U2D 113 +#define U2F 114 +#define U2LL 115 +#define U2ULL 116 #define D2I (DOP+I2I) @@ -439,27 +440,27 @@ /* statement start */ -#define ST_DECL 118 -#define ST_IF 119 -#define ST_DO 120 -#define ST_WHILE 121 -#define ST_FOR 122 -#define ST_SWITCH 123 -#define ST_COMP 124 -#define ST_BREAK 125 -#define ST_CONTINUE 126 -#define ST_CASE 127 -#define ST_DEFAULT 128 -#define ST_RETURN 129 -#define ST_GOTO 130 -#define ST_ASM 131 -#define ST_LABEL 132 -#define ST_OP 133 -#define ST_COMMENT 134 +#define ST_DECL 117 +#define ST_IF 118 +#define ST_DO 119 +#define ST_WHILE 120 +#define ST_FOR 121 +#define ST_SWITCH 122 +#define ST_COMP 123 +#define ST_BREAK 124 +#define ST_CONTINUE 125 +#define ST_CASE 126 +#define ST_DEFAULT 127 +#define ST_RETURN 128 +#define ST_GOTO 129 +#define ST_ASM 130 +#define ST_LABEL 131 +#define ST_OP 132 +#define ST_COMMENT 133 #define IS_STATEMENT(i) (i==INLINE||(ST_DECL<=i&&i<=ST_COMMENT)) -#define HAS_ADDRESS 135 +#define HAS_ADDRESS 134 /* statement end */ @@ -515,9 +516,10 @@ #define MAX_INCLUDE_PATH_COUNT 10 /* For this comiler 8192*2 is Ok. Linux kernel requires 8192*4. + we need automatic increment of gsyms? */ -#define GSYMS (8192*4) -#define HEAPSIZE 30000 +#define GSYMS (8192*32) +#define HEAPSIZE 120000 #define CHEAPSIZE (sizeof(NMTBL)*8192) #define LBUFSIZE 4096 #define STRSIZE 4096 @@ -553,6 +555,10 @@ extern void free_nptr(NMTBL *n); extern NMTBL *get_nptr(); +// mc-tree.c + +extern void print_expr(int e, FILE *vout); + #if 1 extern int heapsize; #define CHECK_HEAP(b) ({int _k=(int)(b);if(_k>heapsize||_k<0)error(-1);_k;})