Mercurial > hg > CbC > old > device
changeset 446:6654aa80851b
fix array pointer in decl_data and cast
author | kono |
---|---|
date | Mon, 22 Nov 2004 14:53:28 +0900 |
parents | 5ec2a88b9f4d |
children | 818505dd6e1f |
files | Changes Makefile.linuxzaurus Makefile.mips mc-code-arm.c mc-code-ia32.c mc-codegen.c mc-parse.c rsyncs |
diffstat | 8 files changed, 104 insertions(+), 112 deletions(-) [+] |
line wrap: on
line diff
--- a/Changes Sun Nov 21 19:20:18 2004 +0900 +++ b/Changes Mon Nov 22 14:53:28 2004 +0900 @@ -6718,3 +6718,28 @@ どこ? dsp? attr? address の引き算が間違ってる。 + +定数は .literal4 っていうのに割り振られるみたいね。 + +l.c がlocal typeの爆撃で壊れている。list3 にしたからだろうな。 + +macro.c に signed char の依存性がある? + +size_t に関しては少し調べた方がいいんじゃないの? + +## struct temp temp3 = { +## .c = (int)&b, +## .d = -10, +## .a = (int)b +## }; +.globl _temp3 +_temp3: + .long 0 はぁ? + .space 4 + .long 59997 + .long -10 + space は? +## +## + +いろいろあるな。
--- a/Makefile.linuxzaurus Sun Nov 21 19:20:18 2004 +0900 +++ b/Makefile.linuxzaurus Mon Nov 22 14:53:28 2004 +0900 @@ -5,6 +5,7 @@ # LDFLAGS = -pg # for Linux Zaurus CFLAGS = -fsigned-char -pipe -g -I. -I/home/zaurus/develop/include +CFLAGS1 = -g -I. -fsigned-char BASE=0 STAGE=1 MFLAGS=$(MFALGS) BASE=$(BASE) STAGE=$(STAGE) @@ -110,7 +111,7 @@ make check-code$(MK) TARGET=test/scope check-nkf: - ( cd nkf203; $(CC) -g -o nkf1 nkf.c utf8tbl.c ) + ( cd nkf203; $(CC) $(CFLAGS) $(CFLAGS1) -g -o nkf1 nkf.c utf8tbl.c ) ( cd nkf203; ../mc-$(ARCH) -s nkf.c utf8tbl.c ) ( cd nkf203; $(CC) -g -o nkf nkf.s utf8tbl.s ) ( cd nkf203; perl test.pl ) @@ -118,7 +119,7 @@ # -./$(MC) -Itest/ -s $(TARGET).c check: $(MC) $(TARGET).c - -gcc $(CFLAGS) $(STDFLAG) $(TARGET).c -o b.out $(MLIB) + -gcc $(CFLAGS1) $(STDFLAG) $(TARGET).c -o b.out $(MLIB) -./b.out > $(TARGET).gcc.out -./$(MC) -s $(TARGET).c -gcc $(TARGET).s $(MLIB) @@ -216,3 +217,5 @@ -diff b04.s b24.s +# DO NOT DELETE +
--- a/Makefile.mips Sun Nov 21 19:20:18 2004 +0900 +++ b/Makefile.mips Mon Nov 22 14:53:28 2004 +0900 @@ -5,6 +5,7 @@ # LDFLAGS = -pg # for Linux Zaurus # CFLAGS = -fsigned-char -pipe -g -I. -I/home/zaurus/develop/include +CFLAGS1 = -g -I. BASE=0 STAGE=1 MFLAGS=$(MFALGS) BASE=$(BASE) STAGE=$(STAGE) @@ -118,7 +119,7 @@ # -./$(MC) -Itest/ -s $(TARGET).c check: $(MC) $(TARGET).c - -gcc $(STDFLAG) $(TARGET).c -o b.out $(MLIB) + -gcc $(CFLAGS1) $(STDFLAG) $(TARGET).c -o b.out $(MLIB) -./b.out > $(TARGET).gcc.out -./$(MC) -s $(TARGET).c -gcc $(TARGET).s $(MLIB) @@ -216,67 +217,3 @@ -diff b04.s b24.s -# DO NOT DELETE - -mc-code-ia32.o: /usr/include/stdio.h /usr/include/sys/types.h -mc-code-ia32.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h -mc-code-ia32.o: /usr/include/machine/types.h /usr/include/ppc/types.h -mc-code-ia32.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h -mc-code-ia32.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h mc.h -mc-code-ia32.o: mc-parse.h mc-codegen.h mc-code.h -mc-codegen.o: /usr/include/stdio.h /usr/include/sys/types.h -mc-codegen.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h -mc-codegen.o: /usr/include/machine/types.h /usr/include/ppc/types.h -mc-codegen.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h -mc-codegen.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h mc.h -mc-codegen.o: mc-parse.h mc-codegen.h mc-code.h -mc-parse.o: /usr/include/stdio.h /usr/include/sys/types.h -mc-parse.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h -mc-parse.o: /usr/include/machine/types.h /usr/include/ppc/types.h -mc-parse.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h -mc-parse.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h mc.h -mc-parse.o: mc-parse.h mc-codegen.h mc-switch.h mc-macro.h conv/conv.h -mc-tree.o: /usr/include/stdio.h /usr/include/sys/types.h -mc-tree.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h -mc-tree.o: /usr/include/machine/types.h /usr/include/ppc/types.h -mc-tree.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h -mc-tree.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h mc.h -mc-tree.o: mc-parse.h -mc-switch.o: /usr/include/stdio.h /usr/include/sys/types.h -mc-switch.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h -mc-switch.o: /usr/include/machine/types.h /usr/include/ppc/types.h -mc-switch.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h -mc-switch.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h mc.h -mc-switch.o: mc-parse.h mc-codegen.h mc-code.h -mc-macro.o: /usr/include/stdio.h /usr/include/sys/types.h -mc-macro.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h -mc-macro.o: /usr/include/machine/types.h /usr/include/ppc/types.h -mc-macro.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h -mc-macro.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h mc.h -mc-macro.o: mc-parse.h mc-macro.h mc-code.h -conv/c.o: /usr/include/stdio.h /usr/include/sys/types.h -conv/c.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h -conv/c.o: /usr/include/machine/types.h /usr/include/ppc/types.h -conv/c.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h -conv/c.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h mc.h -conv/c.o: mc-parse.h conv/conv.h conv/convdef.h conv/c.h -conv/c2cbc.o: mc.h -conv/cbc2c.o: mc.h -conv/null.o: /usr/include/stdio.h /usr/include/sys/types.h -conv/null.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h -conv/null.o: /usr/include/machine/types.h /usr/include/ppc/types.h -conv/null.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h -conv/null.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h mc.h -conv/null.o: mc-parse.h conv/conv.h conv/convdef.h conv/null.h -mc-code-powerpc.o: /usr/include/stdio.h /usr/include/sys/types.h -mc-code-powerpc.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h -mc-code-powerpc.o: /usr/include/machine/types.h /usr/include/ppc/types.h -mc-code-powerpc.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h -mc-code-powerpc.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h -mc-code-powerpc.o: mc.h mc-parse.h mc-code.h mc-codegen.h -mc-code-mips.o: /usr/include/stdio.h /usr/include/sys/types.h -mc-code-mips.o: /usr/include/sys/appleapiopts.h /usr/include/sys/cdefs.h -mc-code-mips.o: /usr/include/machine/types.h /usr/include/ppc/types.h -mc-code-mips.o: /usr/include/machine/ansi.h /usr/include/ppc/ansi.h -mc-code-mips.o: /usr/include/machine/endian.h /usr/include/ppc/endian.h mc.h -mc-code-mips.o: mc-parse.h mc-code.h mc-codegen.h
--- a/mc-code-arm.c Sun Nov 21 19:20:18 2004 +0900 +++ b/mc-code-arm.c Mon Nov 22 14:53:28 2004 +0900 @@ -2628,7 +2628,7 @@ // half register case writes *(sp-1) but it will be Ok. if (max_func_args<4) max_func_args=4; g_expr_u(assign_expr0(list3(REGISTER,4,0), - list3(LVAR,caller_arg_offset_v(3)),INT,INT),0); + list3(LVAR,caller_arg_offset_v(3),0),INT,INT)); use_input_reg(4,1); } nargs = reg_arg = freg_arg = 0;
--- a/mc-code-ia32.c Sun Nov 21 19:20:18 2004 +0900 +++ b/mc-code-ia32.c Mon Nov 22 14:53:28 2004 +0900 @@ -548,6 +548,7 @@ stack_depth = 0; text_mode(); gexpr_code_init(); + regs[creg]=1; regv[creg]=1; register_usage("gexpr_init"); } @@ -1248,6 +1249,9 @@ if(scalar(t)) { if (car(e4)==REGISTER) { printf("\tpushl %s\n",register_name(cadr(e4),0)); + } else if (car(e4)==CONST) { + use_int0(); + printf("\tpushl $%d\n",cadr(e4)); } else { g_expr(e4); printf("\tpushl %s\n",register_name(creg,0)); @@ -1255,7 +1259,12 @@ stack_depth += SIZE_OF_INT; } else if (t==LONGLONG||t==ULONGLONG) { if (car(e4)==LREGISTER) { - printf("\tpushl %s\n\tpushl %s\n",l_edx(cadr(e4)),l_eax(cadr(e4))); + printf("\tpushl %s\n\tpushl %s\n", + l_edx(cadr(e4)),l_eax(cadr(e4))); + } else if (car(e4)==LCONST) { + use_longlong0(USE_CREG); + printf("\tpushl $%d\n\tpushl $%d\n", + code_l2(lcadr(e4)),code_l1(lcadr(e4))); } else { g_expr(e4); printf("\tpushl %%edx\n\tpushl %%eax\n"); @@ -2537,7 +2546,7 @@ int pop_fregister() { if (freg_sp<0) { error(-1); return -1;} - printf("# fpop: %d\n",freg_sp-1); + // printf("# fpop: %d\n",freg_sp-1); return freg_stack[--freg_sp]; } @@ -2566,7 +2575,7 @@ if (freg_sp>=MAX_FPU_STACK) code_save_fstacks(); if (freg_sp>MAX_MAX) error(-1); freg_stack[freg_sp++]=-1; - printf("# fpush:%d\n",freg_sp); + // printf("# fpush:%d\n",freg_sp); } #endif
--- a/mc-codegen.c Sun Nov 21 19:20:18 2004 +0900 +++ b/mc-codegen.c Mon Nov 22 14:53:28 2004 +0900 @@ -91,11 +91,6 @@ if (chk) return INT; gexpr_init(); use = use0; -#if 0 - if(lineno==2862) { - return g_expr0(e1); /*break here*/ - } -#endif return g_expr0(e1); } @@ -2720,6 +2715,13 @@ { int ass,sz,bfd; + if (car(e)==ADDRESS||car(e)==GVAR) { + if (scalar(t)) { + t = list2(POINTER,VOID); // fake + } else { + error(TYERR); + } + } if(mode==GDECL) { emit_data(e,t,n); } else if(mode==STADECL) { @@ -3549,31 +3551,44 @@ extern int correct_type(int e,int t) { - int t1; /* e = rvalue(e); */ #if BIT_FIELD_CODE if (type==BIT_FIELD) e = rvalue(e); #endif - if (type==FLOAT && t==DOTS) { t=DOUBLE;} // fall thru - if (type==CHAR && t==DOTS) { t=INT;} // fall thru - if (t==DOTS) return e; - else if (t==UNSIGNED) e = unsigned_value(e); - else if (t==CHAR) { e = char_value(e); t = INT; } - else if (t==UCHAR) { e = uchar_value(e); t = UNSIGNED; } - else if (t==SHORT) { e = short_value(e); t = INT; } - else if (t==USHORT) { e = ushort_value(e); t = UNSIGNED; } - else if (integral(t)) e = int_value(e); + if (t==DOTS) { + if (type==FLOAT) t=DOUBLE; + else if (type==CHAR) t=INT; + else if (type==UCHAR) t=UNSIGNED; + } + if (type>0 && car(type)==ARRAY && car(e)==GVAR) { + e=list2(ADDRESS,e); + } + if (t>0) { + switch(car(t)) { + case STRUCT: case UNION: + if(size(t)!=size(type)) error(TYERR); + break; + } + } else { + switch(t) { + case DOTS: return e; + case UNSIGNED: e = unsigned_value(e); break; + case CHAR: e = char_value(e); t = INT; break; + case UCHAR: e = uchar_value(e); t = UNSIGNED; break; + case SHORT: e = short_value(e); t = INT; break; + case USHORT: e = ushort_value(e); t = UNSIGNED; break; #if FLOAT_CODE - else if (t==FLOAT) e = float_value(e); - else if (t==DOUBLE) e = double_value(e); + case FLOAT: e = float_value(e); break; + case DOUBLE: e = double_value(e); break; #endif #if LONGLONG_CODE - else if (t==LONGLONG) e = longlong_value(e); - else if (t==ULONGLONG) e = ulonglong_value(e); + case LONGLONG: e = longlong_value(e); break; + case ULONGLONG: e = ulonglong_value(e); break; #endif - else if ((t1=car(t))==STRUCT||t1==UNION) { - if(size(t)!=size(type)) error(TYERR); - } /* else error(TYERR); */ + default: + if (integral(t)) e = int_value(e); + } + } type = t; return e; }
--- a/mc-parse.c Sun Nov 21 19:20:18 2004 +0900 +++ b/mc-parse.c Mon Nov 22 14:53:28 2004 +0900 @@ -22,7 +22,7 @@ extern double strtod(const char *nptr, char **endptr); #endif -#define HEAP_REPORT 0 +static int HEAP_REPORT = 0; NMTBL null_nptr; NMTBL *fnptr; @@ -198,6 +198,9 @@ case 'd': debug = 1; break; + case 'v': + HEAP_REPORT = 1; + break; case 'D': break; case 'C': @@ -237,9 +240,8 @@ mode=TOP; if (gfree > heapsize-HEAPSIZE) { heapsize *= 2; -#if HEAP_REPORT - fprintf(stderr,"** heap extended to %d\n",heapsize); -#endif + if (HEAP_REPORT) + fprintf(stderr,"** heap extended to %d\n",heapsize); heap = realloc(heap,heapsize*sizeof(int)); if(!heap) { error(MMERR); exit(1); } } @@ -1208,9 +1210,11 @@ int e,t1; int foffset; int offset0 = offset; + int offset1 = offset; int decl_str_init_save = decl_str_init; int mode_save=mode; NMTBL *nptr0; + int sz= size(type); decl_str_init = 0; if(cadr(type)==-1) { @@ -1223,13 +1227,12 @@ nptr0=new_static_name("__lstruct",'_'); nptr0->next = local_static_list; local_static_list = nptr0; nptr0->sc = GVAR; - e = size(type); nptr0->ty = type; mode=STADECL; decl_data_field(type,nptr0,offset); init_vars = list2( list4(STASS,list3(LVAR,n->dsp+offset,0), - list3(RSTRUCT,list3(GVAR,0,(int)nptr0),e),e), + list3(RSTRUCT,list3(GVAR,0,(int)nptr0),sz),sz), init_vars); return; } @@ -1245,14 +1248,11 @@ if (sym==ASS) { decl_data(t1,n,foffset,0); } else - error(TYERR); /* should be initialization error */ + error(INERR); } else - error(TYERR); /* should be initialization error */ + error(INERR); } else { - if(!t1) { - // empty field case (it can happen...) - break; - } + if(!t1) break; // empty field case (it can happen...) // next decl_data must skip getsym offset = decl_data(car(t1),n,offset,1); /* alignment? */ t1 = cadr(t1); @@ -1278,6 +1278,9 @@ offset0 = assign_data(e,type,n,offset); decl_str_init = cadr(decl_str_init); } + offset = offset0; + if ((sz=(offset1+sz-offset))>0) + assign_data(list2(CONST,sz),EMPTY,n,offset0); decl_str_init = decl_str_init_save; } @@ -3157,9 +3160,8 @@ struct cheap *p = (struct cheap *)malloc(sizeof(struct cheap)); if (!p) error(MMERR); // fatal p->ptr = p->first = (char *)malloc(CHEAPSIZE); -#if HEAP_REPORT - fprintf(stderr,"** new cheap %d\n",(int)CHEAPSIZE); -#endif + if (HEAP_REPORT) + fprintf(stderr,"** new cheap %d\n",(int)CHEAPSIZE); p->last = p->first + CHEAPSIZE; if (!p->ptr) error(MMERR); // fatal p->next = 0; @@ -3669,9 +3671,8 @@ if (nptr_pool->next) { nptr_pool = nptr_pool->next; } else { -#if HEAP_REPORT - fprintf(stderr,"** nptr extended\n"); -#endif + if (HEAP_REPORT) + fprintf(stderr,"** nptr extended\n"); nptr_pool->next = new_cheap(); nptr_pool = nptr_pool->next; } @@ -4008,6 +4009,7 @@ switch (mode) { case GDECL: case GSDECL: case GUDECL: case GTDECL: case MDECL: case ADECL: case LSDECL: case LUDECL: case GEDECL: + case INLINE: e=gfree; gfree+=n; break;
--- a/rsyncs Sun Nov 21 19:20:18 2004 +0900 +++ b/rsyncs Mon Nov 22 14:53:28 2004 +0900 @@ -5,9 +5,10 @@ --exclude '*.bak' --exclude '*.out' \ kono@"$1":~/src/device $HOME touch * */* +cp Makefile.ia32 Makefile make clean cp .gdbinit.ia32 .gdbinit rm -f mc-ia32 make depend rm b*.s -make diff ARCH=ia32 +make diff