changeset 632:704b483c3122

Intel mac continue... switch/function stack alignment
author kono
date Wed, 11 Oct 2006 03:39:45 +0900
parents 76242dc0bbc9
children fbd815a59787
files mc-code-ia32.c
diffstat 1 files changed, 33 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mc-code-ia32.c	Wed Oct 11 01:20:21 2006 +0900
+++ b/mc-code-ia32.c	Wed Oct 11 03:39:45 2006 +0900
@@ -1539,8 +1539,8 @@
 	}
 	++nargs;
     }
-    if (nargs%4) {
-	length = (4-(nargs%4))*4;
+    length = 16-((nargs*4+stack_depth)%16);
+    if (length) {
 	stack_depth += length;
 	printf("\tleal %d(%%esp),%%esp\n",-length);
     }
@@ -1613,7 +1613,8 @@
     } else {
 	printf("\tcall\t*%s\n",register_name(REG_EAX,0));
     }
-    if (nargs) printf("\taddl $%d,%%esp\n",stack_depth-stack_depth_save);
+    if (stack_depth!=stack_depth_save)
+	printf("\taddl $%d,%%esp\n",stack_depth-stack_depth_save);
     if (ret_type==DOUBLE||ret_type==FLOAT) {
     } else if (ret_type==LONGLONG||ret_type==ULONGLONG) {
 	use_longlong0(USE_CREG);
@@ -2556,7 +2557,10 @@
 	    printf(".comm _%s,%d\n",n->nm,size(n->ty));
         } else if ((n->sc==STATIC) && n->dsp != -1) {
             /* n->dsp = -1 means initialized global */
-            if (is_code(n)||is_function(n)) continue;
+            if (is_code(n)||is_function(n)) {
+		printf("\t.set L_%s$stub,_%s\n",n->nm,n->nm);
+		continue;
+	    }
             if (init==0) {
                 data_mode(0);
                 init=1;
@@ -2578,6 +2582,11 @@
     }
     for(n = global_list;n!=&null_nptr;n = n->next) {
         if (n->sc==EXTRN1) {
+	    if (!(is_code(n) || is_function(n))) {
+	printf("\t.section __IMPORT,__pointers,non_lazy_symbol_pointers\n");
+	printf("L_%s$non_lazy_ptr:\n\t.indirect_symbol _%s\n\t.long\t0\n",
+				n->nm,n->nm);
+	    }
 	    printf("\t.section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5\n");
 	    printf("L_%s$stub:\n",n->nm);
 	    printf("\t.indirect_symbol _%s\n",n->nm);
@@ -3836,7 +3845,8 @@
     printf("\tja\t_%d\n",dlabel);
     if (delta==1)  {
 #ifdef __APPLE__
-	printf("\tmovl\t_%d-_%d(%%ebx,%s,4)\n",l,goffset_label,crn);
+	printf("\tmovl\t_%d-_%d(%%ebx,%s,4),%s\n",l,goffset_label,crn,crn);
+	printf("\taddl\t%%ebx,%s\n",crn);
 	printf("\tjmp\t*%s\n",crn);
 #else
 	printf("\tjmp\t*_%d(,%s,4)\n",l,crn);
@@ -3844,7 +3854,7 @@
 	return;
     }
     use_register(creg,REG_EAX,1);
-    crn = register_name(creg,0);
+    crn = "%eax";
     
     switch(delta) {
     case 2:
@@ -3852,32 +3862,38 @@
 	printf("\tandl\t%%eax,%%edx\n");
 	printf("\tjne\t_%d\n",dlabel);
 #ifdef __APPLE__
-	printf("\tmovl\t_%d-_%d(%%ebx,%s,2)\n",l,goffset_label,crn);
+	printf("\tmovl\t_%d-_%d(%%ebx,%s,2),%s\n",l,goffset_label,crn,crn);
+	printf("\taddl\t%%ebx,%s\n",crn);
 	printf("\tjmp\t*%s\n",crn);
 #else
-	printf("\tjmp\t*_%d(,%%eax,2)\n",l); break;
+	printf("\tjmp\t*_%d(,%%eax,2)\n",l); 
 #endif
+	break;
     case 4:
 	printf("\tmovl\t$3,%%edx\n");
 	printf("\tandl\t%%eax,%%edx\n");
 	printf("\tjne\t_%d\n",dlabel);
 #ifdef __APPLE__
-	printf("\tmovl\t_%d-_%d(%%ebx,%s)\n",l,goffset_label,crn);
+	printf("\tmovl\t_%d-_%d(%%ebx,%s),%s\n",l,goffset_label,crn,crn);
+	printf("\taddl\t%%ebx,%s\n",crn);
 	printf("\tjmp\t*%s\n",crn);
 #else
-	printf("\tjmp\t*_%d(%%eax)\n",l); break;
+	printf("\tjmp\t*_%d(%%eax)\n",l); 
 #endif
+	break;
     default:
 	printf("\tmovl $%d,%%ecx\n",delta);
 	printf("\txor %%edx,%%edx\n\tdivl %%ecx\n");
 	printf("\tandl\t%%edx,%%edx\n");
 	printf("\tjne\t_%d\n",dlabel);
 #ifdef __APPLE__
-	printf("\tmovl\t_%d-_%d(%%ebx,%s,4)\n",l,goffset_label,crn);
+	printf("\tmovl\t_%d-_%d(%%ebx,%s,4),%s\n",l,goffset_label,crn,crn);
+	printf("\taddl\t%%ebx,%s\n",crn);
 	printf("\tjmp\t*%s\n",crn);
 #else
-	printf("\tjmp\t*_%d(,%%eax,4)\n",l); break;
+	printf("\tjmp\t*_%d(,%%eax,4)\n",l); 
 #endif
+	break;
     }
     
 }
@@ -3887,7 +3903,7 @@
 {
     output_mode=DATA_EMIT_MODE;
 #ifdef __APPLE__
-    printf(" \t.literal4\n\t.align 2\n");
+    printf(" \t.align 2\n");
 #else
     printf(" \t.section\t.rodata\n\t.align 4\n");
 #endif
@@ -3897,7 +3913,11 @@
 void
 code_table_value(int label,int table_top)
 {
+#ifdef __APPLE__
+    printf("\t.long _%d-_%d\n",label,goffset_label);
+#else
     printf("\t.long _%d\n",label);
+#endif
 }
 
 void