changeset 109:e09f9de6f5d3

*** empty log message ***
author kono
date Wed, 19 Mar 2003 02:22:33 +0900
parents 69e2e763cce5
children fb502a0071f8
files Makefile mc-code-ia32.c mc-code-powerpc.c mc-code.h mc-codegen.c mc-parse.c
diffstat 6 files changed, 111 insertions(+), 61 deletions(-) [+]
line wrap: on
line diff
--- a/Makefile	Tue Mar 18 20:50:37 2003 +0900
+++ b/Makefile	Wed Mar 19 02:22:33 2003 +0900
@@ -8,8 +8,8 @@
 CONVERTER=conv/c.o conv/null.o
 # conv/c2cbc.o conv/cbc2c.o
 COMPLIB = mc-parse.o mc-codegen.o mc-tree.o
-# CODE=mc-code-ia32.o
-CODE=mc-code-powerpc.o
+# CODE=mc-code-ia32.c
+CODE=mc-code-powerpc.c
 
 all: mc mc-ia32 mc-powerpc
 
@@ -47,12 +47,12 @@
 	$(CC) -g -o $@ $(PRINTF) b00.s b01.s mc-codegen.o mc-tree.o $(CONVERTER)
 b00.s : mc-parse.c $(MC)
 	./$(MC) -s -ob00.s mc-parse.c
-b01.s : mc-code-ia32.c $(MC)
-	./$(MC) -s -ob01.s mc-code-ia32.c 
+b01.s : $(CODE) $(MC)
+	./$(MC) -s -ob01.s $(CODE)
 b10.s : mc-parse.c mc1
 	./mc1 -s -ob10.s mc-parse.c
-b11.s : mc-code-ia32.c $(PRINTF) mc1
-	./mc1 -s -ob11.s mc-code-ia32.c 
+b11.s : $(CODE) $(PRINTF) mc1
+	./mc1 -s -ob11.s $(CODE)
 
 diff :  b00.s b01.s b10.s b11.s
 	-diff b00.s b10.s
--- a/mc-code-ia32.c	Tue Mar 18 20:50:37 2003 +0900
+++ b/mc-code-ia32.c	Wed Mar 19 02:22:33 2003 +0900
@@ -287,6 +287,11 @@
     printf("\n");
 }
 
+void
+code_arg_register()
+{
+}
+
 void 
 gexpr_init(void)
 {
@@ -461,20 +466,20 @@
 
 void
 code_gvar(int e1,int creg) {
-    printf("\tmovl $%s,%s\n",(char *)caddr(e1),register_name(creg,0));
+    printf("\tmovl $%s,%s\n",((NMTBL*)cadr(e1))->nm,register_name(creg,0));
     regv[creg]=1;
 }
 
 
 void
 code_rgvar(int e1,int creg) {
-    printf("\tmovl %s,%s\n",(char *)caddr(e1),register_name(creg,0));
+    printf("\tmovl %s,%s\n",((NMTBL*)cadr(e1))->nm,register_name(creg,0));
     regv[creg]=1;
 }
 
 void
 code_crgvar(int e1,int creg){
-    printf("\tmovsbl %s,%s\n",(char *)caddr(e1),register_name(creg,0));
+    printf("\tmovsbl %s,%s\n",((NMTBL*)cadr(e1))->nm,register_name(creg,0));
     regv[creg]=1;
 }
 
@@ -508,8 +513,8 @@
 
 
 void
-code_fname(char *e2,int creg) {
-    printf("\tmovl $%s,%s\n",e2,register_name(creg,0));
+code_fname(NMTBL *n,int creg) {
+    printf("\tmovl $%s,%s\n",n->nm,register_name(creg,0));
     regv[creg]=1;
 }
 
@@ -699,7 +704,7 @@
 
 void
 code_cmp_crgvar(int e1) {
-    printf("\tcmpb $0,%s\n",(char *)caddr(e1));
+    printf("\tcmpb $0,%s\n",((NMTBL*)cadr(e1))->nm);
 }
 
 
@@ -711,7 +716,7 @@
 
 void
 code_cmp_rgvar(int e1) {
-    printf("\tcmpl $0,%s\n",(char *)caddr(e1));
+    printf("\tcmpl $0,%s\n",((NMTBL*)cadr(e1))->nm);
 }
 
 
@@ -1047,7 +1052,7 @@
 void
 code_assign_gvar(int e2,int creg,int byte) {
     if (byte) use_data_reg(creg,1);
-    printf("\t%s %s,%s\n",move(byte),register_name(creg,byte),(char *)caddr(e2));
+    printf("\t%s %s,%s\n",move(byte),register_name(creg,byte),((NMTBL*)cadr(e2))->nm);
 }
 
 void
@@ -1477,7 +1482,9 @@
     } else if(t!=CHAR) {       
 	gpc += size_of_int;
 	if(car(e)==ADDRESS&&car(cadr(e))==GVAR) {
-	    printf("\t.long %s\n",(char *)caddr(cadr(e)));
+	    printf("\t.long %s\n",((NMTBL *)cadr(cadr(e)))->nm);
+	} else if(car(e)==GVAR) {
+	    printf("\t.long %s\n",((NMTBL *)cadr(e))->nm);
 	} else if(car(e)==FNAME) {
 	    printf("\t.long %s\n",((NMTBL *)cadr(e))->nm);
 	} else if(car(e)==STRING) {       
@@ -1602,7 +1609,7 @@
 
 void code_dassign_gvar(int e2,int freg,int d)
 { 
-    printf("\t%s %s\n",fstore(d),(char *)caddr(e2)) ;
+    printf("\t%s %s\n",fstore(d),((NMTBL*)cadr(e2))->nm);
 }
 
 void code_dassign_lvar(int e2,int freg,int d)
@@ -1706,7 +1713,7 @@
 
 void code_drgvar(int e2,int d,int freg)
 { 
-    printf("\t%s %s\n",fload(d),(char *)caddr(e2)) ;
+    printf("\t%s %s\n",fload(d),((NMTBL*)cadr(e2))->nm);
 }
 
 
@@ -1717,7 +1724,7 @@
 
 void code_cmp_drgvar(int e2)
 { 
-    printf("\tfcomp %s\n",(char *)caddr(e2)) ;
+    printf("\tfcomp %s\n",((NMTBL*)cadr(e2))->nm);
 }
 
 void code_cmp_drlvar(int e2)
--- a/mc-code-powerpc.c	Tue Mar 18 20:50:37 2003 +0900
+++ b/mc-code-powerpc.c	Wed Mar 19 02:22:33 2003 +0900
@@ -120,6 +120,11 @@
     "f30","f31"
 }; 
 
+static
+NMTBL float_zero = {"_float_zero",STATIC,FLOAT,0};
+static
+NMTBL float_one = {"_float_one",STATIC,FLOAT,0};
+
 char * fload(int d);
 int code_d1(double d);
 int code_d2(double d);
@@ -173,6 +178,12 @@
     return 0;
 }
 
+void
+code_arg_register()
+{
+    code_save_input_registers();
+}
+
 int 
 get_register(void)
 {    /* 使われていないレジスタを調べる */
@@ -327,6 +338,7 @@
 {
     int i;
     if (chk) return;
+    if (!lsrc) return;
     printf("# %d: %s:",lineno,s);
     printf(" creg=%s fgreg=%s\n# regs:",register_name(creg),fregister_name(freg));
 #if 0
@@ -492,11 +504,11 @@
 
 
 int
-get_ptr_cache(char *name)
+get_ptr_cache(NMTBL *nptr)
 {
     int r;
     int ptcptr=ptr_cache;
-    int g = (int)name;
+    int g = (int)nptr;
     int p,p1;
     char *rrn;
 
@@ -516,10 +528,17 @@
 	car(p)=g;
     }
     rrn = register_name(r);
-    printf("\taddis %s,r31,ha16(L_%s$non_lazy_ptr-L_%d)\n",
-	     rrn,(char *)g,code_base);
-    printf("\tla %s,lo16(L_%s$non_lazy_ptr-L_%d)(%s)\n",
-	     rrn,(char *)g,code_base,rrn);
+    if (nptr->sc==STATIC) {
+	printf("\taddis %s,r31,ha16(_%s-L_%d)\n",
+		 rrn,nptr->nm,code_base);
+	printf("\tla %s,lo16(_%s-L_%d)(%s)\n",
+		 rrn,nptr->nm,code_base,rrn);
+    } else {
+	printf("\taddis %s,r31,ha16(L_%s$non_lazy_ptr-L_%d)\n",
+		 rrn,nptr->nm,code_base);
+	printf("\tlwz %s,lo16(L_%s$non_lazy_ptr-L_%d)(%s)\n",
+		 rrn,nptr->nm,code_base,rrn);
+    }
     return r;
 }
 
@@ -533,7 +552,7 @@
 void
 code_gvar(int e1,int creg) {
     int r;
-    r = get_ptr_cache((char*)caddr(e1));
+    r = get_ptr_cache((NMTBL*)cadr(e1));
     if(r!=creg)
 	printf("\tmr %s,%s\n",register_name(creg),register_name(r));
     regv[creg]=1;
@@ -543,7 +562,7 @@
 void
 code_rgvar(int e1,int creg) {
     printf("\tlwz %s,0(%s)\n",register_name(creg),
-                             register_name(get_ptr_cache((char*)caddr(e1))));
+                             register_name(get_ptr_cache((NMTBL*)cadr(e1))));
     regv[creg]=1;
 }
 
@@ -551,7 +570,7 @@
 code_crgvar(int e1,int creg){
     char *crn = register_name(creg);
     printf("\tlbz %s,0(%s)\n",crn,
-                             register_name(get_ptr_cache((char*)caddr(e1))));
+                             register_name(get_ptr_cache((NMTBL*)cadr(e1))));
     printf("\textsb %s,%s\n",crn,crn);
     regv[creg]=1;
 }
@@ -589,9 +608,9 @@
 
 
 void
-code_fname(char *e2,int creg) {
+code_fname(NMTBL *n,int creg) {
     int r;
-    r = get_ptr_cache(e2);
+    r = get_ptr_cache(n);
     if(r!=creg)
 	printf("\tmr %s,%s\n",register_name(creg),register_name(r));
     regv[creg]=1;
@@ -855,7 +874,7 @@
 code_cmp_crgvar(int e1) {
     int r;
     char *crn = register_name(creg);
-    r = get_ptr_cache((char *)caddr(e1));
+    r = get_ptr_cache((NMTBL*)cadr(e1));
     printf("\tlbz %s,0(%s)\n",crn,register_name(r));
     printf("\tcmpwi cr0,%s,0\n",crn);
     regv[creg]=0;
@@ -875,7 +894,7 @@
 code_cmp_rgvar(int e1) {
     int r;
     char *crn = register_name(creg);
-    r = get_ptr_cache((char *)caddr(e1));
+    r = get_ptr_cache((NMTBL*)cadr(e1));
     printf("\tlwz %s,0(%s)\n",crn,register_name(r));
     code_cmp_register(creg);
     regv[creg]=0;
@@ -923,7 +942,7 @@
     crn=register_name(creg);
 
     s=(char *)cadr(e1);
-    printf(".data\t.cstring\n\t.align 2\n");
+    printf(".data\t\n.cstring\n\t.align 2\n");
     lb=fwdlabel();
     printf("L_%d:\n",lb);
     ascii(s);
@@ -1276,7 +1295,7 @@
 code_assign_gvar(int e2,int creg,int byte) {
     int r;
     char *crn,*rrn;
-    r = get_ptr_cache((char*)caddr(e2));
+    r = get_ptr_cache((NMTBL*)cadr(e2));
     rrn=register_name(r);
     crn=register_name(creg);
     if (byte) {
@@ -1576,7 +1595,6 @@
 void
 enter1()
 {
-    code_save_input_registers();
     set_creg(CREG_REGISTER,0);
     set_freg(FREG_FREGISTER,0);
 }
@@ -1730,9 +1748,11 @@
     } else if(t!=CHAR) {       
 	gpc += size_of_int;
 	if(car(e)==ADDRESS&&car(cadr(e))==GVAR) {
-	    printf("\t.long %s\n",(char *)caddr(cadr(e)));
+	    printf("\t.long %s\n",((NMTBL *)cadr(cadr(e)))->nm);
 	} else if(car(e)==FNAME) {
 	    printf("\t.long %s\n",((NMTBL *)cadr(e))->nm);
+	} else if(car(e)==GVAR) {
+	    printf("\t.long %s\n",((NMTBL *)cadr(e))->nm);
 	} else if(car(e)==STRING) {       
 	    if (car(n->ty)!=ARRAY || cadr(n->ty)!=CHAR) {
 		l = fwdlabel();
@@ -1770,13 +1790,20 @@
     int init; char *extrn;
     init=0;
     for(n=ntable;n < &ntable[GSYMS];n++) {
-	if (n->sc == GVAR && n->dsp != -1) {
+	if ((n->sc == GVAR) && n->dsp != -1) {
 	    /* n->dsp = -1 means initialized global */
 	    if (init==0) {
 		data_mode(0);
 		init=1;
 	    }
 	    printf(".comm _%s,%d\n",n->nm,size(n->ty));
+	} else if ((n->sc==STATIC) && n->dsp != -1) {
+	    /* n->dsp = -1 means initialized global */
+	    if (init==0) {
+		data_mode(0);
+		init=1;
+	    }
+	    printf(".lcomm _%s,%d\n",n->nm,size(n->ty));
 	}
     }
     for(n=ntable;n < &ntable[GSYMS];n++) {
@@ -1805,13 +1832,24 @@
 	    } else if (n->sc==FUNCTION||n->sc==CODE) {
 		text_mode();
 printf("\t.set L_%s$stub,_%s\n",extrn,extrn);
-printf("\t.set L_%s$non_lazy_ptr,_%s\n",extrn,extrn);
+		data_mode(0);
+printf("L_%s$non_lazy_ptr:\n\t.long\t_%s\n\n",extrn,extrn);
 	    } 
 	}
     }
+    init=0;
+    for(n=ntable;n < &ntable[GSYMS];n++) {
+	if (n->sc == GVAR) {
+	    if (init==0) {
+		data_mode(0);
+		init=1;
+	    }
+printf("L_%s$non_lazy_ptr:\n\t.long\t_%s\n\n",n->nm,n->nm);
+	}
+    }
     init = 0;
     for(n=ntable;n < &ntable[GSYMS];n++) {
-	if (n->sc==GVAR&& n->dsp == EXTRN1) {
+	if (n->sc==EXTRN1) {
 	    if(init==0) {
 		data_mode(0);
 printf(".non_lazy_symbol_pointer\n");
@@ -1887,7 +1925,7 @@
 "__float_one:",
 "        .long   1065353216",
 ".text",
-".set L__float_one$non_lazy_ptr,__float_one",
+/* ".set L__float_one$non_lazy_ptr,__float_one", */
 0
 };
 static int float_zero_lib_used=0;
@@ -1898,7 +1936,7 @@
 "__float_zero:",
 "        .long   0",
 ".text",
-".set L__float_zero$non_lazy_ptr,__float_zero",
+/* ".set L__float_zero$non_lazy_ptr,__float_zero", */
 0
 };
 
@@ -1924,7 +1962,7 @@
     grn =  register_name(greg = get_fregister());
     frn = register_name(freg);
     float_zero_lib_used=1;
-    r = get_ptr_cache("_float_zero");
+    r = get_ptr_cache(&float_zero);
     rrn = register_name(r);
     printf("\tlfs %s,0(%s)\n",grn,rrn);
     printf("\tfcmpu cr0,%s,%s\n",grn,frn);
@@ -1944,7 +1982,7 @@
 void code_dassign_gvar(int e2,int freg,int d)
 { 
     int r;
-    r = get_ptr_cache((char*)caddr(e2));
+    r = get_ptr_cache((NMTBL*)cadr(e2));
     printf("\t%s %s,0(%s)\n",fstore(d),fregister_name(freg),register_name(r));
     fregv[freg]=1;
 }
@@ -1987,14 +2025,14 @@
     frn = fregister_name(freg);
     if (d==0.0) {
 	float_zero_lib_used=1;
-	r = get_ptr_cache("_float_zero");
+	r = get_ptr_cache(&float_zero);
 	rrn = register_name(r);
 	printf("\tlfs %s,0(%s)\n",frn,rrn);
 	return;
     }
     if (d==1.0) {
 	float_one_lib_used=1;
-	r = get_ptr_cache("_float_one");
+	r = get_ptr_cache(&float_one);
 	rrn = register_name(r);
 	printf("\tlfs %s,0(%s)\n",frn,rrn);
 	return;
@@ -2060,7 +2098,7 @@
 "        lfd f1,lo16(__i2dLC0-__i2dL1$pb)(r9)",
 "        fsub f1,f0,f1",
 "        blr",
-".set L_i2d$non_lazy_ptr,i2d",
+/* ".set L_i2d$non_lazy_ptr,i2d", */
 0
 };
 
@@ -2107,7 +2145,7 @@
 "        lwz r3,-20(r1)",
 "        xoris r3,r3,0x8000",
 "        blr",
-".set L_d2u$non_lazy_ptr,d2u",
+/* ".set L_d2u$non_lazy_ptr,d2u", */
 0
 };
 
@@ -2145,7 +2183,7 @@
 "        lfd f1,lo16(__u2dLC1-__u2dL2$pb)(r9)",
 "        fsub f1,f0,f1",
 "        blr",
-".set L_u2d$non_lazy_ptr,u2d",
+/* ".set L_u2d$non_lazy_ptr,u2d", */
 0
 };
 
@@ -2164,7 +2202,7 @@
 void code_drgvar(int e2,int d,int freg)
 { 
     int r;
-    r = get_ptr_cache((char*)caddr(e2));
+    r = get_ptr_cache((NMTBL*)cadr(e2));
     printf("\t%s %s,0(%s)\n",fload(d),fregister_name(freg),register_name(r));
     fregv[freg]=1;
 }
@@ -2183,7 +2221,7 @@
     char *frn=fregister_name(freg);
     int g=get_fregister();
     char *grn=fregister_name(g);
-    r = get_ptr_cache((char*)caddr(e2));
+    r = get_ptr_cache((NMTBL*)cadr(e2));
     printf("\t%s %s,0(%s)\n",fload(1),grn,register_name(r));
     printf("\tfcmpu cr0,%s,%s\n",frn,grn);
     free_fregister(g);
@@ -2249,7 +2287,7 @@
     int  g;
     char *grn,*drn;
     int r;
-    r = get_ptr_cache("_float_one");
+    r = get_ptr_cache(&float_one);
     float_one_lib_used=1;
 
     g_expr(e2);
@@ -2277,7 +2315,7 @@
     int  g;
     char *grn,*drn;
     int r;
-    r = get_ptr_cache("_float_one");
+    r = get_ptr_cache(&float_one);
     float_one_lib_used=1;
 
     g_expr(e2);
--- a/mc-code.h	Tue Mar 18 20:50:37 2003 +0900
+++ b/mc-code.h	Wed Mar 19 02:22:33 2003 +0900
@@ -38,7 +38,7 @@
 extern void code_register(int e2,int reg);
 extern void code_rlvar(int e2,int reg);
 extern void code_crlvar(int e2,int reg);
-extern void code_fname(char *e2,int reg);
+extern void code_fname(NMTBL *n,int reg);
 extern void code_const(int e2,int reg);
 extern void code_neg(int reg);
 extern void code_not(int reg);
@@ -118,7 +118,7 @@
 extern void code_dpostinc(int e1,int e2,int d,int reg);
 extern void code_dassop(int op,int d);
 
-extern void code_arg_register(int);
+extern void code_arg_register();
 
 extern int get_register(void);
 extern int get_fregister(void);
--- a/mc-codegen.c	Tue Mar 18 20:50:37 2003 +0900
+++ b/mc-codegen.c	Wed Mar 19 02:22:33 2003 +0900
@@ -122,7 +122,7 @@
 	code_drgvar(e1,1,freg);
 	return DOUBLE;
     case FNAME:
-	code_fname(((NMTBL *)(e2))->nm,creg);
+	code_fname((NMTBL *)(e2),creg);
 	return ADDRESS;
     case CONST:  /* 代入する値が0でも特別な処理はしない */
 	code_const(e2,creg);
@@ -486,6 +486,7 @@
         }
 	args = cadr(args);
     }
+    code_arg_register();
 }
 
 static int
--- a/mc-parse.c	Tue Mar 18 20:50:37 2003 +0900
+++ b/mc-parse.c	Wed Mar 19 02:22:33 2003 +0900
@@ -95,7 +95,7 @@
 static int sdecl_f = 1;
 static int stypedecl;
 
-Converter *conv = &null_converter;
+static Converter *conv = &null_converter;
 /* Converter *conv = &c_converter; */
 
 static char *ccout = 0;
@@ -746,6 +746,8 @@
 	n->dsp = ndsp;  /* emit_data will override this */
 	if (stmode==EXTRN)
 	    nsc = EXTRN;
+	else if (stmode==STATIC)
+	    nsc = STATIC;
 	n->sc = nsc;
 	if (stmode==LDECL) {
 	    copy(n,n->nm);
@@ -2157,11 +2159,13 @@
 	conv->id_(sym,nptr);
 	switch(nptr->sc) {
 	case EXTRN: case EXTRN1:
+	    extrn_use(nptr);
 	    if(is_code(nptr)||is_function(nptr)) {
 		return fname(nptr);
 	    }
 	case GVAR:
-	    e1=list3(GVAR,nptr->dsp,(int)nptr->nm);
+	case STATIC:
+	    e1=list2(GVAR,(int)nptr);
 	    type=nptr->ty;
 	    getsym();
 	    extrn_use(nptr);
@@ -2306,7 +2310,7 @@
 	type= INT;
 	switch(car(e)) {
 	case GVAR:
-	    return(list3(CRGVAR,cadr(e),caddr(e)));
+	    return(list2(CRGVAR,cadr(e)));
 	case LVAR:
 	    return(list2(CRLVAR,cadr(e)));
 	case INDIRECT:
@@ -2317,7 +2321,7 @@
     if(type==FLOAT) {
 	switch(car(e)) {
 	case GVAR:
-	    return(list3(FRGVAR,cadr(e),caddr(e)));
+	    return(list2(FRGVAR,cadr(e)));
 	case LVAR:
 	    return(list2(FRLVAR,cadr(e)));
 	case INDIRECT:
@@ -2328,7 +2332,7 @@
     if(type==DOUBLE) {
 	switch(car(e)) {
 	case GVAR:
-	    return(list3(DRGVAR,cadr(e),caddr(e)));
+	    return(list2(DRGVAR,cadr(e)));
 	case LVAR:
 	    return(list2(DRLVAR,cadr(e)));
 	case INDIRECT:
@@ -2339,7 +2343,7 @@
     if(type==LONGLONG) {
 	switch(car(e)) {
 	case GVAR:
-	    return(list3(LRGVAR,cadr(e),caddr(e)));
+	    return(list2(LRGVAR,cadr(e)));
 	case LVAR:
 	    return(list2(LRLVAR,cadr(e)));
 	case INDIRECT:
@@ -2366,7 +2370,7 @@
     }
     switch(car(e)) {
     case GVAR:
-	return(list3(RGVAR,cadr(e),caddr(e)));
+	return(list2(RGVAR,cadr(e)));
     case LVAR:
 	return(list2(RLVAR,cadr(e)));
     case INDIRECT: