changeset 767:c14a1426cfed

i64 strop/simp1/alloca
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Thu, 18 Nov 2010 00:12:12 +0900
parents 43b9c46a3c95
children ec9fdbb27351
files .gdbinit mc-code-i64.c mc-codegen.c mc-inline.c mc-parse.c tools/find-gcc-include-path
diffstat 6 files changed, 31 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/.gdbinit	Wed Nov 17 19:31:12 2010 +0900
+++ b/.gdbinit	Thu Nov 18 00:12:12 2010 +0900
@@ -13,7 +13,7 @@
 x/1i $rip
 end
 b errmsg
-# r -s test/tmp7.c
+r -s test/tmp7.c
 # r -s test/tmp6.c
 # r -s test/call.c
 # r -s test/static.c
@@ -21,7 +21,8 @@
 # r -s test/code-gen-all.c
 # r -s mc-code-powerpc.c
 # r -s test/macro.c
-r -s test/basic.c
+# r -s test/basic.c
+# r -s test/float.c
 # r -s test/strinit.c
 # r -s test/arg.c
 # r -s -DINLINE=inline test/strinit.c
--- a/mc-code-i64.c	Wed Nov 17 19:31:12 2010 +0900
+++ b/mc-code-i64.c	Thu Nov 18 00:12:12 2010 +0900
@@ -1,4 +1,4 @@
-/* Micro-C Code Generation Part for intel386 */
+/* Micro Codu Generation Part for intel386 */
 
 /************************************************************************
 ** Copyright (C) 2006 Shinji Kono
@@ -40,6 +40,8 @@
 
 static
 char *init_src0 = "\
+typedef long __builtin_va_list;\n\
+#define __inline inline \n\
 #define __DBL_MIN_EXP__ (-1021) \n\
 #define __FLT_MIN__ 1.17549435e-38F \n\
 #define __DEC64_DEN__ 0.000000000000001E-383DD \n\
@@ -368,6 +370,7 @@
 #define REG_EDX   4
 #define REG_ECX   5    // for strange reason (code_assop)
 #define REG_EAX   8
+#define REG_R10   9
 #define REG_EBX   11
 #define REG_R15   15
 #define is_int_reg(reg) (1<=reg&&reg<=MAX_REGISTER)
@@ -381,8 +384,8 @@
 #define RET_REGISTER    REG_EAX
 
 //  defalut current register
-#define CREG_REGISTER   REG_ECX
-#define FREG_FREGISTER  17
+#define CREG_REGISTER   REG_R10
+#define FREG_FREGISTER  27
 
 static char *reg_name_l[] = {0,
     0,
@@ -465,7 +468,7 @@
 };
 
 static char *reg_name_d[] = {    
-    "%xmm0", // 18
+    "%xmm0", // 17
     "%xmm1",
     "%xmm2",
     "%xmm3",
@@ -582,8 +585,9 @@
 	// printf(".set %s%d,%d\n",lpfx,r1_offset_label,r1_offsetv);
     }
     if (max_func_arg_label) {
-        printf(".set %s%d,%d\n",lpfx,max_func_arg_label,
-            round16(max_func_args*SIZE_OF_INT));
+	data_mode(0);
+	code_label(max_func_arg_label);
+	emit_longlong(round16(max_func_args*SIZE_OF_INT));
         max_func_arg_label = 0;
     }
 
@@ -1331,7 +1335,7 @@
     xreg=pop_register();
     if (xreg<= -REG_LVAR_OFFSET) {
         reg = get_register();
-        code_rlvar(REG_LVAR_OFFSET+xreg,reg);
+        code_lrlvar(REG_LVAR_OFFSET+xreg,reg);
         free_lvar(REG_LVAR_OFFSET+xreg);
         xreg = reg;
     }
@@ -2338,7 +2342,7 @@
     crn = register_name(reg,0);
     printf("\tsubq\t%s, %%rsp\n",crn);
     if (!max_func_arg_label) max_func_arg_label = fwdlabel();
-    printf("\tmovq $%s%d,%s\n",lpfx,max_func_arg_label ,crn);
+    printf("\tmovq %s%d(%%rip),%s\n",lpfx,max_func_arg_label ,crn);
     printf("\taddq\t%%rsp, %s\n",crn);
 }
 
@@ -2585,6 +2589,7 @@
 	    use_register(oreg,REG_ECX,1);
 	    oreg = REG_ECX;
 	}
+	code_clear_stack_reg(REG_EDX);
         if (sz<=SIZE_OF_INT) {
 	    orn = register_name(oreg,SIZE_OF_INT);
 	    printf((op==DIV||op==MOD)?
@@ -2595,7 +2600,7 @@
         } else {
 	    orn = register_name(oreg,0);
 	    if (op==LDIV||op==LMOD) {
-		code_lassign_lregister(REG_EDX,oreg);
+		code_lassign_lregister(REG_EDX,REG_EAX);
 		printf("\tsarq $63,%%rdx\n");
 		printf("\tidivq %s\n",orn);
             } else {
@@ -3005,14 +3010,16 @@
 	make_return_continuation();
     }
     fwddef(retlabel);
-    int r1_offset = code_offset_set(fnptr);
 
     printf("\tleaq %d(%%rbp),%%rsp\n",max_reg_var<0?0:-(max_reg_var+1)*SIZE_OF_LONGLONG);
     code_register_pop();
     printf("\tleave\n");
     printf("\tret\n");
+    control=0;
+    int r1_offset = code_offset_set(fnptr);
 
     // we can do this in enter(), in parse tree mode
+    text_mode(0);
     fwddef(code_setup);
     code_register_push();
     printf("\tsubq $%d,%%rsp\n",r1_offset); 
@@ -5069,7 +5076,8 @@
 {
     switch(e3) {
         case FUNCTION: case CONV: case STASS: case ALLOCA:
-        //case LDIV: case LUDIV: case LMOD: case LUMOD:
+        case LDIV: case LUDIV: case LMOD: case LUMOD:
+        case DIV: case UDIV: case MOD: case UMOD:
         //case LMUL: case LUMUL:
         //case LLSHIFT: case LULSHIFT: case LRSHIFT: case LURSHIFT:
         //case DDIV: case DADD: case DSUB: case DMUL: case DMINUS:
--- a/mc-codegen.c	Wed Nov 17 19:31:12 2010 +0900
+++ b/mc-codegen.c	Thu Nov 18 00:12:12 2010 +0900
@@ -1511,7 +1511,8 @@
 	 */
 	    g_expr_u(assign_expr0(
 		list2(INDIRECT,
-    list3(ADD,rvalue_t(envreg,INT),list2(CONST,-arg_size-sz+disp_offset))
+    lp64?list3(LADD,rvalue_t(envreg,INT),llist2(LCONST,-arg_size-sz+disp_offset))
+         :list3(ADD,rvalue_t(envreg,INT),list2(CONST,-arg_size-sz+disp_offset))
 		),
 		e2,ty,ty));
 	} else {
@@ -1777,7 +1778,8 @@
 	case INDIRECT:
 	case PERIOD:
 	case ARROW:
-	    return(list3(ADD,e1,e));
+	    if (lp64) return list3(LADD,e1,llist2(LCONST,cadr(e)));
+	    return list3(ADD,e1,e);
 	default:
 	    error(-1); // ?
 	}
--- a/mc-inline.c	Wed Nov 17 19:31:12 2010 +0900
+++ b/mc-inline.c	Thu Nov 18 00:12:12 2010 +0900
@@ -1593,7 +1593,7 @@
 	n = local_statics;
 	while(n->next != &null_nptr) n=n->next;
 	n->next = local_static_list; local_static_list = local_statics;
-	cadddr(e1) = 0;  // prevent duplicate initialize
+	ncadddr(e1) = 0;  // prevent duplicate initialize
     }
 
     // free used local variables or registers
--- a/mc-parse.c	Wed Nov 17 19:31:12 2010 +0900
+++ b/mc-parse.c	Thu Nov 18 00:12:12 2010 +0900
@@ -1654,8 +1654,9 @@
     init_vars = list2(
 	list4(STASS,
 	    inmode?(
-		offset?
-		    list3(ADD,list3n(IVAR,n->dsp,0),list2(CONST,offset)):
+		offset?(
+		    lp64?list3(LADD,list3n(IVAR,n->dsp,0),llist2(LCONST,offset)):
+			list3(ADD,list3n(IVAR,n->dsp,0),list2(CONST,offset))):
 		    list3n(IVAR,n->dsp,0)):
 		list3n(LVAR,n->dsp+offset,0),
 	    list3(RSTRUCT,v0,sz),sz),
--- a/tools/find-gcc-include-path	Wed Nov 17 19:31:12 2010 +0900
+++ b/tools/find-gcc-include-path	Thu Nov 18 00:12:12 2010 +0900
@@ -9,8 +9,8 @@
 if ($ARGV[0]=~/-l/) {
 print <<EOF
 char *l_include_path[] = {
+    "$gcc_path",
     "/usr/include/",
-    "$gcc_path",
     0
 };
 EOF