changeset 807:22a253cbb9d2

merged
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 24 Nov 2010 22:42:10 +0900
parents 93587e4c480f (current diff) 362b0258b4db (diff)
children 2a4a40168fa4
files
diffstat 5 files changed, 372 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/.gdbinit	Wed Nov 24 22:41:18 2010 +0900
+++ b/.gdbinit	Wed Nov 24 22:42:10 2010 +0900
@@ -1,37 +1,34 @@
 tb main
+r -s test/basic.c
 define regs 
-call (void)printf("rax=%08lx rbx=%08lx rcx=%08lx rdx=%08lx\nrsi=%08lx rdi=%08lx rbp=%08lx rsp=%08lx rip=%08lx\n",$rax,$rbx,$rcx,$rdx,$rsi,$rdi,$rbp,$rsp,$rip)
+printf "pc =%08x lr =%08x r0 =%08x r1 =%08x r3= %08x r4= %08x\n",$pc,$lr,$r0,$r1,$r3,$r4
+printf "r10=%08x r11=%08x r12=%08x r13=%08x r14=%08x r15=%08x\n",$r10,$r11,$r12,$r13,$r14,$r15
+end
+define fregs 
+printf "f1=%g f2=%g f3=%g f4=%g f5=%g f6=%g\n",$f1,$f2,$f3,$f4,$f5,$f6
+printf "f10=%g f11=%g f12=%g f13=%g f14=%g f15=%g\n",$f10,$f11,$f12,$f13,$f14,$f15
+end
+define allreg
+printf "pc =%08x lr =%08x r0 =%08x r1 =%08x r3= %08x r4= %08x\n",$pc,$lr,$r0,$r1,$r3,$r4
+printf "r5=%08x r6=%08x r7=%08x r8=%08x r9=%08x\n",$r5,$r6,$r7,$r8,$r9
+printf "r10=%08x r11=%08x r12=%08x r13=%08x r14=%08x r15=%08x\n",$r10,$r11,$r12,$r13,$r14,$r15
+printf "r16=%08x r17=%08x r18=%08x r19=%08x r20=%08x r21=%08x\n",$r10,$r11,$r12,$r13,$r14,$r15
+printf "f1=%g f2=%g f3=%g f4=%g f5=%g f6=%g\n",$f1,$f2,$f3,$f4,$f5,$f6
+printf "f10=%g f11=%g f12=%g f13=%g f14=%g f15=%g\n",$f10,$f11,$f12,$f13,$f14,$f15
+printf "f20=%g f21=%g f22=%g f23=%g f24=%g f25=%g\n",$f20,$f21,$f22,$f23,$f24,$f25
+end
+define sh
+regs
+x/20i $pc-36
 end
 define si
 stepi
 regs
-x/1i $rip
+x/1i $pc
 end
 define ni
 nexti
 regs
-x/1i $rip
+x/1i $pc
 end
 b errmsg
-# r -s test/tmp7.c
-# r -s -DINLINE=inline test/tmp7.c
-# r -s test/int.c
-# r -s test/tmp6.c
-# r -s test/call.c
-# r -s test/static.c
-# r -s test/tmpa.c
-# r -s test/code-gen-all.c
-# r -s mc-code-powerpc.c
-# r -s test/macro.c
-# r -s test/basic.c
-# r -s test/float.c
-# r -s test/strinit.c
-# r -s test/bitfield.c
-# r -s test/tstdarg.c
-r -s test/ps2.c
-# r -s test/arg.c
-# r -s test/obsf2.c
-# r -s test/putenemy.c
-# r -s -DINLINE=inline test/code-gen-all.c
-# r -s -DINLINE=inline test/strinit.c
-# r -s test/fact-a.c
--- a/.gdbinit.i64	Wed Nov 24 22:41:18 2010 +0900
+++ b/.gdbinit.i64	Wed Nov 24 22:42:10 2010 +0900
@@ -1,28 +1,37 @@
 tb main
 define regs 
-call (void)printf("eax=%08lx ebx=%08lx ecx=%08lx edx=%08lx\nesi=%08lx edi=%08lx ebp=%08lx esp=%08lx eip=%08lx\n",$eax,$ebx,$ecx,$edx,$esi,$edi,$ebp,$esp,$eip)
+call (void)printf("rax=%08lx rbx=%08lx rcx=%08lx rdx=%08lx\nrsi=%08lx rdi=%08lx rbp=%08lx rsp=%08lx rip=%08lx\n",$rax,$rbx,$rcx,$rdx,$rsi,$rdi,$rbp,$rsp,$rip)
 end
 define si
 stepi
 regs
-x/1i $eip
+x/1i $rip
 end
 define ni
 nexti
 regs
-x/1i $eip
+x/1i $rip
 end
 b errmsg
 # r -s test/tmp7.c
+# r -s -DINLINE=inline test/tmp7.c
+# r -s test/int.c
 # r -s test/tmp6.c
 # r -s test/call.c
 # r -s test/static.c
 # r -s test/tmpa.c
-r -s test/code-gen-all.c
+# r -s test/code-gen-all.c
 # r -s mc-code-powerpc.c
 # r -s test/macro.c
 # r -s test/basic.c
+# r -s test/float.c
 # r -s test/strinit.c
+# r -s test/bitfield.c
+# r -s test/tstdarg.c
+r -s test/ps2.c
 # r -s test/arg.c
+# r -s test/obsf2.c
+# r -s test/putenemy.c
+# r -s -DINLINE=inline test/code-gen-all.c
 # r -s -DINLINE=inline test/strinit.c
 # r -s test/fact-a.c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Makefile.i64	Wed Nov 24 22:42:10 2010 +0900
@@ -0,0 +1,290 @@
+GCC = gcc
+CC = $(GCC) -std=c99 $(CCEXT) $(M)  -fgnu89-inline 
+# -O3
+# MCFLAGS = -DUSE_CODE_KEYWORD
+CFLAGS = -g -Wall -I. $(MCFLAGS) # -O
+# 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.
+BASE=0
+STAGE=1
+MFLAGS=$(MFALGS) BASE=$(BASE) STAGE=$(STAGE)
+ARCH=i64
+MC=mc-$(ARCH)
+MLIB = -lm
+PRINTF= # printf.c
+CONVERTER=conv/c.o conv/null.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
+GCC_INCLUDE=`perl tools/find-gcc-include-path -p $(CC)`
+#
+#
+TARGET=test/simp
+
+all: mc tags
+
+predefined:
+	$(CC) -xc -E -dM /dev/null
+
+ppc:
+	make ARCH=powerpc CCEXT="-arch ppc" check-all
+
+ia32:
+	make ARCH=ia32 CCEXT="-m32" check-all
+
+ia32-make-code-check:
+	make ARCH=ia32 CCEXT="-m32" MK=-make check-all-code
+
+mc:   mc-$(ARCH)
+	cp mc-$(ARCH) mc
+
+mc-i64 :conv/conv.h mc-include.c mc-code-i64.o $(COMPLIB) $(CONVERTER)
+	$(CC) $(LDFLAGS) -g mc-code-i64.o $(COMPLIB) $(CONVERTER) -o $@
+
+mc-powerpc :conv/conv.h mc-include.c mc-code-powerpc.o $(COMPLIB) $(CONVERTER)
+	$(CC) $(LDFLAGS) -g mc-code-powerpc.o $(COMPLIB) $(CONVERTER) -o $@
+
+mc-ia32 :conv/conv.h mc-include.c mc-code-ia32.o $(COMPLIB) $(CONVERTER)
+	$(CC) $(LDFLAGS) -g mc-code-ia32.o $(COMPLIB) $(CONVERTER) -o $@
+
+mc-mips :conv/conv.h mc-include.c mc-code-mips.o $(COMPLIB) $(CONVERTER)
+	$(CC) $(LDFLAGS) -g mc-code-mips.o $(COMPLIB) $(CONVERTER) -o $@
+
+mc-arm :conv/conv.h mc-include.c mc-code-arm.o $(COMPLIB) $(CONVERTER)
+	$(CC) $(LDFLAGS) -g mc-code-arm.o $(COMPLIB) $(CONVERTER) -o $@
+
+mc-spu :conv/conv.h mc-include.c mc-code-spu.o $(COMPLIB) $(CONVERTER)
+	$(CC) $(LDFLAGS) -g mc-code-spu.o $(COMPLIB) $(CONVERTER) -o $@
+
+conv/conv.h: conv_func.tbl tools/conv_func.pl
+	perl tools/conv_func.pl
+conv/convdef.h: conv_func.tbl tools/conv_func.pl
+	perl tools/conv_func.pl
+conv/null.c: conv_func.tbl tools/conv_func.pl
+	perl tools/conv_func.pl
+
+mc-include.c:
+	perl tools/find-gcc-include-path -l $(CC) > mc-include.c
+
+mc.h-new:
+	perl tools/mc-h-renum.pl mc.h > mc.h.1
+	mv mc.h.1 mc.h
+
+check-all:  check-all-c check-all-code
+
+check-all-c:
+	make check TARGET=test/basic
+	make check-inline TARGET=test/basic
+	make check TARGET=test/call
+	make check TARGET=test/fact0
+	make check TARGET=test/float
+	make check TARGET=test/ifdef
+	make check TARGET=test/int
+	make check TARGET=test/macro
+	make check TARGET=test/regargs
+	make check TARGET=test/short
+	make check TARGET=test/simp
+	make check TARGET=test/simp0
+	make check TARGET=test/simp1
+	make check TARGET=test/static
+	make check-inline TARGET=test/static
+	make check TARGET=test/tmp
+	make check TARGET=test/tmp10
+	make check TARGET=test/tmp11
+	make check TARGET=test/tmp12
+	make check TARGET=test/tmp5
+	make check TARGET=test/tmp7
+	make check-inline TARGET=test/tmp7
+	make check TARGET=test/tmp8
+	make check TARGET=test/tmp9
+	make check TARGET=test/enum
+	make check TARGET=test/obsf
+	make check TARGET=test/obsf2
+	make check TARGET=test/long
+	make check TARGET=test/tstdarg
+	make check TARGET=test/switch
+	make check-inline TARGET=test/switch
+	make check TARGET=test/strinit
+	make check-inline TARGET=test/strinit
+	make check TARGET=test/code-gen-all
+	make check-inline TARGET=test/code-gen-all
+	make check TARGET=test/bitfield
+	make check TARGET=test/bitfield1
+	make check-inline TARGET=test/bitfield1
+	make check TARGET=test/cext
+	make check TARGET=test/const
+	make check TARGET=test/void_code
+	make check TARGET=test/putenemy
+	make check TARGET=test/inline
+	make check TARGET=test/ps2
+	make check-inline TARGET=test/ps2
+	make check TARGET=test/offset
+	make check TARGET=test/multi
+	make check-inline TARGET=test/multi
+	make check TARGET=test/comp
+	make check-inline TARGET=test/comp
+#	make check TARGET=test/scope STDFLAG="-std=gnu99"
+#	make check-inline TARGET=test/scope STDFLAG="-std=gnu99"
+#MK =-make
+MK=
+check-all-code:
+	make check-code$(MK) TARGET=test/arg
+	make check-code$(MK) TARGET=test/conv
+	make check-code$(MK) TARGET=test/conv1
+	make check-code$(MK) TARGET=test/fact-a
+	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
+	make check-code$(MK) TARGET=test/tmp4
+	make check-code$(MK) TARGET=test/tmp6
+	make check-code$(MK) TARGET=test/tmpb
+	make check-code-inline TARGET=test/tmpb
+	make check-code$(MK) TARGET=test/scope
+	make check-code-inline TARGET=test/scope
+	# make check-code$(MK) TARGET=test/throw
+	make check-code$(MK) TARGET=test/too-long-argument
+
+check-nkf: mc
+	( cd nkf203; $(CC) -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 )
+
+#	-./$(MC) -Itest/ -s $(TARGET).c
+
+check: mc $(MC) $(TARGET).c
+	-$(CC) $(CFLAGS1) $(STDFLAG) $(TARGET).c -o b.out $(MLIB)
+	-./b.out > $(TARGET).gcc.out
+	-./$(MC) -s $(TARGET).c
+	-$(CC) $(TARGET).s $(MLIB)
+	-./a.out > $(TARGET).$(MC).out
+	-diff $(TARGET).gcc.out $(TARGET).$(MC).out
+
+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
+	-$(CC) $(TARGET).s $(MLIB)
+	-./a.out > $(TARGET).$(MC).out
+	-diff $(TARGET).gcc.out $(TARGET).$(MC).out
+
+check-code: mc $(MC)
+	-./$(MC) -s $(TARGET).c
+	-$(CC) $(TARGET).s $(MLIB)
+	-./a.out > $(TARGET).$(MC).out
+	-diff  $(TARGET).code-out $(TARGET).$(MC).out
+check-code-inline: mc $(MC)
+	-./$(MC) -s -DINLINE=inline $(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
+	-$(CC) $(TARGET).s $(MLIB)
+	-./a.out > $(TARGET).code-out
+
+check-flip: mc $(MC)
+	-$(CC) -DFLIP -c test/basic2.c
+	-$(CC) basic2.o test/basic2.c
+	./a.out
+	-./$(MC) -s test/basic2.c
+	-$(CC) test/basic2.s -DFLIP test/basic2.c
+	./a.out
+	-./$(MC) -DFLIP -s test/basic2.c
+	-$(CC) test/basic2.s test/basic2.c
+	./a.out
+
+test/code-gen-all.c: test/code-gen.pl test/code-gen.c
+	perl test/code-gen.pl < test/code-gen.c > test/code-gen-all.c
+
+incpri:
+	perl tools/incpri.pl test/*.c
+
+tags:   tags-$(ARCH)
+
+tags-$(ARCH):  
+	ctags mc.h mc-code.h mc-code-$(ARCH).c  mc-codegen.c mc-codegen.h \
+		mc-parse.h mc-tree.c mc-inline.h mc-switch.h \
+		mc-macro.h mc-macro.c \
+	    conv/c.c conv/c.h \
+	    conv/conv.h conv/convdef.h 
+
+tar :
+	make clean
+	tar cBf - . | gzip > ../comp.tgz 
+
+depend : mc.h mc-include.c
+	makedepend -I$(GCC_INCLUDE) 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-inline.c mc-macro.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-arm.c \
+                mc-code-powerpc.c \
+                mc-code-mips.c
+
+clean :
+	-rm -rf mc mc-spu 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 mc-include.c *.dSYM
+
+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)
+
+mc2 : b00.s b01.s b02.s b03.s mc-macro.o  mc-inline.o $(CONVERTER)
+	$(CC) -g -o $@ $(PRINTF) b00.s b01.s b02.s b03.s b04.s mc-macro.o mc-inline.o $(CONVERTER)
+
+b00.s : mc-parse.c $(MC)
+	./$(MC) $(MCFLAGS) -s -ob00.s mc-parse.c
+b01.s : $(CODE) $(MC)
+	./$(MC) $(MCFLAGS) -s -ob01.s $(CODE)
+b02.s : mc-codegen.c $(MC)
+	./$(MC) $(MCFLAGS) -s -ob02.s mc-codegen.c
+b03.s : mc-tree.c $(MC)
+	./$(MC) $(MCFLAGS) -s -ob03.s mc-tree.c
+b04.s : mc-switch.c $(MC)
+	./$(MC) $(MCFLAGS) -s -ob04.s mc-switch.c
+
+b10.s : mc-parse.c mc1
+	./mc1 $(MCFLAGS) -s -ob10.s mc-parse.c
+b11.s : $(CODE) $(PRINTF) mc1
+	./mc1 $(MCFLAGS) -s -ob11.s $(CODE)
+b12.s : mc-codegen.c mc1
+	./mc1 $(MCFLAGS) -s -ob12.s mc-codegen.c
+b13.s : mc-tree.c mc1
+	./mc1 $(MCFLAGS) -s -ob13.s mc-tree.c
+b14.s : mc-switch.c mc1
+	./mc1 $(MCFLAGS) -s -ob14.s mc-switch.c
+
+b20.s : mc-parse.c mc2
+	./mc2 $(MCFLAGS) -s -ob20.s mc-parse.c
+b21.s : $(CODE) $(PRINTF) mc2
+	./mc2 $(MCFLAGS) -s -ob21.s $(CODE)
+b22.s : mc-codegen.c mc2
+	./mc2 $(MCFLAGS) -s -ob22.s mc-codegen.c
+b23.s : mc-tree.c mc2
+	./mc2 $(MCFLAGS) -s -ob23.s mc-tree.c
+b24.s : mc-switch.c mc1
+	./mc2 $(MCFLAGS) -s -ob24.s mc-switch.c
+
+diff :  b00.s b01.s b02.s b03.s b04.s b10.s b11.s b12.s b13.s b14.s
+	-diff b00.s b10.s
+	-diff b01.s b11.s
+	-diff b02.s b12.s
+	-diff b03.s b13.s
+	-diff b04.s b14.s
+
+diff2 :  b00.s b01.s b02.s b03.s b04.s b20.s b21.s b22.s b23.s b24.s
+	-diff b00.s b20.s
+	-diff b01.s b21.s
+	-diff b02.s b22.s
+	-diff b03.s b23.s
+	-diff b04.s b24.s
+
+
+# DO NOT DELETE
--- a/mc-code-powerpc.c	Wed Nov 24 22:41:18 2010 +0900
+++ b/mc-code-powerpc.c	Wed Nov 24 22:42:10 2010 +0900
@@ -294,10 +294,10 @@
 #else
 // PS3 (PowerPC Fedora Core)
 static char *reg_name[] = {
-    "0","1","2","3","4","5","6","7","8","9",
-    "10","11","12","13","14","15","16","17","18","19",
-    "20","21","22","23","24","25","26","27","28","29",
-    "30","31",
+    "r0","r1","r2","r3","r4","r5","r6","r7","r8","r9",
+    "r10","r11","r12","r13","r14","r15","r16","r17","r18","r19",
+    "r20","r21","r22","r23","r24","r25","r26","r27","r28","r29",
+    "r30","r31",
     "0","1","2","3","4","5","6","7","8","9",
     "10","11","12","13","14","15","16","17","18","19",
     "20","21","22","23","24","25","26","27","28","29",
@@ -493,8 +493,8 @@
 #define arg_offset0  (8)
 #define arg_offset1  (8)
 
-#define func_disp_offset (8)
-#define code_disp_offset0 (0)
+#define func_disp_offset (12)
+#define code_disp_offset0 (-4)
 
 #endif
 
@@ -3234,8 +3234,45 @@
 {
     printf("\t.file \"%s\"\n",filename);
     /* printf("\t.version\t\"01.01\"\n"); */
-    /* printf("gcc2_compiled.:\n"); */
+    printf("cbc_compiled.:\n"); 
     // printf(".text\n");
+#ifndef __APPLE__
+    printf(
+"     .set r0,0\n"
+"     .set r1,1\n"
+"     .set r2,2\n"
+"     .set r3,3\n"
+"     .set r4,4\n"
+"     .set r5,5\n"
+"     .set r6,6\n"
+"     .set r7,7\n"
+"     .set r8,8\n"
+"     .set r9,9\n"
+"     .set r10,10\n"
+"     .set r11,11\n"
+"     .set r12,12\n"
+"     .set r13,13\n"
+"     .set r14,14\n"
+"     .set r15,15\n"
+"     .set r16,16\n"
+"     .set r17,17\n"
+"     .set r18,18\n"
+"     .set r19,19\n"
+"     .set r20,20\n"
+"     .set r21,21\n"
+"     .set r22,22\n"
+"     .set r23,23\n"
+"     .set r24,24\n"
+"     .set r25,25\n"
+"     .set r26,26\n"
+"     .set r27,27\n"
+"     .set r28,28\n"
+"     .set r29,29\n"
+"     .set r30,30\n"
+"     .set r31,31\n"
+      );
+#endif
+
 }
 
 #define CRBITSIZ 4
@@ -3452,6 +3489,7 @@
     printf("\t.type\t%s,@function\n",name);
  */
     printf("%s:\n",name);
+    control = 1;
     code_setup=fwdlabel();
     arg_offset_label = fwdlabel();
     printf("\tmflr 0\n");
--- a/mc-codegen.c	Wed Nov 24 22:41:18 2010 +0900
+++ b/mc-codegen.c	Wed Nov 24 22:42:10 2010 +0900
@@ -1900,6 +1900,7 @@
     /* しかし、わかる場合もある */
     if (is_same_type(e2,e4)) {
 	if(cadr(e2)>cadr(e4)) { 
+	    offset = 0;
 	    if (!(sz==1 || sz==2 || sz==3 || (lp64 && sz==8))) {
 		offset=sz; sz=-sz;
 	    }
@@ -3637,7 +3638,7 @@
 	if ((e=attr_value(n,ASM))) {
 	    if (car(e)==STRINGS) {
 		// first element only
-		return scaddr(str->dsp); // may non terminated
+		return scaddr(e); // may non terminated
 	    }
 	    if (car(e)!=STRING) error(-1);
 	    str = ncaddr(e);