Mercurial > hg > CbC > old > device
changeset 619:509d637a58b2
Intel Mac first try.
author | kono |
---|---|
date | Thu, 07 Sep 2006 01:21:38 +0900 |
parents | a7f5796e540a |
children | 0e7281ec9007 |
files | mc-code-ia32.c |
diffstat | 1 files changed, 214 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mc-code-ia32.c Wed Sep 06 21:16:47 2006 +0900 +++ b/mc-code-ia32.c Thu Sep 07 01:21:38 2006 +0900 @@ -41,7 +41,6 @@ #define alloca __builtin_alloca\n\ #define __STDC__ 1\n\ #define __extension__\n\ -#define __STDC__ 1\n\ #define __flexarr\n\ #define __const const\n\ #define __THORW\n\ @@ -122,7 +121,12 @@ #define __PTRDIFF_TYPE__ int\n\ #define __LDBL_MIN_10_EXP__ (-4931)\n\ #define __LDBL_DIG__ 18\n\ -"; +" +#ifdef __APPLE__ +"#define __APPLE__ 1\n" +"#define __GNUC__ 4\n" +#endif +; /* @@ -201,7 +205,10 @@ #define DATA_EMIT_MODE 1 #define RODATA_EMIT_MODE 2 +#ifdef __APPLE__ +#else #define DOT_SIZE 1 +#endif static int output_mode = TEXT_EMIT_MODE; @@ -266,6 +273,7 @@ static int code_disp_label; static int func_disp_label; +// static int goffset_label; static int lvar(int l) @@ -898,23 +906,40 @@ void code_gvar(int e1,int creg) { use_int(creg); +#ifdef __APPLE__ + if (cadr(e1)) { + printf("\tmovl $_%s+%d,%s\n",((NMTBL*)caddr(e1))->nm,cadr(e1), + register_name(creg,0)); + } else { + printf("\tmovl $_%s,%s\n",((NMTBL*)caddr(e1))->nm,register_name(creg,0)); + } +#else if (cadr(e1)) { printf("\tmovl $%s+%d,%s\n",((NMTBL*)caddr(e1))->nm,cadr(e1), register_name(creg,0)); } else { printf("\tmovl $%s,%s\n",((NMTBL*)caddr(e1))->nm,register_name(creg,0)); } +#endif } void code_rgvar(int e1,int creg) { use_int(creg); +#ifdef __APPLE__ + if (cadr(e1)) { + printf("\tmovl _%s+%d,%s\n",((NMTBL*)caddr(e1))->nm,cadr(e1), + register_name(creg,0)); + } else + printf("\tmovl _%s,%s\n",((NMTBL*)caddr(e1))->nm,register_name(creg,0)); +#else if (cadr(e1)) { printf("\tmovl %s+%d,%s\n",((NMTBL*)caddr(e1))->nm,cadr(e1), register_name(creg,0)); } else printf("\tmovl %s,%s\n",((NMTBL*)caddr(e1))->nm,register_name(creg,0)); +#endif } @@ -927,12 +952,21 @@ void code_crgvar(int e1,int creg,int sign,int sz){ use_int(creg); +#ifdef __APPLE__ + if (cadr(e1)) { + printf("\t%s _%s+%d,%s\n",cload(sign,sz), + ((NMTBL*)caddr(e1))->nm,cadr(e1),register_name(creg,0)); + } else + printf("\t%s _%s,%s\n",cload(sign,sz), + ((NMTBL*)caddr(e1))->nm,register_name(creg,0)); +#else if (cadr(e1)) { printf("\t%s %s+%d,%s\n",cload(sign,sz), ((NMTBL*)caddr(e1))->nm,cadr(e1),register_name(creg,0)); } else printf("\t%s %s,%s\n",cload(sign,sz), ((NMTBL*)caddr(e1))->nm,register_name(creg,0)); +#endif } @@ -1001,7 +1035,11 @@ void code_fname(NMTBL *n,int creg) { use_int(creg); +#ifdef __APPLE__ + printf("\tmovl $_%s,%s\n",n->nm,register_name(creg,0)); +#else printf("\tmovl $%s,%s\n",n->nm,register_name(creg,0)); +#endif } void @@ -1151,6 +1189,19 @@ void code_cmp_crgvar(int e1,int reg,int sz,int label,int cond) { use_int(reg); +#ifdef __APPLE__ + if (cadr(e1)) { + if (sz==1) + printf("\tcmpb $0,_%s+%d\n",((NMTBL*)caddr(e1))->nm,cadr(e1)); + else if (sz==SIZE_OF_SHORT) + printf("\tcmpw $0,_%s+%d\n",((NMTBL*)caddr(e1))->nm,cadr(e1)); + } else { + if (sz==1) + printf("\tcmpb $0,_%s\n",((NMTBL*)caddr(e1))->nm); + else if (sz==SIZE_OF_SHORT) + printf("\tcmpw $0,_%s\n",((NMTBL*)caddr(e1))->nm); + } +#else if (cadr(e1)) { if (sz==1) printf("\tcmpb $0,%s+%d\n",((NMTBL*)caddr(e1))->nm,cadr(e1)); @@ -1162,6 +1213,7 @@ else if (sz==SIZE_OF_SHORT) printf("\tcmpw $0,%s\n",((NMTBL*)caddr(e1))->nm); } +#endif jcond(label,cond); } @@ -1180,10 +1232,17 @@ void code_cmp_rgvar(int e1,int reg,int label,int cond) { use_int(reg); +#ifdef __APPLE + if (cadr(e1)) + printf("\tcmpl $0,_%s+%d\n",((NMTBL*)caddr(e1))->nm,cadr(e1)); + else + printf("\tcmpl $0,_%s\n",((NMTBL*)caddr(e1))->nm); +#else if (cadr(e1)) printf("\tcmpl $0,%s+%d\n",((NMTBL*)caddr(e1))->nm,cadr(e1)); else printf("\tcmpl $0,%s\n",((NMTBL*)caddr(e1))->nm); +#endif jcond(label,cond); } @@ -1432,7 +1491,11 @@ } if (car(e2) == FNAME) { +#ifdef __APPLE__ + printf("\tcall\tL_%s$stub\n",n->nm); +#else printf("\tcall\t%s\n",n->nm); +#endif } else { printf("\tcall\t*%s\n",register_name(REG_EAX,0)); } @@ -1496,7 +1559,11 @@ void code_jmp(char *s) { +#ifdef __APPLE__ + printf("\tjmp\tL_%s$stub\n",s); +#else printf("\tjmp %s\n",s); +#endif } @@ -1565,10 +1632,17 @@ code_assign_gvar(int e2,int creg,int byte) { if (byte) { use_data_reg(creg,1); } else { use_int(creg); } +#ifdef __APPLE__ + if (cadr(e2)) + printf("\t%s %s,_%s+%d\n",move(byte),register_name(creg,byte),((NMTBL*)caddr(e2))->nm,cadr(e2)); + else + printf("\t%s %s,_%s\n",move(byte),register_name(creg,byte),((NMTBL*)caddr(e2))->nm); +#else if (cadr(e2)) printf("\t%s %s,%s+%d\n",move(byte),register_name(creg,byte),((NMTBL*)caddr(e2))->nm,cadr(e2)); else printf("\t%s %s,%s\n",move(byte),register_name(creg,byte),((NMTBL*)caddr(e2))->nm); +#endif } void @@ -1910,10 +1984,16 @@ { text_mode(0); printf("\t.align 4\n"); +#ifndef __APPLE__ if (stmode!=STATIC) printf(".globl %s\n",name); printf("\t.type\t%s,@function\n",name); printf("%s:\n",name); +#else + if (stmode!=STATIC) + printf(".globl _%s\n",name); + printf("_%s:\n",name); +#endif } @@ -1931,10 +2011,14 @@ { disp &= -SIZE_OF_INT; printf("\t.set _%d,%d\n",code_disp_label,disp+code_disp_offset-8); +#ifndef __APPLE__ printf("_%d:\n",labelno); printf("\t.size\t%s,_%d-%s\n",name,labelno,name); local_table(); labelno++; +#else + local_table(); +#endif free_all_register(); } @@ -1943,10 +2027,16 @@ { text_mode(0); printf("\t.align 2\n"); +#ifndef __APPLE__ if (stmode!=STATIC) printf(".globl %s\n",name); printf("%s:\n",name); printf("\t.type\t%s,@function\n",name); +#else + if (stmode!=STATIC) + printf(".globl _%s\n",name); + printf("_%s:\n",name); +#endif printf("\tpushl %%ebp\n"); printf("\tmovl %%esp,%%ebp\n"); printf("\tpushl %%ebx\n"); @@ -1954,6 +2044,15 @@ printf("\tpushl %%edi\n"); func_disp_label=fwdlabel(); printf("\tlea _%d(%%ebp),%%esp\n",func_disp_label); +#ifdef __APPLE__ +#if 0 + printf("\tcalli\t___i686.get_pc_thunk.cx\n"); + printf("_%d:\n",labelno); + goffset_label = labelno; + labelno++; +#endif +#endif + control=1; } @@ -2012,8 +2111,10 @@ printf("\tleave\n"); printf("\tret\n"); printf("\t.set _%d,%d\n",func_disp_label,disp+disp_offset); +#ifndef __APPLE__ printf("_%d:\n",labelno); printf("\t.size\t%s,_%d-%s\n",name,labelno,name); +#endif local_table(); labelno++; free_all_register(); @@ -2071,7 +2172,11 @@ extern void ascii(char *s) { +#ifdef __APPLE__ + printf("\t.ascii \""); +#else printf("\t.string \""); +#endif while(*s) { if (*s=='\n') printf("%cn",92); @@ -2085,7 +2190,11 @@ printf("%c",*s); s++; } +#ifdef __APPLE__ + printf("\\0%c\n",34); +#else printf("%c\n",34); +#endif } extern int @@ -2138,9 +2247,15 @@ } else data_mode(n->nm); align(a); +#ifdef __APPLE__ + if (n && n->sc!=STATIC) + printf(".globl\t_%s\n",n->nm); + printf("_%s:\n",n->nm); +#else if (n && n->sc!=STATIC) printf(".globl\t%s\n",n->nm); printf("%s:\n",n->nm); +#endif } extern void @@ -2213,10 +2328,17 @@ emit_address(char *s,int offset) { data_mode(0); +#ifdef __APPLE__ + if (offset) + printf("\t.long _%s+%d\n",s,offset); + else + printf("\t.long _%s\n",s); +#else if (offset) printf("\t.long %s+%d\n",s,offset); else printf("\t.long %s\n",s); +#endif } extern void @@ -2267,6 +2389,8 @@ 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 (is_code(n)||is_function(n)) continue; /* n->dsp = -1 means initialized global */ @@ -2274,10 +2398,28 @@ data_mode(0); init=1; } +#ifdef __APPLE__ + printf(".comm _%s,%d\n",n->nm,size(n->ty)); +#else printf(".comm %s,%d\n",n->nm,size(n->ty)); +#endif // .lcomm? } } +#ifdef __APPLE__ + for(n = global_list;n!=&null_nptr;n = n->next) { + if (is_code(n)||is_function(n)) { + if (n->sc==EXTRN1) { + data_mode(0); + } + 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); + printf("\thlt ; hlt ; hlt ; hlt ; hlt\n"); + } + } +#endif + } void @@ -2293,8 +2435,13 @@ data_mode(0); init=1; } +#ifdef __APPLE__ + if (n->dsp!= -1) /* -1 means initialized global */ + printf(".lcomm _%s,%d\n",n->nm,size(n->ty)); +#else if (n->dsp!= -1) /* -1 means initialized global */ printf(".lcomm %s,%d\n",n->nm,size(n->ty)); +#endif } } } @@ -2303,7 +2450,11 @@ cstring_mode(int align) { if (output_mode!=RODATA_EMIT_MODE) { +#ifndef __APPLE__ printf(".section\t.rodata\n\t.align 2\n"); +#else + printf("\t.cstring\n"); +#endif output_mode = RODATA_EMIT_MODE; } } @@ -2325,8 +2476,10 @@ printf(".data\n"); output_mode = DATA_EMIT_MODE; } +#ifndef __APPLE__ if (name) printf("\t.type\t%s,@object\n",name); +#endif } #if FLOAT_CODE @@ -2358,10 +2511,17 @@ void code_dassign_gvar(int e2,int freg,int d) { +#ifdef __APPLE__ + if (cadr(e2)) + printf("\t%s _%s+%d\n",fstore(d),((NMTBL*)caddr(e2))->nm,cadr(e2)); + else + printf("\t%s _%s\n",fstore(d),((NMTBL*)caddr(e2))->nm); +#else if (cadr(e2)) printf("\t%s %s+%d\n",fstore(d),((NMTBL*)caddr(e2))->nm,cadr(e2)); else printf("\t%s %s\n",fstore(d),((NMTBL*)caddr(e2))->nm); +#endif } void code_dassign_lvar(int e2,int freg,int d) @@ -2406,7 +2566,11 @@ if (value==1.0) { printf("\tfld1\n"); return; } +#ifdef __APPLE__ + printf(" \t.literal8\n\t.align 3\n"); +#else printf(" \t.section\t.rodata\n\t.align 8\n"); +#endif lb=fwdlabel(); printf("_%d:\n",lb); #if ENDIAN_D==0 @@ -2497,10 +2661,17 @@ void code_drgvar(int e2,int d,int freg) { +#ifdef __APPLE__ + if (cadr(e2)) + printf("\t%s _%s+%d\n",fload(d),((NMTBL*)caddr(e2))->nm,cadr(e2)); + else + printf("\t%s _%s\n",fload(d),((NMTBL*)caddr(e2))->nm); +#else if (cadr(e2)) printf("\t%s %s+%d\n",fload(d),((NMTBL*)caddr(e2))->nm,cadr(e2)); else printf("\t%s %s\n",fload(d),((NMTBL*)caddr(e2))->nm); +#endif } @@ -2511,10 +2682,17 @@ void code_cmp_drgvar(int e2,int reg,int d,int label,int cond) { +#ifdef __APPLE__ + if (cadr(e2)) + printf("\tfcomp _%s+%d\n",((NMTBL*)caddr(e2))->nm,cadr(e2)); + else + printf("\tfcomp _%s\n",((NMTBL*)caddr(e2))->nm); +#else if (cadr(e2)) printf("\tfcomp %s+%d\n",((NMTBL*)caddr(e2))->nm,cadr(e2)); else printf("\tfcomp %s\n",((NMTBL*)caddr(e2))->nm); +#endif jcond(label,cond); } @@ -2863,6 +3041,15 @@ n = ((NMTBL*)caddr(e1))->nm; use_int(e2); crn = register_name(e2,0); +#ifdef __APPLE__ + if (cadr(e1)) { + printf("\tmovl _%s+%d,%s\n",n,cadr(e1),crn); + printf("\torl _%s+%d,%s\n",n,cadr(e1)+4,crn); + } else { + printf("\tmovl _%s,%s\n",n,crn); + printf("\torl _%s+4,%s\n",n,crn); + } +#else if (cadr(e1)) { printf("\tmovl %s+%d,%s\n",n,cadr(e1),crn); printf("\torl %s+%d,%s\n",n,cadr(e1)+4,crn); @@ -2870,6 +3057,7 @@ printf("\tmovl %s,%s\n",n,crn); printf("\torl %s+4,%s\n",n,crn); } +#endif printf("\ttestl %s,%s\n",crn,crn); jcond(label,cond); } @@ -2903,6 +3091,15 @@ n = ((NMTBL*)caddr(e1))->nm; use_longlong(e2); #if ENDIAN_L==0 +#ifdef __APPLE__ + if (cadr(e1)) { + printf("\tmovl %s,_%s+%d\n",l_eax(e2),n,cadr(e1)); + printf("\tmovl %s,_%s+%d\n",l_edx(e2),n,cadr(e1)+4); + } else { + printf("\tmovl %s,_%s\n",l_eax(e2),n); + printf("\tmovl %s,_%s+4\n",l_edx(e2),n); + } +#else if (cadr(e1)) { printf("\tmovl %s,%s+%d\n",l_eax(e2),n,cadr(e1)); printf("\tmovl %s,%s+%d\n",l_edx(e2),n,cadr(e1)+4); @@ -2911,6 +3108,7 @@ printf("\tmovl %s,%s+4\n",l_edx(e2),n); } #endif +#endif } void code_lassign_lvar(int e1,int e2) @@ -2956,6 +3154,15 @@ n = ((NMTBL*)caddr(e1))->nm; use_longlong(e2); #if ENDIAN_L==0 +#ifdef __APPLE__ + if (cadr(e1)) { + printf("\tmovl _%s+%d,%s\n",n,cadr(e1),l_eax(e2)); + printf("\tmovl _%s+%d,%s\n",n,cadr(e1)+4,l_edx(e2)); + } else { + printf("\tmovl _%s,%s\n",n,l_eax(e2)); + printf("\tmovl _%s+4,%s\n",n,l_edx(e2)); + } +#else if (cadr(e1)) { printf("\tmovl %s+%d,%s\n",n,cadr(e1),l_eax(e2)); printf("\tmovl %s+%d,%s\n",n,cadr(e1)+4,l_edx(e2)); @@ -2964,6 +3171,7 @@ printf("\tmovl %s+4,%s\n",n,l_edx(e2)); } #endif +#endif } void code_lrlvar(int e1,int e2) @@ -3437,7 +3645,11 @@ code_table_open(int l) { output_mode=DATA_EMIT_MODE; +#ifdef __APPLE__ + printf(" \t.literal4\n\t.align 2\n"); +#else printf(" \t.section\t.rodata\n\t.align 4\n"); +#endif fwddef(l); }