changeset 392:28c60758dac9

ARM codegeneration (with no error)
author kono
date Wed, 08 Sep 2004 18:31:57 +0900
parents a460a3f118d1
children fe5aceeb6e89
files .gdbinit mc-code-arm.c
diffstat 2 files changed, 54 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/.gdbinit	Wed Sep 08 01:10:37 2004 +0900
+++ b/.gdbinit	Wed Sep 08 18:31:57 2004 +0900
@@ -6,7 +6,8 @@
 # run  -s -ob01.s mc-switch.c
 # run  -s l.c
 # run  -s test/bitfield.c
-run -s test/code-gen-all.c
+run  -s test/basic.c
+# run -s test/code-gen-all.c
 define regs 
 printf "pc =%08x lr =%08x r0 =%08x r1 =%08x r3= %08x r4= %08x\n",$pc,$lr,$r0,$r1,$r3,$r4
 printf "r10=%08x r11=%08x r12=%08x r13=%08x r14=%08x r15=%08x\n",$r10,$r11,$r12,$r13,$r14,$r15
--- a/mc-code-arm.c	Wed Sep 08 01:10:37 2004 +0900
+++ b/mc-code-arm.c	Wed Sep 08 18:31:57 2004 +0900
@@ -51,9 +51,8 @@
 static int register_save_return_label;
 static int code_size_label ;
 
-static int r1_offset_label;
-static int lvar_offset_label;
-// static int cprestore_label;
+// static int r1_offset_label;
+// static int lvar_offset_label;
 static int    max_func_args = 0;
 
 
@@ -355,8 +354,8 @@
 printf("        @ args = %d, pretend = %d, frame = %d\n",
 	max_func_args,0,round16(-disp));
 printf("        @ frame_needed = 1, current_function_anonymous_args = 0\n");
-printf("\t.set .L%d, %d\n",lvar_offset_label,lvar_offsetv);
-printf("\t.set .L%d, %d\n",r1_offset_label,r1_offsetv);
+// printf("\t.set .L%d, %d\n",lvar_offset_label,lvar_offsetv);
+// printf("\t.set .L%d, %d\n",r1_offset_label,r1_offsetv);
 
 #if 0
 printf("# vars= %d, regs= %d/%d, args= %d, extra= %d\n",
@@ -393,11 +392,13 @@
         } else
             printf("[fp, #%d]%s\n",CODE_LVAR(l),cext);
     } else if (l<0) {  /* local variable */
-        printf("[fp, #%d+.L%d]%s\n",FUNC_LVAR(l),lvar_offset_label,cext);
+//        printf("[fp, #%d+.L%d]%s\n",FUNC_LVAR(l),lvar_offset_label,cext);
+        printf("[fp, #%d]%s\n",FUNC_LVAR(l),cext);
     } else if (l>=ARG_LVAR_OFFSET) {  /* caller's arguments */
         printf("[sp, #%d]%s\n",CALLER_ARG(l-ARG_LVAR_OFFSET),cext);
     } else { /* callee's arguments */
-        printf("[fp, #%d+.L%d]%s\n",CALLEE_ARG(l),r1_offset_label,cext);
+//        printf("[fp, #%d+.L%d]%s\n",CALLEE_ARG(l),r1_offset_label,cext);
+        printf("[fp, #%d]%s\n",CALLEE_ARG(l),cext);
     }
 }
 
@@ -411,13 +412,16 @@
         } else
 	    code_add(creg,CODE_LVAR(l),REG_fp);
     } else if (l<0) {  /* local variable */
-        printf("\tsub\t%s, fp, #%d+.L%d\n",register_name(creg),
-		FUNC_LVAR(l),lvar_offset_label);
+//        printf("\tsub\t%s, fp, #%d+.L%d\n",register_name(creg),
+//		FUNC_LVAR(l),lvar_offset_label);
+        printf("\tsub\t%s, fp, #%d\n",register_name(creg), FUNC_LVAR(l));
     } else if (l>=ARG_LVAR_OFFSET) {  /* caller's arguments */
 	code_add(creg,CALLER_ARG(l-ARG_LVAR_OFFSET),REG_sp);
     } else { /* callee's arguments */
-        printf("\tsub\t%s, fp, #%d+.L%d\n",
-		register_name(creg),CALLEE_ARG(l),r1_offset_label);
+//        printf("\tsub\t%s, fp, #%d+.L%d\n",
+//		register_name(creg),CALLEE_ARG(l),r1_offset_label);
+        printf("\tsub\t%s, fp, #%d\n",
+		register_name(creg),CALLEE_ARG(l));
     }
 }
 
@@ -443,7 +447,6 @@
 #define __inline__\n\
 #define __STDC__ 1\n\
 #define __SIZE_TYPE__ int\n\
-#define __externsion__\n\
 #define __attribute__(a)\n\
 #define __flexarr\n\
 #define __WCHAR_TYPE__ int\n\
@@ -452,6 +455,14 @@
 #define __GNUC__ 2\n\
 #define __const const\n\
 #define alloca __builtin_alloca\n\
+#define __restrict\n\
+#define __gnuc_va_list int\n\
+#define __flexarr\n\
+#define __const const\n\
+#define __THORW\n\
+#define __attribute__(a)\n\
+#define __inline__\n\
+#define wchar_t int\n\
 ";
 
 void
@@ -526,16 +537,26 @@
                 cadddr(args)=SIZE_OF_INT;
             }
         } else if (type==FLOAT) {
-            if ((reg = get_input_dregister_var(freg_var,n,is_code0,0))) {
-                n->sc = FREGISTER;
-                n->dsp = cadr(reg);
-                regs[n->dsp]= INPUT_REG;
-                freg_var++;
-                cadddr(args)=size(type);
-            }
+	    if (is_function(fnptr)) {
+		if ((reg = get_input_dregister_var(reg_var,n,is_code0,0))) {
+		    n->sc = REGISTER;
+		    n->dsp = cadr(reg);
+		    regs[n->dsp]= INPUT_REG;
+		    reg_var++;
+		    cadddr(args)=size(type);
+		}
+	    } else {
+		if ((reg = get_input_dregister_var(freg_var,n,is_code0,0))) {
+		    n->sc = REGISTER;
+		    n->dsp = cadr(reg);
+		    regs[n->dsp]= INPUT_REG;
+		    freg_var++;
+		    cadddr(args)=size(type);
+		}
+	    }
         } else if (type==DOUBLE) {
-            if ((reg = get_input_lregister_var(reg_var,n,is_code0))) {
-                n->sc = DREGISTER;
+            if ((reg = get_input_dregister_var(reg_var,n,is_code0,1))) {
+                n->sc = LREGISTER;
                 n->dsp = cadr(reg);
                 regs[i=n->dsp]= INPUT_DREG;
                 regs[regv_l(i)]= INPUT_REG;
@@ -848,20 +869,6 @@
     return list3(REGISTER,i,(int)n);
 }
 
-/* double register case? */
-
-int
-get_input_register_var_1(int i,NMTBL *n,int is_code)
-{
-    if (is_code) {
-	if(!(i<REG_VAR_BASE-REG_VAR_MIN)) return 0;
-	i = REG_VAR_BASE-i;
-    } else {
-	if (i<0||i>=MAX_INPUT_REGISTER_VAR+1) return 0;
-	i = i+MIN_TMP_REG;
-    }
-    return list3(REGISTER,i,(int)n);
-}
 
 int
 free_register_count(int d)
@@ -2036,29 +2043,11 @@
 	    offset+=SIZE_OF_INT;
 	    t = INT;
 	    reg_var++;
-	} else if (tag==FREGISTER) {
-	    /* regs[reg]==INPUT_REG case should be considered */
-	    n->dsp = offset;
-	    t = n->ty;
-	    if(t==FLOAT) {
-		offset+=SIZE_OF_FLOAT; reg_offset+=1;
-		if (reg==6||reg==7) {   // int register case
-		    tag = REGISTER; t = INT;
-		}
-	    }
-	    // else if(t==DOUBLE) { offset+=SIZE_OF_DOUBLE; reg_offset+=2; }
-	    else error(-1);
-	    reg_var++;
-	} else if (tag==DREGISTER) {
-	    /* regs[reg]==INPUT_REG case should be considered */
-	    n->dsp = offset;
-	    t = n->ty;
-	    offset+=SIZE_OF_DOUBLE; reg_offset+=2;
-	    reg_var += 2;
 	} else if (tag==LREGISTER) {
 	    /* regs[reg]==INPUT_REG case should be considered */
 	    n->dsp = offset;
-	    t = n->ty;
+	    // t = n->ty;
+	    t = LONGLONG;
 	    offset+=SIZE_OF_LONGLONG; reg_offset+=2;
 	    reg_var += 2;
 	} else {
@@ -3064,7 +3053,7 @@
     printf("\t.globl\t%s\n",name);
     printf("\t.type\t%s,function\n",name);
     code_size_label = backdef();
-    lvar_offset_label = fwdlabel();
+//    lvar_offset_label = fwdlabel();
     max_func_args = 0;
 }
 
@@ -3098,8 +3087,8 @@
     
     max_func_args = 0;
 
-    lvar_offset_label = fwdlabel();
-    r1_offset_label = fwdlabel();
+//    lvar_offset_label = fwdlabel();
+//    r1_offset_label = fwdlabel();
     code_size_label = fwdlabel();
     printf("\t.type\t%s,function\n",name);
     if (stmode!=STATIC)
@@ -3157,7 +3146,8 @@
 #else
 	inc_inst(1);
 	printf("\tsub\tfp, ");
-	printf("fp, #%d+.L%d\n",FUNC_LVAR(0),lvar_offset_label);
+//	printf("fp, #%d+.L%d\n",FUNC_LVAR(0),lvar_offset_label);
+	printf("fp, #%d\n",FUNC_LVAR(0));
 #endif
     }
     fwddef(retlabel);
@@ -3286,7 +3276,7 @@
 extern void
 emit_global(char *name,int t)
 {
-    printf(".globl\t%s\n",name);
+    printf("\t.globl\t%s\n",name);
     data_mode(name);
     align(t);
     printf("%s:\n",name); 
@@ -3469,7 +3459,7 @@
 	output_mode = DATA_EMIT_MODE;
     }
     if (name)
-	printf("\t.type\t%s,@object\n",name);
+	printf("\t.type\t%s,object\n",name);
 }
 
 #define lib_args(max) if (max_func_args<max) max_func_args=max
@@ -5447,7 +5437,7 @@
 code_table_open(int l)
 {
     output_mode = DATA_EMIT_MODE;
-    printf("\t.palign 2\n");
+    printf("\t.align 2\n");
     fwddef(l);
 }