changeset 516:bfa4c834a3b8

data/text/rodata segment fix (incomplete)
author kono
date Mon, 26 Dec 2005 10:55:15 +0900
parents 3d921f7a8e74
children d686497e8fd2
files Changes mc-code-arm.c mc-code-ia32.c mc-code-mips.c mc-code-powerpc.c mc-code.h mc-codegen.c mc-parse.c test/inline.c
diffstat 9 files changed, 150 insertions(+), 85 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Mon Dec 26 09:18:36 2005 +0900
+++ b/Changes	Mon Dec 26 10:55:15 2005 +0900
@@ -7572,9 +7572,11 @@
         code_set_fixed_creg(t,1,d);
 ですか。
 
-
-
-
-
-
-
+Mon Dec 26 10:54:29 JST 2005
+
+  .cstring とかのデータモードとglobalラベルが変。
+
+
+
+
+
--- a/mc-code-arm.c	Mon Dec 26 09:18:36 2005 +0900
+++ b/mc-code-arm.c	Mon Dec 26 10:55:15 2005 +0900
@@ -29,8 +29,8 @@
 
 #define DOT_SIZE 1
 
-static void data_mode(char *name);
-static void text_mode(int alignment);
+// static void data_mode(char *name);
+// static void text_mode(int alignment);
 static void ld_indexx(int byte, int n, int xreg,int reg,int sign);
 static void local_table(void);
 static void shift(char *op, int creg,int reg);
@@ -3580,20 +3580,23 @@
 
     lb=fwdlabel();
     // should put on different segement
-    printf(".section\t.rodata\n\t.align 2\n");
+    cstring_mode();
     printf(".L%d:\n",lb);
-    output_mode = RODATA_EMIT_MODE;
     return lb;
 }
 
 
 void
-emit_global(char *name,int t)
-{
-    // data_mode(name);
-    printf("\t.globl\t%s\n",name);
-    align(t);
-    printf("%s:\n",name); 
+emit_global(NMTBL *n,int t,int e)
+{
+    if (e && car(e)==STRING) {
+	cstring_mode();
+    } else {
+	data_mode(n->nm);
+	align(t);
+    }
+    printf("\t.globl\t%s\n",n->nm);
+    printf("%s:\n",n->nm); 
 }
 
 void
@@ -3756,6 +3759,15 @@
 }
 
 void
+cstring_mode(int align)
+{
+    if (output_mode!=RODATA_EMIT_MODE) {
+	printf(".section\t.rodata\n\t.align 2\n");
+	output_mode = RODATA_EMIT_MODE;
+    }
+}
+
+void
 text_mode(int align)
 {
     if (output_mode!=TEXT_EMIT_MODE) {
--- a/mc-code-ia32.c	Mon Dec 26 09:18:36 2005 +0900
+++ b/mc-code-ia32.c	Mon Dec 26 10:55:15 2005 +0900
@@ -172,8 +172,8 @@
 static int virtual(int real);
 static void shift(char *op, int reg,int creg);
 static void ld_indexx(int byte, int n, int xreg,int reg,int sign);
-static void data_mode(char *name);
-static void text_mode();
+//static void data_mode(char *name);
+// static void text_mode(int align);
 static int edx_setup(int rreg);
 static void edx_cleanup();
 static void local_table(void);
@@ -544,7 +544,7 @@
     reg_sp = 0;
     freg_sp = 0;
     stack_depth = 0;
-    text_mode();
+    text_mode(0);
     gexpr_code_init();
     regs[creg]=1; regv[creg]=1;
     register_usage("gexpr_init");
@@ -1067,7 +1067,7 @@
     if (output_mode==TEXT_EMIT_MODE) {
 	printf(".text\n");
     } else {
-	text_mode();
+	text_mode(0);
     }
     printf("\tlea _%d,%s\n",lb,register_name(creg,0));
 }
@@ -1834,7 +1834,7 @@
 void
 code_enter(char *name)
 {
-    text_mode();
+    text_mode(0);
     printf("\t.align 4\n");
     if (stmode!=STATIC)
 	printf(".globl %s\n",name);
@@ -1867,7 +1867,7 @@
 void
 enter(char *name)
 {
-    text_mode();
+    text_mode(0);
     printf("\t.align 2\n");
     if (stmode!=STATIC)
 	printf(".globl %s\n",name);
@@ -1886,7 +1886,7 @@
 void
 enter1()
 {
-    text_mode();
+    text_mode(0);
     /* if(disp) printf("\tsubl $%d,%%esp\n",-disp); */
 }
 
@@ -2009,10 +2009,9 @@
 emit_string_label()
 {
     int lb;
-    printf(".section\t.rodata\n");
+    cstring_mode();
     lb=fwdlabel();
     printf("_%d:\n",lb);
-    output_mode = RODATA_EMIT_MODE;
     return lb;
 }
 
@@ -2032,12 +2031,16 @@
 }
 
 extern void
-emit_global(char *name,int t)
+emit_global(NMTBL *n,int t,int e)
 {
-    // data_mode(name);
-    printf(".globl\t%s\n",name);
-    align(t);
-    printf("%s:\n",name); 
+    if (e && car(e)==STRING) {
+        cstring_mode();
+    } else {
+        data_mode(n->nm);
+        align(t);
+    }
+    printf(".globl\t%s\n",n->nm);
+    printf("%s:\n",n->nm); 
 }
 
 extern void
@@ -2195,7 +2198,16 @@
 }
 
 void
-text_mode(void)
+cstring_mode(int align)
+{
+    if (output_mode!=RODATA_EMIT_MODE) {
+        printf(".section\t.rodata\n\t.align 2\n");
+        output_mode = RODATA_EMIT_MODE;
+    }
+}
+
+void
+text_mode(int align)
 {
     if (output_mode!=TEXT_EMIT_MODE) {
 	printf(".text\n");
@@ -2301,7 +2313,7 @@
     if (output_mode==TEXT_EMIT_MODE) {
 	printf(".text\n");
     } else {
-	text_mode();
+	text_mode(0);
     }
     printf("\tfldl _%d\n",lb);
 }
@@ -3306,7 +3318,7 @@
 void
 code_table_close()
 {
-    text_mode();
+    text_mode(0);
 }
 
 #endif
@@ -3424,7 +3436,7 @@
     char *p;
     int reg[MAX_ASM_REG];
 
-    text_mode();
+    text_mode(0);
     c = *asm_str;
     if (c!='\t'&&c!=' ') printf("\t");
     for(i=0;repl && i<MAX_ASM_REG;i++) {
--- a/mc-code-mips.c	Mon Dec 26 09:18:36 2005 +0900
+++ b/mc-code-mips.c	Mon Dec 26 10:55:15 2005 +0900
@@ -22,8 +22,8 @@
 
 #define DOT_SIZE 1
 
-static void data_mode(char *name);
-static void text_mode(int alignment);
+// static void data_mode(char *name);
+// static void text_mode(int alignment);
 static void ld_indexx(int byte, int n, int xreg,int reg,int sign);
 static void local_table(void);
 static void shift(char *op, int creg,int reg);
@@ -3259,21 +3259,23 @@
     int lb;
 
     lb=fwdlabel();
-    // should put on different segement
-    printf("\t.rdata\n\t.align 2\n");
+    cstring_mode();
     printf("$L_%d:\n",lb);
-    output_mode = RODATA_EMIT_MODE;
     return lb;
 }
 
 
 extern void
-emit_global(char *name,int t)
-{
-    // data_mode(name);
-    printf(".globl\t%s\n",name);
-    align(t);
-    printf("%s:\n",name); 
+emit_global(NMTBL *n,int t,int e)
+{
+    if (e && car(e)==STRING) {
+        cstring_mode();
+    } else {
+        data_mode(n->nm);
+        align(t);
+    }
+    printf("\t.globl\t%s\n",n->nm);
+    printf("%s:\n",n->nm);
 }
 
 extern void
@@ -3432,6 +3434,15 @@
 }
 
 void
+cstring_mode(int align)
+{
+    if (output_mode!=RODATA_EMIT_MODE) {
+        printf(".section\t.rodata\n\t.align 2\n");
+        output_mode = RODATA_EMIT_MODE;
+    }
+}
+
+void
 text_mode(int align)
 {
     if (output_mode!=TEXT_EMIT_MODE) {
--- a/mc-code-powerpc.c	Mon Dec 26 09:18:36 2005 +0900
+++ b/mc-code-powerpc.c	Mon Dec 26 10:55:15 2005 +0900
@@ -30,8 +30,6 @@
 #define DATA_EMIT_MODE 1
 #define RODATA_EMIT_MODE 2
 
-static void data_mode(char *name);
-static void text_mode();
 static void ld_indexx(int byte, int n, int xreg,int reg,int sign);
 static void local_table(void);
 static void shift(char *op, int creg,int reg);
@@ -975,7 +973,7 @@
 	free_register(lreg_stack[--lreg_sp]);
     }
     use_int0();
-    text_mode();
+    text_mode(0);
     gexpr_code_init();
     register_usage("gexpr_init");
 }
@@ -1481,7 +1479,7 @@
     if (output_mode==TEXT_EMIT_MODE) {
 	printf(".text\n");
     } else {
-	text_mode();
+	text_mode(0);
     }
     printf("\taddis %s,r31,ha16(L_%d-L_%d)\n",crn,lb,code_base);
     printf("\tla %s,lo16(L_%d-L_%d)(%s)\n",crn,lb,code_base,crn);
@@ -2699,7 +2697,7 @@
 code_enter(char *name)
 {
     if (output_mode!=TEXT_EMIT_MODE) 
-	text_mode();
+	text_mode(0);
     else
 	printf("\t.align 2\n");
     if (stmode!=STATIC)
@@ -2751,7 +2749,7 @@
 enter(char *name)
 {
     if (output_mode!=TEXT_EMIT_MODE) 
-	text_mode();
+	text_mode(0);
     else
 	printf("\t.align 2\n");
     if (stmode!=STATIC)
@@ -2785,7 +2783,7 @@
 void
 enter1()
 {
-    text_mode();
+    text_mode(0);
     // set_lreg(LREG_LREGISTER,0);
     set_ireg(CREG_REGISTER,0);
     set_freg(FREG_FREGISTER,0);
@@ -2948,10 +2946,9 @@
 emit_string_label() {
     int lb;
 
-    printf(".data\t\n.cstring\n\t.align 2\n");
     lb=fwdlabel();
+    cstring_mode();
     printf("L_%d:\n",lb);
-    output_mode = RODATA_EMIT_MODE;
     return lb;
 }
 
@@ -2970,13 +2967,17 @@
     }
 }
 
-extern void
-emit_global(char *name,int t)
+void
+emit_global(NMTBL *n,int t,int e)
 {
-    // data_mode(name);
-    printf(".globl\t_%s\n",name);
-    align(t);
-    printf("_%s:\n",name); 
+    if (e && car(e)==STRING) {
+        cstring_mode();
+    } else {
+        data_mode(n->nm);
+        align(t);
+    }
+    printf("\t.globl\t_%s\n",n->nm);
+    printf("_%s:\n",n->nm);
 }
 
 extern void
@@ -3125,7 +3126,7 @@
 printf("\t.indirect_symbol _%s\n",extrn);
 printf("\t.long dyld_stub_binding_helper\n");
 	    } else if (n->sc==FUNCTION||n->sc==CODE) {
-		text_mode();
+		text_mode(0);
 printf("\t.set L_%s$stub,_%s\n",extrn,extrn);
 		data_mode(0);
 printf("L_%s$non_lazy_ptr:\n\t.long\t_%s\n",extrn,extrn);
@@ -3181,7 +3182,16 @@
 }
 
 void
-text_mode(void)
+cstring_mode(int align)
+{
+    if (output_mode!=RODATA_EMIT_MODE) {
+        printf(".cstring\n\t.align 2\n");
+        output_mode = RODATA_EMIT_MODE;
+    }
+}
+
+void
+text_mode(int align)
 {
     if (output_mode!=TEXT_EMIT_MODE) {
 	printf(".text\n");
@@ -3369,7 +3379,7 @@
     if (output_mode==TEXT_EMIT_MODE) {
 	printf(".text\n");
     } else {
-	text_mode();
+	text_mode(0);
     }
     printf("\taddis %s,r31,ha16(L_%d-L_%d)\n",rrn,lb,code_base);
     printf("\tla %s,lo16(L_%d-L_%d)(%s)\n",rrn,lb,code_base,rrn);
@@ -5201,7 +5211,7 @@
     char *p;
     int reg[MAX_ASM_REG];
 
-    text_mode();
+    text_mode(0);
     c = *asm_str;
     if (c!='\t'&&c!=' ') printf("\t");
     for(i=0;repl && i<MAX_ASM_REG;i++) {
--- a/mc-code.h	Mon Dec 26 09:18:36 2005 +0900
+++ b/mc-code.h	Mon Dec 26 10:55:15 2005 +0900
@@ -29,6 +29,10 @@
 
 /* used by mc-codegen */
 
+extern void data_mode(char *name);
+extern void text_mode(int align);
+extern void cstring_mode();
+
 extern void gexpr_init(void);  /* code generator initialize for each statement */
 extern void emit_init(void);   /* called before delcalartion */
 extern void gen_gdecl(char *n, int gpc);   /* global definition */
@@ -126,7 +130,7 @@
 extern void oprtc(int op,int reg,int v);
 
 extern void align(int t);
-extern void emit_global(char *name,int t);
+extern void emit_global(NMTBL *n,int t,int e);
 extern void emit_space(int sp);
 extern void emit_char(int d);
 extern void emit_short(int d);
--- a/mc-codegen.c	Mon Dec 26 09:18:36 2005 +0900
+++ b/mc-codegen.c	Mon Dec 26 10:55:15 2005 +0900
@@ -2907,16 +2907,14 @@
 emit_data(int e, int t, NMTBL *n)
 {
     int l;
-    char *name;
     t = type_value(t);
-    name = n->nm; 
     if(mode!=GDECL && mode!=STADECL)  { 
 	error(-1); return;
     }
     if (chk) return;
-    if ((car(e)!=STRING && n->dsp != -1)) {
+    if (n->dsp != -1) {
 	n->dsp = -1;   /* initialized flag */
-	emit_global(name,t);
+	emit_global(n,t,e);
     }
     switch(t) {
     case EMPTY:
@@ -2974,17 +2972,9 @@
 	case STRING:
 	    if (car(type_value(n->ty))!=ARRAY || cadr(type_value(n->ty))!=CHAR) {
 		l = emit_string_label();
-		if (n->dsp != -1) {
-		    n->dsp = -1;   /* initialized flag */
-		    emit_global(name,t);
-		}
 		ascii((char *)cadr(e));
 		emit_label(l);
 	    } else {
-		if (n->dsp != -1) {
-		    n->dsp = -1;   /* initialized flag */
-		    emit_global(name,t);
-		}
 		ascii((char *)cadr(e));
 	    }
 	    return;
--- a/mc-parse.c	Mon Dec 26 09:18:36 2005 +0900
+++ b/mc-parse.c	Mon Dec 26 10:55:15 2005 +0900
@@ -1810,8 +1810,8 @@
         e=list3(a->sc==IVAR?LVAR:a->sc,a->dsp,(int)a);
 	cargs = list3(e,cargs,a->ty);
     }
-    e = list4(INLINE,list2(FNAME,(int)n),reverse0(cargs),
-	list3(car(fnptr->ty),cadr(fnptr->ty),caddr(fnptr->ty)));
+    e = list4(INLINE,list2(FNAME,(int)n),cargs,
+	    list3(car(fnptr->ty),cadr(fnptr->ty),caddr(fnptr->ty)));
 
     typedefed=0;
     init_vars=0;
--- a/test/inline.c	Mon Dec 26 09:18:36 2005 +0900
+++ b/test/inline.c	Mon Dec 26 10:55:15 2005 +0900
@@ -50,9 +50,9 @@
 }
 
 static
-inline int ins1(int i,int j)
+inline int ins1(int i,int j, int k)
 {
-   printf("#0054:%d %d\n",i,j);
+   printf("#0054:%d %d %d\n",i,j,k);
    if (f(i)>j) return j;
    else return i;
 }
@@ -102,7 +102,7 @@
 
 }
 
-int (*fnp)(int i,int j);
+int (*fnp)(int i,int j,int k);
 
 int (*fnp3)(int i,int j,int k);
 
@@ -132,8 +132,8 @@
     j1 = ins(k,j-6)+f(v);
     printf("#0132:%d %d %s\n",k1,j1,haa);
 
-    k1 = fnp(v,x);
-    j1 = ins1(k,j-6)+f(v);
+    k1 = fnp(v,x,5);
+    j1 = ins1(k,j-6,6)+f(v);
     printf("#0136:%d %d %s\n",k1,j1,haa);
 }
 
@@ -153,19 +153,43 @@
 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("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);
 }
 
+int (*order1p)(int a0,int a1,int a2, int a3, int a4) = order1;
+
+static inline int inmain(int ac,char *av[])
+{
+     fnp = ins1;
+     order(11,12,13,14,15);
+     order1p(11,12,13,14,15);
+     a0(15,16);
+     a0(-19,16);
+     fnp3 = in2;
+     a1(19,110);
+     main0(ac,av);
+     return 0;
+}
+
+
 int
 main(int ac,char *av[])
 {
      fnp = ins1;
      order(1,2,3,4,5);
+     order1p(1,2,3,4,5);
      a0(5,6);
      a0(-9,6);
      fnp3 = in2;
      a1(9,10);
      main0(ac,av);
+     inmain(ac,av);
      return 0;
 }