/* gnuMac - Stuff concerned especially with code generation for * the Gnu Mac pentium assembler . */ #include "common.h" #include "dlist.h" #include "pfParse.h" #include "pfToken.h" #include "pfType.h" #include "pfScope.h" #include "pfCompile.h" #include "pfPreamble.h" #include "isx.h" #include "pentCode.h" #include "backEnd.h" #include "gnuMac.h" #define cstrPrefix "JK_" /* Prefix before string constants */ void gnuMacModuleVars(struct dlList *iList, FILE *f) /* Print out info on uninitialized variables - actually all vars..... */ { struct dlNode *node; for (node = iList->head; !dlEnd(node); node = node->next) { struct isx *isx = node->val; struct isxAddress *dest = isx->dest; struct pfVar *var = dest->val.var; enum pfAccessType access = var->ty->access; boolean isGlobal = (access == paGlobal || access == paWritable); int size = pentTypeSize(dest->valType); if (isGlobal) { fprintf(f, ".align %d\n", size); fprintf(f, ".comm"); fprintf(f, " %s%s,%d\n", isxPrefixC, var->cName, size); } else { fprintf(f, ".lcomm"); fprintf(f, " %s%s,%d,%d\n", isxPrefixC, var->cName, size, size); } } } void gnuMacModulePreamble(FILE *f) /* Print out various incantations needed at start of every * source file for working on Mac OS X on Pentiums, or at * least on my mini. Also print initialized vars. */ { fprintf(f, "# ParaFlow Pentium Output\n\n"); fprintf(f, "%s", "# Preamble found in all modules for Mac OS-X Pentium\n" " .text\n" "doNothing:\n" " ret\n" "\n" " .data\n" " .align 3\n" "longLongMinusOne:\n" " .long -1\n" " .long -1\n" "bunchOfZero:\n" " .long 0\n" " .long 0\n" " .long 0\n" " .long 0\n" "\n" ); } void gnuMacModulePostscript(FILE *f) /* Print out various incantations needed at end of every * source file for working on Mac OS X on Pentiums, or at * least on my mini. Also print uninitialized vars. */ { fprintf(f, "%s", "\n" ); } static void dataSegment(struct pfBackEnd *backEnd, FILE *f) /* Switch to data segment */ { if (backEnd->segment != pfbData) { fprintf(f, "\t.data\n"); backEnd->segment = pfbData; } } static void codeSegment(struct pfBackEnd *backEnd, FILE *f) /* Switch to code segment */ { if (backEnd->segment != pfbCode) { fprintf(f, "\t.text\n"); backEnd->segment = pfbCode; } } static void bssSegment(struct pfBackEnd *backEnd, FILE *f) /* Switch to bss segment */ { codeSegment(backEnd, f); /* Seems to be case on mac....??? */ } static void stringSegment(struct pfBackEnd *backEnd, FILE *f) /* Switch to string segment */ { if (backEnd->segment != pfbString) { fprintf(f, "\t.cstring\n"); backEnd->segment = pfbString; } } static void emitLabel(struct pfBackEnd *backEnd, char *label, int aliSize, boolean isGlobal, FILE *f) /* Emit label aligned to aliSize. */ { if (aliSize > 8) fprintf(f, "\t.align\t4\n"); else if (aliSize > 4) fprintf(f, "\t.align\t3\n"); else if (aliSize > 2) fprintf(f, "\t.align\t2\n"); if (isGlobal) fprintf(f, ".globl\t%s\n", label); fprintf(f, "%s:\n", label); } static void emitAscii(struct pfBackEnd *backEnd, char *string,int size,FILE *f) /* Emit string of ascii chars of given size. */ { char c; int i; fprintf(f, "\t.ascii\t\""); for (i=0; i