diff mc-code-ia32.c @ 629:d3067773659c

*** empty log message ***
author kono
date Tue, 10 Oct 2006 22:35:28 +0900
parents c9b67b1c42f5
children 557b2a266f75
line wrap: on
line diff
--- a/mc-code-ia32.c	Tue Oct 10 16:53:54 2006 +0900
+++ b/mc-code-ia32.c	Tue Oct 10 22:35:28 2006 +0900
@@ -1095,6 +1095,11 @@
 code_fname(NMTBL *n,int creg) {
     use_int(creg);
 #ifdef __APPLE__
+    if (n->sc==STATIC) {
+	printf("\tleal _%s-_%d(%%ebx),%s\n", n->nm, goffset_label,
+	    register_name(creg,0));
+	return;
+    }
     int r = get_ptr_cache(n);
     printf("\tmovl %s,%s\n", register_name(r,0), register_name(creg,0));
 #else
@@ -1298,7 +1303,7 @@
 void
 code_cmp_rgvar(int e1,int reg,int label,int cond) {
     use_int(reg);
-#ifdef __APPLE
+#ifdef __APPLE__
     int r = get_ptr_cache((NMTBL*)caddr(e1));
     if (cadr(e1))
 	printf("\tcmpl $0,%d(%s)\n",cadr(e1),register_name(r,0));
@@ -2495,9 +2500,7 @@
     int init;
     init=0;
     for(n=global_list;n;n = n->next) {
-	if (is_code(n) || is_function(n)) {
-	}
-	if ((n->sc == GVAR||n->sc == STATIC) && n->dsp != -1) {
+	if ((n->sc == GVAR) && n->dsp != -1) {
 	    if (is_code(n)||is_function(n)) continue;
 	    /* n->dsp = -1 means initialized global */
 	    if (init==0) {
@@ -2517,24 +2520,27 @@
     }
     init=0;
     for(n = global_list;n!=&null_nptr;n = n->next) {
-        if (n->sc == GVAR) {
+        if (n->sc == GVAR || 
+		((is_code(n) || is_function(n)) &&has_attr(n,FNAME)) ) {
             if (init==0) {
-                printf(".data\n");
+	printf("\t.section __IMPORT,__pointers,non_lazy_symbol_pointers\n");
                 init=1;
             }
-printf("L_%s$non_lazy_ptr:\n\t.long\t_%s\n",n->nm,n->nm);
-        }
+	printf("L_%s$non_lazy_ptr:\n\t.indirect_symbol _%s\n\t.long\t0\n",
+				n->nm,n->nm);
+	}
     }
+    init=0;
     for(n = global_list;n!=&null_nptr;n = n->next) {
-        if (is_code(n)||is_function(n)) {
-            if (n->sc==EXTRN1) {
-                data_mode(0);
-	    }
+        if (n->sc==EXTRN1) {
+            if(init==0) {
 	    printf("\t.section __IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5\n");
+                init=1;
+            }
 	    printf("L_%s$stub:\n",n->nm);
 	    printf("\t.indirect_symbol _%s\n",n->nm);
 	    printf("\thlt ; hlt ; hlt ; hlt ; hlt\n");
-	}
+        }
     }
     printf("	    .subsections_via_symbols\n");
     printf("	    .section __TEXT,__textcoal_nt,coalesced,pure_instructions\n");
@@ -3418,10 +3424,21 @@
 	// printf("\taddl $8,%%esp\n");
 	printf("\tlea 16(%%esp),%%esp\n");
 	return;
+#ifdef __APPLE__
+    case LDIV:  call="L___divdi3$stub"; 
+         extern_define("__divdi3",0,FUNCTION,1); break;
+    case LUDIV: call="L___udivdi3$stub";
+         extern_define("__udivdi3",0,FUNCTION,1); break;
+    case LMOD:  call="L___moddi3$stub";
+         extern_define("__moddi3",0,FUNCTION,1); break;
+    case LUMOD: call="L___umoddi3$stub";
+         extern_define("__umoddi3",0,FUNCTION,1); break;
+#else
     case LDIV:  call="__divdi3"; break;
     case LUDIV: call="__udivdi3"; break;
     case LMOD:  call="__moddi3"; break;
     case LUMOD: call="__umoddi3"; break;
+#endif
     default: error(-1);
     }
     if (opl) {
@@ -3649,7 +3666,12 @@
 #endif
         printf("\tsubl $16,%%esp\n");
         printf("\tfstpl (%%esp)\n");
+#ifdef __APPLE__
+        printf("\tcall L___fixunsdfdi$stub\n");
+        extern_define("__fixunsdfdi",0,FUNCTION,1); 
+#else
         printf("\tcall __fixunsdfdi\n");
+#endif
         printf("\taddl $16,%%esp\n");
 }
 
@@ -3666,7 +3688,12 @@
 #endif
         printf("\tsubl $16,%%esp\n");
         printf("\tfstps (%%esp)\n");
+#ifdef __APPLE__
+        printf("\tcall L___fixunssfdi$stub\n");
+        extern_define("__fixunssfdi",0,FUNCTION,1); 
+#else
         printf("\tcall __fixunssfdi\n");
+#endif
         printf("\taddl $16,%%esp\n");
 }