changeset 319:88cf6512fa1b asm-statement

asm for powerpc done.
author kono
date Fri, 18 Jun 2004 19:18:44 +0900
parents 9fe0b32a7d57
children 183726ccd83d
files mc-code-powerpc.c
diffstat 1 files changed, 52 insertions(+), 55 deletions(-) [+]
line wrap: on
line diff
--- a/mc-code-powerpc.c	Fri Jun 18 18:34:42 2004 +0900
+++ b/mc-code-powerpc.c	Fri Jun 18 19:18:44 2004 +0900
@@ -1480,20 +1480,27 @@
     printf("\\0%c\n\t.align 2\n",34);
 }
 
+static int
+emit_string_label() {
+    int lb;
+
+    printf(".data\t\n.cstring\n\t.align 2\n");
+    lb=fwdlabel();
+    printf("L_%d:\n",lb);
+    output_mode = RODATA_EMIT_MODE;
+    return lb;
+}
+
 void
 code_string(int e1,int creg)
 {
-    char *s,*crn;
     int lb;
+    char *crn;
 
     use_int(creg);
     crn = register_name(creg);
-
-    s=(char *)cadr(e1);
-    printf(".data\t\n.cstring\n\t.align 2\n");
-    lb=fwdlabel();
-    printf("L_%d:\n",lb);
-    ascii(s);
+    lb = emit_string_label();
+    ascii((char *)cadr(e1));
     if (output_mode==TEXT_EMIT_MODE) {
 	printf(".text\n");
     } else {
@@ -2993,11 +3000,7 @@
 	    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();
-		printf("\t.long L_%d\n",l);
-		printf(".cstring\n\t.align 2\n");
-		printf("L_%d:\n",l);
-		output_mode = RODATA_EMIT_MODE;
+		l = emit_string_label();
 	    }
 	    ascii((char *)cadr(e));
 	} else error(TYERR);
@@ -4965,62 +4968,50 @@
 	printf("%s",register_name(cadr(rstr)));
     } else if (car(rstr)==CONST) {
 	printf("%d",cadr(rstr));
+    } else if (car(rstr)==FNAME) {
+	printf("%s",(char*)cadr(rstr));
     } else if (car(rstr)==STRING) {
-	printf("%s",(char*)cadr(rstr));
+	printf("L_%d",cadr(rstr));
     } else {
 	error(-1);
     }
 }
 
 static void
-replase_asm_string(char *asm_str,int repl)
+replace_asm_string(char *asm_str,int repl)
 {
-    int c,i,rstr,val,path;
+    int c,i,rstr,val;
     char *p;
     int reg[MAX_ASM_REG];
 
+    text_mode();
     c = *asm_str;
     if (c!='\t'&&c!=' ') printf("\t");
-    for(i=0;i<MAX_ASM_REG;i++) {
-	reg[i] = 0;
+    for(i=0;repl && i<MAX_ASM_REG;i++) {
+	reg[i] = car(repl);
+	repl = cadr(repl);
     }
-    // asm parameters %0,%1 may be not contiguous nor starting from 0.
-    // two path execution is necessary. 
-    for(path=1;path<=2;path++) {
-	p = asm_str;
-	if (path==2) {
-	    for(i=0;repl && i<MAX_ASM_REG;i++) {
-		if (reg[i]) {
-		    reg[i] = car(repl);
-		    repl = cadr(repl);
-		}
+    p = asm_str;
+    while((c = *p++)) {
+	if (c=='%') {
+	    c = *p++;
+	    if (!c) { break;
+	    } else if (c=='%') {
+		printf("%%"); continue;
+	    } else if (!digit(c)) {
+		printf("%%%c",c); continue;
 	    }
+	    val = 0;
+	    do { val = val*10 + c-'0'; } while (digit(c=*p++)) ;
+	    p--;
+	    if (val>MAX_ASM_REG) error(-1); // too large register
+	    rstr = reg[val];
+	    print_asm_reg(rstr);
+	} else {
+	    printf("%c",c);
 	}
-	while((c = *p++)) {
-	    if (c=='%') {
-		c = *p++;
-		if (!c) { break;
-		} else if (c=='%') {
-		    if (path==2) printf("%%"); continue;
-		} else if (!digit(c)) {
-		    if (path==2) printf("%%%c",c); continue;
-		}
-		val = 0;
-		do { val = val*10 + c-'0'; } while (digit(c=*asm_str++)) ;
-		asm_str--;
-		if (val>MAX_ASM_REG) error(-1); // too large register
-		if (path==1) {
-		    reg[val] = 1;
-		} else  {
-		    rstr = reg[val];
-		    print_asm_reg(rstr);
-		}
-	    } else {
-		if (path==2) printf("%c",c);
-	    }
-	}
-	if (path==2) printf("\n");
     }
+    printf("\n");
 }
 
 #define ASM_INPUT  1
@@ -5061,11 +5052,16 @@
 	}
 	repl = list3(list2(REGISTER,r),repl,clobber);
     } else if (c=='m') {
+	repl = list3(list2(0,0),repl,clobber);
     } else if (c=='i') {
 	if (car(e1)==GVAR||car(e1)==FNAME) {
-	    e1=list3(STRING,(int)(((NMTBL *)cadr(e1))->nm),0);
-	}
-	if (car(e1)!=CONST && car(e1)!=STRING) error(-1);
+	    e1=list3(FNAME,(int)(((NMTBL *)cadr(e1))->nm),0);
+	} else if (car(e1)==STRING) {
+	    val = emit_string_label();
+	    ascii((char*)cadr(e1));
+	    e1=list3(STRING,val,0);
+	} else if (car(e1)==CONST) {
+	} else error(-1);
 	repl = list3(e1,repl,clobber);
     } else if (digit(c)) {
 	val = 0;
@@ -5117,7 +5113,8 @@
 	    g_expr_u(assign_expr0(car(repl),e1,INT,INT));
 	}
     }
-    replase_asm_string((char*)cadr(asm0),repl);
+    repl = reverse0(repl);
+    replace_asm_string((char*)cadr(asm0),repl);
     for(i=assign;i;i=cadr(i)) {
 	g_expr_u(car(i));
     }