changeset 177:352feeae4b0a

macro else/ccout
author kono
date Fri, 28 Nov 2003 15:16:43 +0900
parents 3a7b45f62c66
children 0f395aa93438
files Changes mc-code-powerpc.c mc-parse.c mc.h test/macro.c
diffstat 5 files changed, 86 insertions(+), 37 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Fri Nov 28 13:58:39 2003 +0900
+++ b/Changes	Fri Nov 28 15:16:43 2003 +0900
@@ -3569,3 +3569,12 @@
 なんか、知らないけど、やっぱり全部実装しないとだめなのね。
 
 あと、const int かな。
+
+Fri Nov 28 14:01:25 JST 2003
+
+volatile ... (なにすればいいんだろう?)
+
+なんか、*.c 以外だとソースを上書きしちゃうんじゃ...
+
+うーん、struct のtagとtype名を一緒にされちゃうのか...
+こういうことをされると変数テーブルを直さないと動かせない...
--- a/mc-code-powerpc.c	Fri Nov 28 13:58:39 2003 +0900
+++ b/mc-code-powerpc.c	Fri Nov 28 15:16:43 2003 +0900
@@ -301,7 +301,7 @@
 code_init(void)
 {
     macro_define("__ppc__ 1\n");
-
+    macro_define("__BIG_ENDIAN__ 1\n");
     init_ptr_cache();
 }
 
--- a/mc-parse.c	Fri Nov 28 13:58:39 2003 +0900
+++ b/mc-parse.c	Fri Nov 28 15:16:43 2003 +0900
@@ -290,6 +290,7 @@
     reserve("double",DOUBLE);
     reserve("inline",INLINE);
     reserve("enum",ENUM);
+    reserve("volatile",VOLATILE);
 
     gpc=glineno=0;
     gfree=ilabel=1;
@@ -315,6 +316,7 @@
 newfile(void)
 {
     char *s;
+    int flag = 0;
 
     lineno=0;
     if (chk) fprintf(stderr,"%s:\n",av[ac2]);
@@ -329,9 +331,14 @@
 	    if(s[0]=='.'&&s[1]=='c') {
 		*cheapp++=*s++; *cheapp++=*s++;
 		cheapp[-1]='s';
+		flag =1;
 	    }
 	}
-	if ( (freopen(ccout,"w",stdout)) == NULL ) error(FILERR);
+	if (flag) {
+	    if ( (freopen(ccout,"w",stdout)) == NULL ) error(FILERR);
+	} else {
+	    if ( (freopen("mcout.s","w",stdout)) == NULL ) error(FILERR);
+	}
 	cheapp=ccout;
 	ccout=0;
     }
@@ -377,6 +384,9 @@
 static void
 strage_class()
 {
+   if(sym==VOLATILE) {
+	getsym();
+   }
    if(sym==STATIC) {
 	if(mode==LDECL) {
 		getsym();
@@ -496,7 +506,9 @@
 	else if (sym==CHAR) { getsym(); t = UCHAR; }
 	else if (sym==SHORT) { getsym(); t = USHORT; }
 	else if (sym==LONG) {
-	    getsym(); t = ULONG;
+	    getsym(); 
+	    // t = ULONG;
+	    t = UNSIGNED;
 	    if(sym==LONG) {
 		getsym();
 		// t=ULONGLONG;
@@ -3188,7 +3200,7 @@
 	gnptr=nptr=nptr0;
 	if (mode==ADECL && nptr0->sc ==TYPE) return sym;
 	if (mode==GDECL || mode==GSDECL || mode==GUDECL ||
-	    mode==GTDECL || mode==TOP || GEDECL) {
+	    mode==GTDECL || mode==TOP || mode==GEDECL) {
 	    return sym;
 	}
 	nptr1=lsearch(nptr0->nm);
@@ -3662,6 +3674,29 @@
 }
 
 static void
+macro_if()
+{
+    int c,i;
+    for(c=0;chptr[c];c++);
+    chptr[c] = ';';  /* this can't happen in macro expression */
+    ch= *chptr;
+    getsym();
+    /* i=cexpr(expr(1)); #if allow undefined symbols.. */
+    i=expr(1); 
+    if (car(i)==CONST) i=cadr(i);
+    else i=0;
+    if (ch) {
+	if (chptr[-1]==ch) {
+	/* we are fall into getch(), which lost the last ch */
+	/* chptr[-1]==ch check is fanatic, but ... */
+	    chptr--;
+	} else error(-1);
+    }
+    macro_if_depth = macro_if_current;
+    macro_if_skip = !i;
+}
+
+static void
 macro_processing()
 {
     int i;
@@ -3682,26 +3717,23 @@
 	    macro_if_skip = (!i)^c;
 	}
 	return;
+    } else if (macroeq("elif")) {
+	if (macro_if_current==0) {
+	    error(MCERR); /* extra #else */
+	    return;
+	}
+	if (macro_if_current == macro_if_depth) {
+	    if (!macro_if_skip || macro_if_skip==2) {
+		macro_if_skip=2;
+		return;
+	    }
+	    macro_if();
+	}
+	return;
     } else if (macroeq("if")) {
 	macro_if_current++;
 	if (!macro_if_skip) {
-            for(c=0;chptr[c];c++);
-            chptr[c] = ';';  /* this can't happen in macro expression */
-	    ch= *chptr;
-	    getsym();
-	    /* i=cexpr(expr(1)); #if allow undefined symbols.. */
-	    i=expr(1); 
-	    if (car(i)==CONST) i=cadr(i);
-	    else i=0;
-	    if (ch) {
-		if (chptr[-1]==ch) {
-		/* we are fall into getch(), which lost the last ch */
-		/* chptr[-1]==ch check is fanatic, but ... */
-		    chptr--;
-		} else error(-1);
-	    }
-	    macro_if_depth = macro_if_current;
-	    macro_if_skip = !i;
+	    macro_if();
 	}
 	return;
     } else if (macroeq("else")) {
@@ -3709,23 +3741,12 @@
 	    error(MCERR); /* extra #else */
 	    return;
 	}
-	if (macro_if_current == macro_if_depth)
-	    macro_if_skip = !macro_if_skip;
-	return;
-    } else if (macroeq("elif")) {
-	if (macro_if_current==0) {
-	    error(MCERR); /* extra #else */
-	    return;
+	if (macro_if_current == macro_if_depth) {
+	    if (macro_if_skip==2) ;
+	    else if (macro_if_skip) macro_if_skip=0;
+	    else macro_if_skip=1;
 	}
-	if (macro_if_current == macro_if_depth) {
-	    if (macro_if_skip) {
-		mode_save = mode; mode = IFDEF;
-		ch= *chptr;
-		i = getsym();
-		mode = mode_save;
-		macro_if_skip = (!i)^c;
-	    }
-	}
+	return;
     } else if (macroeq("endif")) {
 	if (macro_if_current == macro_if_depth) {
 	    macro_if_skip = 0;
--- a/mc.h	Fri Nov 28 13:58:39 2003 +0900
+++ b/mc.h	Fri Nov 28 15:16:43 2003 +0900
@@ -70,6 +70,7 @@
 #define DOUBLE	(-53)
 #define LONGLONG	(-54)
 #define ULONGLONG	(-55)
+#define VOLATILE	(-56)
 
 /* reserved word end */
 
--- a/test/macro.c	Fri Nov 28 13:58:39 2003 +0900
+++ b/test/macro.c	Fri Nov 28 15:16:43 2003 +0900
@@ -29,6 +29,24 @@
 #if 0
    g(car(cadr(e)),cadr(e));
 #endif
+#if 0
+   printf("1\n");
+#elif (1)
+   printf("2\n");
+#elif (2)
+   printf("3\n");
+#else
+   printf("4\n");
+#endif
+#if 0
+   printf("1\n");
+#elif (0)
+   printf("2\n");
+#elif (0)
+   printf("3\n");
+#else
+   printf("4\n");
+#endif
     return 0;
 }