changeset 517:d686497e8fd2

cstring array fix.
author kono
date Mon, 26 Dec 2005 12:17:23 +0900
parents bfa4c834a3b8
children 9f2d6aea201f
files mc-code-arm.c mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-codegen.c test/basic.c test/inline.c
diffstat 7 files changed, 44 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/mc-code-arm.c	Mon Dec 26 10:55:15 2005 +0900
+++ b/mc-code-arm.c	Mon Dec 26 12:17:23 2005 +0900
@@ -3587,14 +3587,15 @@
 
 
 void
-emit_global(NMTBL *n,int t,int e)
-{
-    if (e && car(e)==STRING) {
-	cstring_mode();
-    } else {
+emit_global(NMTBL *n,int a,int e)
+{
+    int t = type_value(n->ty);
+    if (e>0 && car(e)==STRING && t>0 && car(t)==ARRAY &&  
+            (type_value(cadr(t))==CHAR||type_value(cadr(t))==UCHAR)) {
+        cstring_mode();
+    } else
 	data_mode(n->nm);
-	align(t);
-    }
+    align(a);
     printf("\t.globl\t%s\n",n->nm);
     printf("%s:\n",n->nm); 
 }
--- a/mc-code-ia32.c	Mon Dec 26 10:55:15 2005 +0900
+++ b/mc-code-ia32.c	Mon Dec 26 12:17:23 2005 +0900
@@ -2031,14 +2031,15 @@
 }
 
 extern void
-emit_global(NMTBL *n,int t,int e)
+emit_global(NMTBL *n,int a,int e)
 {
-    if (e && car(e)==STRING) {
+    int t = type_value(n->ty);
+    if (e>0 && car(e)==STRING && t>0 && car(t)==ARRAY &&  
+            (type_value(cadr(t))==CHAR||type_value(cadr(t))==UCHAR)) {
         cstring_mode();
-    } else {
-        data_mode(n->nm);
-        align(t);
-    }
+    } else
+	data_mode(n->nm);
+    align(a);
     printf(".globl\t%s\n",n->nm);
     printf("%s:\n",n->nm); 
 }
--- a/mc-code-mips.c	Mon Dec 26 10:55:15 2005 +0900
+++ b/mc-code-mips.c	Mon Dec 26 12:17:23 2005 +0900
@@ -3266,14 +3266,15 @@
 
 
 extern void
-emit_global(NMTBL *n,int t,int e)
-{
-    if (e && car(e)==STRING) {
+emit_global(NMTBL *n,int a,int e)
+{
+    int t = type_value(n->ty);
+    if (e>0 && car(e)==STRING && t>0 && car(t)==ARRAY &&  
+            (type_value(cadr(t))==CHAR||type_value(cadr(t))==UCHAR)) {
         cstring_mode();
-    } else {
-        data_mode(n->nm);
-        align(t);
-    }
+    } else
+	data_mode(n->nm);
+    align(a);
     printf("\t.globl\t%s\n",n->nm);
     printf("%s:\n",n->nm);
 }
--- a/mc-code-powerpc.c	Mon Dec 26 10:55:15 2005 +0900
+++ b/mc-code-powerpc.c	Mon Dec 26 12:17:23 2005 +0900
@@ -2925,6 +2925,7 @@
 extern void
 ascii(char *s)
 {
+    cstring_mode();
     printf("\t.ascii \"");
     while(*s) {
 	if (*s=='\n')
@@ -2968,14 +2969,14 @@
 }
 
 void
-emit_global(NMTBL *n,int t,int e)
+emit_global(NMTBL *n,int a,int e)
 {
-    if (e && car(e)==STRING) {
-        cstring_mode();
-    } else {
-        data_mode(n->nm);
-        align(t);
-    }
+    int t = type_value(n->ty);
+    if (e>0 && car(e)==STRING && t>0 && car(t)==ARRAY && 
+	    (type_value(cadr(t))==CHAR||type_value(cadr(t))==UCHAR)) {
+	cstring_mode();
+    } else 
+	data_mode(n->nm);
     printf("\t.globl\t_%s\n",n->nm);
     printf("_%s:\n",n->nm);
 }
--- a/mc-codegen.c	Mon Dec 26 10:55:15 2005 +0900
+++ b/mc-codegen.c	Mon Dec 26 12:17:23 2005 +0900
@@ -2970,12 +2970,14 @@
 	    emit_address(((NMTBL *)caddr(e))->nm,0);
 	    return;
 	case STRING:
-	    if (car(type_value(n->ty))!=ARRAY || cadr(type_value(n->ty))!=CHAR) {
+	    t = type_value(n->ty);
+	    if (car(t)==ARRAY && 
+		    (type_value(cadr(t))==CHAR||type_value(cadr(t))==UCHAR)) {
+		ascii((char *)cadr(e));
+	    } else {
 		l = emit_string_label();
 		ascii((char *)cadr(e));
 		emit_label(l);
-	    } else {
-		ascii((char *)cadr(e));
 	    }
 	    return;
 	}
--- a/test/basic.c	Mon Dec 26 10:55:15 2005 +0900
+++ b/test/basic.c	Mon Dec 26 12:17:23 2005 +0900
@@ -14,6 +14,9 @@
 double ggg0;
 float fff0;
 
+char *memchar = "memory string\n";
+char arraychar[] = "array string\n";
+
 #if 0
 extern double reggg;
 extern float refff;
@@ -233,5 +236,7 @@
     print(1.234e-10);
     tmp1();
     double_int();
+    printf("%s", memchar );
+    printf("%s", arraychar);
     return 0;
 }
--- a/test/inline.c	Mon Dec 26 10:55:15 2005 +0900
+++ b/test/inline.c	Mon Dec 26 12:17:23 2005 +0900
@@ -2,6 +2,7 @@
 int kkkk = 333;
 static const int as = 5,bs = -3;
 const char hoo[] = "test";
+char hoo0[] = "test";
 static const char haa[] = "test";
 static inline const int f(int k);
 
@@ -153,13 +154,13 @@
 static
 inline int order(int a0,int a1,int a2, int a3, int a4)
 {
-    printf("order  %d %d %d %d %d\n",a0,a1,a2,a3,a4);
+    printf("#0155:order  %d %d %d %d %d\n",a0,a1,a2,a3,a4);
 }
 
 static
 inline int order1(int a0,int a1,int a2, int a3, int a4)
 {
-    printf("orderp %d %d %d %d %d\n",a0,a1,a2,a3,a4);
+    printf("#0161:orderp %d %d %d %d %d\n",a0,a1,a2,a3,a4);
 }
 
 int (*order1p)(int a0,int a1,int a2, int a3, int a4) = order1;