changeset 541:4d853ee76ad6

minor fixes for s-dandy
author kono
date Sun, 01 Jan 2006 12:25:08 +0900
parents fe37f32b552b
children 492f06738550
files mc-code-mips.c mc-codegen.c mc-parse.c test/simp.c
diffstat 4 files changed, 61 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/mc-code-mips.c	Sun Jan 01 11:14:34 2006 +0900
+++ b/mc-code-mips.c	Sun Jan 01 12:25:08 2006 +0900
@@ -14,6 +14,30 @@
     0
 };
 
+// va_start, va_arg is wrong, use va_mips.h
+
+static char *init_src0 = "\
+/* #define __builtin_va_list int */\n\
+/* #define __builtin_va_start(ap,arg) ap=(((int)(&arg))+sizeof(arg)) */\n\
+/* #define __builtin_va_arg(ap,type)  (*((type *)ap)++) */\n\
+#define __builtin_next_arg(arg)  ap=((void *)(&arg)),va_arg(ap,typeof(arg))\n\
+#define __mips__ 1\n\
+#define __LITTLE_ENDIAN__ 1\n\
+#define __inline__\n\
+#define __STDC__ 1\n\
+#define __SIZE_TYPE__ int\n\
+#define __externsion__\n\
+#define __attribute__(a)\n\
+#define __flexarr\n\
+#define __WCHAR_TYPE__ int\n\
+#define __alignof__(type) (sizeof(type)==1?1:sizeof(type)==2?2:sizeof(type)<=4?4:8)\n\
+#define __PTRDIFF_TYPE__ int\n\
+#define __GNUC__ 2\n\
+#define __const const\n\
+#define __signed__ signed\n\
+#define alloca __builtin_alloca\n\
+";
+
 int data_alignment = 0;
 
 #define TEXT_EMIT_MODE 0
@@ -462,29 +486,6 @@
 }
 
 
-// va_start, va_arg is wrong, use va_mips.h
-
-static char *init_src0 = "\
-/* #define __builtin_va_list int */\n\
-/* #define __builtin_va_start(ap,arg) ap=(((int)(&arg))+sizeof(arg)) */\n\
-/* #define __builtin_va_arg(ap,type)  (*((type *)ap)++) */\n\
-#define __builtin_next_arg(arg)  ap=((void *)(&arg)),va_arg(ap,typeof(arg))\n\
-#define __mips__ 1\n\
-#define __LITTLE_ENDIAN__ 1\n\
-#define __inline__\n\
-#define __STDC__ 1\n\
-#define __SIZE_TYPE__ int\n\
-#define __externsion__\n\
-#define __attribute__(a)\n\
-#define __flexarr\n\
-#define __WCHAR_TYPE__ int\n\
-#define __alignof__(type) (sizeof(type)==1?1:sizeof(type)==2?2:sizeof(type)<=4?4:8)\n\
-#define __PTRDIFF_TYPE__ int\n\
-#define __GNUC__ 2\n\
-#define __const const\n\
-#define alloca __builtin_alloca\n\
-";
-
 void
 code_init(void)
 {
--- a/mc-codegen.c	Sun Jan 01 11:14:34 2006 +0900
+++ b/mc-codegen.c	Sun Jan 01 12:25:08 2006 +0900
@@ -2167,17 +2167,17 @@
 	return(list4(LASSOP,e1,e2,op+LOP+((op==MUL+AS||op==DIV+AS)?US:0)));
 #endif
     case CHAR:
-	type= set_type_with_attr(INT,type); ass = CASSOP;  break;
+	e2=correct_type(e2,INT); ass = CASSOP;  break;
     case SHORT:
-	type= set_type_with_attr(INT,type); ass = SASSOP; break;
+	e2=correct_type(e2,INT); ass = SASSOP; break;
     case INT:
-	type= set_type_with_attr(INT,type); ass = ASSOP;  break;
+	e2=correct_type(e2,INT); ass = ASSOP;  break;
     case UCHAR:
-	type= set_type_with_attr(UNSIGNED,type); ass = CUASSOP; u=1; break;
+	e2=correct_type(e2,UNSIGNED); ass = CUASSOP; u=1; break;
     case USHORT:
-	type= set_type_with_attr(UNSIGNED,type); ass = SUASSOP; u=1; break;
+	e2=correct_type(e2,UNSIGNED); ass = SUASSOP; u=1; break;
     case UNSIGNED:
-	type= set_type_with_attr(UNSIGNED,type); ass = ASSOP;  u=1; break;
+	e2=correct_type(e2,UNSIGNED); ass = ASSOP;  u=1; break;
     default:
 	if (t>0 && car(t)==BIT_FIELD) {
             //        type = list4(BIT_FIELD,type,
@@ -2764,7 +2764,12 @@
 	    else if ( n->sc==TYPE) {
 		n = lsearch(n->nm,0);
 	    } else error(RDERR);
-	  } else error(RDERR);
+	  } else {
+	    if (mode==GDECL)
+		compatible(n->ty,type);
+	    else
+		error(RDERR); // on different type
+	  }
 	}
 	sz = size(n->ty = type);
     }
--- a/mc-parse.c	Sun Jan 01 11:14:34 2006 +0900
+++ b/mc-parse.c	Sun Jan 01 12:25:08 2006 +0900
@@ -1438,14 +1438,16 @@
     } else if (scalar(t)) {
  	e=expr1();
 	mode = mode_save;
- 	if(car(e)!=CONST && t==CHAR)
- 	    error(TYERR);
+ 	//if(car(e)!=CONST && t==CHAR)
+ 	//    error(TYERR);
+	e = correct_type(e,t0);
  	offset = assign_data(e,t,n,offset);
  	type=t;
 	return offset;
     } else if (t0==FLOAT||t0==DOUBLE||t0==LONGLONG||t0==ULONGLONG) {
  	e=expr1();
 	mode = mode_save;
+	e = correct_type(e,t0);
  	offset = assign_data(e,t,n,offset);
  	type=t;
 	return offset;
@@ -1492,6 +1494,7 @@
     } else if (t1==BIT_FIELD) {
  	e=expr1();
 	mode = mode_save;
+	// e = correct_type(e,t);  correct me
  	offset = assign_data(e,t,n,offset);
  	type=t;
 	return offset;
@@ -3015,6 +3018,10 @@
 	}
 	type=list2(POINTER,type);
 	return e;
+    case ADD:  /* +p */
+	conv->prefix_(sym);
+	getsym(0);
+	return expr13();
     case SUB:  /* -p */
 	conv->prefix_(sym);
 	getsym(0);
@@ -3413,7 +3420,7 @@
 	}
 	checksym(RPAR);
 	break;
-    default:error(EXERR);
+    default:error(EXERR); e1=list2(CONST,0);
     }
     return expr16(e1);
 }
@@ -3992,12 +3999,12 @@
 	} else {
 #if FLOAT_CODE
 	    /* floating point case */
-	    while(digit(ch)|| ch=='.'||ch=='e') {
+	    while(digit(ch)|| ch=='.'||ch=='e'||ch=='f') {
 		*cheap->ptr = ch;
 		cheap = increment_cheap(cheap,&num);
 		getch();
-		if ((ch=='-' && cheap->ptr[-1]=='e')||
-			(ch=='+' && cheap->ptr[-1]=='e')) {
+		if ((ch=='-' && cheap->ptr[-1]=='e'&& cheap->ptr[-1]=='f')||
+			(ch=='+' && cheap->ptr[-1]=='e'&& cheap->ptr[-1]=='f')) {
 		    *cheap->ptr = ch;
 		    cheap = increment_cheap(cheap,&num);
 		    getch();
--- a/test/simp.c	Sun Jan 01 11:14:34 2006 +0900
+++ b/test/simp.c	Sun Jan 01 12:25:08 2006 +0900
@@ -1,5 +1,16 @@
 #include "stdio.h"
 
+
+float f = 3;
+float g = 4096.0f;
+
+int
+main2(int i)
+{
+    i+=f;
+    return +i;
+}
+
 int
 alpha(c)
 char c;
@@ -22,6 +33,7 @@
     }
     ch = 'E';
     main1(-8);
+    printf("%d\n",main2(3));
     return main0(ac,ch,av);
 }