changeset 355:6188f66c0c0b arg_scope

cond op, and arg scope.
author kono
date Sun, 04 Jul 2004 19:08:42 +0900
parents 32cd53208b79
children 6818bd03767d
files .gdbinit Changes mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-code.h mc-codegen.c mc-parse.c mc-parse.h mc.h
diffstat 10 files changed, 91 insertions(+), 139 deletions(-) [+]
line wrap: on
line diff
--- a/.gdbinit	Sat Jul 03 14:40:30 2004 +0900
+++ b/.gdbinit	Sun Jul 04 19:08:42 2004 +0900
@@ -1,6 +1,7 @@
 tb main
 # run  -s test/arg.c
-run  -s -ob00.s mc-parse.c
+# run  -s -ob00.s mc-parse.c
+run  -s nkf203/nkf.c
 # run  -s -ob01.s mc-switch.c
 # run  -s l.c
 # run  -s test/simp0.c
--- a/Changes	Sat Jul 03 14:40:30 2004 +0900
+++ b/Changes	Sun Jul 04 19:08:42 2004 +0900
@@ -5421,3 +5421,21 @@
 
 K&R argument が redefined 扱いで、新しい変数になって
 しまう。
+
+Sat Jul  3 15:16:50 JST 2004
+
+ようやっと recovery できました。
+
+global heap の拡張は難しいよね。特に、heap の使い方が
+割りと雑な今は難しい。nptr,heap,local ともinteger で
+アクセスするならともかく。
+
+また、くだらん、gcc の拡張か... 使うなよ... __label__
+
+やっぱり、型名は大域変数とは別な名前空間だよな。
+
+まぁねぇ。 code が、結構、コンフリクトしているな。ま、そうだけど。
+
+三項演算子の一部を省略できるのか。
+
+いくつか問題はあるが、kernel source は、通りました。
--- a/mc-code-ia32.c	Sat Jul 03 14:40:30 2004 +0900
+++ b/mc-code-ia32.c	Sun Jul 04 19:08:42 2004 +0900
@@ -233,6 +233,7 @@
 #define __const const\n\
 #define __THORW\n\
 #define __attribute__(a)\n\
+#define __inline__\n\
 #define wchar_t int\n\
 #define __GNUC__ 2\n\
 ";
@@ -1336,43 +1337,15 @@
     printf("\tjmp *%s\n",register_name(e2,0));
 }
 
-int
-code_rindirect(int e1, int reg,int offset, int sign)
+void
+code_rindirect(int e1, int reg,int offset, int sign,int byte)
 {
     char *crn,*op;
-    int byte;
     g_expr(e1);
-    byte = 0; op="movl";
+    op=cload(sign,byte);
     crn = register_name(creg,0);
     use_int(reg);
     printf("\t%s %d(%s),%s\n",op,offset,crn,register_name(reg,0));
-    return sign?INT:UNSIGNED;
-}
-
-int
-code_crindirect(int e1, int reg,int offset, int sign)
-{
-    char *crn,*op;
-    int byte;
-    g_expr(e1);
-    byte = 0; op=sign?"movsbl":"movzbl";
-    crn = register_name(creg,0);
-    use_int(reg);
-    printf("\t%s %d(%s),%s\n",op,offset,crn,register_name(reg,0));
-    return sign?CHAR:UCHAR;
-}
-
-int
-code_srindirect(int e1, int reg,int offset, int sign)
-{
-    char *crn,*op;
-    int byte;
-    g_expr(e1);
-    byte = 0; op=sign?"movswl":"movzwl";
-    crn = register_name(creg,0);
-    use_int(reg);
-    printf("\t%s %d(%s),%s\n",op,offset,crn,register_name(reg,0));
-    return sign?SHORT:USHORT;
 }
 
 #if FLOAT_CODE
@@ -1687,16 +1660,13 @@
 void
 ld_indexx(int byte, int n, int xreg,int reg,int sign)
 {	
-    char *op;
-
     use_int(reg);
-    op = byte ? (sign?"movsbl":"movzbl") : "movl";
     if (n) 
-	    printf("\t%s %d(%s),%s\n",op,n,
-		register_name(xreg,0),register_name(reg,byte));
+	    printf("\t%s %d(%s),%s\n",cload(sign,byte),n,
+		register_name(xreg,0),register_name(reg,0));
     else
-	    printf("\t%s (%s),%s\n",op,
-		register_name(xreg,0),register_name(reg,byte));
+	    printf("\t%s (%s),%s\n",cload(sign,byte),
+		register_name(xreg,0),register_name(reg,0));
 }
 
 int
--- a/mc-code-mips.c	Sat Jul 03 14:40:30 2004 +0900
+++ b/mc-code-mips.c	Sun Jul 04 19:08:42 2004 +0900
@@ -2291,21 +2291,8 @@
     control=0;
 }
 
-int
-code_rindirect(int e1, int reg,int offset, int us)
-{
-    char *crn,*rrn;
-    g_expr(e1);
-    if (!is_int_reg(creg)) error(-1);
-    crn=register_name(creg);
-    use_int(reg);
-    rrn=register_name(reg);
-    printf("\tlw %s,%d(%s)\n",rrn,offset,crn);
-    return us?UNSIGNED:INT;
-}
-
-int
-code_crindirect(int e1, int reg,int offset, int sign)
+void
+code_rindirect(int e1, int reg,int offset, int sign,int sz)
 {
     char *crn,*rrn;
     g_expr(e1);
@@ -2313,29 +2300,8 @@
     crn=register_name(creg);
     use_int(reg);
     rrn=register_name(reg);
-    printf("\t%s %s,%d(%s)\n",cload(1,sign),rrn,offset,crn);
-    if (sign) {
-	cext(sign,1,reg);
-	return CHAR;
-    }
-    return UCHAR;
-}
-
-int
-code_srindirect(int e1, int reg,int offset, int sign)
-{
-    char *crn,*rrn;
-    g_expr(e1);
-    if (!is_int_reg(creg)) error(-1);
-    crn=register_name(creg);
-    use_int(reg);
-    rrn = register_name(reg);
-    printf("\t%s %s,%d(%s)\n",cload(SIZE_OF_SHORT,sign),rrn,offset,crn);
-    if (sign) {
-	cext(sign,SIZE_OF_SHORT,reg);
-	return SHORT;
-    }
-    return USHORT;
+    printf("\t%s %s,%d(%s)\n",cload(sz,sign),rrn,offset,crn);
+    cext(sign,sz,reg);
 }
 
 #if FLOAT_CODE
--- a/mc-code-powerpc.c	Sat Jul 03 14:40:30 2004 +0900
+++ b/mc-code-powerpc.c	Sun Jul 04 19:08:42 2004 +0900
@@ -2223,21 +2223,8 @@
     control=0;
 }
 
-int
-code_rindirect(int e1, int reg,int offset, int us)
-{
-    char *crn,*rrn;
-    g_expr(e1);
-    if (!is_int_reg(creg)) error(-1);
-    crn=register_name(creg);
-    use_int(reg);
-    rrn=register_name(reg);
-    printf("\tlwz %s,%d(%s)\n",rrn,offset,crn);
-    return us?UNSIGNED:INT;
-}
-
-int
-code_crindirect(int e1, int reg,int offset, int sign)
+void
+code_rindirect(int e1, int reg,int offset, int sign,int sz)
 {
     char *crn,*rrn;
     g_expr(e1);
@@ -2245,29 +2232,8 @@
     crn=register_name(creg);
     use_int(reg);
     rrn=register_name(reg);
-    printf("\tlbz %s,%d(%s)\n",rrn,offset,crn);
-    if (sign) {
-	cext(sign,1,reg);
-	return CHAR;
-    }
-    return UCHAR;
-}
-
-int
-code_srindirect(int e1, int reg,int offset, int sign)
-{
-    char *crn,*rrn;
-    g_expr(e1);
-    if (!is_int_reg(creg)) error(-1);
-    crn=register_name(creg);
-    use_int(reg);
-    rrn = register_name(reg);
-    printf("\tlhz %s,%d(%s)\n",rrn,offset,crn);
-    if (sign) {
-	cext(sign,SIZE_OF_SHORT,reg);
-	return SHORT;
-    }
-    return USHORT;
+    printf("\t%s %s,%d(%s)\n",cload(sz),rrn,offset,crn);
+    cext(sign,sz,reg);
 }
 
 #if FLOAT_CODE
--- a/mc-code.h	Sat Jul 03 14:40:30 2004 +0900
+++ b/mc-code.h	Sun Jul 04 19:08:42 2004 +0900
@@ -92,9 +92,7 @@
 extern void code_jmp(char *s);
 extern void code_indirect_jmp(int e2);
 
-extern int code_rindirect(int e1, int reg,int offset, int us);
-extern int code_crindirect(int e1, int reg,int offset, int us);
-extern int code_srindirect(int e1, int reg,int offset, int us);
+extern void code_rindirect(int e1, int reg,int offset, int us,int sz);
 #if FLOAT_CODE
 extern int code_drindirect(int e1, int reg,int offset, int d);
 #endif
--- a/mc-codegen.c	Sat Jul 03 14:40:30 2004 +0900
+++ b/mc-codegen.c	Sun Jul 04 19:08:42 2004 +0900
@@ -247,17 +247,17 @@
     case INDIRECT:
 	return g_expr0(e2);
     case RINDIRECT:  
-	return code_rindirect(e2,USE_CREG,caddr(e1),1);
+	code_rindirect(e2,USE_CREG,caddr(e1),1,0); return INT;
     case URINDIRECT:  
-	return code_rindirect(e2,USE_CREG,caddr(e1),0);
+	code_rindirect(e2,USE_CREG,caddr(e1),0,0); return UNSIGNED;
     case CRINDIRECT: 
-	return code_crindirect(e2,USE_CREG,caddr(e1),1);
+	code_rindirect(e2,USE_CREG,caddr(e1),1,1); return CHAR;
     case CURINDIRECT:
-	return code_crindirect(e2,USE_CREG,caddr(e1),0);
+	code_rindirect(e2,USE_CREG,caddr(e1),0,1); return UCHAR;
     case SRINDIRECT: 
-	return code_srindirect(e2,USE_CREG,caddr(e1),1);
+	code_rindirect(e2,USE_CREG,caddr(e1),1,size_of_short); return SHORT;
     case SURINDIRECT:
-	return code_srindirect(e2,USE_CREG,caddr(e1),0);
+	code_rindirect(e2,USE_CREG,caddr(e1),0,size_of_short); return USHORT;
 #if FLOAT_CODE
     case FRINDIRECT:
 	return code_drindirect(e2,USE_CREG,caddr(e1),0);
@@ -416,8 +416,12 @@
         d = (car(e1)==LCOND?LONGLONG:
 		car(e1)==COND?INT:car(e1)==DCOND?DOUBLE:FLOAT);
 	e2=fwdlabel();
-	b_expr(cadr(e1),0,e2,0);
-        g_expr0(caddr(e1));
+	if (caddr(e1)) {
+	    b_expr(cadr(e1),0,e2,0);
+	    g_expr0(caddr(e1));
+	} else {
+	    bexpr(cadr(e1),0,e2); // value used
+	}
 	t = code_get_fixed_creg(USE_CREG,d);
 	jmp(e3=fwdlabel());
 	fwddef(e2);
@@ -1862,24 +1866,24 @@
 #if FLOAT_CODE
     if(type==DOUBLE||t==DOUBLE) {
 	e3=double_value(e3);
-	type = t; e2=double_value(e2);
+	type = t; if (e2) e2=double_value(e2);
 	return(list4(DCOND,e1,e2,e3));
     }
     if(type==FLOAT||t==FLOAT) {
 	e3=float_value(e3);
-	type = t; e2=float_value(e2);
+	type = t; if (e2) e2=float_value(e2);
 	return(list4(FCOND,e1,e2,e3));
     }
 #endif
 #if LONGLONG_CODE
     if(type==LONGLONG||t==LONGLONG) {
 	e3=longlong_value(e3);
-	type = t; e2=longlong_value(e2);
+	type = t; if (e2) e2=longlong_value(e2);
 	return(list4(LCOND,e1,e2,e3));
     }
     if(type==ULONGLONG||t==ULONGLONG) {
 	e3=ulonglong_value(e3);
-	type = t; e2=ulonglong_value(e2);
+	type = t; if (e2) e2=ulonglong_value(e2);
 	return(list4(LCOND,e1,e2,e3));
     }
 #endif
@@ -2392,7 +2396,9 @@
 	  if (mode==ADECL) {  /* K&R arguments case */
 	    if (n->sc==LVAR && n->ty==INT);
 	    else if ( n->sc==REGISTER && n->ty==INT);
-	    else error(RDERR);
+	    else if ( n->sc==TYPE) {
+		n = lsearch(n->nm,0);
+	    } else error(RDERR);
 	  } else error(RDERR);
 	}
 	sz = size(n->ty = type);
--- a/mc-parse.c	Sat Jul 03 14:40:30 2004 +0900
+++ b/mc-parse.c	Sun Jul 04 19:08:42 2004 +0900
@@ -827,14 +827,24 @@
 		if(sym==RPAR) {
 		    getsym(0);arg=0;
 		} else {
-		    arg=adecl(n);
+		    if (mode==ADECL) {
+			enter_scope();
+			arg=adecl(n);
+			leave_scope();
+		    } else 
+			arg=adecl(n);
 		}
 		type=glist3(CODE,CODE,arg);
 	    } else {
 		if(sym==RPAR) {
 		    getsym(0);arg=0;
 		} else {
-		    arg=adecl(n);
+		    if (mode==ADECL) {
+			enter_scope();
+			arg=adecl(n);
+			leave_scope();
+		    } else 
+			arg=adecl(n);
 		}
 		type=glist3(FUNCTION,type,arg);
 	    }
@@ -2122,11 +2132,17 @@
 	conv->cond_();
 	e1=rvalue(e1);
 	getsym(0);
-	conv->cond1_();
-	e2=rvalue(expr0());
-	t=type;
-	conv->cond2_();
-	checksym(COLON);
+	if (sym==COLON) {
+	    e2 = 0; // dumb extension of gcc
+	    t=type;
+	    getsym(0);
+	} else {
+	    conv->cond1_();
+	    e2=rvalue(expr0());
+	    t=type;
+	    conv->cond2_();
+	    checksym(COLON);
+	}
 	e3=rvalue(expr2());
 	conv->cond_end_();
 	return cond(t,e1,e2,e3);
@@ -3230,6 +3246,7 @@
 	if (nptr0->sc == RESERVE) return sym = nptr0->dsp;
 	sym = IDENT;
 	gnptr=nptr=nptr0;
+
 	if (mode==ADECL && nptr0->sc ==TYPE) return sym;
 	if (mode==GDECL || mode==GSDECL || mode==GUDECL ||
 	    mode==GTDECL || mode==TOP || mode==GEDECL) {
@@ -3451,6 +3468,15 @@
     return n;
 }
 
+extern NMTBL *
+lsearch(char *name,int sc)
+{
+    NMTBL *nlist,*nptr1;
+    nptr1 = name_space_search(
+		nlist = name_space_search(get_name(name,0,DEF),LDECL),sc);
+    return make_local_scope(nlist,nptr1,sc);
+}
+
 static NMTBL *
 l_top_search(char *name,int sc)
 {
--- a/mc-parse.h	Sat Jul 03 14:40:30 2004 +0900
+++ b/mc-parse.h	Sun Jul 04 19:08:42 2004 +0900
@@ -77,6 +77,7 @@
 extern NMTBL * anonymous_nptr();;
 extern int append4(int p,int a1,int a2,int a3);
 extern void display_ntable(NMTBL *n, char *s);
+extern NMTBL * lsearch(char *name,int sc);
 #if FLOAT_CODE
 extern int
 dlist2(int e1, double d1);
--- a/mc.h	Sat Jul 03 14:40:30 2004 +0900
+++ b/mc.h	Sun Jul 04 19:08:42 2004 +0900
@@ -421,7 +421,7 @@
 #define MAX_INCLUDE_PATH_COUNT 10
 
 #define GSYMS		8192
-#define HEAPSIZE        30000*2
+#define HEAPSIZE        30000*2*6
 #define CHEAPSIZE       (sizeof(NMTBL)*GSYMS)
 #define LBUFSIZE        4096
 #define STRSIZE		4096