changeset 251:fb6efe8ff816

*** empty log message ***
author kono
date Wed, 12 May 2004 11:26:01 +0900
parents 7637295c4fb8
children 1452eb0eab20
files Changes mc-code-mips.c
diffstat 2 files changed, 129 insertions(+), 95 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Tue May 11 17:37:29 2004 +0900
+++ b/Changes	Wed May 12 11:26:01 2004 +0900
@@ -4169,3 +4169,9 @@
 
 関数呼び出しパートをCbC自身で書けないのかなぁ。
 あまりにめんどくさすぎ。
+
+cpload は、gp レジスタの処理に関係するらしい。gp レジスタって何?
+cploat $25 の $25 は、stack offset みたいね。$sp を変更するときに、
+なんかのフラグを壊さないようにするための処理みたい。
+
+だとすれば、code segement 側でstackを頻繁に移動するのはまずい?
--- a/mc-code-mips.c	Tue May 11 17:37:29 2004 +0900
+++ b/mc-code-mips.c	Wed May 12 11:26:01 2004 +0900
@@ -28,10 +28,12 @@
 static int data_alignment = 0;
 
 static int code_disp_label;
-static int disp_label;
-static int r1_offset_label;
+// static int disp_label;
+int code_top_label;
+
+// static int r1_offset_label;
 static int lvar_offset_label;
-static int cprestore_label;
+// static int cprestore_label;
 static int    max_func_args = 0;
 static int    max_func_iargs = 0;
 
@@ -260,12 +262,7 @@
 static void    set_freg(int,int);
 static void    set_lreg(int,int);
 
-static int    mask_label;
-static int    mask1_label;
-static int    fmask_label;
-static int    fmask1_label;
-
-static FILE *asi;
+// static FILE *asi;
 
 static int max_func_args;
 static int my_func_args;
@@ -318,6 +315,7 @@
 #define CALLER_ARG (l-ARG_LVAR_OFFSET)+arg_offset1
 #define CALLEE_ARG l+arg_offset
 
+#if 0
 void
 code_offset_set()
 {
@@ -326,8 +324,8 @@
 #endif
     int lvar_offsetv = -disp+max_func_args*SIZE_OF_INT+func_disp_offset;
     int r1_offsetv = -disp+max_func_args*SIZE_OF_INT-reg_save+r1_offset;
-    printf(".set L_%d,%d\n",lvar_offset_label,lvar_offsetv);
-    printf(".set L_%d,%d\n",r1_offset_label,r1_offsetv);
+    printf(".set $L_%d,%d\n",lvar_offset_label,lvar_offsetv);
+    printf(".set $L_%d,%d\n",r1_offset_label,r1_offsetv);
 #if 0
 printf("# function %s\n",fnptr->nm);
     l = ARG_LVAR_OFFSET;
@@ -347,6 +345,7 @@
 printf("# offset cargn\t%d %d\n",CALLEE_ARG+r1_offsetv,my_func_args);
 #endif
 }
+#endif
 
 static void
 lvar(int l)
@@ -357,11 +356,11 @@
         } else
             printf("%d($fp)\n",CODE_LVAR);
     } else if (l<0) {  /* local variable */
-        printf("%d+L_%d($fp)\n",FUNC_LVAR,lvar_offset_label);
+        printf("%d($fp)\n",FUNC_LVAR);
     } else if (l>=ARG_LVAR_OFFSET) {  /* caller's arguments */
         printf("%d($fp)\n",CALLER_ARG);
     } else { /* callee's arguments */
-        printf("%d+L_%d($fp)\n",CALLEE_ARG,r1_offset_label);
+        printf("%d($fp)\n",CALLEE_ARG);
     }
 }
 
@@ -374,11 +373,11 @@
         } else
             printf("\taddu\t%s,$fp,%d\n",register_name(creg),CODE_LVAR);
     } else if (l<0) {  /* local variable */
-        printf("\taddu\t%s,$fp,%d+L_%d\n",register_name(creg),FUNC_LVAR,lvar_offset_label);
+        printf("\taddu\t%s,$fp,%d\n",register_name(creg),FUNC_LVAR);
     } else if (l>=ARG_LVAR_OFFSET) {  /* caller's arguments */
         printf("\taddu\t%s,$fp,%d\n",register_name(creg),CALLER_ARG);
     } else { /* callee's arguments */
-        printf("\taddu\t%s,$fp,%d+L_%d\n",register_name(creg),CALLEE_ARG,r1_offset_label);
+        printf("\taddu\t%s,$fp,%d\n",register_name(creg),CALLEE_ARG);
     }
 }
 
@@ -1044,7 +1043,7 @@
 code_label(int labelno)
 {
     clear_ptr_cache();
-    printf("L_%d:\n",labelno);
+    printf("$L_%d:\n",labelno);
 }
 
 void
@@ -1211,7 +1210,7 @@
     char *crn;
     use_int(creg);
     crn = register_name(creg);
-    printf("\tla %s,L_%d\n",crn,retcont);
+    printf("\tla %s,$L_%d\n",crn,retcont);
 }
 
 #define R1SAVE 1
@@ -1225,7 +1224,7 @@
 #else
     int l = 0;
     printf("\taddu %s,",register_name(creg));
-    printf("$fp,%d+L_%d\n",FUNC_LVAR,lvar_offset_label);
+    printf("$fp,%d+$L_%d\n",FUNC_LVAR,lvar_offset_label);
 #endif
 }
 
@@ -1359,14 +1358,14 @@
     s=(char *)cadr(e1);
     printf("\t.rdata\n\t.align 2\n");
     lb=fwdlabel();
-    printf("L_%d:\n",lb);
+    printf("$L_%d:\n",lb);
     ascii(s);
     if (output_mode==TEXT_EMIT_MODE) {
 	printf(".text\n");
     } else {
 	text_mode();
     }
-    printf("\tla %s,L_%d\n",crn,lb);
+    printf("\tla %s,$L_%d\n",crn,lb);
 }
 
 #define MAX_COPY_LEN 20
@@ -1427,7 +1426,7 @@
 	printf("\tmove $5,%s\n",frn);
 	printf("\tmove $4,%s\n",trn);
         /* overrap must be allowed */
-	printf("\tjal L_%s\n",memmove);
+	printf("\tjal %s\n",memmove);
 	extern_define(memmove,0,FUNCTION,1);
         fix=0;
 	set_ireg(RET_REGISTER,0);
@@ -1742,7 +1741,7 @@
     switch(car(e2)) {
     case FCONST:
 	value = dcadr(e2);
-        printf("\t.lis %s,%g\n",frn,value);
+        printf("\tli.s %s,%g\n",frn,value);
 	break;
     case FRGVAR:
 	r = get_ptr_cache((NMTBL*)cadr(e2));
@@ -1901,7 +1900,7 @@
     }
     clear_ptr_cache();
     if (car(e2) == FNAME) {	
-	printf("\tjal\tL_%s\n",fn->nm);
+	printf("\tjal\t%s\n",fn->nm);
     } else {
         jrn = register_name(cadr(jmp));
         printf("\tj %s\n",jrn);
@@ -1943,14 +1942,14 @@
 code_fix_frame_pointer(int disp_offset) {
     int l = 0;
     printf("\tla $fp,");
-    printf("%d+L_%d($sp)\n",FUNC_LVAR,lvar_offset_label);
+    printf("%d+$L_%d($sp)\n",FUNC_LVAR,lvar_offset_label);
 }
 
 void
 code_jmp(char *s) {
     max_reg_var = REG_VAR_BASE-REG_VAR_MIN;
     max_freg_var = FREG_VAR_BASE-FREG_VAR_MIN;
-    printf("\tj L_%s\n",s);
+    printf("\tj $L_%s\n",s);
 }
 
 
@@ -2304,11 +2303,14 @@
 code_opening(char *filename)
 {
     /* this is called once per file */
+#if 0
     char *p=cheapp;
     char *s,*t;
+#endif
     printf("\t.file \"%s\"\n",filename);
     printf(".abicalls\n");
     printf(".text\n");
+#if 0
     if (asi) {
         fclose(asi);
         asi = 0;
@@ -2327,6 +2329,7 @@
     asi = fopen(p,"w");
     printf(".include \"%s\"\n",p);
     if (!asi) error(-1);
+#endif
 }
 
 void
@@ -2336,11 +2339,11 @@
     if (car(e1)==EQ||car(e1)==NEQ) {
          op = s?CMPEQ:CMPNEQ;
 	 g_expr(list3(op,cadr(e1),caddr(e1)));
-	 printf(",L_%d\n",l1);
+	 printf(",$L_%d\n",l1);
     } else {
          op = t==INT?CMP:UCMP;
 	 g_expr(list3(op,cadr(e1),caddr(e1)));
-	 printf("\tb%s %s,$0,L_%d\n",s,register_name(cmpreg),l1);
+	 printf("\tb%s %s,$0,$L_%d\n",s,register_name(cmpreg),l1);
     }
 }
 
@@ -2351,9 +2354,9 @@
 {       
     if (chk) return;
     if (cmpreg==CMP_C1T) 
-      printf("\tbc1%s L_%d\n",cond?"f":"t",l);
+      printf("\tbc1%s $L_%d\n",cond?"f":"t",l);
     else
-      printf("\tb%s %s,$0,L_%d\n",register_name(cmpreg),cond?"ne":"eq",l);
+      printf("\tb%s %s,$0,$L_%d\n",cond?"ne":"eq",register_name(cmpreg),l);
 }
 
 void
@@ -2361,7 +2364,7 @@
 {       
     control=0;
     if (chk) return;
-    printf("\tj\tL_%d\n",l);
+    printf("\tj\t$L_%d\n",l);
 }
 
 void
@@ -2383,13 +2386,11 @@
 #ifdef DOT_SIZE
     printf("\t.type\t%s,@function\n",name);
 #endif
-    printf("_%s:\n",name);
-    code_disp_label=fwdlabel();
-    printf("\t.set noreorder\n");
-    printf("\t.cpload $25\n");
-    printf("\t.set reorder\n");
-    printf("\tsubu $sp,$sp,L_%d\n",code_disp_label);
-    printf("\t.cprestore L_%d\n",cprestore_label);
+    // printf("\t.set noreorder\n");
+    // printf("\t.cpload $25\n");
+    // printf("\t.set reorder\n");
+    printf("\tsubu $sp,$sp,$L_%d\n",code_disp_label);
+    // printf("\t.cprestore $L_%d\n",cprestore_label);
 
     max_func_args = 0;
     max_func_iargs = 0;
@@ -2411,8 +2412,9 @@
     disp&= -SIZE_OF_INT;
     r1_offsetv = -disp+max_func_args*SIZE_OF_INT+code_disp_offset;
 
-    printf(".set L_%d,%d\n",code_disp_label,-r1_offsetv);
+    printf(".set $L_%d,%d\n",code_disp_label,-r1_offsetv);
     local_table();
+    printf("\t.end    %s\n",name);
     // free_all_register();
 }
 
@@ -2424,25 +2426,8 @@
     else
 	printf("\t.align 2\n");
     printf(".ent %s\n",name);
-    printf("_%s:\n",name);
-
-    r1_offset_label = fwdlabel();
-    lvar_offset_label = fwdlabel();
-    mask_label = fwdlabel();
-    mask1_label = fwdlabel();
-    fmask_label = fwdlabel();
-    fmask1_label = fwdlabel();
-    cprestore_label = fwdlabel();
-
-    printf("\t.frame $fp,L_%d,$31\n",r1_offset_label);
-    printf("\t.mask L_%d,L_%d\n",mask_label,mask1_label);
-    printf("\t.fmask L_%d,L_%d\n",fmask_label,fmask1_label);
-
-    printf("\t.set noreorder\n");
-    printf("\t.cpload $25\n");
-    printf("\t.set reorder\n");
-    printf("\tsubu $sp,$sp,L_%d\n",disp_label);
-    printf("\t.cprestore L_%d\n",cprestore_label);
+    code_top_label = backdef();
+
     max_func_args = 0;
     max_func_iargs = 0;
 }
@@ -2457,7 +2442,7 @@
 }
 
 static unsigned int
-code_mask_label()
+code_mask()
 {
     int i;
     unsigned int mask=0;
@@ -2470,7 +2455,7 @@
 }
 
 static unsigned int
-code_fmask_label()
+code_fmask()
 {
     int i;
     unsigned int mask=0;
@@ -2482,6 +2467,34 @@
     return mask;
 }
 
+static void
+code_register_save(reg_save,freg_save,disp)
+{
+    int i;
+    for(i=REG_VAR_MIN;i<=max_reg_var;i++) {
+	printf("\tsw    %s,%d($sp)\n",register_name(i),disp);
+	disp += SIZE_OF_INT;
+    }
+    for(i=FREG_VAR_MIN;i<=max_freg_var;i++) {
+	printf("\ts.s    %s,%d($sp)\n",register_name(i),disp);
+	disp += SIZE_OF_FLOAT;
+    }
+}
+
+static void
+code_register_restore(reg_save,freg_save,disp)
+{
+    int i;
+    for(i=REG_VAR_MIN;i<=max_reg_var;i++) {
+	printf("\tlw    %s,%d($sp)\n",register_name(i),disp);
+	disp += SIZE_OF_INT;
+    }
+    for(i=FREG_VAR_MIN;i<=max_freg_var;i++) {
+	printf("\tl.s    %s,%d($sp)\n",register_name(i),disp);
+	disp += SIZE_OF_FLOAT;
+    }
+}
+
 
 void
 leave(int control, char *name)
@@ -2521,7 +2534,7 @@
 	    if (creg!=RET_REGISTER)
 		printf("\tmove $3,%s\n",register_name(creg));
 	}
-	printf("\tj L_%d\n",retcont1);
+	printf("\tj $L_%d\n",retcont1);
     }
     fwddef(retlabel);
     if (retcont) {
@@ -2530,28 +2543,43 @@
     if (max_freg_var>=0) {
     } else {
     }
-    fprintf(asi,"L_%d=%d\n",r1_offset_label,0);
-    fprintf(asi,"L_%d=%d\n",lvar_offset_label,0);
-    fprintf(asi,"L_%d=0x%x\n",mask_label,code_mask_label());
-    fprintf(asi,"L_%d=%d\n",mask1_label,0);
-    fprintf(asi,"L_%d=0x%x\n",fmask_label ,code_fmask_label());
-    fprintf(asi,"L_%d=%d\n",fmask1_label,0);
-    fprintf(asi,"L_%d=%d\n",cprestore_label ,max_func_iargs);
+#if 0
+    fprintf(asi,"$L_%d=%d\n",r1_offset_label,0);
+    fprintf(asi,"$L_%d=%d\n",lvar_offset_label,0);
+    fprintf(asi,"$L_%d=0x%x\n",mask_label,code_mask_label());
+    fprintf(asi,"$L_%d=%d\n",mask1_label,0);
+    fprintf(asi,"$L_%d=0x%x\n",fmask_label ,code_fmask_label());
+    fprintf(asi,"$L_%d=%d\n",fmask1_label,0);
+    fprintf(asi,"$L_%d=%d\n",cprestore_label ,max_func_iargs);
+#endif
 
     disp &= -size_of_int;
-    r1_offsetv = 0;
+    r1_offsetv = disp;
 
     printf("\tmove    $sp,$fp\n");
+    code_register_restore(reg_save,freg_save,disp);
     printf("\tlw      $31,%d($sp)\n",-disp);
     printf("\tlw      $fp,%d($sp)\n",-disp-4);
     printf("\taddu    $sp,$sp,%d\n",r1_offsetv);
     printf("\tj       $31\n");
-    printf("\t.end    print\n");
-
-    fprintf(asi,"L_%d=%d\n",disp_label,-r1_offsetv);
-
-    code_offset_set();
+
+    printf("\t.align 2\n");
+    printf("%s:\n",name);
+    printf("\t.frame $fp,%d,$31\n",0);
+    printf("\t.mask  0x%x,%d\n",code_mask(),0);
+    printf("\t.fmask 0x%x,%d\n",code_fmask(),0);
+
+    printf("\t.set noreorder\n");
+    printf("\t.cpload $25\n");
+    printf("\t.set reorder\n");
+    printf("\tsubu $sp,$sp,$L_%d\n",-r1_offsetv);
+    printf("\t.cprestore %d\n",max_func_iargs);
+    code_register_save(reg_save,freg_save,disp);
+    printf("\tj $L_%d\n",code_top_label);
+
     local_table();
+    printf("\t.end    %s\n",name);
+
     labelno++;
     free_all_register();
 }
@@ -2672,7 +2700,7 @@
 		l = fwdlabel();
 		printf("\t.long L_%d\n",l);
 		printf(".cstring\n\t.align 2\n");
-		printf("L_%d:\n",l);
+		printf("$L_%d:\n",l);
 		output_mode = RODATA_EMIT_MODE;
 	    }
 	    ascii((char *)cadr(e));
@@ -2691,8 +2719,8 @@
 	data_mode(0);
 #ifdef DOT_SIZE
 	lb=fwdlabel();
-	printf("L_%d:\n",lb);
-	printf("\t.size\t%s,L_%d-%s\n",n->nm,lb,n->nm);
+	printf("$L_%d:\n",lb);
+	printf("\t.size\t%s,$L_%d-%s\n",n->nm,lb,n->nm);
 #endif
     }
 }
@@ -2890,11 +2918,11 @@
 
     use_float(d,freg);
     if (d) {
-	printf("\t.li %s,0x%x\n",lregister_name_high(freg),code_d2(value));
-	printf("\t.li %s,0x%x\n",lregister_name_low(freg),code_d1(value));
+	printf("\tli %s,0x%x\n",lregister_name_high(freg),code_d2(value));
+	printf("\tli %s,0x%x\n",lregister_name_low(freg),code_d1(value));
     } else {
         frn = fregister_name(freg);
-        printf("\t.lis %s,%g\n",frn,value);
+        printf("\tli.s %s,%g\n",frn,value);
     }
 }
 
@@ -3011,10 +3039,10 @@
     
     printf("\tli.s    %s,2.14748364800000000000e9\n",fr1);
     printf("\tc.le.s  %s,%s\n",fr1,fr0);
-    printf("\tbc1t    L_%d\n",lb1=fwdlabel());
+    printf("\tbc1t    $L_%d\n",lb1=fwdlabel());
     printf("\ttrunc.w.s %s,%s,%s\n",fr2,fr0,r0);
     printf("\tmfc1    %s,%s\n",r0,fr2);
-    printf("\tj       L_%d\n",lb2=fwdlabel());
+    printf("\tj       $L_%d\n",lb2=fwdlabel());
     printf("\t.p2align 2\n");
     fwddef(lb1);
     printf("\tsub.s   %s,%s,%s\n",fr0,fr0,fr1);
@@ -3044,14 +3072,14 @@
      int lb1,lb2;
      char *frn,*r0,*r1;
      code_assign_lvar(n,ireg,SIZE_OF_INT);
-     printf("\tbltz    %s,L_%d\n",r0=register_name(ireg),lb1=fwdlabel());
+     printf("\tbltz    %s,$L_%d\n",r0=register_name(ireg),lb1=fwdlabel());
      use_float(0,reg);
      code_drlvar(n,reg,0);
      r0= register_name(reg0 = get_register());
      r1= register_name(reg1 = get_register());
      frn = fregister_name(reg);
      printf("\tcvt.s.w %s,%s\n",frn,frn);
-     printf("\tj       L_%d\n",lb2=fwdlabel());
+     printf("\tj       $L_%d\n",lb2=fwdlabel());
     printf("\t.p2align 2\n");
     fwddef(lb1);
     printf("\tandi    %s,%s,0x1\n",r1,r0);
@@ -3163,7 +3191,7 @@
     }
     set_lreg(RET_LREGISTER,0);
     extern_define(opc,0,FUNCTION,1);
-    printf("\tjal L_%s\n",opc);
+    printf("\tjal %s\n",opc);
     if (max_func_iargs<16) max_func_iargs=16;
 }
 
@@ -3288,7 +3316,7 @@
       extern_define(opc,0,FUNCTION,1);
       if (max_func_iargs<16) max_func_iargs=16;
       printf("\tli.d $6,%g\n",value);
-      printf("\tjal L_%s\n",opc);
+      printf("\tjal %s\n",opc);
 }
 
 void
@@ -3463,14 +3491,14 @@
     }
     g_expr(list3(op,e2,e1));
     switch(op) {
-	case DOP+GT:	printf("\tbgez\t$2,L_%d\n",l1);break;
-	case FOP+GT:	printf("\tbc1t\tL_%d\n",l1);break;
-	case DOP+GE:	printf("\tbltz\t$2,L_%d\n",l1);break;
-	case FOP+GE:	printf("\tbc1t\t$2,L_%d\n",l1);break;
-	case DOP+EQ:	printf("\tbeq\t$2,$0,L_%d\n",l1);break;
-	case FOP+EQ:	printf("\tbc1t\tL_%d\n",l1);break;
-	case DOP+NEQ:	printf("\tbne\t$2,$0,L_%d\n",l1);break;
-        case FOP+NEQ:	printf("\tbc1t\tL_%d\n",l1);break;
+	case DOP+GT:	printf("\tbgez\t$2,$L_%d\n",l1);break;
+	case FOP+GT:	printf("\tbc1t\t$L_%d\n",l1);break;
+	case DOP+GE:	printf("\tbltz\t$2,$L_%d\n",l1);break;
+	case FOP+GE:	printf("\tbc1t\t$2,$L_%d\n",l1);break;
+	case DOP+EQ:	printf("\tbeq\t$2,$0,$L_%d\n",l1);break;
+	case FOP+EQ:	printf("\tbc1t\t$L_%d\n",l1);break;
+	case DOP+NEQ:	printf("\tbne\t$2,$0,$L_%d\n",l1);break;
+        case FOP+NEQ:	printf("\tbc1t\t$L_%d\n",l1);break;
     }
 }
 
@@ -3560,9 +3588,9 @@
 pcond(int op,char *s,int l1)
 {
     if (op==EQ||op==NEQ) {
-	 printf(",L_%d\n",l1);
+	 printf(",$L_%d\n",l1);
     } else {
-	 printf("\tb%s %s,$0,L_%d\n",s,register_name(cmpreg),l1);
+	 printf("\tb%s %s,$0,$L_%d\n",s,register_name(cmpreg),l1);
     }
 }