changeset 442:86b04fb4562e

minor fix...
author kono
date Sun, 21 Nov 2004 00:42:42 +0900
parents 1edaa643458e
children f2d2e27a00a0
files Changes mc-code-arm.c mc-codegen.c test/simp.c
diffstat 4 files changed, 90 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/Changes	Sat Nov 20 20:07:17 2004 +0900
+++ b/Changes	Sun Nov 21 00:42:42 2004 +0900
@@ -6686,3 +6686,6 @@
 気がするんだが...
 
 
+Sat Nov 20 22:00:36 JST 2004
+
+あぁ、なんかいろいろ破壊しているし〜
--- a/mc-code-arm.c	Sat Nov 20 20:07:17 2004 +0900
+++ b/mc-code-arm.c	Sun Nov 21 00:42:42 2004 +0900
@@ -1307,17 +1307,22 @@
 }
 #endif
 
+static int inst_count;
+
 static void
 const_list_table()
 {
     int p,lb=0;
+    inst_count = 0;
+
     if (const_list) {
 	if (control) {
 	    lb = fwdlabel();
-	    jmp(lb);
-	    printf("\t.align\t2\n");
+	    gen_jmp(lb);
+	    // printf("\t.align\t2\n");
 	}
 	fwddef(const_list_label);
+	control=0;
 	for(p = const_list; p ; p = cadr(p)) {
 	    switch(car(p)) {
 	    case GVAR:	printf("\t.word\t%s\n",((NMTBL *)caddr(p))->nm); break;
@@ -1330,7 +1335,7 @@
 	    }
 	}
 	if (lb) {
-	    fwddef(lb);
+	    fwddef(lb);  // control==1 now
 	}
 	prev_const_list_label=const_list_label;
 	const_list_label = 0;
@@ -1348,7 +1353,6 @@
 static void
 inc_inst(int count)
 {
-    static int inst_count;
 // printf("# inst %d\n",inst_count);
     if ((inst_count+=count)>CONST_TBL_COUNT) {
 	inst_count = 0;
@@ -1805,7 +1809,7 @@
         use_int(reg);
         xrn = register_name(reg);
         printf("\tmov\t%s, #0\n",xrn);
-        jmp(e3=fwdlabel());
+        gen_jmp(e3=fwdlabel());
         fwddef(e2);
         printf("\tmov\t%s, #1\n",xrn);
         fwddef(e3);
@@ -3132,7 +3136,10 @@
 	code_const(e,reg);
 	printf("\tcmp\t%s, %s\n",crn,rn);
     } else {
-	printf("\t%s\t%s, #%d\n",sign?"cmp":"cmn",crn,e);
+	if (sign>0) 
+	    printf("\tcmp\t%s, #%d\n",crn,e);
+	else
+	    printf("\tcmn\t%s, #%d\n",crn,-e);
     }
     switch(cond) {
     case -1: break;
@@ -3162,6 +3169,8 @@
 
 #define COND_BRANCH 1
 #define COND_VALUE  2
+#define COND_BRANCH_CONST 3
+#define COND_VALUE_CONST  4
 
     /*
             if (r1 cmp r2) goto l1   COND_BRANCH
@@ -3175,9 +3184,17 @@
     char *rn0;
     char *cc,*ncc;
 
-    rn1 =		register_name(r1);
-    rn2 =		register_name(r2);
-    printf("\tcmp\t%s, %s\n",rn1,rn2);
+    if (mode==COND_BRANCH_CONST||mode==COND_VALUE_CONST) {
+	rn1 =		register_name(r1);
+	if (r2>=0) 
+	    printf("\tcmp\t%s, #%d\n",rn1,r2);
+	else
+	    printf("\tcmn\t%s, #%d\n",rn1,-r2);
+    } else {
+	rn1 =		register_name(r1);
+	rn2 =		register_name(r2);
+	printf("\tcmp\t%s, %s\n",rn1,rn2);
+    }
 
     switch(op+(!cond)*BNOT) {
     case GT:  case LE+BNOT:	cc="gt"; ncc="le"; break;
@@ -3193,10 +3210,10 @@
     default:        error(-1);
     }
 
-    if (mode==COND_BRANCH) {
+    if (mode==COND_BRANCH||mode==COND_BRANCH_CONST) {
 	printf("\tb%s\t.L%d\n",cc,l1);
 	inc_inst(2);
-    } else if (mode==COND_VALUE) {
+    } else if (mode==COND_VALUE||mode==COND_VALUE_CONST) {
 	rn0 =		register_name(r0);
 	printf("\tmov%s\t%s, #0\n",ncc,rn0);
 	printf("\tmov%s\t%s, #1\n",cc,rn0);
@@ -3214,14 +3231,21 @@
 	op== ULE || op== UGE || op== LE || op== GE ||
 	op== EQ || op== NEQ
     )) return 0;
-    g_expr(cadr(e1));
-    emit_push();
-    g_expr(caddr(e1));
-    e2 = emit_pop(1);
-    reg0 = ireg;
-    use_int(reg);
-    pcond(op, reg0,e2,reg,1,0,COND_VALUE);
-    emit_pop_free(e2);
+    if (car(caddr(e1))==CONST  && is_stage1_const(cadr(caddr(e1)),CMP)) {
+	g_expr(cadr(e1));
+	reg0 = ireg;
+	use_int(reg);
+	pcond(op, cadr(caddr(e1)),reg0,reg,1,0,COND_VALUE_CONST);
+    } else {
+	g_expr(cadr(e1));
+	emit_push();
+	g_expr(caddr(e1));
+	e2 = emit_pop(1);
+	reg0 = ireg;
+	use_int(reg);
+	pcond(op, reg0,e2,reg,1,0,COND_VALUE);
+	emit_pop_free(e2);
+    }
     return 1;
 }
 
@@ -3231,12 +3255,17 @@
     int e2;
     int op = car(e1);
 
-    g_expr(cadr(e1));
-    emit_push();
-    g_expr(caddr(e1));
-    e2 = emit_pop(1);
-    pcond(op, ireg,e2,0,cond,l1,COND_BRANCH);
-    emit_pop_free(e2);
+    if (car(caddr(e1))==CONST  && is_stage1_const(cadr(caddr(e1)),CMP)) {
+	g_expr(cadr(e1));
+	pcond(op, cadr(caddr(e1)),ireg,0,cond,l1,COND_BRANCH_CONST);
+    } else {
+	g_expr(cadr(e1));
+	emit_push();
+	g_expr(caddr(e1));
+	e2 = emit_pop(1);
+	pcond(op, ireg,e2,0,cond,l1,COND_BRANCH);
+	emit_pop_free(e2);
+    }
     return l1;
 }
 
@@ -3255,7 +3284,10 @@
 {       
     if (chk) return;
     printf("\tb\t.L%d\n",l);
-    inc_inst(1);
+    if (inst_count>CONST_TBL_COUNT/2) {
+	const_list_table();
+    } else
+	inc_inst(1);
 }
 
 void
@@ -3354,7 +3386,7 @@
 	printf("\t.globl\t%s\n",name);
     printf("%s:\n",name);
     printf("\tmov\tip, sp\n");
-    jmp(entry_label = fwdlabel());
+    gen_jmp(entry_label = fwdlabel());
     register_save_return_label = backdef();
 }
 
@@ -3369,17 +3401,17 @@
 
 
 void
-leave(int control, char *name)
+leave(int control0, char *name)
 {
     int retcont1=0,sz;
 
-    if (control) {
+    if (control0) {
 	code_set_return_register(1);
     } else
 	text_mode(2);
     if (retcont) { 
 	/* return from CbC segement */
-	if (control) jmp(retlabel);
+	if (control0) gen_jmp(retlabel);
 	retcont1 = fwdlabel();
 	fwddef(retcont);
 	if (cadr(fnptr->ty)==FLOAT) {
@@ -3426,7 +3458,7 @@
 
     printf("\tsub\tfp, ip, #%d\n",4+arg_on_register);
     code_add(REG_sp,disp-max_func_args*SIZE_OF_INT,REG_sp);
-    jmp(register_save_return_label);
+    gen_jmp(register_save_return_label);
     local_table();
 
     printf("\t.size\t%s,.L%d-%s\n",name, backdef(),name);
@@ -3703,8 +3735,8 @@
 {
     NMTBL *n;
     int init;
+    free_glist3_a(prev_const_list); prev_const_list = 0;
     const_list_table();
-    free_glist3_a(prev_const_list); prev_const_list = 0;
 
     init=0;
     /* static local variables */
@@ -5324,7 +5356,7 @@
         if (v==0) return;
         if (v==32) {
             code_register(regv_h(creg),regv_l(creg));
-            printf("\tmov\t%s, %s asr #31\n",crn_h,crn_l);
+            printf("\tmov\t%s, %s, asr #31\n",crn_h,crn_l);
             return;
         } else if (v>31) {
             printf("\tmov\t%s, %s, asr #%d\n",crn_l,crn_h,v-32);
@@ -5739,28 +5771,27 @@
     code_add(t,-min,csvalue);
     switch(delta) {
     case 1: 
+	inc_inst(2+(max-min));
 	code_cmpdimm(max-min,t,dlabel,-1);
 	printf("\tldrls\tpc, [pc, %s, asl #2]\n",trn);
-	inc_inst(1);
 	break;
     case 2:
+	inc_inst(4+(max-min)/2);
 	printf("\ttst\t%s, #1\n",trn);
 	printf("\tbne\t.L%d\n",dlabel);
 	code_cmpdimm(max-min,t,dlabel,-1);
 	printf("\tldrls\tpc, [pc, %s, asl #1]\n",trn); break;
-	inc_inst(3);
 	break;
     case 4:
+	inc_inst(5+(max-min)/4);
 	printf("\ttst\t%s, #3\n",trn);
 	printf("\tbne\t.L%d\n",dlabel);
 	code_cmpdimm(max-min,t,dlabel,-1);
 	printf("\tldrls\tpc, [pc, %s]\n",trn); break;
-	inc_inst(4);
 	break;
     default:
 	error(-1);
     }
-    inc_inst(1);
     printf("\tb\t.L%d\n",dlabel);
 
     free_register(t);
--- a/mc-codegen.c	Sat Nov 20 20:07:17 2004 +0900
+++ b/mc-codegen.c	Sun Nov 21 00:42:42 2004 +0900
@@ -2207,12 +2207,13 @@
 static void
 checkjmp(int l)
 {
-    if (pending_jmp) {
-	if (pending_jmp!=l) {
-	    jmp(pending_jmp);
+    int p = pending_jmp;
+    pending_jmp = 0;
+    if (p) {
+	if (p!=l) {
 	    control=0;
+	    jmp(p);
 	}
-	pending_jmp=0;
     }
 }
 
@@ -2905,8 +2906,9 @@
 {
     if (cslabel==0) {
 	if (!control) error(-1); // no execute code in switch
+	checkjmp(0);
+	control=0;
 	jmp(cslabel=fwdlabel());
-	control=0;
     } else if (retpending) {
 	ret();
 	control=0;
@@ -3443,7 +3445,8 @@
     if(op==ADD) {
 	if(integral(t1)) {
 	    if(integral(t2)) {
-		if(t1==INT) type=t2;else type=t1;
+		// if(t1==INT) type=t2;else type=t1;
+		if (us) type=UNSIGNED; else type=INT;
 		return(list3(ADD,e1,e2));
 	    }
 	    if(car(t2)!=POINTER) error(TYERR);
--- a/test/simp.c	Sat Nov 20 20:07:17 2004 +0900
+++ b/test/simp.c	Sun Nov 21 00:42:42 2004 +0900
@@ -16,6 +16,7 @@
 	printf("#0015:%s\n",&av[i][3]);
     }
     ch = 'E';
+    main1(-8);
     return main0(ac,ch,av);
 }
 
@@ -33,3 +34,12 @@
     return 0;
 }
 
+main1(int l)
+{
+   printf("%d\n", ((l+0)<-511||(l+0)>511));
+   if ((l+0)<-511||(l+0)>511) printf("yes\n");
+   l = -1;
+   printf("%d\n", l==-1? 555:333);
+}
+
+