changeset 705:0554b7f985ee parse-mode

parse mode done.
author kono
date Wed, 24 Oct 2007 10:39:57 +0900
parents 6e6dc2d644ed
children afcba0382231
files Changes Makefile mc-code-arm.c mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-code-spu.c mc-code.h mc-codegen.c mc-codegen.h mc-inline.c mc-macro.c mc-parse.c test/macro.c test/switch.c
diffstat 15 files changed, 120 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Wed Oct 24 00:13:06 2007 +0900
+++ b/Changes	Wed Oct 24 10:39:57 2007 +0900
@@ -9585,3 +9585,15 @@
 
 まぁ、順調に進んではいるんだけどねぇ。
 
+Wed Oct 24 01:15:25 JST 2007
+
+PowerPC の方が diff が通る。微妙になんか残っているようだが...
+
+IA32 は、diff が通らない。何故だ?
+
+あぁ、switch のparse mode がぜんぜん通ってないよ...
+non parse mode の inline は、通っているのに。
+
+Wed Oct 24 08:33:49 JST 2007
+
+switch をparse mode で二回 inline 展開すると破綻するらしい。
--- a/Makefile	Wed Oct 24 00:13:06 2007 +0900
+++ b/Makefile	Wed Oct 24 10:39:57 2007 +0900
@@ -23,7 +23,7 @@
 #
 TARGET=test/simp
 
-all: mc
+all: mc tags
 
 ppc:
 	make ARCH=powerpc CCEXT="-arch ppc" check-all
@@ -32,7 +32,7 @@
 	cp mc-$(ARCH) mc
 
 TAGS:
-	ctags mc-code-powerpc.c mc-code.h mc-codegen.c mc-codegen.h \
+	ctags mc-code-*.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 \
@@ -85,6 +85,7 @@
 	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
@@ -100,18 +101,25 @@
 	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/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
@@ -131,7 +139,9 @@
 	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
 
@@ -164,6 +174,11 @@
 	-$(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/mc-code-arm.c	Wed Oct 24 00:13:06 2007 +0900
+++ b/mc-code-arm.c	Wed Oct 24 10:39:57 2007 +0900
@@ -3520,21 +3520,26 @@
 }
 
 
-void
+int
 code_set_return_register(int mode) {
     if (cadr(fnptr->ty)==FLOAT) {
 	set_freg(RET_FREGISTER,mode);
+	return freg;
     } else if (cadr(fnptr->ty)==DOUBLE) {
 #if FLOAT_CODE
 	set_dreg(RET_DREGISTER,mode);
+	return freg;
 #endif
     } else if (cadr(fnptr->ty)==LONGLONG||cadr(fnptr->ty)==ULONGLONG) {
 #if LONGLONG_CODE
 	set_lreg(RET_LREGISTER,mode);
+	return lreg;
 #endif
     } else if (cadr(fnptr->ty)==VOID) {
+	return 0;
     } else {
 	set_ireg(RET_REGISTER,mode);
+	return ireg;
     }
 }
 
--- a/mc-code-ia32.c	Wed Oct 24 00:13:06 2007 +0900
+++ b/mc-code-ia32.c	Wed Oct 24 10:39:57 2007 +0900
@@ -2625,18 +2625,23 @@
     }
 }
 
-void
+int
 code_set_return_register(int mode) {
     // before goto leave code, set return register
     if (cadr(fnptr->ty)==FLOAT) {
         // set_freg(RET_FREGISTER,mode);
+	return 0;
     } else if (cadr(fnptr->ty)==DOUBLE) {
         // set_dreg(RET_DREGISTER,mode);
+	return 0;
     } else if (cadr(fnptr->ty)==LONGLONG||cadr(fnptr->ty)==ULONGLONG) {
         set_lreg(RET_LREGISTER,mode);
+	return ireg;
     } else if (cadr(fnptr->ty)==VOID) {
+	return 0;
     } else {
         set_ireg(RET_REGISTER,mode);
+	return ireg;
     }
 }
 
@@ -4213,7 +4218,8 @@
 code_table_jump(int l,int csvalue,int delta,int max,int min,int dlabel)
 {
     char *crn;
-    use_register(creg,csvalue,0);
+    // use_register(creg,csvalue,0);
+    set_ireg(csvalue,0);
     crn = register_name(creg,0);
     printf("\tsubl\t$%d,%s\n",min,crn);
     printf("\tcmpl\t$%d,%s\n",max-min,crn);
--- a/mc-code-mips.c	Wed Oct 24 00:13:06 2007 +0900
+++ b/mc-code-mips.c	Wed Oct 24 10:39:57 2007 +0900
@@ -3204,17 +3204,22 @@
 }
 
 
-void
+int
 code_set_return_register(int mode) {
     if (cadr(fnptr->ty)==FLOAT) {
 	set_freg(RET_FREGISTER,mode);
+	return freg;
     } else if (cadr(fnptr->ty)==DOUBLE) {
 	set_dreg(RET_DREGISTER,mode);
+	return lreg;
     } else if (cadr(fnptr->ty)==LONGLONG||cadr(fnptr->ty)==ULONGLONG) {
 	set_lreg(RET_LREGISTER,mode);
+	return lreg;
     } else if (cadr(fnptr->ty)==VOID) {
+	return 0;
     } else {
 	set_ireg(RET_REGISTER,mode);
+	return ireg;
     }
 }
 
--- a/mc-code-powerpc.c	Wed Oct 24 00:13:06 2007 +0900
+++ b/mc-code-powerpc.c	Wed Oct 24 10:39:57 2007 +0900
@@ -3645,15 +3645,19 @@
 }
 
 
-void
+int
 code_set_return_register(int mode) {
     if (cadr(fnptr->ty)==DOUBLE||cadr(fnptr->ty)==FLOAT) {
 	set_freg(RET_FREGISTER,mode);
+	return freg;
     } else if (cadr(fnptr->ty)==LONGLONG||cadr(fnptr->ty)==ULONGLONG) {
 	set_lreg(RET_LREGISTER,mode);
+	return lreg;
     } else if (cadr(fnptr->ty)==VOID) {
+	return 0;
     } else {
 	set_ireg(RET_REGISTER,mode);
+	return ireg;
     }
 }
 
--- a/mc-code-spu.c	Wed Oct 24 00:13:06 2007 +0900
+++ b/mc-code-spu.c	Wed Oct 24 10:39:57 2007 +0900
@@ -3408,21 +3408,25 @@
 }
 
 
-void
+int
 code_set_return_register(int mode) {
     if (cadr(fnptr->ty)==FLOAT) {
 	set_freg(RET_FREGISTER,mode);
+	return ireg;
     } else if (cadr(fnptr->ty)==DOUBLE) {
 #if FLOAT_CODE
 	set_dreg(RET_DREGISTER,mode);
+	return ireg;
 #endif
     } else if (cadr(fnptr->ty)==LONGLONG||cadr(fnptr->ty)==ULONGLONG) {
 #if LONGLONG_CODE
 	set_lreg(RET_LREGISTER,mode);
+	return ireg;
 #endif
     } else if (cadr(fnptr->ty)==VOID) {
     } else {
 	set_ireg(RET_REGISTER,mode);
+	return ireg;
     }
 }
 
--- a/mc-code.h	Wed Oct 24 00:13:06 2007 +0900
+++ b/mc-code.h	Wed Oct 24 10:39:57 2007 +0900
@@ -158,7 +158,7 @@
 extern void jmp(int l);
 extern int code_get_fixed_creg(int reg,int type);
 extern void code_set_fixed_creg(int reg,int mode,int type);
-extern void code_set_return_register(int mode);
+extern int code_set_return_register(int mode);
 extern void global_table(void);
 extern void code_label(int labelno);
 extern void code_label_value(int labelno,int reg);
--- a/mc-codegen.c	Wed Oct 24 00:13:06 2007 +0900
+++ b/mc-codegen.c	Wed Oct 24 10:39:57 2007 +0900
@@ -4621,7 +4621,7 @@
 
 /* binary integer computation */
 
-static int
+extern int
 binop0(int op, int e1, int e2, int t1, int t2)
 {
     int e=0;
--- a/mc-codegen.h	Wed Oct 24 00:13:06 2007 +0900
+++ b/mc-codegen.h	Wed Oct 24 10:39:57 2007 +0900
@@ -50,6 +50,7 @@
 extern int assop(int e1,int e2,int op,int t,int no_float);
 extern int backdef(void);
 extern int binop(int op, int e1, int e2, int t1, int t2);
+extern int binop0(int op, int e1, int e2, int t1, int t2); // no inline
 extern int cexpr(int e);
 extern int cond(int t,int e1,int e2,int e3);
 extern int correct_type(int e,int t);
--- a/mc-inline.c	Wed Oct 24 00:13:06 2007 +0900
+++ b/mc-inline.c	Wed Oct 24 10:39:57 2007 +0900
@@ -378,13 +378,17 @@
 	// copy is included in e, pass the pointer
 	t = list2(POINTER,type_value(cadr(fnptr->ty)));
     } 
-    g_expr(e);
-    if (ret_reg_mode==0) {
-	// return value register is not fixed
-	ret_reg_mode=1;
-	ret_register = code_get_fixed_creg(USE_CREG,t);
-    } else {
-	code_set_fixed_creg(ret_register,1,t);
+    if (e) {
+	g_expr(e);
+    }
+    if (e && t!=VOID) {
+	if (ret_reg_mode==0) {
+	    // return value register is not fixed
+	    ret_reg_mode=1;
+	    ret_register = code_get_fixed_creg(USE_CREG,t);
+	} else {
+	    code_set_fixed_creg(ret_register,1,t);
+	}
     }
     // conv->return_end_();
     retpending = 1;
@@ -1262,7 +1266,7 @@
     case ST_OP:
 	e3=caddr(e1);
 	e1=pexpr(car(e3));
-	return binop(e2,e1,pexpr(cadr(e3)),caddr(e3),cadddr(e3));
+	return binop0(e2,e1,pexpr(cadr(e3)),caddr(e3),cadddr(e3));
     case MINUS:
 	if ((e3 = pexpr(e2))==e2) return e1;
 	if (car(e3)==CONST) return list2(CONST,-cadr(e3));
@@ -1640,17 +1644,18 @@
     cslabel = -1;
     retpending = 0;
     inline_lvars = 0;
-    retlabel = fwdlabel();
+    if (!toplevel) {
+	retlabel = fwdlabel();
+    }
 
     enter_inline(n,e,toplevel);
 
     if (toplevel) {
-	code_set_return_register(0); // fnptr required
+	ret_register = code_set_return_register(0); // fnptr required
 	ret_reg_mode = 1;
-	ret_register = code_get_fixed_creg(USE_CREG,ret_type);
     } else {
+	ret_register = 555;
 	ret_reg_mode = 0;
-	ret_register = 555;
     }
 
     // partial evaluation of parse tree
@@ -1665,9 +1670,11 @@
     else
 	g_expr_u(parse);
 
-    checkret();
-    fwddef(retlabel);
-    control=1;
+    if (!toplevel) {
+	checkret();
+	fwddef(retlabel);
+	control=1;
+    }
 
     leave_inline(e1,toplevel);
 
--- a/mc-macro.c	Wed Oct 24 00:13:06 2007 +0900
+++ b/mc-macro.c	Wed Oct 24 10:39:57 2007 +0900
@@ -26,6 +26,7 @@
 #include "mc-macro.h"
 #include "mc-codegen.h"
 #include "mc-code.h"
+#include "mc-inline.h"
 
 extern struct {int fd,ln;char *name0;int inc;FILE *fcb;} *filep,filestack[FILES];
 
@@ -468,6 +469,7 @@
     getsym(0);
     /* i=cexpr(expr(1)); #if allow undefined symbols.. */
     i=expr(1); 
+    if (inmode) i = pexpr(i);  // it contain const value only
     in_macro_if = 0;
     if (car(i)==CONST) i=cadr(i);
     else i=0;
--- a/mc-parse.c	Wed Oct 24 00:13:06 2007 +0900
+++ b/mc-parse.c	Wed Oct 24 10:39:57 2007 +0900
@@ -4908,26 +4908,9 @@
     Tokenizer
  */
 
-#if 0
-extern int
-getsym0(int sc); 
-
 extern int
 getsym(int sc)
 {
-    int a = getsym0(sc);
-    fprintf(stderr,"sym = %d, %s glineno %d\n", a, nptr?nptr->nm?nptr->nm:"":"",
-	    glineno);
-    return a;
-}
-
-extern int
-getsym0(int sc)
-#else
-extern int
-getsym(int sc)
-#endif
-{
     NMTBL *nlist,*nptr0,*nptrm;
     char c;
 
--- a/test/macro.c	Wed Oct 24 00:13:06 2007 +0900
+++ b/test/macro.c	Wed Oct 24 10:39:57 2007 +0900
@@ -14,6 +14,7 @@
 
 #define TEST0 33
 #define TEST111 TEST0
+#define ENDIAN_L 0
 
 #define c(a,b)  g(a+1,b+1)
 #define g(a,b)  printf("#0018:%d %d\n",a+1,b+1);
@@ -25,6 +26,16 @@
     f (a,b)
 */
 
+int f()
+{
+#if ENDIAN_L==0
+    printf("ok\n");
+#else
+    printf("bad\n");
+#endif
+}
+
+
 // name concateneation
 
 #define name(a,b)   name_##b(a)
@@ -76,6 +87,7 @@
     printf("#0071:%d\n",name(3,hoge));
     printf("#0072:%d\n",names(3,hoge));
     printf("#0073:%d\n",hoge000(3));
+    f();
     return 0;
 }
 
--- a/test/switch.c	Wed Oct 24 00:13:06 2007 +0900
+++ b/test/switch.c	Wed Oct 24 10:39:57 2007 +0900
@@ -1,24 +1,10 @@
 #include <stdio.h>
 
-void main1(int i);
-void main2(int i);
-void main3(int i);
-void main4(int i);
-void main5(int i);
-int
-main(int ac,char *av[])
-{
-    int i;
-    for(i=-1000;i<3000;i++) {
-	main1(i);
-	main2(i);
-	main3(i);
-	main4(i);
-	main5(i);
-    }
-    return 0;
-}
-void
+#ifndef INLINE
+#define INLINE
+#endif
+
+INLINE void
 main1(int i)
 {
    switch(i) {
@@ -405,7 +391,7 @@
 case 399: printf("#0404:case 1 399\n"); break;
    }
 }
-void
+INLINE void
 main2(int i)
 {
    switch(i) {
@@ -733,7 +719,7 @@
 default: printf("#0732:default 2 %d\n",i); break;
    }
 }
-void
+INLINE void
 main3(int i)
 {
    switch(i) {
@@ -1124,7 +1110,7 @@
 case 10299: printf("#1123:case 3 10299\n"); break;
    }
 }
-void
+INLINE void
 main4(int i)
 {
    switch(i) {
@@ -1233,7 +1219,7 @@
 case 79: printf("#1232:case 4 79\n"); break;
    }
 }
-void
+INLINE void
 main5(int r)
 {
     int i,j,k;
@@ -1254,3 +1240,16 @@
     printf("#1253:main5 %d\n",i);
    
 }
+int
+main(int ac,char *av[])
+{
+    int i;
+    for(i=-1000;i<3000;i++) {
+	main1(i);
+	main2(i);
+	main3(i);
+	main4(i);
+	main5(i);
+    }
+    return 0;
+}