From e6484f85c7f440aa8b12bbf956bed0b87e4ddeed Mon Sep 17 00:00:00 2001 From: cuz Date: Sat, 5 May 2001 13:51:42 +0000 Subject: [PATCH] Working on the new backend git-svn-id: svn://svn.cc65.org/cc65/trunk@715 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/asmcode.c | 36 +- src/cc65/codeent.c | 4 +- src/cc65/codeent.h | 2 +- src/cc65/codegen.c | 1510 +++++++++++++++++++---------------------- src/cc65/codegen.h | 28 +- src/cc65/codelab.c | 4 +- src/cc65/codelab.h | 2 +- src/cc65/codeopt.c | 4 +- src/cc65/codeseg.c | 73 +- src/cc65/codeseg.h | 28 +- src/cc65/dataseg.c | 86 +-- src/cc65/dataseg.h | 25 +- src/cc65/function.c | 5 +- src/cc65/main.c | 2 +- src/cc65/make/gcc.mak | 16 +- src/cc65/pragma.c | 21 +- src/cc65/pragma.h | 8 +- src/cc65/segments.c | 250 +++++++ src/cc65/segments.h | 132 ++++ src/cc65/symentry.h | 28 +- src/cc65/symtab.c | 3 +- 21 files changed, 1212 insertions(+), 1055 deletions(-) create mode 100644 src/cc65/segments.c create mode 100644 src/cc65/segments.h diff --git a/src/cc65/asmcode.c b/src/cc65/asmcode.c index 3522ce169..046043f2b 100644 --- a/src/cc65/asmcode.c +++ b/src/cc65/asmcode.c @@ -40,6 +40,7 @@ #include "codeopt.h" #include "codeseg.h" #include "dataseg.h" +#include "segments.h" #include "symtab.h" #include "asmcode.h" @@ -62,7 +63,7 @@ void AddCodeHint (const char* Hint) CodeMark GetCodePos (void) /* Get a marker pointing to the current output position */ { - return GetCodeSegEntries (CS); + return GetCodeSegEntries (CS->Code); } @@ -70,22 +71,7 @@ CodeMark GetCodePos (void) void RemoveCode (CodeMark M) /* Remove all code after the given code marker */ { - DelCodeSegAfter (CS, M); -} - - - -static void PrintFunctionHeader (FILE* F, SymEntry* Entry) -{ - /* Print a comment with the function signature */ - fprintf (F, - "; ---------------------------------------------------------------\n" - "; "); - PrintFuncSig (F, Entry->Name, Entry->Type); - fprintf (F, - "\n" - "; ---------------------------------------------------------------\n" - "\n"); + DelCodeSegAfter (CS->Code, M); } @@ -96,9 +82,9 @@ void WriteOutput (FILE* F) SymTable* SymTab; SymEntry* Entry; - /* Output the data segment (the global code segment should be empty) */ - OutputDataSeg (F, DS); - CHECK (GetCodeSegEntries (CS) == 0); + /* Output the global data segment */ + CHECK (GetCodeSegEntries (CS->Code) == 0); + OutputSegments (CS, F); /* Output all global or referenced functions */ SymTab = GetGlobalSymTab (); @@ -108,13 +94,9 @@ void WriteOutput (FILE* F) (Entry->Flags & SC_DEF) != 0 && (Entry->Flags & (SC_REF | SC_EXTERN)) != 0) { /* Function which is defined and referenced or extern */ - PrintFunctionHeader (F, Entry); - MergeCodeLabels (Entry->V.F.CS); - RunOpt (Entry->V.F.CS); - fprintf (F, "; Data segment for function %s:\n", Entry->Name); - OutputDataSeg (F, Entry->V.F.DS); - fprintf (F, "; Code segment for function %s:\n", Entry->Name); - OutputCodeSeg (F, Entry->V.F.CS); + MergeCodeLabels (Entry->V.F.Seg->Code); + RunOpt (Entry->V.F.Seg->Code); + OutputSegments (Entry->V.F.Seg, F); } Entry = Entry->NextSym; } diff --git a/src/cc65/codeent.c b/src/cc65/codeent.c index 09e4b3ef8..9ac25317c 100644 --- a/src/cc65/codeent.c +++ b/src/cc65/codeent.c @@ -119,7 +119,7 @@ int CodeEntryHasLabel (const CodeEntry* E) -void OutputCodeEntry (FILE* F, const CodeEntry* E) +void OutputCodeEntry (const CodeEntry* E, FILE* F) /* Output the code entry to a file */ { const OPCDesc* D; @@ -129,7 +129,7 @@ void OutputCodeEntry (FILE* F, const CodeEntry* E) unsigned LabelCount = CollCount (&E->Labels); unsigned I; for (I = 0; I < LabelCount; ++I) { - OutputCodeLabel (F, CollConstAt (&E->Labels, I)); + OutputCodeLabel (CollConstAt (&E->Labels, I), F); } /* Get the opcode description */ diff --git a/src/cc65/codeent.h b/src/cc65/codeent.h index 61cd3b55f..785ed974e 100644 --- a/src/cc65/codeent.h +++ b/src/cc65/codeent.h @@ -91,7 +91,7 @@ void FreeCodeEntry (CodeEntry* E); int CodeEntryHasLabel (const CodeEntry* E); /* Check if the given code entry has labels attached */ -void OutputCodeEntry (FILE* F, const CodeEntry* E); +void OutputCodeEntry (const CodeEntry* E, FILE* F); /* Output the code entry to a file */ diff --git a/src/cc65/codegen.c b/src/cc65/codegen.c index ce7ef5d2c..183a91ce9 100644 --- a/src/cc65/codegen.c +++ b/src/cc65/codegen.c @@ -45,13 +45,13 @@ /* cc65 */ #include "asmcode.h" -#include "asmlabel.h" +#include "asmlabel.h" #include "codeseg.h" #include "cpu.h" #include "dataseg.h" #include "error.h" #include "global.h" -#include "segname.h" +#include "segments.h" #include "util.h" #include "codegen.h" @@ -66,13 +66,10 @@ /* Compiler relative stack pointer */ int oursp = 0; -/* Current segment */ -segment_t CurSeg = SEG_INV; - /*****************************************************************************/ -/* Helpers */ +/* Helpers */ /*****************************************************************************/ @@ -142,84 +139,50 @@ static char* GetLabelName (unsigned flags, unsigned long label, unsigned offs) void g_preamble (void) /* Generate the assembler code preamble */ { - /* Generate the global segments and push them */ - PushCodeSeg (NewCodeSeg (SegmentNames[SEG_CODE], "")); - PushDataSeg (NewDataSeg ("")); + /* Create a new segment list */ + PushSegments (0); /* Identify the compiler version */ - AddDataSegLine (DS, "; File generated by cc65 v %u.%u.%u", - VER_MAJOR, VER_MINOR, VER_PATCH); + AddDataLine ("; File generated by cc65 v %u.%u.%u", + VER_MAJOR, VER_MINOR, VER_PATCH); /* Insert some object file options */ - AddDataSegLine (DS, ".fopt\t\tcompiler,\"cc65 v %u.%u.%u\"", + AddDataLine (".fopt\t\tcompiler,\"cc65 v %u.%u.%u\"", VER_MAJOR, VER_MINOR, VER_PATCH); /* If we're producing code for some other CPU, switch the command set */ if (CPU == CPU_65C02) { - AddDataSegLine (DS, ".pc02"); + AddDataLine (".pc02"); } /* Allow auto import for runtime library routines */ - AddDataSegLine (DS, ".autoimport\ton"); + AddDataLine (".autoimport\ton"); /* Switch the assembler into case sensitive mode */ - AddDataSegLine (DS, ".case\t\ton"); + AddDataLine (".case\t\ton"); /* Tell the assembler if we want to generate debug info */ - AddDataSegLine (DS, ".debuginfo\t%s", (DebugInfo != 0)? "on" : "off"); + AddDataLine (".debuginfo\t%s", (DebugInfo != 0)? "on" : "off"); /* Import the stack pointer for direct auto variable access */ - AddDataSegLine (DS, ".importzp\tsp, sreg, regsave, regbank, tmp1, ptr1"); + AddDataLine (".importzp\tsp, sreg, regsave, regbank, tmp1, ptr1"); /* Define long branch macros */ - AddDataSegLine (DS, ".macpack\tlongbranch"); + AddDataLine (".macpack\tlongbranch"); } /*****************************************************************************/ -/* Segment support */ +/* Segment support */ /*****************************************************************************/ -static void UseSeg (int NewSeg) -/* Switch to a specific segment */ -{ - if (CurSeg != NewSeg) { - CurSeg = (segment_t) NewSeg; - if (CurSeg != SEG_CODE) { - AddDataSegLine (DS, ".segment\t\"%s\"", SegmentNames [CurSeg]); - } - } -} - - - -void g_pushseg (struct CodeSeg** FCS, struct DataSeg** FDS, const char* FuncName) -/* Push the current segments and generate new ones for the given function */ -{ - PushCodeSeg (NewCodeSeg (SegmentNames[SEG_CODE], FuncName)); - *FCS = CS; - PushDataSeg (NewDataSeg (FuncName)); - *FDS = DS; -} - - - -void g_popseg (void) -/* Restore the old segments */ -{ - PopCodeSeg (); - PopDataSeg (); -} - - - void g_userodata (void) /* Switch to the read only data segment */ { - UseSeg (SEG_RODATA); + UseDataSeg (SEG_RODATA); } @@ -227,7 +190,7 @@ void g_userodata (void) void g_usedata (void) /* Switch to the data segment */ { - UseSeg (SEG_DATA); + UseDataSeg (SEG_DATA); } @@ -235,56 +198,7 @@ void g_usedata (void) void g_usebss (void) /* Switch to the bss segment */ { - UseSeg (SEG_BSS); -} - - - -static void SegName (segment_t Seg, const char* Name) -/* Set the name of a segment */ -{ - /* Free the old name and set a new one */ - NewSegName (Seg, Name); - - /* If the new segment is the current segment, emit a segment directive - * with the new name. - */ - if (Seg == CurSeg) { - CurSeg = SEG_INV; /* Invalidate */ - UseSeg (Seg); - } -} - - - -void g_codename (const char* Name) -/* Set the name of the CODE segment */ -{ - SegName (SEG_CODE, Name); -} - - - -void g_rodataname (const char* Name) -/* Set the name of the RODATA segment */ -{ - SegName (SEG_RODATA, Name); -} - - - -void g_dataname (const char* Name) -/* Set the name of the DATA segment */ -{ - SegName (SEG_DATA, Name); -} - - - -void g_bssname (const char* Name) -/* Set the name of the BSS segment */ -{ - SegName (SEG_BSS, Name); + UseDataSeg (SEG_BSS); } @@ -372,7 +286,7 @@ static unsigned MakeByteOffs (unsigned Flags, unsigned Offs) void g_defcodelabel (unsigned label) /* Define a local code label */ { - AddCodeLabel (CS, LocalLabelName (label)); + AddCodeLabel (CS->Code, LocalLabelName (label)); } @@ -380,7 +294,7 @@ void g_defcodelabel (unsigned label) void g_defdatalabel (unsigned label) /* Define a local data label */ { - AddDataSegLine (DS, "%s:", LocalLabelName (label)); + AddDataLine ("%s:", LocalLabelName (label)); } @@ -395,7 +309,7 @@ void g_defgloblabel (const char* Name) /* Define a global label with the given name */ { /* Global labels are always data labels */ - AddDataSegLine (DS, "_%s:", Name); + AddDataLine ("_%s:", Name); } @@ -404,9 +318,9 @@ void g_defexport (const char* Name, int ZP) /* Export the given label */ { if (ZP) { - AddDataSegLine (DS, "\t.exportzp\t_%s", Name); + AddDataLine ("\t.exportzp\t_%s", Name); } else { - AddDataSegLine (DS, "\t.export\t\t_%s", Name); + AddDataLine ("\t.export\t\t_%s", Name); } } @@ -416,9 +330,9 @@ void g_defimport (const char* Name, int ZP) /* Import the given label */ { if (ZP) { - AddDataSegLine (DS, "\t.importzp\t_%s", Name); + AddDataLine ("\t.importzp\t_%s", Name); } else { - AddDataSegLine (DS, "\t.import\t\t_%s", Name); + AddDataLine ("\t.import\t\t_%s", Name); } } @@ -433,7 +347,7 @@ void g_defimport (const char* Name, int ZP) static void ldaconst (unsigned val) /* Load a with a constant */ { - AddCodeSegLine (CS, "lda #$%02X", val & 0xFF); + AddCodeLine ("lda #$%02X", val & 0xFF); } @@ -441,7 +355,7 @@ static void ldaconst (unsigned val) static void ldxconst (unsigned val) /* Load x with a constant */ { - AddCodeSegLine (CS, "ldx #$%02X", val & 0xFF); + AddCodeLine ("ldx #$%02X", val & 0xFF); } @@ -449,7 +363,7 @@ static void ldxconst (unsigned val) static void ldyconst (unsigned val) /* Load y with a constant */ { - AddCodeSegLine (CS, "ldy #$%02X", val & 0xFF); + AddCodeLine ("ldy #$%02X", val & 0xFF); } @@ -476,7 +390,7 @@ void g_enter (unsigned flags, unsigned argsize) funcargs = argsize; } else { funcargs = -1; - AddCodeSegLine (CS, "jsr enter"); + AddCodeLine ("jsr enter"); } } @@ -509,14 +423,14 @@ void g_leave (int flags, int val) k += funcargs; if (k == 0) { AddCodeHint ("y:-"); /* Y register no longer used */ - AddCodeSegLine (CS, "rts"); + AddCodeLine ("rts"); } else if (k <= 8) { AddCodeHint ("y:-"); /* Y register no longer used */ - AddCodeSegLine (CS, "jmp incsp%d", k); + AddCodeLine ("jmp incsp%d", k); } else { CheckLocalOffs (k); ldyconst (k); - AddCodeSegLine (CS, "jmp addysp"); + AddCodeLine ("jmp addysp"); } } else { @@ -551,7 +465,7 @@ void g_leave (int flags, int val) } /* Output the jump */ - AddCodeSegLine (CS, buf); + AddCodeLine (buf); } } @@ -569,14 +483,14 @@ void g_save_regvars (int RegOffs, unsigned Bytes) /* Don't loop for up to two bytes */ if (Bytes == 1) { - AddCodeSegLine (CS, "lda regbank%+d", RegOffs); - AddCodeSegLine (CS, "jsr pusha"); + AddCodeLine ("lda regbank%+d", RegOffs); + AddCodeLine ("jsr pusha"); } else if (Bytes == 2) { - AddCodeSegLine (CS, "lda regbank%+d", RegOffs); - AddCodeSegLine (CS, "ldx regbank%+d", RegOffs+1); - AddCodeSegLine (CS, "jsr pushax"); + AddCodeLine ("lda regbank%+d", RegOffs); + AddCodeLine ("ldx regbank%+d", RegOffs+1); + AddCodeLine ("jsr pushax"); } else { @@ -586,11 +500,11 @@ void g_save_regvars (int RegOffs, unsigned Bytes) ldyconst (Bytes - 1); ldxconst (Bytes); g_defcodelabel (Label); - AddCodeSegLine (CS, "lda regbank%+d,x", RegOffs-1); - AddCodeSegLine (CS, "sta (sp),y"); - AddCodeSegLine (CS, "dey"); - AddCodeSegLine (CS, "dex"); - AddCodeSegLine (CS, "bne %s", LocalLabelName (Label)); + AddCodeLine ("lda regbank%+d,x", RegOffs-1); + AddCodeLine ("sta (sp),y"); + AddCodeLine ("dey"); + AddCodeLine ("dex"); + AddCodeLine ("bne %s", LocalLabelName (Label)); } @@ -611,17 +525,17 @@ void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes) if (Bytes == 1) { ldyconst (StackOffs); - AddCodeSegLine (CS, "lda (sp),y"); - AddCodeSegLine (CS, "sta regbank%+d", RegOffs); + AddCodeLine ("lda (sp),y"); + AddCodeLine ("sta regbank%+d", RegOffs); } else if (Bytes == 2) { ldyconst (StackOffs); - AddCodeSegLine (CS, "lda (sp),y"); - AddCodeSegLine (CS, "sta regbank%+d", RegOffs); - AddCodeSegLine (CS, "iny"); - AddCodeSegLine (CS, "lda (sp),y"); - AddCodeSegLine (CS, "sta regbank%+d", RegOffs+1); + AddCodeLine ("lda (sp),y"); + AddCodeLine ("sta regbank%+d", RegOffs); + AddCodeLine ("iny"); + AddCodeLine ("lda (sp),y"); + AddCodeLine ("sta regbank%+d", RegOffs+1); } else { @@ -630,11 +544,11 @@ void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes) ldyconst (StackOffs+Bytes-1); ldxconst (Bytes); g_defcodelabel (Label); - AddCodeSegLine (CS, "lda (sp),y"); - AddCodeSegLine (CS, "sta regbank%+d,x", RegOffs-1); - AddCodeSegLine (CS, "dey"); - AddCodeSegLine (CS, "dex"); - AddCodeSegLine (CS, "bne %s", LocalLabelName (Label)); + AddCodeLine ("lda (sp),y"); + AddCodeLine ("sta regbank%+d,x", RegOffs-1); + AddCodeLine ("dey"); + AddCodeLine ("dex"); + AddCodeLine ("bne %s", LocalLabelName (Label)); } } @@ -668,39 +582,39 @@ void g_getimmed (unsigned flags, unsigned long val, unsigned offs) case CF_LONG: if (val < 0x100) { - AddCodeSegLine (CS, "ldx #$00"); - AddCodeSegLine (CS, "stx sreg+1"); - AddCodeSegLine (CS, "stx sreg"); - AddCodeSegLine (CS, "lda #$%02X", (unsigned char) val); + AddCodeLine ("ldx #$00"); + AddCodeLine ("stx sreg+1"); + AddCodeLine ("stx sreg"); + AddCodeLine ("lda #$%02X", (unsigned char) val); } else if ((val & 0xFFFF00FF) == 0) { - AddCodeSegLine (CS, "lda #$00"); - AddCodeSegLine (CS, "sta sreg+1"); - AddCodeSegLine (CS, "sta sreg"); - AddCodeSegLine (CS, "ldx #$%02X", (unsigned char) (val >> 8)); + AddCodeLine ("lda #$00"); + AddCodeLine ("sta sreg+1"); + AddCodeLine ("sta sreg"); + AddCodeLine ("ldx #$%02X", (unsigned char) (val >> 8)); } else if ((val & 0xFFFF0000) == 0 && CodeSizeFactor > 140) { - AddCodeSegLine (CS, "lda #$00"); - AddCodeSegLine (CS, "sta sreg+1"); - AddCodeSegLine (CS, "sta sreg"); - AddCodeSegLine (CS, "lda #$%02X", (unsigned char) val); - AddCodeSegLine (CS, "ldx #$%02X", (unsigned char) (val >> 8)); + AddCodeLine ("lda #$00"); + AddCodeLine ("sta sreg+1"); + AddCodeLine ("sta sreg"); + AddCodeLine ("lda #$%02X", (unsigned char) val); + AddCodeLine ("ldx #$%02X", (unsigned char) (val >> 8)); } else if ((val & 0xFFFFFF00) == 0xFFFFFF00) { - AddCodeSegLine (CS, "ldx #$FF"); - AddCodeSegLine (CS, "stx sreg+1"); - AddCodeSegLine (CS, "stx sreg"); + AddCodeLine ("ldx #$FF"); + AddCodeLine ("stx sreg+1"); + AddCodeLine ("stx sreg"); if ((val & 0xFF) == 0xFF) { - AddCodeSegLine (CS, "txa"); + AddCodeLine ("txa"); } else { - AddCodeSegLine (CS, "lda #$%02X", (unsigned char) val); + AddCodeLine ("lda #$%02X", (unsigned char) val); } } else if ((val & 0xFFFF00FF) == 0xFFFF00FF) { - AddCodeSegLine (CS, "lda #$FF"); - AddCodeSegLine (CS, "sta sreg+1"); - AddCodeSegLine (CS, "sta sreg"); - AddCodeSegLine (CS, "ldx #$%02X", (unsigned char) (val >> 8)); + AddCodeLine ("lda #$FF"); + AddCodeLine ("sta sreg+1"); + AddCodeLine ("sta sreg"); + AddCodeLine ("ldx #$%02X", (unsigned char) (val >> 8)); } else { /* Call a subroutine that will load following value */ - AddCodeSegLine (CS, "jsr ldeax"); - AddCodeSegLine (CS, ".dword $%08lX", val & 0xFFFFFFFF); + AddCodeLine ("jsr ldeax"); + AddCodeLine (".dword $%08lX", val & 0xFFFFFFFF); } break; @@ -716,8 +630,8 @@ void g_getimmed (unsigned flags, unsigned long val, unsigned offs) const char* Label = GetLabelName (flags, val, offs); /* Load the address into the primary */ - AddCodeSegLine (CS, "lda #<(%s)", Label); - AddCodeSegLine (CS, "ldx #>(%s)", Label); + AddCodeLine ("lda #<(%s)", Label); + AddCodeLine ("ldx #>(%s)", Label); } } @@ -735,41 +649,41 @@ void g_getstatic (unsigned flags, unsigned long label, unsigned offs) case CF_CHAR: if ((flags & CF_FORCECHAR) || (flags & CF_TEST)) { - AddCodeSegLine (CS, "lda %s", lbuf); /* load A from the label */ + AddCodeLine ("lda %s", lbuf); /* load A from the label */ } else { ldxconst (0); - AddCodeSegLine (CS, "lda %s", lbuf); /* load A from the label */ + AddCodeLine ("lda %s", lbuf); /* load A from the label */ if (!(flags & CF_UNSIGNED)) { /* Must sign extend */ - AddCodeSegLine (CS, "bpl *+3"); - AddCodeSegLine (CS, "dex"); + AddCodeLine ("bpl *+3"); + AddCodeLine ("dex"); AddCodeHint ("x:!"); /* X is invalid now */ } } break; case CF_INT: - AddCodeSegLine (CS, "lda %s", lbuf); + AddCodeLine ("lda %s", lbuf); if (flags & CF_TEST) { - AddCodeSegLine (CS, "ora %s+1", lbuf); + AddCodeLine ("ora %s+1", lbuf); } else { - AddCodeSegLine (CS, "ldx %s+1", lbuf); + AddCodeLine ("ldx %s+1", lbuf); } break; case CF_LONG: if (flags & CF_TEST) { - AddCodeSegLine (CS, "lda %s+3", lbuf); - AddCodeSegLine (CS, "ora %s+2", lbuf); - AddCodeSegLine (CS, "ora %s+1", lbuf); - AddCodeSegLine (CS, "ora %s+0", lbuf); + AddCodeLine ("lda %s+3", lbuf); + AddCodeLine ("ora %s+2", lbuf); + AddCodeLine ("ora %s+1", lbuf); + AddCodeLine ("ora %s+0", lbuf); } else { - AddCodeSegLine (CS, "lda %s+3", lbuf); - AddCodeSegLine (CS, "sta sreg+1"); - AddCodeSegLine (CS, "lda %s+2", lbuf); - AddCodeSegLine (CS, "sta sreg"); - AddCodeSegLine (CS, "ldx %s+1", lbuf); - AddCodeSegLine (CS, "lda %s", lbuf); + AddCodeLine ("lda %s+3", lbuf); + AddCodeLine ("sta sreg+1"); + AddCodeLine ("lda %s+2", lbuf); + AddCodeLine ("sta sreg"); + AddCodeLine ("ldx %s+1", lbuf); + AddCodeLine ("lda %s", lbuf); } break; @@ -791,23 +705,23 @@ void g_getlocal (unsigned flags, int offs) case CF_CHAR: if ((flags & CF_FORCECHAR) || (flags & CF_TEST)) { if (CPU == CPU_65C02 && offs == 0) { - AddCodeSegLine (CS, "lda (sp)"); + AddCodeLine ("lda (sp)"); } else { ldyconst (offs); - AddCodeSegLine (CS, "lda (sp),y"); + AddCodeLine ("lda (sp),y"); } } else { if (offs == 0) { - AddCodeSegLine (CS, "ldx #$00"); - AddCodeSegLine (CS, "lda (sp,x)"); + AddCodeLine ("ldx #$00"); + AddCodeLine ("lda (sp,x)"); } else { ldyconst (offs); - AddCodeSegLine (CS, "ldx #$00"); - AddCodeSegLine (CS, "lda (sp),y"); + AddCodeLine ("ldx #$00"); + AddCodeLine ("lda (sp),y"); } if ((flags & CF_UNSIGNED) == 0) { - AddCodeSegLine (CS, "bpl *+3"); - AddCodeSegLine (CS, "dex"); + AddCodeLine ("bpl *+3"); + AddCodeLine ("dex"); AddCodeHint ("x:!"); /* X is invalid now */ } } @@ -817,22 +731,22 @@ void g_getlocal (unsigned flags, int offs) CheckLocalOffs (offs + 1); if (flags & CF_TEST) { ldyconst (offs + 1); - AddCodeSegLine (CS, "lda (sp),y"); - AddCodeSegLine (CS, "dey"); - AddCodeSegLine (CS, "ora (sp),y"); + AddCodeLine ("lda (sp),y"); + AddCodeLine ("dey"); + AddCodeLine ("ora (sp),y"); } else { if (CodeSizeFactor > 180) { ldyconst (offs + 1); - AddCodeSegLine (CS, "lda (sp),y"); - AddCodeSegLine (CS, "tax"); - AddCodeSegLine (CS, "dey"); - AddCodeSegLine (CS, "lda (sp),y"); + AddCodeLine ("lda (sp),y"); + AddCodeLine ("tax"); + AddCodeLine ("dey"); + AddCodeLine ("lda (sp),y"); } else { if (offs) { ldyconst (offs+1); - AddCodeSegLine (CS, "jsr ldaxysp"); + AddCodeLine ("jsr ldaxysp"); } else { - AddCodeSegLine (CS, "jsr ldax0sp"); + AddCodeLine ("jsr ldax0sp"); } } } @@ -841,9 +755,9 @@ void g_getlocal (unsigned flags, int offs) case CF_LONG: if (offs) { ldyconst (offs+3); - AddCodeSegLine (CS, "jsr ldeaxysp"); + AddCodeLine ("jsr ldeaxysp"); } else { - AddCodeSegLine (CS, "jsr ldeax0sp"); + AddCodeLine ("jsr ldeax0sp"); } break; @@ -873,22 +787,22 @@ void g_getind (unsigned flags, unsigned offs) if (offs) { ldyconst (offs); if (flags & CF_UNSIGNED) { - AddCodeSegLine (CS, "jsr ldauidx"); + AddCodeLine ("jsr ldauidx"); } else { - AddCodeSegLine (CS, "jsr ldaidx"); + AddCodeLine ("jsr ldaidx"); } } else { if (flags & CF_UNSIGNED) { if (CodeSizeFactor > 250) { - AddCodeSegLine (CS, "sta ptr1"); - AddCodeSegLine (CS, "stx ptr1+1"); - AddCodeSegLine (CS, "ldx #$00"); - AddCodeSegLine (CS, "lda (ptr1,x)"); + AddCodeLine ("sta ptr1"); + AddCodeLine ("stx ptr1+1"); + AddCodeLine ("ldx #$00"); + AddCodeLine ("lda (ptr1,x)"); } else { - AddCodeSegLine (CS, "jsr ldaui"); + AddCodeLine ("jsr ldaui"); } } else { - AddCodeSegLine (CS, "jsr ldai"); + AddCodeLine ("jsr ldai"); } } break; @@ -896,30 +810,30 @@ void g_getind (unsigned flags, unsigned offs) case CF_INT: if (flags & CF_TEST) { ldyconst (offs); - AddCodeSegLine (CS, "sta ptr1"); - AddCodeSegLine (CS, "stx ptr1+1"); - AddCodeSegLine (CS, "lda (ptr1),y"); - AddCodeSegLine (CS, "iny"); - AddCodeSegLine (CS, "ora (ptr1),y"); + AddCodeLine ("sta ptr1"); + AddCodeLine ("stx ptr1+1"); + AddCodeLine ("lda (ptr1),y"); + AddCodeLine ("iny"); + AddCodeLine ("ora (ptr1),y"); } else { if (offs == 0) { - AddCodeSegLine (CS, "jsr ldaxi"); + AddCodeLine ("jsr ldaxi"); } else { ldyconst (offs+1); - AddCodeSegLine (CS, "jsr ldaxidx"); + AddCodeLine ("jsr ldaxidx"); } } break; case CF_LONG: if (offs == 0) { - AddCodeSegLine (CS, "jsr ldeaxi"); + AddCodeLine ("jsr ldeaxi"); } else { ldyconst (offs+3); - AddCodeSegLine (CS, "jsr ldeaxidx"); + AddCodeLine ("jsr ldeaxidx"); } if (flags & CF_TEST) { - AddCodeSegLine (CS, "jsr tsteax"); + AddCodeLine ("jsr tsteax"); } break; @@ -939,27 +853,27 @@ void g_leasp (int offs) /* For value 0 we do direct code */ if (offs == 0) { - AddCodeSegLine (CS, "lda sp"); - AddCodeSegLine (CS, "ldx sp+1"); + AddCodeLine ("lda sp"); + AddCodeLine ("ldx sp+1"); } else { if (CodeSizeFactor < 300) { ldaconst (offs); /* Load A with offset value */ - AddCodeSegLine (CS, "jsr leaasp"); /* Load effective address */ + AddCodeLine ("jsr leaasp"); /* Load effective address */ } else { if (CPU == CPU_65C02 && offs == 1) { - AddCodeSegLine (CS, "lda sp"); - AddCodeSegLine (CS, "ldx sp+1"); - AddCodeSegLine (CS, "ina"); - AddCodeSegLine (CS, "bne *+3"); - AddCodeSegLine (CS, "inx"); + AddCodeLine ("lda sp"); + AddCodeLine ("ldx sp+1"); + AddCodeLine ("ina"); + AddCodeLine ("bne *+3"); + AddCodeLine ("inx"); AddCodeHint ("x:!"); /* Invalidate X */ } else { ldaconst (offs); - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "ldx sp+1"); - AddCodeSegLine (CS, "adc sp"); - AddCodeSegLine (CS, "bcc *+3"); - AddCodeSegLine (CS, "inx"); + AddCodeLine ("clc"); + AddCodeLine ("ldx sp+1"); + AddCodeLine ("adc sp"); + AddCodeLine ("bcc *+3"); + AddCodeLine ("inx"); AddCodeHint ("x:!"); /* Invalidate X */ } } @@ -987,22 +901,22 @@ void g_leavariadic (int Offs) /* Get the size of all parameters. */ if (ArgSizeOffs == 0 && CPU == CPU_65C02) { - AddCodeSegLine (CS, "lda (sp)"); + AddCodeLine ("lda (sp)"); } else { ldyconst (ArgSizeOffs); - AddCodeSegLine (CS, "lda (sp),y"); + AddCodeLine ("lda (sp),y"); } /* Add the value of the stackpointer */ if (CodeSizeFactor > 250) { - AddCodeSegLine (CS, "ldx sp+1"); - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc sp"); - AddCodeSegLine (CS, "bcc *+3"); - AddCodeSegLine (CS, "inx"); + AddCodeLine ("ldx sp+1"); + AddCodeLine ("clc"); + AddCodeLine ("adc sp"); + AddCodeLine ("bcc *+3"); + AddCodeLine ("inx"); AddCodeHint ("x:!"); /* Invalidate X */ } else { - AddCodeSegLine (CS, "jsr leaasp"); + AddCodeLine ("jsr leaasp"); } /* Add the offset to the primary */ @@ -1031,21 +945,21 @@ void g_putstatic (unsigned flags, unsigned long label, unsigned offs) switch (flags & CF_TYPE) { case CF_CHAR: - AddCodeSegLine (CS, "sta %s", lbuf); + AddCodeLine ("sta %s", lbuf); break; case CF_INT: - AddCodeSegLine (CS, "sta %s", lbuf); - AddCodeSegLine (CS, "stx %s+1", lbuf); + AddCodeLine ("sta %s", lbuf); + AddCodeLine ("stx %s+1", lbuf); break; case CF_LONG: - AddCodeSegLine (CS, "sta %s", lbuf); - AddCodeSegLine (CS, "stx %s+1", lbuf); - AddCodeSegLine (CS, "ldy sreg"); - AddCodeSegLine (CS, "sty %s+2", lbuf); - AddCodeSegLine (CS, "ldy sreg+1"); - AddCodeSegLine (CS, "sty %s+3", lbuf); + AddCodeLine ("sta %s", lbuf); + AddCodeLine ("stx %s+1", lbuf); + AddCodeLine ("ldy sreg"); + AddCodeLine ("sty %s+2", lbuf); + AddCodeLine ("ldy sreg+1"); + AddCodeLine ("sty %s+3", lbuf); break; default: @@ -1065,59 +979,59 @@ void g_putlocal (unsigned Flags, int Offs, long Val) case CF_CHAR: if (Flags & CF_CONST) { - AddCodeSegLine (CS, "lda #$%02X", (unsigned char) Val); + AddCodeLine ("lda #$%02X", (unsigned char) Val); } if (CPU == CPU_65C02 && Offs == 0) { - AddCodeSegLine (CS, "sta (sp)"); + AddCodeLine ("sta (sp)"); } else { ldyconst (Offs); - AddCodeSegLine (CS, "sta (sp),y"); + AddCodeLine ("sta (sp),y"); } break; case CF_INT: if (Flags & CF_CONST) { ldyconst (Offs+1); - AddCodeSegLine (CS, "lda #$%02X", (unsigned char) (Val >> 8)); - AddCodeSegLine (CS, "sta (sp),y"); + AddCodeLine ("lda #$%02X", (unsigned char) (Val >> 8)); + AddCodeLine ("sta (sp),y"); if ((Flags & CF_NOKEEP) == 0) { /* Place high byte into X */ - AddCodeSegLine (CS, "tax"); + AddCodeLine ("tax"); } if (CPU == CPU_65C02 && Offs == 0) { - AddCodeSegLine (CS, "lda #$%02X", (unsigned char) Val); - AddCodeSegLine (CS, "sta (sp)"); + AddCodeLine ("lda #$%02X", (unsigned char) Val); + AddCodeLine ("sta (sp)"); } else { if ((Val & 0xFF) == Offs+1) { /* The value we need is already in Y */ - AddCodeSegLine (CS, "tya"); - AddCodeSegLine (CS, "dey"); + AddCodeLine ("tya"); + AddCodeLine ("dey"); } else { - AddCodeSegLine (CS, "dey"); - AddCodeSegLine (CS, "lda #$%02X", (unsigned char) Val); + AddCodeLine ("dey"); + AddCodeLine ("lda #$%02X", (unsigned char) Val); } - AddCodeSegLine (CS, "sta (sp),y"); + AddCodeLine ("sta (sp),y"); } } else { if ((Flags & CF_NOKEEP) == 0 || CodeSizeFactor < 160) { if (Offs) { ldyconst (Offs); - AddCodeSegLine (CS, "jsr staxysp"); + AddCodeLine ("jsr staxysp"); } else { - AddCodeSegLine (CS, "jsr stax0sp"); + AddCodeLine ("jsr stax0sp"); } } else { if (CPU == CPU_65C02 && Offs == 0) { - AddCodeSegLine (CS, "sta (sp)"); + AddCodeLine ("sta (sp)"); ldyconst (1); - AddCodeSegLine (CS, "txa"); - AddCodeSegLine (CS, "sta (sp),y"); + AddCodeLine ("txa"); + AddCodeLine ("sta (sp),y"); } else { ldyconst (Offs); - AddCodeSegLine (CS, "sta (sp),y"); - AddCodeSegLine (CS, "iny"); - AddCodeSegLine (CS, "txa"); - AddCodeSegLine (CS, "sta (sp),y"); + AddCodeLine ("sta (sp),y"); + AddCodeLine ("iny"); + AddCodeLine ("txa"); + AddCodeLine ("sta (sp),y"); } } } @@ -1129,9 +1043,9 @@ void g_putlocal (unsigned Flags, int Offs, long Val) } if (Offs) { ldyconst (Offs); - AddCodeSegLine (CS, "jsr steaxysp"); + AddCodeLine ("jsr steaxysp"); } else { - AddCodeSegLine (CS, "jsr steax0sp"); + AddCodeLine ("jsr steax0sp"); } break; @@ -1156,17 +1070,17 @@ void g_putind (unsigned Flags, unsigned Offs) if ((Offs & 0xFF) > 256 - sizeofarg (Flags | CF_FORCECHAR)) { /* Overflow - we need to add the low byte also */ - AddCodeSegLine (CS, "ldy #$00"); - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "pha"); - AddCodeSegLine (CS, "lda #$%02X", Offs & 0xFF); - AddCodeSegLine (CS, "adc (sp),y"); - AddCodeSegLine (CS, "sta (sp),y"); - AddCodeSegLine (CS, "iny"); - AddCodeSegLine (CS, "lda #$%02X", (Offs >> 8) & 0xFF); - AddCodeSegLine (CS, "adc (sp),y"); - AddCodeSegLine (CS, "sta (sp),y"); - AddCodeSegLine (CS, "pla"); + AddCodeLine ("ldy #$00"); + AddCodeLine ("clc"); + AddCodeLine ("pha"); + AddCodeLine ("lda #$%02X", Offs & 0xFF); + AddCodeLine ("adc (sp),y"); + AddCodeLine ("sta (sp),y"); + AddCodeLine ("iny"); + AddCodeLine ("lda #$%02X", (Offs >> 8) & 0xFF); + AddCodeLine ("adc (sp),y"); + AddCodeLine ("sta (sp),y"); + AddCodeLine ("pla"); /* Complete address is on stack, new offset is zero */ Offs = 0; @@ -1174,13 +1088,13 @@ void g_putind (unsigned Flags, unsigned Offs) } else if ((Offs & 0xFF00) != 0) { /* We can just add the high byte */ - AddCodeSegLine (CS, "ldy #$01"); - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "pha"); - AddCodeSegLine (CS, "lda #$%02X", (Offs >> 8) & 0xFF); - AddCodeSegLine (CS, "adc (sp),y"); - AddCodeSegLine (CS, "sta (sp),y"); - AddCodeSegLine (CS, "pla"); + AddCodeLine ("ldy #$01"); + AddCodeLine ("clc"); + AddCodeLine ("pha"); + AddCodeLine ("lda #$%02X", (Offs >> 8) & 0xFF); + AddCodeLine ("adc (sp),y"); + AddCodeLine ("sta (sp),y"); + AddCodeLine ("pla"); /* Offset is now just the low byte */ Offs &= 0x00FF; @@ -1192,27 +1106,27 @@ void g_putind (unsigned Flags, unsigned Offs) case CF_CHAR: if (Offs) { ldyconst (Offs); - AddCodeSegLine (CS, "jsr staspidx"); + AddCodeLine ("jsr staspidx"); } else { - AddCodeSegLine (CS, "jsr staspp"); + AddCodeLine ("jsr staspp"); } break; case CF_INT: if (Offs) { ldyconst (Offs); - AddCodeSegLine (CS, "jsr staxspidx"); + AddCodeLine ("jsr staxspidx"); } else { - AddCodeSegLine (CS, "jsr staxspp"); + AddCodeLine ("jsr staxspp"); } break; case CF_LONG: if (Offs) { ldyconst (Offs); - AddCodeSegLine (CS, "jsr steaxspidx"); + AddCodeLine ("jsr steaxspidx"); } else { - AddCodeSegLine (CS, "jsr steaxspp"); + AddCodeLine ("jsr steaxspp"); } break; @@ -1241,9 +1155,9 @@ void g_toslong (unsigned flags) case CF_CHAR: case CF_INT: if (flags & CF_UNSIGNED) { - AddCodeSegLine (CS, "jsr tosulong"); + AddCodeLine ("jsr tosulong"); } else { - AddCodeSegLine (CS, "jsr toslong"); + AddCodeLine ("jsr toslong"); } push (CF_INT); break; @@ -1268,7 +1182,7 @@ void g_tosint (unsigned flags) break; case CF_LONG: - AddCodeSegLine (CS, "jsr tosint"); + AddCodeLine ("jsr tosint"); pop (CF_INT); break; @@ -1289,13 +1203,13 @@ void g_reglong (unsigned flags) if (flags & CF_UNSIGNED) { if (CodeSizeFactor >= 200) { ldyconst (0); - AddCodeSegLine (CS, "sty sreg"); - AddCodeSegLine (CS, "sty sreg+1"); + AddCodeLine ("sty sreg"); + AddCodeLine ("sty sreg+1"); } else { - AddCodeSegLine (CS, "jsr axulong"); + AddCodeLine ("jsr axulong"); } } else { - AddCodeSegLine (CS, "jsr axlong"); + AddCodeLine ("jsr axlong"); } break; @@ -1416,7 +1330,7 @@ void g_scale (unsigned flags, long val) case CF_CHAR: if (flags & CF_FORCECHAR) { while (p2--) { - AddCodeSegLine (CS, "asl a"); + AddCodeLine ("asl a"); } break; } @@ -1424,26 +1338,26 @@ void g_scale (unsigned flags, long val) case CF_INT: if (CodeSizeFactor >= (p2+1)*130U) { - AddCodeSegLine (CS, "stx tmp1"); + AddCodeLine ("stx tmp1"); while (p2--) { - AddCodeSegLine (CS, "asl a"); - AddCodeSegLine (CS, "rol tmp1"); + AddCodeLine ("asl a"); + AddCodeLine ("rol tmp1"); } - AddCodeSegLine (CS, "ldx tmp1"); + AddCodeLine ("ldx tmp1"); } else { if (flags & CF_UNSIGNED) { - AddCodeSegLine (CS, "jsr shlax%d", p2); + AddCodeLine ("jsr shlax%d", p2); } else { - AddCodeSegLine (CS, "jsr aslax%d", p2); + AddCodeLine ("jsr aslax%d", p2); } } break; case CF_LONG: if (flags & CF_UNSIGNED) { - AddCodeSegLine (CS, "jsr shleax%d", p2); + AddCodeLine ("jsr shleax%d", p2); } else { - AddCodeSegLine (CS, "jsr asleax%d", p2); + AddCodeLine ("jsr asleax%d", p2); } break; @@ -1472,12 +1386,12 @@ void g_scale (unsigned flags, long val) if (flags & CF_FORCECHAR) { if (flags & CF_UNSIGNED) { while (p2--) { - AddCodeSegLine (CS, "lsr a"); + AddCodeLine ("lsr a"); } break; } else if (p2 <= 2) { - AddCodeSegLine (CS, "cmp #$80"); - AddCodeSegLine (CS, "ror a"); + AddCodeLine ("cmp #$80"); + AddCodeLine ("ror a"); break; } } @@ -1486,35 +1400,35 @@ void g_scale (unsigned flags, long val) case CF_INT: if (flags & CF_UNSIGNED) { if (CodeSizeFactor >= (p2+1)*130U) { - AddCodeSegLine (CS, "stx tmp1"); + AddCodeLine ("stx tmp1"); while (p2--) { - AddCodeSegLine (CS, "lsr tmp1"); - AddCodeSegLine (CS, "ror a"); + AddCodeLine ("lsr tmp1"); + AddCodeLine ("ror a"); } - AddCodeSegLine (CS, "ldx tmp1"); + AddCodeLine ("ldx tmp1"); } else { - AddCodeSegLine (CS, "jsr lsrax%d", p2); + AddCodeLine ("jsr lsrax%d", p2); } } else { if (CodeSizeFactor >= (p2+1)*150U) { - AddCodeSegLine (CS, "stx tmp1"); + AddCodeLine ("stx tmp1"); while (p2--) { - AddCodeSegLine (CS, "cpx #$80"); - AddCodeSegLine (CS, "ror tmp1"); - AddCodeSegLine (CS, "ror a"); + AddCodeLine ("cpx #$80"); + AddCodeLine ("ror tmp1"); + AddCodeLine ("ror a"); } - AddCodeSegLine (CS, "ldx tmp1"); + AddCodeLine ("ldx tmp1"); } else { - AddCodeSegLine (CS, "jsr asrax%d", p2); + AddCodeLine ("jsr asrax%d", p2); } } break; case CF_LONG: if (flags & CF_UNSIGNED) { - AddCodeSegLine (CS, "jsr lsreax%d", p2); + AddCodeLine ("jsr lsreax%d", p2); } else { - AddCodeSegLine (CS, "jsr asreax%d", p2); + AddCodeLine ("jsr asreax%d", p2); } break; @@ -1550,24 +1464,24 @@ void g_addlocal (unsigned flags, int offs) switch (flags & CF_TYPE) { case CF_CHAR: - AddCodeSegLine (CS, "ldy #$%02X", offs & 0xFF); - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc (sp),y"); - AddCodeSegLine (CS, "bcc *+3"); - AddCodeSegLine (CS, "inx"); + AddCodeLine ("ldy #$%02X", offs & 0xFF); + AddCodeLine ("clc"); + AddCodeLine ("adc (sp),y"); + AddCodeLine ("bcc *+3"); + AddCodeLine ("inx"); AddCodeHint ("x:!"); break; case CF_INT: - AddCodeSegLine (CS, "ldy #$%02X", offs & 0xFF); - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc (sp),y"); - AddCodeSegLine (CS, "pha"); - AddCodeSegLine (CS, "txa"); - AddCodeSegLine (CS, "iny"); - AddCodeSegLine (CS, "adc (sp),y"); - AddCodeSegLine (CS, "tax"); - AddCodeSegLine (CS, "pla"); + AddCodeLine ("ldy #$%02X", offs & 0xFF); + AddCodeLine ("clc"); + AddCodeLine ("adc (sp),y"); + AddCodeLine ("pha"); + AddCodeLine ("txa"); + AddCodeLine ("iny"); + AddCodeLine ("adc (sp),y"); + AddCodeLine ("tax"); + AddCodeLine ("pla"); break; case CF_LONG: @@ -1594,21 +1508,21 @@ void g_addstatic (unsigned flags, unsigned long label, unsigned offs) switch (flags & CF_TYPE) { case CF_CHAR: - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc %s", lbuf); - AddCodeSegLine (CS, "bcc *+3"); - AddCodeSegLine (CS, "inx"); + AddCodeLine ("clc"); + AddCodeLine ("adc %s", lbuf); + AddCodeLine ("bcc *+3"); + AddCodeLine ("inx"); AddCodeHint ("x:!"); break; case CF_INT: - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc %s", lbuf); - AddCodeSegLine (CS, "tay"); - AddCodeSegLine (CS, "txa"); - AddCodeSegLine (CS, "adc %s+1", lbuf); - AddCodeSegLine (CS, "tax"); - AddCodeSegLine (CS, "tya"); + AddCodeLine ("clc"); + AddCodeLine ("adc %s", lbuf); + AddCodeLine ("tay"); + AddCodeLine ("txa"); + AddCodeLine ("adc %s+1", lbuf); + AddCodeLine ("tax"); + AddCodeLine ("tya"); break; case CF_LONG: @@ -1666,25 +1580,25 @@ void g_addeqstatic (unsigned flags, unsigned long label, unsigned offs, case CF_CHAR: if (flags & CF_FORCECHAR) { - AddCodeSegLine (CS, "ldx #$00"); + AddCodeLine ("ldx #$00"); if (flags & CF_CONST) { if (val == 1) { - AddCodeSegLine (CS, "inc %s", lbuf); - AddCodeSegLine (CS, "lda %s", lbuf); + AddCodeLine ("inc %s", lbuf); + AddCodeLine ("lda %s", lbuf); } else { - AddCodeSegLine (CS, "lda #$%02X", (int)(val & 0xFF)); - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc %s", lbuf); - AddCodeSegLine (CS, "sta %s", lbuf); + AddCodeLine ("lda #$%02X", (int)(val & 0xFF)); + AddCodeLine ("clc"); + AddCodeLine ("adc %s", lbuf); + AddCodeLine ("sta %s", lbuf); } } else { - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc %s", lbuf); - AddCodeSegLine (CS, "sta %s", lbuf); + AddCodeLine ("clc"); + AddCodeLine ("adc %s", lbuf); + AddCodeLine ("sta %s", lbuf); } if ((flags & CF_UNSIGNED) == 0) { - AddCodeSegLine (CS, "bpl *+3"); - AddCodeSegLine (CS, "dex"); + AddCodeLine ("bpl *+3"); + AddCodeLine ("dex"); AddCodeHint ("x:!"); /* Invalidate X */ } break; @@ -1695,54 +1609,54 @@ void g_addeqstatic (unsigned flags, unsigned long label, unsigned offs, if (flags & CF_CONST) { if (val == 1) { unsigned L = GetLocalLabel (); - AddCodeSegLine (CS, "inc %s", lbuf); - AddCodeSegLine (CS, "bne %s", LocalLabelName (L)); - AddCodeSegLine (CS, "inc %s+1", lbuf); + AddCodeLine ("inc %s", lbuf); + AddCodeLine ("bne %s", LocalLabelName (L)); + AddCodeLine ("inc %s+1", lbuf); g_defcodelabel (L); - AddCodeSegLine (CS, "lda %s", lbuf); /* Hmmm... */ - AddCodeSegLine (CS, "ldx %s+1", lbuf); + AddCodeLine ("lda %s", lbuf); /* Hmmm... */ + AddCodeLine ("ldx %s+1", lbuf); } else { - AddCodeSegLine (CS, "lda #$%02X", (int)(val & 0xFF)); - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc %s", lbuf); - AddCodeSegLine (CS, "sta %s", lbuf); + AddCodeLine ("lda #$%02X", (int)(val & 0xFF)); + AddCodeLine ("clc"); + AddCodeLine ("adc %s", lbuf); + AddCodeLine ("sta %s", lbuf); if (val < 0x100) { unsigned L = GetLocalLabel (); - AddCodeSegLine (CS, "bcc %s", LocalLabelName (L)); - AddCodeSegLine (CS, "inc %s+1", lbuf); + AddCodeLine ("bcc %s", LocalLabelName (L)); + AddCodeLine ("inc %s+1", lbuf); g_defcodelabel (L); - AddCodeSegLine (CS, "ldx %s+1", lbuf); + AddCodeLine ("ldx %s+1", lbuf); } else { - AddCodeSegLine (CS, "lda #$%02X", (unsigned char)(val >> 8)); - AddCodeSegLine (CS, "adc %s+1", lbuf); - AddCodeSegLine (CS, "sta %s+1", lbuf); - AddCodeSegLine (CS, "tax"); - AddCodeSegLine (CS, "lda %s", lbuf); + AddCodeLine ("lda #$%02X", (unsigned char)(val >> 8)); + AddCodeLine ("adc %s+1", lbuf); + AddCodeLine ("sta %s+1", lbuf); + AddCodeLine ("tax"); + AddCodeLine ("lda %s", lbuf); } } } else { - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc %s", lbuf); - AddCodeSegLine (CS, "sta %s", lbuf); - AddCodeSegLine (CS, "txa"); - AddCodeSegLine (CS, "adc %s+1", lbuf); - AddCodeSegLine (CS, "sta %s+1", lbuf); - AddCodeSegLine (CS, "tax"); - AddCodeSegLine (CS, "lda %s", lbuf); + AddCodeLine ("clc"); + AddCodeLine ("adc %s", lbuf); + AddCodeLine ("sta %s", lbuf); + AddCodeLine ("txa"); + AddCodeLine ("adc %s+1", lbuf); + AddCodeLine ("sta %s+1", lbuf); + AddCodeLine ("tax"); + AddCodeLine ("lda %s", lbuf); } break; case CF_LONG: if (flags & CF_CONST) { if (val < 0x100) { - AddCodeSegLine (CS, "ldy #<(%s)", lbuf); - AddCodeSegLine (CS, "sty ptr1"); - AddCodeSegLine (CS, "ldy #>(%s+1)", lbuf); + AddCodeLine ("ldy #<(%s)", lbuf); + AddCodeLine ("sty ptr1"); + AddCodeLine ("ldy #>(%s+1)", lbuf); if (val == 1) { - AddCodeSegLine (CS, "jsr laddeq1"); + AddCodeLine ("jsr laddeq1"); } else { - AddCodeSegLine (CS, "lda #$%02X", (int)(val & 0xFF)); - AddCodeSegLine (CS, "jsr laddeqa"); + AddCodeLine ("lda #$%02X", (int)(val & 0xFF)); + AddCodeLine ("jsr laddeqa"); } } else { g_getstatic (flags, label, offs); @@ -1750,10 +1664,10 @@ void g_addeqstatic (unsigned flags, unsigned long label, unsigned offs, g_putstatic (flags, label, offs); } } else { - AddCodeSegLine (CS, "ldy #<(%s)", lbuf); - AddCodeSegLine (CS, "sty ptr1"); - AddCodeSegLine (CS, "ldy #>(%s+1)", lbuf); - AddCodeSegLine (CS, "jsr laddeq"); + AddCodeLine ("ldy #<(%s)", lbuf); + AddCodeLine ("sty ptr1"); + AddCodeLine ("ldy #>(%s+1)", lbuf); + AddCodeLine ("jsr laddeq"); } break; @@ -1777,34 +1691,34 @@ void g_addeqlocal (unsigned flags, int offs, unsigned long val) case CF_CHAR: if (flags & CF_FORCECHAR) { if (offs == 0) { - AddCodeSegLine (CS, "ldx #$00"); + AddCodeLine ("ldx #$00"); if (flags & CF_CONST) { - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "lda #$%02X", (int)(val & 0xFF)); - AddCodeSegLine (CS, "adc (sp,x)"); - AddCodeSegLine (CS, "sta (sp,x)"); + AddCodeLine ("clc"); + AddCodeLine ("lda #$%02X", (int)(val & 0xFF)); + AddCodeLine ("adc (sp,x)"); + AddCodeLine ("sta (sp,x)"); } else { - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc (sp,x)"); - AddCodeSegLine (CS, "sta (sp,x)"); + AddCodeLine ("clc"); + AddCodeLine ("adc (sp,x)"); + AddCodeLine ("sta (sp,x)"); } } else { ldyconst (offs); - AddCodeSegLine (CS, "ldx #$00"); + AddCodeLine ("ldx #$00"); if (flags & CF_CONST) { - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "lda #$%02X", (int)(val & 0xFF)); - AddCodeSegLine (CS, "adc (sp),y"); - AddCodeSegLine (CS, "sta (sp),y"); + AddCodeLine ("clc"); + AddCodeLine ("lda #$%02X", (int)(val & 0xFF)); + AddCodeLine ("adc (sp),y"); + AddCodeLine ("sta (sp),y"); } else { - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc (sp),y"); - AddCodeSegLine (CS, "sta (sp),y"); + AddCodeLine ("clc"); + AddCodeLine ("adc (sp),y"); + AddCodeLine ("sta (sp),y"); } } if ((flags & CF_UNSIGNED) == 0) { - AddCodeSegLine (CS, "bpl *+3"); - AddCodeSegLine (CS, "dex"); + AddCodeLine ("bpl *+3"); + AddCodeLine ("dex"); AddCodeHint ("x:!"); /* Invalidate X */ } break; @@ -1816,10 +1730,10 @@ void g_addeqlocal (unsigned flags, int offs, unsigned long val) g_getimmed (flags, val, 0); } if (offs == 0) { - AddCodeSegLine (CS, "jsr addeq0sp"); + AddCodeLine ("jsr addeq0sp"); } else { ldyconst (offs); - AddCodeSegLine (CS, "jsr addeqysp"); + AddCodeLine ("jsr addeqysp"); } break; @@ -1828,10 +1742,10 @@ void g_addeqlocal (unsigned flags, int offs, unsigned long val) g_getimmed (flags, val, 0); } if (offs == 0) { - AddCodeSegLine (CS, "jsr laddeq0sp"); + AddCodeLine ("jsr laddeq0sp"); } else { ldyconst (offs); - AddCodeSegLine (CS, "jsr laddeqysp"); + AddCodeLine ("jsr laddeqysp"); } break; @@ -1855,47 +1769,47 @@ void g_addeqind (unsigned flags, unsigned offs, unsigned long val) switch (flags & CF_TYPE) { case CF_CHAR: - AddCodeSegLine (CS, "sta ptr1"); - AddCodeSegLine (CS, "stx ptr1+1"); + AddCodeLine ("sta ptr1"); + AddCodeLine ("stx ptr1+1"); if (offs == 0) { - AddCodeSegLine (CS, "ldx #$00"); - AddCodeSegLine (CS, "lda #$%02X", (int)(val & 0xFF)); - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc (ptr1,x)"); - AddCodeSegLine (CS, "sta (ptr1,x)"); + AddCodeLine ("ldx #$00"); + AddCodeLine ("lda #$%02X", (int)(val & 0xFF)); + AddCodeLine ("clc"); + AddCodeLine ("adc (ptr1,x)"); + AddCodeLine ("sta (ptr1,x)"); } else { - AddCodeSegLine (CS, "ldy #$%02X", offs); - AddCodeSegLine (CS, "ldx #$00"); - AddCodeSegLine (CS, "lda #$%02X", (int)(val & 0xFF)); - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc (ptr1),y"); - AddCodeSegLine (CS, "sta (ptr1),y"); + AddCodeLine ("ldy #$%02X", offs); + AddCodeLine ("ldx #$00"); + AddCodeLine ("lda #$%02X", (int)(val & 0xFF)); + AddCodeLine ("clc"); + AddCodeLine ("adc (ptr1),y"); + AddCodeLine ("sta (ptr1),y"); } break; case CF_INT: if (CodeSizeFactor >= 200) { /* Lots of code, use only if size is not important */ - AddCodeSegLine (CS, "sta ptr1"); - AddCodeSegLine (CS, "stx ptr1+1"); - AddCodeSegLine (CS, "ldy #$%02X", offs); - AddCodeSegLine (CS, "lda #$%02X", (int)(val & 0xFF)); - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc (ptr1),y"); - AddCodeSegLine (CS, "sta (ptr1),y"); - AddCodeSegLine (CS, "pha"); - AddCodeSegLine (CS, "iny"); - AddCodeSegLine (CS, "lda #$%02X", (unsigned char)(val >> 8)); - AddCodeSegLine (CS, "adc (ptr1),y"); - AddCodeSegLine (CS, "sta (ptr1),y"); - AddCodeSegLine (CS, "tax"); - AddCodeSegLine (CS, "pla"); + AddCodeLine ("sta ptr1"); + AddCodeLine ("stx ptr1+1"); + AddCodeLine ("ldy #$%02X", offs); + AddCodeLine ("lda #$%02X", (int)(val & 0xFF)); + AddCodeLine ("clc"); + AddCodeLine ("adc (ptr1),y"); + AddCodeLine ("sta (ptr1),y"); + AddCodeLine ("pha"); + AddCodeLine ("iny"); + AddCodeLine ("lda #$%02X", (unsigned char)(val >> 8)); + AddCodeLine ("adc (ptr1),y"); + AddCodeLine ("sta (ptr1),y"); + AddCodeLine ("tax"); + AddCodeLine ("pla"); break; } /* FALL THROUGH */ case CF_LONG: - AddCodeSegLine (CS, "jsr pushax"); /* Push the address */ + AddCodeLine ("jsr pushax"); /* Push the address */ push (flags); /* Correct the internal sp */ g_getind (flags, offs); /* Fetch the value */ g_inc (flags, val); /* Increment value in primary */ @@ -1921,27 +1835,27 @@ void g_subeqstatic (unsigned flags, unsigned long label, unsigned offs, case CF_CHAR: if (flags & CF_FORCECHAR) { - AddCodeSegLine (CS, "ldx #$00"); + AddCodeLine ("ldx #$00"); if (flags & CF_CONST) { if (val == 1) { - AddCodeSegLine (CS, "dec %s", lbuf); - AddCodeSegLine (CS, "lda %s", lbuf); + AddCodeLine ("dec %s", lbuf); + AddCodeLine ("lda %s", lbuf); } else { - AddCodeSegLine (CS, "sec"); - AddCodeSegLine (CS, "lda %s", lbuf); - AddCodeSegLine (CS, "sbc #$%02X", (int)(val & 0xFF)); - AddCodeSegLine (CS, "sta %s", lbuf); + AddCodeLine ("sec"); + AddCodeLine ("lda %s", lbuf); + AddCodeLine ("sbc #$%02X", (int)(val & 0xFF)); + AddCodeLine ("sta %s", lbuf); } } else { - AddCodeSegLine (CS, "sec"); - AddCodeSegLine (CS, "sta tmp1"); - AddCodeSegLine (CS, "lda %s", lbuf); - AddCodeSegLine (CS, "sbc tmp1"); - AddCodeSegLine (CS, "sta %s", lbuf); + AddCodeLine ("sec"); + AddCodeLine ("sta tmp1"); + AddCodeLine ("lda %s", lbuf); + AddCodeLine ("sbc tmp1"); + AddCodeLine ("sta %s", lbuf); } if ((flags & CF_UNSIGNED) == 0) { - AddCodeSegLine (CS, "bpl *+3"); - AddCodeSegLine (CS, "dex"); + AddCodeLine ("bpl *+3"); + AddCodeLine ("dex"); AddCodeHint ("x:!"); /* Invalidate X */ } break; @@ -1949,49 +1863,49 @@ void g_subeqstatic (unsigned flags, unsigned long label, unsigned offs, /* FALLTHROUGH */ case CF_INT: - AddCodeSegLine (CS, "sec"); + AddCodeLine ("sec"); if (flags & CF_CONST) { - AddCodeSegLine (CS, "lda %s", lbuf); - AddCodeSegLine (CS, "sbc #$%02X", (unsigned char)val); - AddCodeSegLine (CS, "sta %s", lbuf); + AddCodeLine ("lda %s", lbuf); + AddCodeLine ("sbc #$%02X", (unsigned char)val); + AddCodeLine ("sta %s", lbuf); if (val < 0x100) { unsigned L = GetLocalLabel (); - AddCodeSegLine (CS, "bcs %s", LocalLabelName (L)); - AddCodeSegLine (CS, "dec %s+1", lbuf); + AddCodeLine ("bcs %s", LocalLabelName (L)); + AddCodeLine ("dec %s+1", lbuf); g_defcodelabel (L); - AddCodeSegLine (CS, "ldx %s+1", lbuf); + AddCodeLine ("ldx %s+1", lbuf); } else { - AddCodeSegLine (CS, "lda %s+1", lbuf); - AddCodeSegLine (CS, "sbc #$%02X", (unsigned char)(val >> 8)); - AddCodeSegLine (CS, "sta %s+1", lbuf); - AddCodeSegLine (CS, "tax"); - AddCodeSegLine (CS, "lda %s", lbuf); + AddCodeLine ("lda %s+1", lbuf); + AddCodeLine ("sbc #$%02X", (unsigned char)(val >> 8)); + AddCodeLine ("sta %s+1", lbuf); + AddCodeLine ("tax"); + AddCodeLine ("lda %s", lbuf); } } else { - AddCodeSegLine (CS, "sta tmp1"); - AddCodeSegLine (CS, "lda %s", lbuf); - AddCodeSegLine (CS, "sbc tmp1"); - AddCodeSegLine (CS, "sta %s", lbuf); - AddCodeSegLine (CS, "stx tmp1"); - AddCodeSegLine (CS, "lda %s+1", lbuf); - AddCodeSegLine (CS, "sbc tmp1"); - AddCodeSegLine (CS, "sta %s+1", lbuf); - AddCodeSegLine (CS, "tax"); - AddCodeSegLine (CS, "lda %s", lbuf); + AddCodeLine ("sta tmp1"); + AddCodeLine ("lda %s", lbuf); + AddCodeLine ("sbc tmp1"); + AddCodeLine ("sta %s", lbuf); + AddCodeLine ("stx tmp1"); + AddCodeLine ("lda %s+1", lbuf); + AddCodeLine ("sbc tmp1"); + AddCodeLine ("sta %s+1", lbuf); + AddCodeLine ("tax"); + AddCodeLine ("lda %s", lbuf); } break; case CF_LONG: if (flags & CF_CONST) { if (val < 0x100) { - AddCodeSegLine (CS, "ldy #<(%s)", lbuf); - AddCodeSegLine (CS, "sty ptr1"); - AddCodeSegLine (CS, "ldy #>(%s+1)", lbuf); + AddCodeLine ("ldy #<(%s)", lbuf); + AddCodeLine ("sty ptr1"); + AddCodeLine ("ldy #>(%s+1)", lbuf); if (val == 1) { - AddCodeSegLine (CS, "jsr lsubeq1"); + AddCodeLine ("jsr lsubeq1"); } else { - AddCodeSegLine (CS, "lda #$%02X", (unsigned char)val); - AddCodeSegLine (CS, "jsr lsubeqa"); + AddCodeLine ("lda #$%02X", (unsigned char)val); + AddCodeLine ("jsr lsubeqa"); } } else { g_getstatic (flags, label, offs); @@ -1999,10 +1913,10 @@ void g_subeqstatic (unsigned flags, unsigned long label, unsigned offs, g_putstatic (flags, label, offs); } } else { - AddCodeSegLine (CS, "ldy #<(%s)", lbuf); - AddCodeSegLine (CS, "sty ptr1"); - AddCodeSegLine (CS, "ldy #>(%s+1)", lbuf); - AddCodeSegLine (CS, "jsr lsubeq"); + AddCodeLine ("ldy #<(%s)", lbuf); + AddCodeLine ("sty ptr1"); + AddCodeLine ("ldy #>(%s+1)", lbuf); + AddCodeLine ("jsr lsubeq"); } break; @@ -2026,20 +1940,20 @@ void g_subeqlocal (unsigned flags, int offs, unsigned long val) case CF_CHAR: if (flags & CF_FORCECHAR) { ldyconst (offs); - AddCodeSegLine (CS, "ldx #$00"); - AddCodeSegLine (CS, "sec"); + AddCodeLine ("ldx #$00"); + AddCodeLine ("sec"); if (flags & CF_CONST) { - AddCodeSegLine (CS, "lda (sp),y"); - AddCodeSegLine (CS, "sbc #$%02X", (unsigned char)val); + AddCodeLine ("lda (sp),y"); + AddCodeLine ("sbc #$%02X", (unsigned char)val); } else { - AddCodeSegLine (CS, "sta tmp1"); - AddCodeSegLine (CS, "lda (sp),y"); - AddCodeSegLine (CS, "sbc tmp1"); + AddCodeLine ("sta tmp1"); + AddCodeLine ("lda (sp),y"); + AddCodeLine ("sbc tmp1"); } - AddCodeSegLine (CS, "sta (sp),y"); + AddCodeLine ("sta (sp),y"); if ((flags & CF_UNSIGNED) == 0) { - AddCodeSegLine (CS, "bpl *+3"); - AddCodeSegLine (CS, "dex"); + AddCodeLine ("bpl *+3"); + AddCodeLine ("dex"); AddCodeHint ("x:!"); /* Invalidate X */ } break; @@ -2051,10 +1965,10 @@ void g_subeqlocal (unsigned flags, int offs, unsigned long val) g_getimmed (flags, val, 0); } if (offs == 0) { - AddCodeSegLine (CS, "jsr subeq0sp"); + AddCodeLine ("jsr subeq0sp"); } else { ldyconst (offs); - AddCodeSegLine (CS, "jsr subeqysp"); + AddCodeLine ("jsr subeqysp"); } break; @@ -2063,10 +1977,10 @@ void g_subeqlocal (unsigned flags, int offs, unsigned long val) g_getimmed (flags, val, 0); } if (offs == 0) { - AddCodeSegLine (CS, "jsr lsubeq0sp"); + AddCodeLine ("jsr lsubeq0sp"); } else { ldyconst (offs); - AddCodeSegLine (CS, "jsr lsubeqysp"); + AddCodeLine ("jsr lsubeqysp"); } break; @@ -2090,47 +2004,47 @@ void g_subeqind (unsigned flags, unsigned offs, unsigned long val) switch (flags & CF_TYPE) { case CF_CHAR: - AddCodeSegLine (CS, "sta ptr1"); - AddCodeSegLine (CS, "stx ptr1+1"); + AddCodeLine ("sta ptr1"); + AddCodeLine ("stx ptr1+1"); if (offs == 0) { - AddCodeSegLine (CS, "ldx #$00"); - AddCodeSegLine (CS, "lda (ptr1,x)"); - AddCodeSegLine (CS, "sec"); - AddCodeSegLine (CS, "sbc #$%02X", (unsigned char)val); - AddCodeSegLine (CS, "sta (ptr1,x)"); + AddCodeLine ("ldx #$00"); + AddCodeLine ("lda (ptr1,x)"); + AddCodeLine ("sec"); + AddCodeLine ("sbc #$%02X", (unsigned char)val); + AddCodeLine ("sta (ptr1,x)"); } else { - AddCodeSegLine (CS, "ldy #$%02X", offs); - AddCodeSegLine (CS, "ldx #$00"); - AddCodeSegLine (CS, "lda (ptr1),y"); - AddCodeSegLine (CS, "sec"); - AddCodeSegLine (CS, "sbc #$%02X", (unsigned char)val); - AddCodeSegLine (CS, "sta (ptr1),y"); + AddCodeLine ("ldy #$%02X", offs); + AddCodeLine ("ldx #$00"); + AddCodeLine ("lda (ptr1),y"); + AddCodeLine ("sec"); + AddCodeLine ("sbc #$%02X", (unsigned char)val); + AddCodeLine ("sta (ptr1),y"); } break; case CF_INT: if (CodeSizeFactor >= 200) { /* Lots of code, use only if size is not important */ - AddCodeSegLine (CS, "sta ptr1"); - AddCodeSegLine (CS, "stx ptr1+1"); - AddCodeSegLine (CS, "ldy #$%02X", offs); - AddCodeSegLine (CS, "lda (ptr1),y"); - AddCodeSegLine (CS, "sec"); - AddCodeSegLine (CS, "sbc #$%02X", (unsigned char)val); - AddCodeSegLine (CS, "sta (ptr1),y"); - AddCodeSegLine (CS, "pha"); - AddCodeSegLine (CS, "iny"); - AddCodeSegLine (CS, "lda (ptr1),y"); - AddCodeSegLine (CS, "sbc #$%02X", (unsigned char)(val >> 8)); - AddCodeSegLine (CS, "sta (ptr1),y"); - AddCodeSegLine (CS, "tax"); - AddCodeSegLine (CS, "pla"); + AddCodeLine ("sta ptr1"); + AddCodeLine ("stx ptr1+1"); + AddCodeLine ("ldy #$%02X", offs); + AddCodeLine ("lda (ptr1),y"); + AddCodeLine ("sec"); + AddCodeLine ("sbc #$%02X", (unsigned char)val); + AddCodeLine ("sta (ptr1),y"); + AddCodeLine ("pha"); + AddCodeLine ("iny"); + AddCodeLine ("lda (ptr1),y"); + AddCodeLine ("sbc #$%02X", (unsigned char)(val >> 8)); + AddCodeLine ("sta (ptr1),y"); + AddCodeLine ("tax"); + AddCodeLine ("pla"); break; } /* FALL THROUGH */ case CF_LONG: - AddCodeSegLine (CS, "jsr pushax"); /* Push the address */ + AddCodeLine ("jsr pushax"); /* Push the address */ push (flags); /* Correct the internal sp */ g_getind (flags, offs); /* Fetch the value */ g_dec (flags, val); /* Increment value in primary */ @@ -2158,21 +2072,21 @@ void g_addaddr_local (unsigned flags, int offs) if (offs != 0) { /* We cannot address more then 256 bytes of locals anyway */ CheckLocalOffs (offs); - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc #$%02X", offs & 0xFF); - AddCodeSegLine (CS, "bcc *+4"); /* Do also skip the CLC insn below */ - AddCodeSegLine (CS, "inx"); + AddCodeLine ("clc"); + AddCodeLine ("adc #$%02X", offs & 0xFF); + AddCodeLine ("bcc *+4"); /* Do also skip the CLC insn below */ + AddCodeLine ("inx"); AddCodeHint ("x:!"); /* Invalidate X */ } /* Add the current stackpointer value */ - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc sp"); - AddCodeSegLine (CS, "tay"); - AddCodeSegLine (CS, "txa"); - AddCodeSegLine (CS, "adc sp+1"); - AddCodeSegLine (CS, "tax"); - AddCodeSegLine (CS, "tya"); + AddCodeLine ("clc"); + AddCodeLine ("adc sp"); + AddCodeLine ("tay"); + AddCodeLine ("txa"); + AddCodeLine ("adc sp+1"); + AddCodeLine ("tax"); + AddCodeLine ("tya"); } @@ -2184,13 +2098,13 @@ void g_addaddr_static (unsigned flags, unsigned long label, unsigned offs) char* lbuf = GetLabelName (flags, label, offs); /* Add the address to the current ax value */ - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc #<(%s)", lbuf); - AddCodeSegLine (CS, "tay"); - AddCodeSegLine (CS, "txa"); - AddCodeSegLine (CS, "adc #>(%s)", lbuf); - AddCodeSegLine (CS, "tax"); - AddCodeSegLine (CS, "tya"); + AddCodeLine ("clc"); + AddCodeLine ("adc #<(%s)", lbuf); + AddCodeLine ("tay"); + AddCodeLine ("txa"); + AddCodeLine ("adc #>(%s)", lbuf); + AddCodeLine ("tax"); + AddCodeLine ("tya"); } @@ -2209,18 +2123,18 @@ void g_save (unsigned flags) case CF_CHAR: if (flags & CF_FORCECHAR) { - AddCodeSegLine (CS, "pha"); + AddCodeLine ("pha"); break; } /* FALLTHROUGH */ case CF_INT: - AddCodeSegLine (CS, "sta regsave"); - AddCodeSegLine (CS, "stx regsave+1"); + AddCodeLine ("sta regsave"); + AddCodeLine ("stx regsave+1"); break; case CF_LONG: - AddCodeSegLine (CS, "jsr saveeax"); + AddCodeLine ("jsr saveeax"); break; default: @@ -2238,18 +2152,18 @@ void g_restore (unsigned flags) case CF_CHAR: if (flags & CF_FORCECHAR) { - AddCodeSegLine (CS, "pla"); + AddCodeLine ("pla"); break; } /* FALLTHROUGH */ case CF_INT: - AddCodeSegLine (CS, "lda regsave"); - AddCodeSegLine (CS, "ldx regsave+1"); + AddCodeLine ("lda regsave"); + AddCodeLine ("ldx regsave+1"); break; case CF_LONG: - AddCodeSegLine (CS, "jsr resteax"); + AddCodeLine ("jsr resteax"); break; default: @@ -2269,15 +2183,15 @@ void g_cmp (unsigned flags, unsigned long val) case CF_CHAR: if (flags & CF_FORCECHAR) { - AddCodeSegLine (CS, "cmp #$%02X", (unsigned char)val); + AddCodeLine ("cmp #$%02X", (unsigned char)val); break; } /* FALLTHROUGH */ case CF_INT: - AddCodeSegLine (CS, "cmp #$%02X", (unsigned char)val); - AddCodeSegLine (CS, "bne *+4"); - AddCodeSegLine (CS, "cpx #$%02X", (unsigned char)(val >> 8)); + AddCodeLine ("cmp #$%02X", (unsigned char)val); + AddCodeLine ("bne *+4"); + AddCodeLine ("cpx #$%02X", (unsigned char)(val >> 8)); break; case CF_LONG: @@ -2326,19 +2240,19 @@ static void oper (unsigned flags, unsigned long val, char** subs) /* Constant value given */ if (val == 0 && subs [offs+0]) { /* Special case: constant with value zero */ - AddCodeSegLine (CS, "jsr %s", subs [offs+0]); + AddCodeLine ("jsr %s", subs [offs+0]); } else if (val < 0x100 && subs [offs+1]) { /* Special case: constant with high byte zero */ ldaconst (val); /* Load low byte */ - AddCodeSegLine (CS, "jsr %s", subs [offs+1]); + AddCodeLine ("jsr %s", subs [offs+1]); } else { /* Others: arbitrary constant value */ g_getimmed (flags, val, 0); /* Load value */ - AddCodeSegLine (CS, "jsr %s", subs [offs+2]); + AddCodeLine ("jsr %s", subs [offs+2]); } } else { /* Value not constant (is already in (e)ax) */ - AddCodeSegLine (CS, "jsr %s", subs [offs+2]); + AddCodeLine ("jsr %s", subs [offs+2]); } /* The operation will pop it's argument */ @@ -2354,21 +2268,21 @@ void g_test (unsigned flags) case CF_CHAR: if (flags & CF_FORCECHAR) { - AddCodeSegLine (CS, "tax"); + AddCodeLine ("tax"); break; } /* FALLTHROUGH */ case CF_INT: - AddCodeSegLine (CS, "stx tmp1"); - AddCodeSegLine (CS, "ora tmp1"); + AddCodeLine ("stx tmp1"); + AddCodeLine ("ora tmp1"); break; case CF_LONG: if (flags & CF_UNSIGNED) { - AddCodeSegLine (CS, "jsr utsteax"); + AddCodeLine ("jsr utsteax"); } else { - AddCodeSegLine (CS, "jsr tsteax"); + AddCodeLine ("jsr tsteax"); } break; @@ -2393,9 +2307,9 @@ void g_push (unsigned flags, unsigned long val) /* Handle as 8 bit value */ if (CodeSizeFactor >= 165 || val > 2) { ldaconst (val); - AddCodeSegLine (CS, "jsr pusha"); + AddCodeLine ("jsr pusha"); } else { - AddCodeSegLine (CS, "jsr pushc%d", (int) val); + AddCodeLine ("jsr pushc%d", (int) val); } } else { @@ -2403,15 +2317,15 @@ void g_push (unsigned flags, unsigned long val) /* Handle as 16 bit value */ hi = (unsigned char) (val >> 8); if (val <= 7) { - AddCodeSegLine (CS, "jsr push%u", (unsigned) val); + AddCodeLine ("jsr push%u", (unsigned) val); } else if (hi == 0 || hi == 0xFF) { /* Use special function */ ldaconst (val); - AddCodeSegLine (CS, "jsr %s", (hi == 0)? "pusha0" : "pushaFF"); + AddCodeLine ("jsr %s", (hi == 0)? "pusha0" : "pushaFF"); } else { /* Long way ... */ g_getimmed (flags, val, 0); - AddCodeSegLine (CS, "jsr pushax"); + AddCodeLine ("jsr pushax"); } } @@ -2429,16 +2343,16 @@ void g_push (unsigned flags, unsigned long val) case CF_CHAR: if (flags & CF_FORCECHAR) { /* Handle as char */ - AddCodeSegLine (CS, "jsr pusha"); + AddCodeLine ("jsr pusha"); break; } /* FALL THROUGH */ case CF_INT: - AddCodeSegLine (CS, "jsr pushax"); + AddCodeLine ("jsr pushax"); break; case CF_LONG: - AddCodeSegLine (CS, "jsr pusheax"); + AddCodeLine ("jsr pusheax"); break; default: @@ -2463,11 +2377,11 @@ void g_swap (unsigned flags) case CF_CHAR: case CF_INT: - AddCodeSegLine (CS, "jsr swapstk"); + AddCodeLine ("jsr swapstk"); break; case CF_LONG: - AddCodeSegLine (CS, "jsr swapestk"); + AddCodeLine ("jsr swapestk"); break; default: @@ -2485,7 +2399,7 @@ void g_call (unsigned Flags, const char* Label, unsigned ArgSize) /* Pass the argument count */ ldyconst (ArgSize); } - AddCodeSegLine (CS, "jsr _%s", Label); + AddCodeLine ("jsr _%s", Label); oursp += ArgSize; /* callee pops args */ } @@ -2498,7 +2412,7 @@ void g_callind (unsigned Flags, unsigned ArgSize) /* Pass arg count */ ldyconst (ArgSize); } - AddCodeSegLine (CS, "jsr callax"); /* do the call */ + AddCodeLine ("jsr callax"); /* do the call */ oursp += ArgSize; /* callee pops args */ } @@ -2507,7 +2421,7 @@ void g_callind (unsigned Flags, unsigned ArgSize) void g_jump (unsigned Label) /* Jump to specified internal label number */ { - AddCodeSegLine (CS, "jmp %s", LocalLabelName (Label)); + AddCodeLine ("jmp %s", LocalLabelName (Label)); } @@ -2519,11 +2433,11 @@ void g_switch (unsigned Flags) case CF_CHAR: case CF_INT: - AddCodeSegLine (CS, "jsr switch"); + AddCodeLine ("jsr switch"); break; case CF_LONG: - AddCodeSegLine (CS, "jsr lswitch"); + AddCodeLine ("jsr lswitch"); break; default: @@ -2541,14 +2455,14 @@ void g_case (unsigned flags, unsigned label, unsigned long val) case CF_CHAR: case CF_INT: - AddCodeSegLine (CS, ".word $%04X, %s", + AddCodeLine (".word $%04X, %s", (unsigned)(val & 0xFFFF), LocalLabelName (label)); break; case CF_LONG: - AddCodeSegLine (CS, ".dword $%08lX", val); - AddCodeSegLine (CS, ".word %s", LocalLabelName (label)); + AddCodeLine (".dword $%08lX", val); + AddCodeLine (".word %s", LocalLabelName (label)); break; default: @@ -2562,7 +2476,7 @@ void g_case (unsigned flags, unsigned label, unsigned long val) void g_truejump (unsigned flags, unsigned label) /* Jump to label if zero flag clear */ { - AddCodeSegLine (CS, "jne %s", LocalLabelName (label)); + AddCodeLine ("jne %s", LocalLabelName (label)); } @@ -2570,7 +2484,7 @@ void g_truejump (unsigned flags, unsigned label) void g_falsejump (unsigned flags, unsigned label) /* Jump to label if zero flag set */ { - AddCodeSegLine (CS, "jeq %s", LocalLabelName (label)); + AddCodeLine ("jeq %s", LocalLabelName (label)); } @@ -2578,11 +2492,11 @@ void g_falsejump (unsigned flags, unsigned label) static void mod_internal (int k, char* verb1, char* verb2) { if (k <= 8) { - AddCodeSegLine (CS, "jsr %ssp%c", verb1, k + '0'); + AddCodeLine ("jsr %ssp%c", verb1, k + '0'); } else { CheckLocalOffs (k); ldyconst (k); - AddCodeSegLine (CS, "jsr %ssp", verb2); + AddCodeLine ("jsr %ssp", verb2); } } @@ -2603,7 +2517,7 @@ void g_space (int space) void g_cstackcheck (void) /* Check for a C stack overflow */ { - AddCodeSegLine (CS, "jsr cstkchk"); + AddCodeLine ("jsr cstkchk"); } @@ -2611,7 +2525,7 @@ void g_cstackcheck (void) void g_stackcheck (void) /* Check for a stack overflow */ { - AddCodeSegLine (CS, "jsr stkchk"); + AddCodeLine ("jsr stkchk"); } @@ -2700,27 +2614,27 @@ void g_mul (unsigned flags, unsigned long val) switch (val) { case 3: - AddCodeSegLine (CS, "sta tmp1"); - AddCodeSegLine (CS, "asl a"); - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc tmp1"); + AddCodeLine ("sta tmp1"); + AddCodeLine ("asl a"); + AddCodeLine ("clc"); + AddCodeLine ("adc tmp1"); return; case 5: - AddCodeSegLine (CS, "sta tmp1"); - AddCodeSegLine (CS, "asl a"); - AddCodeSegLine (CS, "asl a"); - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc tmp1"); + AddCodeLine ("sta tmp1"); + AddCodeLine ("asl a"); + AddCodeLine ("asl a"); + AddCodeLine ("clc"); + AddCodeLine ("adc tmp1"); return; case 10: - AddCodeSegLine (CS, "sta tmp1"); - AddCodeSegLine (CS, "asl a"); - AddCodeSegLine (CS, "asl a"); - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc tmp1"); - AddCodeSegLine (CS, "asl a"); + AddCodeLine ("sta tmp1"); + AddCodeLine ("asl a"); + AddCodeLine ("asl a"); + AddCodeLine ("clc"); + AddCodeLine ("adc tmp1"); + AddCodeLine ("asl a"); return; } } @@ -2826,7 +2740,7 @@ void g_or (unsigned flags, unsigned long val) case CF_CHAR: if (flags & CF_FORCECHAR) { if ((val & 0xFF) != 0xFF) { - AddCodeSegLine (CS, "ora #$%02X", (unsigned char)val); + AddCodeLine ("ora #$%02X", (unsigned char)val); } return; } @@ -2834,14 +2748,14 @@ void g_or (unsigned flags, unsigned long val) case CF_INT: if (val <= 0xFF) { - AddCodeSegLine (CS, "ora #$%02X", (unsigned char)val); + AddCodeLine ("ora #$%02X", (unsigned char)val); return; } break; case CF_LONG: if (val <= 0xFF) { - AddCodeSegLine (CS, "ora #$%02X", (unsigned char)val); + AddCodeLine ("ora #$%02X", (unsigned char)val); return; } break; @@ -2884,7 +2798,7 @@ void g_xor (unsigned flags, unsigned long val) case CF_CHAR: if (flags & CF_FORCECHAR) { if ((val & 0xFF) != 0) { - AddCodeSegLine (CS, "eor #$%02X", (unsigned char)val); + AddCodeLine ("eor #$%02X", (unsigned char)val); } return; } @@ -2893,15 +2807,15 @@ void g_xor (unsigned flags, unsigned long val) case CF_INT: if (val <= 0xFF) { if (val != 0) { - AddCodeSegLine (CS, "eor #$%02X", (unsigned char)val); + AddCodeLine ("eor #$%02X", (unsigned char)val); } return; } else if ((val & 0xFF) == 0) { - AddCodeSegLine (CS, "pha"); - AddCodeSegLine (CS, "txa"); - AddCodeSegLine (CS, "eor #$%02X", (unsigned char)(val >> 8)); - AddCodeSegLine (CS, "tax"); - AddCodeSegLine (CS, "pla"); + AddCodeLine ("pha"); + AddCodeLine ("txa"); + AddCodeLine ("eor #$%02X", (unsigned char)(val >> 8)); + AddCodeLine ("tax"); + AddCodeLine ("pla"); return; } break; @@ -2909,7 +2823,7 @@ void g_xor (unsigned flags, unsigned long val) case CF_LONG: if (val <= 0xFF) { if (val != 0) { - AddCodeSegLine (CS, "eor #$%02X", (unsigned char)val); + AddCodeLine ("eor #$%02X", (unsigned char)val); } return; } @@ -2951,7 +2865,7 @@ void g_and (unsigned flags, unsigned long val) case CF_CHAR: if (flags & CF_FORCECHAR) { - AddCodeSegLine (CS, "and #$%02X", (unsigned char)val); + AddCodeLine ("and #$%02X", (unsigned char)val); return; } /* FALLTHROUGH */ @@ -2962,23 +2876,23 @@ void g_and (unsigned flags, unsigned long val) if (val == 0) { ldaconst (0); } else if (val != 0xFF) { - AddCodeSegLine (CS, "and #$%02X", (unsigned char)val); + AddCodeLine ("and #$%02X", (unsigned char)val); } } else if ((val & 0xFF00) == 0xFF00) { - AddCodeSegLine (CS, "and #$%02X", (unsigned char)val); + AddCodeLine ("and #$%02X", (unsigned char)val); } else if ((val & 0x00FF) == 0x0000) { - AddCodeSegLine (CS, "txa"); - AddCodeSegLine (CS, "and #$%02X", (unsigned char)(val >> 8)); - AddCodeSegLine (CS, "tax"); + AddCodeLine ("txa"); + AddCodeLine ("and #$%02X", (unsigned char)(val >> 8)); + AddCodeLine ("tax"); ldaconst (0); } else { - AddCodeSegLine (CS, "tay"); - AddCodeSegLine (CS, "txa"); - AddCodeSegLine (CS, "and #$%02X", (unsigned char)(val >> 8)); - AddCodeSegLine (CS, "tax"); - AddCodeSegLine (CS, "tya"); + AddCodeLine ("tay"); + AddCodeLine ("txa"); + AddCodeLine ("and #$%02X", (unsigned char)(val >> 8)); + AddCodeLine ("tax"); + AddCodeLine ("tya"); if ((val & 0x00FF) != 0x00FF) { - AddCodeSegLine (CS, "and #$%02X", (unsigned char)val); + AddCodeLine ("and #$%02X", (unsigned char)val); } } } @@ -2987,16 +2901,16 @@ void g_and (unsigned flags, unsigned long val) case CF_LONG: if (val <= 0xFF) { ldxconst (0); - AddCodeSegLine (CS, "stx sreg+1"); - AddCodeSegLine (CS, "stx sreg"); + AddCodeLine ("stx sreg+1"); + AddCodeLine ("stx sreg"); if ((val & 0xFF) != 0xFF) { - AddCodeSegLine (CS, "and #$%02X", (unsigned char)val); + AddCodeLine ("and #$%02X", (unsigned char)val); } return; } else if (val == 0xFF00) { ldaconst (0); - AddCodeSegLine (CS, "sta sreg+1"); - AddCodeSegLine (CS, "sta sreg"); + AddCodeLine ("sta sreg+1"); + AddCodeLine ("sta sreg"); return; } break; @@ -3039,13 +2953,13 @@ void g_asr (unsigned flags, unsigned long val) case CF_INT: if (val >= 1 && val <= 3) { if (flags & CF_UNSIGNED) { - AddCodeSegLine (CS, "jsr shrax%ld", val); + AddCodeLine ("jsr shrax%ld", val); } else { - AddCodeSegLine (CS, "jsr asrax%ld", val); + AddCodeLine ("jsr asrax%ld", val); } return; } else if (val == 8 && (flags & CF_UNSIGNED)) { - AddCodeSegLine (CS, "txa"); + AddCodeLine ("txa"); ldxconst (0); return; } @@ -3054,30 +2968,30 @@ void g_asr (unsigned flags, unsigned long val) case CF_LONG: if (val >= 1 && val <= 3) { if (flags & CF_UNSIGNED) { - AddCodeSegLine (CS, "jsr shreax%ld", val); + AddCodeLine ("jsr shreax%ld", val); } else { - AddCodeSegLine (CS, "jsr asreax%ld", val); + AddCodeLine ("jsr asreax%ld", val); } return; } else if (val == 8 && (flags & CF_UNSIGNED)) { - AddCodeSegLine (CS, "txa"); - AddCodeSegLine (CS, "ldx sreg"); - AddCodeSegLine (CS, "ldy sreg+1"); - AddCodeSegLine (CS, "sty sreg"); - AddCodeSegLine (CS, "ldy #$00"); - AddCodeSegLine (CS, "sty sreg+1"); + AddCodeLine ("txa"); + AddCodeLine ("ldx sreg"); + AddCodeLine ("ldy sreg+1"); + AddCodeLine ("sty sreg"); + AddCodeLine ("ldy #$00"); + AddCodeLine ("sty sreg+1"); return; } else if (val == 16) { - AddCodeSegLine (CS, "ldy #$00"); - AddCodeSegLine (CS, "ldx sreg+1"); + AddCodeLine ("ldy #$00"); + AddCodeLine ("ldx sreg+1"); if ((flags & CF_UNSIGNED) == 0) { - AddCodeSegLine (CS, "bpl *+3"); - AddCodeSegLine (CS, "dey"); + AddCodeLine ("bpl *+3"); + AddCodeLine ("dey"); AddCodeHint ("y:!"); } - AddCodeSegLine (CS, "lda sreg"); - AddCodeSegLine (CS, "sty sreg+1"); - AddCodeSegLine (CS, "sty sreg"); + AddCodeLine ("lda sreg"); + AddCodeLine ("sty sreg+1"); + AddCodeLine ("sty sreg"); return; } break; @@ -3121,14 +3035,14 @@ void g_asl (unsigned flags, unsigned long val) case CF_INT: if (val >= 1 && val <= 3) { if (flags & CF_UNSIGNED) { - AddCodeSegLine (CS, "jsr shlax%ld", val); + AddCodeLine ("jsr shlax%ld", val); } else { - AddCodeSegLine (CS, "jsr aslax%ld", val); + AddCodeLine ("jsr aslax%ld", val); } return; } else if (val == 8) { - AddCodeSegLine (CS, "tax"); - AddCodeSegLine (CS, "lda #$00"); + AddCodeLine ("tax"); + AddCodeLine ("lda #$00"); return; } break; @@ -3136,23 +3050,23 @@ void g_asl (unsigned flags, unsigned long val) case CF_LONG: if (val >= 1 && val <= 3) { if (flags & CF_UNSIGNED) { - AddCodeSegLine (CS, "jsr shleax%ld", val); + AddCodeLine ("jsr shleax%ld", val); } else { - AddCodeSegLine (CS, "jsr asleax%ld", val); + AddCodeLine ("jsr asleax%ld", val); } return; } else if (val == 8) { - AddCodeSegLine (CS, "ldy sreg"); - AddCodeSegLine (CS, "sty sreg+1"); - AddCodeSegLine (CS, "stx sreg"); - AddCodeSegLine (CS, "tax"); - AddCodeSegLine (CS, "lda #$00"); + AddCodeLine ("ldy sreg"); + AddCodeLine ("sty sreg+1"); + AddCodeLine ("stx sreg"); + AddCodeLine ("tax"); + AddCodeLine ("lda #$00"); return; } else if (val == 16) { - AddCodeSegLine (CS, "stx sreg+1"); - AddCodeSegLine (CS, "sta sreg"); - AddCodeSegLine (CS, "lda #$00"); - AddCodeSegLine (CS, "tax"); + AddCodeLine ("stx sreg+1"); + AddCodeLine ("sta sreg"); + AddCodeLine ("lda #$00"); + AddCodeLine ("tax"); return; } break; @@ -3181,11 +3095,11 @@ void g_neg (unsigned flags) case CF_CHAR: case CF_INT: - AddCodeSegLine (CS, "jsr negax"); + AddCodeLine ("jsr negax"); break; case CF_LONG: - AddCodeSegLine (CS, "jsr negeax"); + AddCodeLine ("jsr negeax"); break; default: @@ -3201,15 +3115,15 @@ void g_bneg (unsigned flags) switch (flags & CF_TYPE) { case CF_CHAR: - AddCodeSegLine (CS, "jsr bnega"); + AddCodeLine ("jsr bnega"); break; case CF_INT: - AddCodeSegLine (CS, "jsr bnegax"); + AddCodeLine ("jsr bnegax"); break; case CF_LONG: - AddCodeSegLine (CS, "jsr bnegeax"); + AddCodeLine ("jsr bnegeax"); break; default: @@ -3226,11 +3140,11 @@ void g_com (unsigned flags) case CF_CHAR: case CF_INT: - AddCodeSegLine (CS, "jsr complax"); + AddCodeLine ("jsr complax"); break; case CF_LONG: - AddCodeSegLine (CS, "jsr compleax"); + AddCodeLine ("jsr compleax"); break; default: @@ -3256,11 +3170,11 @@ void g_inc (unsigned flags, unsigned long val) if (flags & CF_FORCECHAR) { if (CPU == CPU_65C02 && val <= 2) { while (val--) { - AddCodeSegLine (CS, "ina"); + AddCodeLine ("ina"); } } else { - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc #$%02X", (unsigned char)val); + AddCodeLine ("clc"); + AddCodeLine ("adc #$%02X", (unsigned char)val); } break; } @@ -3268,18 +3182,18 @@ void g_inc (unsigned flags, unsigned long val) case CF_INT: if (CPU == CPU_65C02 && val == 1) { - AddCodeSegLine (CS, "ina"); - AddCodeSegLine (CS, "bne *+3"); - AddCodeSegLine (CS, "inx"); + AddCodeLine ("ina"); + AddCodeLine ("bne *+3"); + AddCodeLine ("inx"); /* Tell the optimizer that the X register may be invalid */ AddCodeHint ("x:!"); } else if (CodeSizeFactor < 200) { /* Use jsr calls */ if (val <= 8) { - AddCodeSegLine (CS, "jsr incax%lu", val); + AddCodeLine ("jsr incax%lu", val); } else if (val <= 255) { ldyconst (val); - AddCodeSegLine (CS, "jsr incaxy"); + AddCodeLine ("jsr incaxy"); } else { g_add (flags | CF_CONST, val); } @@ -3287,31 +3201,31 @@ void g_inc (unsigned flags, unsigned long val) /* Inline the code */ if (val < 0x300) { if ((val & 0xFF) != 0) { - AddCodeSegLine (CS, "clc"); - AddCodeSegLine (CS, "adc #$%02X", (unsigned char) val); - AddCodeSegLine (CS, "bcc *+3"); - AddCodeSegLine (CS, "inx"); + AddCodeLine ("clc"); + AddCodeLine ("adc #$%02X", (unsigned char) val); + AddCodeLine ("bcc *+3"); + AddCodeLine ("inx"); /* Tell the optimizer that the X register may be invalid */ AddCodeHint ("x:!"); } if (val >= 0x100) { - AddCodeSegLine (CS, "inx"); + AddCodeLine ("inx"); } if (val >= 0x200) { - AddCodeSegLine (CS, "inx"); + AddCodeLine ("inx"); } } else { - AddCodeSegLine (CS, "clc"); + AddCodeLine ("clc"); if ((val & 0xFF) != 0) { - AddCodeSegLine (CS, "adc #$%02X", (unsigned char) val); + AddCodeLine ("adc #$%02X", (unsigned char) val); /* Tell the optimizer that the X register may be invalid */ AddCodeHint ("x:!"); } - AddCodeSegLine (CS, "pha"); - AddCodeSegLine (CS, "txa"); - AddCodeSegLine (CS, "adc #$%02X", (unsigned char) (val >> 8)); - AddCodeSegLine (CS, "tax"); - AddCodeSegLine (CS, "pla"); + AddCodeLine ("pha"); + AddCodeLine ("txa"); + AddCodeLine ("adc #$%02X", (unsigned char) (val >> 8)); + AddCodeLine ("tax"); + AddCodeLine ("pla"); } } break; @@ -3319,7 +3233,7 @@ void g_inc (unsigned flags, unsigned long val) case CF_LONG: if (val <= 255) { ldyconst (val); - AddCodeSegLine (CS, "jsr inceaxy"); + AddCodeLine ("jsr inceaxy"); } else { g_add (flags | CF_CONST, val); } @@ -3349,11 +3263,11 @@ void g_dec (unsigned flags, unsigned long val) if (flags & CF_FORCECHAR) { if (CPU == CPU_65C02 && val <= 2) { while (val--) { - AddCodeSegLine (CS, "dea"); + AddCodeLine ("dea"); } } else { - AddCodeSegLine (CS, "sec"); - AddCodeSegLine (CS, "sbc #$%02X", (unsigned char)val); + AddCodeLine ("sec"); + AddCodeLine ("sbc #$%02X", (unsigned char)val); } break; } @@ -3363,10 +3277,10 @@ void g_dec (unsigned flags, unsigned long val) if (CodeSizeFactor < 200) { /* Use subroutines */ if (val <= 8) { - AddCodeSegLine (CS, "jsr decax%d", (int) val); + AddCodeLine ("jsr decax%d", (int) val); } else if (val <= 255) { ldyconst (val); - AddCodeSegLine (CS, "jsr decaxy"); + AddCodeLine ("jsr decaxy"); } else { g_sub (flags | CF_CONST, val); } @@ -3374,31 +3288,31 @@ void g_dec (unsigned flags, unsigned long val) /* Inline the code */ if (val < 0x300) { if ((val & 0xFF) != 0) { - AddCodeSegLine (CS, "sec"); - AddCodeSegLine (CS, "sbc #$%02X", (unsigned char) val); - AddCodeSegLine (CS, "bcs *+3"); - AddCodeSegLine (CS, "dex"); + AddCodeLine ("sec"); + AddCodeLine ("sbc #$%02X", (unsigned char) val); + AddCodeLine ("bcs *+3"); + AddCodeLine ("dex"); /* Tell the optimizer that the X register may be invalid */ AddCodeHint ("x:!"); } if (val >= 0x100) { - AddCodeSegLine (CS, "dex"); + AddCodeLine ("dex"); } if (val >= 0x200) { - AddCodeSegLine (CS, "dex"); + AddCodeLine ("dex"); } } else { - AddCodeSegLine (CS, "sec"); + AddCodeLine ("sec"); if ((val & 0xFF) != 0) { - AddCodeSegLine (CS, "sbc #$%02X", (unsigned char) val); + AddCodeLine ("sbc #$%02X", (unsigned char) val); /* Tell the optimizer that the X register may be invalid */ AddCodeHint ("x:!"); } - AddCodeSegLine (CS, "pha"); - AddCodeSegLine (CS, "txa"); - AddCodeSegLine (CS, "sbc #$%02X", (unsigned char) (val >> 8)); - AddCodeSegLine (CS, "tax"); - AddCodeSegLine (CS, "pla"); + AddCodeLine ("pha"); + AddCodeLine ("txa"); + AddCodeLine ("sbc #$%02X", (unsigned char) (val >> 8)); + AddCodeLine ("tax"); + AddCodeLine ("pla"); } } break; @@ -3406,7 +3320,7 @@ void g_dec (unsigned flags, unsigned long val) case CF_LONG: if (val <= 255) { ldyconst (val); - AddCodeSegLine (CS, "jsr deceaxy"); + AddCodeLine ("jsr deceaxy"); } else { g_sub (flags | CF_CONST, val); } @@ -3447,17 +3361,17 @@ void g_eq (unsigned flags, unsigned long val) case CF_CHAR: if (flags & CF_FORCECHAR) { - AddCodeSegLine (CS, "cmp #$%02X", (unsigned char)val); - AddCodeSegLine (CS, "jsr booleq"); + AddCodeLine ("cmp #$%02X", (unsigned char)val); + AddCodeLine ("jsr booleq"); return; } /* FALLTHROUGH */ case CF_INT: - AddCodeSegLine (CS, "cpx #$%02X", (unsigned char)(val >> 8)); - AddCodeSegLine (CS, "bne *+4"); - AddCodeSegLine (CS, "cmp #$%02X", (unsigned char)val); - AddCodeSegLine (CS, "jsr booleq"); + AddCodeLine ("cpx #$%02X", (unsigned char)(val >> 8)); + AddCodeLine ("bne *+4"); + AddCodeLine ("cmp #$%02X", (unsigned char)val); + AddCodeLine ("jsr booleq"); return; case CF_LONG: @@ -3500,17 +3414,17 @@ void g_ne (unsigned flags, unsigned long val) case CF_CHAR: if (flags & CF_FORCECHAR) { - AddCodeSegLine (CS, "cmp #$%02X", (unsigned char)val); - AddCodeSegLine (CS, "jsr boolne"); + AddCodeLine ("cmp #$%02X", (unsigned char)val); + AddCodeLine ("jsr boolne"); return; } /* FALLTHROUGH */ case CF_INT: - AddCodeSegLine (CS, "cpx #$%02X", (unsigned char)(val >> 8)); - AddCodeSegLine (CS, "bne *+4"); - AddCodeSegLine (CS, "cmp #$%02X", (unsigned char)val); - AddCodeSegLine (CS, "jsr boolne"); + AddCodeLine ("cpx #$%02X", (unsigned char)(val >> 8)); + AddCodeLine ("bne *+4"); + AddCodeLine ("cmp #$%02X", (unsigned char)val); + AddCodeLine ("jsr boolne"); return; case CF_LONG: @@ -3558,11 +3472,11 @@ void g_lt (unsigned flags, unsigned long val) case CF_CHAR: if (flags & CF_FORCECHAR) { - AddCodeSegLine (CS, "cmp #$%02X", (unsigned char)val); + AddCodeLine ("cmp #$%02X", (unsigned char)val); if (flags & CF_UNSIGNED) { - AddCodeSegLine (CS, "jsr boolult"); + AddCodeLine ("jsr boolult"); } else { - AddCodeSegLine (CS, "jsr boollt"); + AddCodeLine ("jsr boollt"); } return; } @@ -3573,16 +3487,16 @@ void g_lt (unsigned flags, unsigned long val) /* If we have a signed compare against zero, we only need to * test the high byte. */ - AddCodeSegLine (CS, "txa"); - AddCodeSegLine (CS, "jsr boollt"); + AddCodeLine ("txa"); + AddCodeLine ("jsr boollt"); return; } /* Direct code only for unsigned data types */ if (flags & CF_UNSIGNED) { - AddCodeSegLine (CS, "cpx #$%02X", (unsigned char)(val >> 8)); - AddCodeSegLine (CS, "bne *+4"); - AddCodeSegLine (CS, "cmp #$%02X", (unsigned char)val); - AddCodeSegLine (CS, "jsr boolult"); + AddCodeLine ("cpx #$%02X", (unsigned char)(val >> 8)); + AddCodeLine ("bne *+4"); + AddCodeLine ("cmp #$%02X", (unsigned char)val); + AddCodeLine ("jsr boolult"); return; } break; @@ -3628,11 +3542,11 @@ void g_le (unsigned flags, unsigned long val) case CF_CHAR: if (flags & CF_FORCECHAR) { - AddCodeSegLine (CS, "cmp #$%02X", (unsigned char)val); + AddCodeLine ("cmp #$%02X", (unsigned char)val); if (flags & CF_UNSIGNED) { - AddCodeSegLine (CS, "jsr boolule"); + AddCodeLine ("jsr boolule"); } else { - AddCodeSegLine (CS, "jsr boolle"); + AddCodeLine ("jsr boolle"); } return; } @@ -3640,10 +3554,10 @@ void g_le (unsigned flags, unsigned long val) case CF_INT: if (flags & CF_UNSIGNED) { - AddCodeSegLine (CS, "cpx #$%02X", (unsigned char)(val >> 8)); - AddCodeSegLine (CS, "bne *+4"); - AddCodeSegLine (CS, "cmp #$%02X", (unsigned char)val); - AddCodeSegLine (CS, "jsr boolule"); + AddCodeLine ("cpx #$%02X", (unsigned char)(val >> 8)); + AddCodeLine ("bne *+4"); + AddCodeLine ("cmp #$%02X", (unsigned char)val); + AddCodeLine ("jsr boolule"); return; } break; @@ -3689,19 +3603,19 @@ void g_gt (unsigned flags, unsigned long val) case CF_CHAR: if (flags & CF_FORCECHAR) { - AddCodeSegLine (CS, "cmp #$%02X", (unsigned char)val); + AddCodeLine ("cmp #$%02X", (unsigned char)val); if (flags & CF_UNSIGNED) { /* If we have a compare > 0, we will replace it by * != 0 here, since both are identical but the latter * is easier to optimize. */ if (val & 0xFF) { - AddCodeSegLine (CS, "jsr boolugt"); + AddCodeLine ("jsr boolugt"); } else { - AddCodeSegLine (CS, "jsr boolne"); + AddCodeLine ("jsr boolne"); } } else { - AddCodeSegLine (CS, "jsr boolgt"); + AddCodeLine ("jsr boolgt"); } return; } @@ -3714,14 +3628,14 @@ void g_gt (unsigned flags, unsigned long val) * is easier to optimize. */ if ((val & 0xFFFF) == 0) { - AddCodeSegLine (CS, "stx tmp1"); - AddCodeSegLine (CS, "ora tmp1"); - AddCodeSegLine (CS, "jsr boolne"); + AddCodeLine ("stx tmp1"); + AddCodeLine ("ora tmp1"); + AddCodeLine ("jsr boolne"); } else { - AddCodeSegLine (CS, "cpx #$%02X", (unsigned char)(val >> 8)); - AddCodeSegLine (CS, "bne *+4"); - AddCodeSegLine (CS, "cmp #$%02X", (unsigned char)val); - AddCodeSegLine (CS, "jsr boolugt"); + AddCodeLine ("cpx #$%02X", (unsigned char)(val >> 8)); + AddCodeLine ("bne *+4"); + AddCodeLine ("cmp #$%02X", (unsigned char)val); + AddCodeLine ("jsr boolugt"); } return; } @@ -3773,11 +3687,11 @@ void g_ge (unsigned flags, unsigned long val) case CF_CHAR: if (flags & CF_FORCECHAR) { - AddCodeSegLine (CS, "cmp #$%02X", (unsigned char)val); + AddCodeLine ("cmp #$%02X", (unsigned char)val); if (flags & CF_UNSIGNED) { - AddCodeSegLine (CS, "jsr booluge"); + AddCodeLine ("jsr booluge"); } else { - AddCodeSegLine (CS, "jsr boolge"); + AddCodeLine ("jsr boolge"); } return; } @@ -3785,10 +3699,10 @@ void g_ge (unsigned flags, unsigned long val) case CF_INT: if (flags & CF_UNSIGNED) { - AddCodeSegLine (CS, "cpx #$%02X", (unsigned char)(val >> 8)); - AddCodeSegLine (CS, "bne *+4"); - AddCodeSegLine (CS, "cmp #$%02X", (unsigned char)val); - AddCodeSegLine (CS, "jsr booluge"); + AddCodeLine ("cpx #$%02X", (unsigned char)(val >> 8)); + AddCodeLine ("bne *+4"); + AddCodeLine ("cmp #$%02X", (unsigned char)val); + AddCodeLine ("jsr booluge"); return; } break; @@ -3822,7 +3736,7 @@ void g_ge (unsigned flags, unsigned long val) void g_res (unsigned n) /* Reserve static storage, n bytes */ { - AddDataSegLine (DS, "\t.res\t%u,$00", n); + AddDataLine ("\t.res\t%u,$00", n); } @@ -3836,15 +3750,15 @@ void g_defdata (unsigned flags, unsigned long val, unsigned offs) switch (flags & CF_TYPE) { case CF_CHAR: - AddDataSegLine (DS, "\t.byte\t$%02lX", val & 0xFF); + AddDataLine ("\t.byte\t$%02lX", val & 0xFF); break; case CF_INT: - AddDataSegLine (DS, "\t.word\t$%04lX", val & 0xFFFF); + AddDataLine ("\t.word\t$%04lX", val & 0xFFFF); break; case CF_LONG: - AddDataSegLine (DS, "\t.dword\t$%08lX", val & 0xFFFFFFFF); + AddDataLine ("\t.dword\t$%08lX", val & 0xFFFFFFFF); break; default: @@ -3859,7 +3773,7 @@ void g_defdata (unsigned flags, unsigned long val, unsigned offs) const char* Label = GetLabelName (flags, val, offs); /* Labels are always 16 bit */ - AddDataSegLine (DS, "\t.word\t%s", Label); + AddDataLine ("\t.word\t%s", Label); } } @@ -3896,7 +3810,7 @@ void g_defbytes (const void* Bytes, unsigned Count) } while (Chunk); /* Output the line */ - AddDataSegLine (DS, Buf); + AddDataLine (Buf); } } @@ -3905,7 +3819,7 @@ void g_defbytes (const void* Bytes, unsigned Count) void g_zerobytes (unsigned n) /* Output n bytes of data initialized with zero */ { - AddDataSegLine (DS, "\t.res\t%u,$00", n); + AddDataLine ("\t.res\t%u,$00", n); } @@ -3922,9 +3836,9 @@ void g_asmcode (const char* Line, int Len) */ { if (Len >= 0) { - AddCodeSegLine (CS, "%.*s", Len, Line); + AddCodeLine ("%.*s", Len, Line); } else { - AddCodeSegLine (CS, "%s", Line); + AddCodeLine ("%s", Line); } } @@ -3949,31 +3863,31 @@ void g_strlen (unsigned flags, unsigned long val, unsigned offs) char* lbuf = GetLabelName (flags, val, offs); /* Generate the strlen code */ - AddCodeSegLine (CS, "ldy #$FF"); + AddCodeLine ("ldy #$FF"); g_defcodelabel (label); - AddCodeSegLine (CS, "iny"); - AddCodeSegLine (CS, "lda %s,y", lbuf); - AddCodeSegLine (CS, "bne %s", LocalLabelName (label)); - AddCodeSegLine (CS, "tax"); - AddCodeSegLine (CS, "tya"); + AddCodeLine ("iny"); + AddCodeLine ("lda %s,y", lbuf); + AddCodeLine ("bne %s", LocalLabelName (label)); + AddCodeLine ("tax"); + AddCodeLine ("tya"); } else { /* Address not constant but in primary */ if (CodeSizeFactor < 400) { /* This is too much code, so call strlen instead of inlining */ - AddCodeSegLine (CS, "jsr _strlen"); + AddCodeLine ("jsr _strlen"); } else { /* Inline the function */ - AddCodeSegLine (CS, "sta ptr1"); - AddCodeSegLine (CS, "stx ptr1+1"); - AddCodeSegLine (CS, "ldy #$FF"); + AddCodeLine ("sta ptr1"); + AddCodeLine ("stx ptr1+1"); + AddCodeLine ("ldy #$FF"); g_defcodelabel (label); - AddCodeSegLine (CS, "iny"); - AddCodeSegLine (CS, "lda (ptr1),y"); - AddCodeSegLine (CS, "bne %s", LocalLabelName (label)); - AddCodeSegLine (CS, "tax"); - AddCodeSegLine (CS, "tya"); + AddCodeLine ("iny"); + AddCodeLine ("lda (ptr1),y"); + AddCodeLine ("bne %s", LocalLabelName (label)); + AddCodeLine ("tax"); + AddCodeLine ("tya"); } } } diff --git a/src/cc65/codegen.h b/src/cc65/codegen.h index b04b5c9d8..02b9fadee 100644 --- a/src/cc65/codegen.h +++ b/src/cc65/codegen.h @@ -38,14 +38,8 @@ -/*****************************************************************************/ -/* Forwards */ -/*****************************************************************************/ - - - -struct CodeSeg; -struct DataSeg; +/* cc65 */ +#include "segments.h" @@ -109,12 +103,6 @@ void g_preamble (void); -void g_pushseg (struct CodeSeg** CS, struct DataSeg** DS, const char* FuncName); -/* Push the current segments and generate new ones for the given function */ - -void g_popseg (void); -/* Restore the old segments */ - void g_userodata (void); /* Switch to the read only data segment */ @@ -124,18 +112,6 @@ void g_usedata (void); void g_usebss (void); /* Switch to the bss segment */ -void g_codename (const char* Name); -/* Set the name of the CODE segment */ - -void g_rodataname (const char* Name); -/* Set the name of the RODATA segment */ - -void g_dataname (const char* Name); -/* Set the name of the DATA segment */ - -void g_bssname (const char* Name); -/* Set the name of the BSS segment */ - /*****************************************************************************/ diff --git a/src/cc65/codelab.c b/src/cc65/codelab.c index 55069c3f9..237e50a32 100644 --- a/src/cc65/codelab.c +++ b/src/cc65/codelab.c @@ -36,7 +36,7 @@ /* common */ #include "xmalloc.h" -/* cc65 */ +/* cc65 */ #include "codeent.h" #include "codelab.h" @@ -107,7 +107,7 @@ unsigned RemoveLabelRef (CodeLabel* L, const struct CodeEntry* E) -void OutputCodeLabel (FILE* F, const CodeLabel* L) +void OutputCodeLabel (const CodeLabel* L, FILE* F) /* Output the code label to a file */ { fprintf (F, "%s:", L->Name); diff --git a/src/cc65/codelab.h b/src/cc65/codelab.h index 203d16bd8..619842862 100644 --- a/src/cc65/codelab.h +++ b/src/cc65/codelab.h @@ -95,7 +95,7 @@ void AddLabelRef (CodeLabel* L, struct CodeEntry* E); unsigned RemoveLabelRef (CodeLabel* L, const struct CodeEntry* E); /* Remove a reference to this label, return the number of remaining references */ -void OutputCodeLabel (FILE* F, const CodeLabel* L); +void OutputCodeLabel (const CodeLabel* L, FILE* F); /* Output the code label to a file */ diff --git a/src/cc65/codeopt.c b/src/cc65/codeopt.c index a0c7be717..15fc48250 100644 --- a/src/cc65/codeopt.c +++ b/src/cc65/codeopt.c @@ -88,7 +88,7 @@ static void OptDeadJumps (CodeSeg* S) if (E->AM == AM_BRA && E->JumpTo && E->JumpTo->Owner == CollAt (&S->Entries, I+1)) { /* Delete the dead jump */ - DelCodeSegLine (S, I); + DelCodeEntry (S, I); /* Keep the number of entries updated */ --Count; @@ -140,7 +140,7 @@ static void OptDeadCode (CodeSeg* S) !CodeEntryHasLabel (CollAt (&S->Entries, I+1))) { /* Delete the next entry */ - DelCodeSegLine (S, I+1); + DelCodeEntry (S, I+1); /* Keep the number of entries updated */ --Count; diff --git a/src/cc65/codeseg.c b/src/cc65/codeseg.c index 264bee2f7..c0be35a02 100644 --- a/src/cc65/codeseg.c +++ b/src/cc65/codeseg.c @@ -52,17 +52,6 @@ -/*****************************************************************************/ -/* Data */ -/*****************************************************************************/ - - - -/* Pointer to current code segment */ -CodeSeg* CS = 0; - - - /*****************************************************************************/ /* Functions for parsing instructions */ /*****************************************************************************/ @@ -309,7 +298,7 @@ static CodeEntry* ParseInsn (CodeSeg* S, const char* L) -CodeSeg* NewCodeSeg (const char* SegName, const char* FuncName) +CodeSeg* NewCodeSeg (const char* SegName, SymEntry* Func) /* Create a new code segment, initialize and return it */ { unsigned I; @@ -318,9 +307,8 @@ CodeSeg* NewCodeSeg (const char* SegName, const char* FuncName) CodeSeg* S = xmalloc (sizeof (CodeSeg)); /* Initialize the fields */ - S->Next = 0; S->SegName = xstrdup (SegName); - S->FuncName = xstrdup (FuncName); + S->Func = Func; InitCollection (&S->Entries); InitCollection (&S->Labels); for (I = 0; I < sizeof(S->LabelHash) / sizeof(S->LabelHash[0]); ++I) { @@ -336,39 +324,12 @@ CodeSeg* NewCodeSeg (const char* SegName, const char* FuncName) void FreeCodeSeg (CodeSeg* S) /* Free a code segment including all code entries */ { - FAIL ("Not implemented"); + Internal ("Not implemented"); } -void PushCodeSeg (CodeSeg* S) -/* Push the given code segment onto the stack */ -{ - S->Next = CS; - CS = S; -} - - - -CodeSeg* PopCodeSeg (void) -/* Remove the current code segment from the stack and return it */ -{ - /* Remember the current code segment */ - CodeSeg* S = CS; - - /* Cannot pop on empty stack */ - PRECONDITION (S != 0); - - /* Pop */ - CS = S->Next; - - /* Return the popped code segment */ - return S; -} - - - -void AddCodeSegLine (CodeSeg* S, const char* Format, ...) +void AddCodeEntry (CodeSeg* S, const char* Format, va_list ap) /* Add a line to the given code segment */ { const char* L; @@ -376,11 +337,8 @@ void AddCodeSegLine (CodeSeg* S, const char* Format, ...) char Token[64]; /* Format the line */ - va_list ap; char Buf [256]; - va_start (ap, Format); xvsprintf (Buf, sizeof (Buf), Format, ap); - va_end (ap); /* Skip whitespace */ L = SkipSpace (Buf); @@ -436,7 +394,7 @@ void AddCodeSegLine (CodeSeg* S, const char* Format, ...) -void DelCodeSegLine (CodeSeg* S, unsigned Index) +void DelCodeEntry (CodeSeg* S, unsigned Index) /* Delete an entry from the code segment. This includes deleting any associated * labels, removing references to labels and even removing the referenced labels * if the reference count drops to zero. @@ -592,7 +550,7 @@ void DelCodeSegAfter (CodeSeg* S, unsigned Last) -void OutputCodeSeg (FILE* F, const CodeSeg* S) +void OutputCodeSeg (const CodeSeg* S, FILE* F) /* Output the code segment data to a file */ { unsigned I; @@ -600,31 +558,26 @@ void OutputCodeSeg (FILE* F, const CodeSeg* S) /* Get the number of entries in this segment */ unsigned Count = CollCount (&S->Entries); - fprintf (F, "; Labels: "); - for (I = 0; I < CS_LABEL_HASH_SIZE; ++I) { - const CodeLabel* L = S->LabelHash[I]; - while (L) { - fprintf (F, "%s ", L->Name); - L = L->Next; - } + /* If the code segment is empty, bail out here */ + if (Count == 0) { + return; } - fprintf (F, "\n"); /* Output the segment directive */ fprintf (F, ".segment\t\"%s\"\n\n", S->SegName); /* If this is a segment for a function, enter a function */ - if (S->FuncName[0] != '\0') { - fprintf (F, ".proc\t_%s\n\n", S->FuncName); + if (S->Func) { + fprintf (F, ".proc\t_%s\n\n", S->Func->Name); } /* Output all entries */ for (I = 0; I < Count; ++I) { - OutputCodeEntry (F, CollConstAt (&S->Entries, I)); + OutputCodeEntry (CollConstAt (&S->Entries, I), F); } /* If this is a segment for a function, leave the function */ - if (S->FuncName[0] != '\0') { + if (S->Func) { fprintf (F, "\n.endproc\n\n"); } } diff --git a/src/cc65/codeseg.h b/src/cc65/codeseg.h index d09f07a8c..91b8536ec 100644 --- a/src/cc65/codeseg.h +++ b/src/cc65/codeseg.h @@ -37,7 +37,8 @@ #define CODESEG_H - + +#include #include /* common */ @@ -46,11 +47,12 @@ /* cc65 */ #include "codelab.h" +#include "symentry.h" /*****************************************************************************/ -/* Data */ +/* Data */ /*****************************************************************************/ @@ -61,41 +63,31 @@ /* Code segment structure */ typedef struct CodeSeg CodeSeg; struct CodeSeg { - CodeSeg* Next; /* Pointer to next CodeSeg */ char* SegName; /* Segment name */ - char* FuncName; /* Name of function */ + SymEntry* Func; /* Owner function */ Collection Entries; /* List of code entries */ Collection Labels; /* Labels for next insn */ CodeLabel* LabelHash [CS_LABEL_HASH_SIZE]; /* Label hash table */ }; -/* Pointer to current code segment */ -extern CodeSeg* CS; - /*****************************************************************************/ -/* Code */ +/* Code */ /*****************************************************************************/ -CodeSeg* NewCodeSeg (const char* SegName, const char* FuncName); +CodeSeg* NewCodeSeg (const char* SegName, SymEntry* Func); /* Create a new code segment, initialize and return it */ void FreeCodeSeg (CodeSeg* S); /* Free a code segment including all code entries */ -void PushCodeSeg (CodeSeg* S); -/* Push the given code segment onto the stack */ - -CodeSeg* PopCodeSeg (void); -/* Remove the current code segment from the stack and return it */ - -void AddCodeSegLine (CodeSeg* S, const char* Format, ...) attribute ((format(printf,2,3))); +void AddCodeEntry (CodeSeg* S, const char* Format, va_list ap) attribute ((format(printf,2,0))); /* Add a line to the given code segment */ -void DelCodeSegLine (CodeSeg* S, unsigned Index); +void DelCodeEntry (CodeSeg* S, unsigned Index); /* Delete an entry from the code segment. This includes deleting any associated * labels, removing references to labels and even removing the referenced labels * if the reference count drops to zero. @@ -113,7 +105,7 @@ void AddCodeSegHint (CodeSeg* S, unsigned Hint); void DelCodeSegAfter (CodeSeg* S, unsigned Last); /* Delete all entries including the given one */ -void OutputCodeSeg (FILE* F, const CodeSeg* S); +void OutputCodeSeg (const CodeSeg* S, FILE* F); /* Output the code segment data to a file */ CodeLabel* FindCodeLabel (CodeSeg* S, const char* Name, unsigned Hash); diff --git a/src/cc65/dataseg.c b/src/cc65/dataseg.c index 72f782853..980246a05 100644 --- a/src/cc65/dataseg.c +++ b/src/cc65/dataseg.c @@ -39,36 +39,26 @@ #include "xsprintf.h" /* cc65 */ +#include "error.h" #include "dataseg.h" -/*****************************************************************************/ -/* Data */ -/*****************************************************************************/ - - - -/* Pointer to current data segment */ -DataSeg* DS = 0; - - - /*****************************************************************************/ /* Code */ /*****************************************************************************/ -DataSeg* NewDataSeg (const char* Name) +DataSeg* NewDataSeg (const char* Name, SymEntry* Func) /* Create a new data segment, initialize and return it */ { /* Allocate memory */ - DataSeg* S = xmalloc (sizeof (DataSeg)); + DataSeg* S = xmalloc (sizeof (DataSeg)); /* Initialize the fields */ - S->Next = 0; - S->Name = xstrdup (Name); + S->SegName = xstrdup (Name); + S->Func = Func; InitCollection (&S->Lines); /* Return the new struct */ @@ -80,50 +70,7 @@ DataSeg* NewDataSeg (const char* Name) void FreeDataSeg (DataSeg* S) /* Free a data segment including all line entries */ { - unsigned I, Count; - - /* Free the name */ - xfree (S->Name); - - /* Free the lines */ - Count = CollCount (&S->Lines); - for (I = 0; I < Count; ++I) { - xfree (CollAt (&S->Lines, I)); - } - - /* Free the collection */ - DoneCollection (&S->Lines); - - /* Free the struct */ - xfree (S); -} - - - -void PushDataSeg (DataSeg* S) -/* Push the given data segment onto the stack */ -{ - /* Push */ - S->Next = DS; - DS = S; -} - - - -DataSeg* PopDataSeg (void) -/* Remove the current data segment from the stack and return it */ -{ - /* Remember the current data segment */ - DataSeg* S = DS; - - /* Cannot pop on empty stack */ - PRECONDITION (S != 0); - - /* Pop */ - DS = S->Next; - - /* Return the popped data segment */ - return S; + Internal ("Not implemented"); } @@ -142,16 +89,12 @@ void AppendDataSeg (DataSeg* Target, const DataSeg* Source) -void AddDataSegLine (DataSeg* S, const char* Format, ...) +void AddDataEntry (DataSeg* S, const char* Format, va_list ap) /* Add a line to the given data segment */ { - va_list ap; - char Buf [256]; - /* Format the line */ - va_start (ap, Format); + char Buf [256]; xvsprintf (Buf, sizeof (Buf), Format, ap); - va_end (ap); /* Add a copy to the data segment */ CollAppend (&S->Lines, xstrdup (Buf)); @@ -159,7 +102,7 @@ void AddDataSegLine (DataSeg* S, const char* Format, ...) -void OutputDataSeg (FILE* F, const DataSeg* S) +void OutputDataSeg (const DataSeg* S, FILE* F) /* Output the data segment data to a file */ { unsigned I; @@ -167,10 +110,21 @@ void OutputDataSeg (FILE* F, const DataSeg* S) /* Get the number of entries in this segment */ unsigned Count = CollCount (&S->Lines); + /* If the segment is actually empty, bail out */ + if (Count == 0) { + return; + } + + /* Output the segment directive */ + fprintf (F, ".segment\t\"%s\"\n\n", S->SegName); + /* Output all entries */ for (I = 0; I < Count; ++I) { fprintf (F, "%s\n", (const char*) CollConstAt (&S->Lines, I)); } + + /* Add an additional newline after the segment output */ + fprintf (F, "\n"); } diff --git a/src/cc65/dataseg.h b/src/cc65/dataseg.h index e03c37211..ab62442d9 100644 --- a/src/cc65/dataseg.h +++ b/src/cc65/dataseg.h @@ -38,30 +38,31 @@ +#include #include /* common */ #include "attrib.h" #include "coll.h" +/* cc65 */ +#include "symentry.h" + /*****************************************************************************/ -/* Data */ +/* Data */ /*****************************************************************************/ typedef struct DataSeg DataSeg; struct DataSeg { - DataSeg* Next; /* Pointer to next DataSeg */ - char* Name; /* Segment name */ + char* SegName; /* Segment name */ + SymEntry* Func; /* Owner function */ Collection Lines; /* List of code lines */ }; -/* Pointer to current data segment */ -extern DataSeg* DS; - /*****************************************************************************/ @@ -70,25 +71,19 @@ extern DataSeg* DS; -DataSeg* NewDataSeg (const char* Name); +DataSeg* NewDataSeg (const char* SegName, SymEntry* Func); /* Create a new data segment, initialize and return it */ void FreeDataSeg (DataSeg* S); /* Free a data segment including all line entries */ -void PushDataSeg (DataSeg* S); -/* Push the given data segment onto the stack */ - -DataSeg* PopDataSeg (void); -/* Remove the current data segment from the stack and return it */ - void AppendDataSeg (DataSeg* Target, const DataSeg* Source); /* Append the data from Source to Target. */ -void AddDataSegLine (DataSeg* S, const char* Format, ...) attribute ((format(printf,2,3))); +void AddDataEntry (DataSeg* S, const char* Format, va_list ap) attribute ((format(printf,2,0))); /* Add a line to the given data segment */ -void OutputDataSeg (FILE* F, const DataSeg* S); +void OutputDataSeg (const DataSeg* S, FILE* F); /* Output the data segment data to a file */ diff --git a/src/cc65/function.c b/src/cc65/function.c index 39f9b5bb6..69b653665 100644 --- a/src/cc65/function.c +++ b/src/cc65/function.c @@ -47,6 +47,7 @@ #include "litpool.h" #include "locals.h" #include "scanner.h" +#include "segments.h" #include "stmt.h" #include "symtab.h" #include "function.h" @@ -246,7 +247,7 @@ void NewFunc (SymEntry* Func) InitRegVars (); /* Allocate code and data segments for this function */ - g_pushseg (&Func->V.F.CS, &Func->V.F.DS, Func->Name); + Func->V.F.Seg = PushSegments (Func); /* If this is a fastcall function, push the last parameter onto the stack */ if (IsFastCallFunc (Func->Type) && D->ParamCount > 0) { @@ -336,7 +337,7 @@ void NewFunc (SymEntry* Func) LeaveFunctionLevel (); /* Switch back to the old segments */ - g_popseg (); + PopSegments (); /* Reset the current function pointer */ FreeFunction (CurrentFunc); diff --git a/src/cc65/main.c b/src/cc65/main.c index 6f3d0bbcf..65346db94 100644 --- a/src/cc65/main.c +++ b/src/cc65/main.c @@ -59,7 +59,7 @@ #include "input.h" #include "macrotab.h" #include "scanner.h" -#include "segname.h" +#include "segments.h" diff --git a/src/cc65/make/gcc.mak b/src/cc65/make/gcc.mak index 4f839e4e1..d9d374e1b 100644 --- a/src/cc65/make/gcc.mak +++ b/src/cc65/make/gcc.mak @@ -56,14 +56,14 @@ OBJS = anonname.o \ opcodes.o \ preproc.o \ pragma.o \ - scanner.o \ - segname.o \ - stdfunc.o \ - stmt.o \ - symentry.o \ - symtab.o \ - typecmp.o \ - util.o + scanner.o \ + segments.o \ + stdfunc.o \ + stmt.o \ + symentry.o \ + symtab.o \ + typecmp.o \ + util.o LIBS = $(COMMON)/common.a diff --git a/src/cc65/pragma.c b/src/cc65/pragma.c index 51a2dbdc4..4f51995d6 100644 --- a/src/cc65/pragma.c +++ b/src/cc65/pragma.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2000 Ullrich von Bassewitz */ +/* (C) 1998-2001 Ullrich von Bassewitz */ /* Wacholderweg 14 */ /* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ @@ -37,13 +37,12 @@ #include /* cc65 */ -#include "codegen.h" #include "error.h" #include "expr.h" #include "global.h" #include "litpool.h" #include "scanner.h" -#include "segname.h" +#include "segments.h" #include "symtab.h" #include "pragma.h" @@ -138,7 +137,7 @@ static void StringPragma (void (*Func) (const char*)) -static void SegNamePragma (void (*Func) (const char*)) +static void SegNamePragma (segment_t Seg) /* Handle a pragma that expects a segment name parameter */ { if (curtok != TOK_SCONST) { @@ -150,8 +149,8 @@ static void SegNamePragma (void (*Func) (const char*)) /* Check if the name is valid */ if (ValidSegName (Name)) { - /* Call the given function to set the name */ - Func (Name); + /* Set the new name */ + NewSegName (Seg, Name); } else { @@ -216,7 +215,7 @@ void DoPragma (void) switch (Pragma) { case PR_BSSSEG: - SegNamePragma (g_bssname); + SegNamePragma (SEG_BSS); break; case PR_CHECKSTACK: @@ -224,11 +223,11 @@ void DoPragma (void) break; case PR_CODESEG: - SegNamePragma (g_codename); + SegNamePragma (SEG_CODE); break; case PR_DATASEG: - SegNamePragma (g_dataname); + SegNamePragma (SEG_DATA); break; case PR_REGVARADDR: @@ -236,7 +235,7 @@ void DoPragma (void) break; case PR_RODATASEG: - SegNamePragma (g_rodataname); + SegNamePragma (SEG_RODATA); break; case PR_SIGNEDCHARS: diff --git a/src/cc65/pragma.h b/src/cc65/pragma.h index 65794a037..82026b35c 100644 --- a/src/cc65/pragma.h +++ b/src/cc65/pragma.h @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* (C) 1998-2001 Ullrich von Bassewitz */ +/* Wacholderweg 14 */ +/* D-70597 Stuttgart */ +/* EMail: uz@cc65.org */ /* */ /* */ /* This software is provided 'as-is', without any expressed or implied */ diff --git a/src/cc65/segments.c b/src/cc65/segments.c new file mode 100644 index 000000000..654927908 --- /dev/null +++ b/src/cc65/segments.c @@ -0,0 +1,250 @@ +/*****************************************************************************/ +/* */ +/* segments.c */ +/* */ +/* Lightweight segment management stuff */ +/* */ +/* */ +/* */ +/* (C) 2001 Ullrich von Bassewitz */ +/* Wacholderweg 14 */ +/* D-70597 Stuttgart */ +/* EMail: uz@cc65.org */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +#include +#include + +/* common */ +#include "chartype.h" +#include "check.h" +#include "coll.h" +#include "xmalloc.h" + +/* cc65 */ +#include "codeseg.h" +#include "dataseg.h" +#include "segments.h" + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +/* Pointer to the current segment list. Output goes here. */ +Segments* CS = 0; + +/* Actual names for the segments */ +static char* SegmentNames[SEG_COUNT]; + +/* We're using a collection for the stack instead of a linked list. Since + * functions may not be nested (at least in the current implementation), the + * maximum stack depth is 2, so there is not really a need for a better + * implementation. + */ +static Collection SegmentStack = STATIC_COLLECTION_INITIALIZER; + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void InitSegNames (void) +/* Initialize the segment names */ +{ + SegmentNames [SEG_BSS] = xstrdup ("BSS"); + SegmentNames [SEG_CODE] = xstrdup ("CODE"); + SegmentNames [SEG_DATA] = xstrdup ("DATA"); + SegmentNames [SEG_RODATA] = xstrdup ("RODATA"); +} + + + +void NewSegName (segment_t Seg, const char* Name) +/* Set a new name for a segment */ +{ + /* Free the old name and set a new one */ + xfree (SegmentNames [Seg]); + SegmentNames [Seg] = xstrdup (Name); +} + + + +int ValidSegName (const char* Name) +/* Return true if the given segment name is valid, return false otherwise */ +{ + /* Must start with '_' or a letter */ + if ((*Name != '_' && !IsAlpha(*Name)) || strlen(Name) > 80) { + return 0; + } + + /* Can have letters, digits or the underline */ + while (*++Name) { + if (*Name != '_' && !IsAlNum(*Name)) { + return 0; + } + } + + /* Name is ok */ + return 1; +} + + + +static Segments* NewSegments (SymEntry* Func) +/* Initialize a Segments structure (set all fields to NULL) */ +{ + /* Allocate memory */ + Segments* S = xmalloc (sizeof (Segments)); + + /* Initialize the fields */ + S->Code = NewCodeSeg (SegmentNames[SEG_CODE], Func); + S->Data = NewDataSeg (SegmentNames[SEG_DATA], Func); + S->ROData = NewDataSeg (SegmentNames[SEG_RODATA], Func); + S->BSS = NewDataSeg (SegmentNames[SEG_BSS], Func); + S->CurDSeg = SEG_DATA; + + /* Return the new struct */ + return S; +} + + + +Segments* PushSegments (SymEntry* Func) +/* Make the new segment list current but remember the old one */ +{ + /* Push the current pointer onto the stack */ + CollAppend (&SegmentStack, CS); + + /* Create a new Segments structure */ + CS = NewSegments (Func); + + /* Return the new struct */ + return CS; +} + + + +void PopSegments (void) +/* Pop the old segment list (make it current) */ +{ + /* Must have something on the stack */ + PRECONDITION (CollCount (&SegmentStack) > 0); + + /* Pop the last segment and set it as current */ + CS = CollPop (&SegmentStack); +} + + + +void UseDataSeg (segment_t DSeg) +/* For the current segment list, use the data segment DSeg */ +{ + /* Check the input */ + PRECONDITION (CS && DSeg != SEG_CODE); + + /* Set the new segment to use */ + CS->CurDSeg = DSeg; +} + + + +struct DataSeg* GetDataSeg (void) +/* Return the current data segment */ +{ + PRECONDITION (CS != 0); + switch (CS->CurDSeg) { + case SEG_BSS: return CS->BSS; + case SEG_DATA: return CS->Data; + case SEG_RODATA: return CS->ROData; + default: FAIL ("Invalid data segment"); + } +} + + + +void AddCodeLine (const char* Format, ...) +/* Add a line of code to the current code segment */ +{ + va_list ap; + va_start (ap, Format); + CHECK (CS != 0); + AddCodeEntry (CS->Code, Format, ap); + va_end (ap); +} + + + +void AddDataLine (const char* Format, ...) +/* Add a line of data to the current data segment */ +{ + va_list ap; + va_start (ap, Format); + CHECK (CS != 0); + AddDataEntry (GetDataSeg(), Format, ap); + va_end (ap); +} + + + +static void PrintFunctionHeader (const SymEntry* Entry, FILE* F) +{ + /* Print a comment with the function signature */ + fprintf (F, + "; ---------------------------------------------------------------\n" + "; "); + PrintFuncSig (F, Entry->Name, Entry->Type); + fprintf (F, + "\n" + "; ---------------------------------------------------------------\n" + "\n"); +} + + + +void OutputSegments (const Segments* S, FILE* F) +/* Output the given segments to the file */ +{ + /* If the code segment is associated with a function, print a function header */ + if (S->Code->Func) { + PrintFunctionHeader (S->Code->Func, F); + } + + /* Output the three data segments */ + OutputDataSeg (S->Data, F); + OutputDataSeg (S->ROData, F); + OutputDataSeg (S->BSS, F); + + /* Output the code segment */ + OutputCodeSeg (S->Code, F); +} + + + diff --git a/src/cc65/segments.h b/src/cc65/segments.h new file mode 100644 index 000000000..de66af9d7 --- /dev/null +++ b/src/cc65/segments.h @@ -0,0 +1,132 @@ +/*****************************************************************************/ +/* */ +/* segments.h */ +/* */ +/* Segment management */ +/* */ +/* */ +/* */ +/* (C) 2000-2001 Ullrich von Bassewitz */ +/* Wacholderweg 14 */ +/* D-70597 Stuttgart */ +/* EMail: uz@cc65.org */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +#ifndef SEGMENTS_H +#define SEGMENTS_H + + + +#include + +/* common */ +#include "attrib.h" + + + +/*****************************************************************************/ +/* Forwards */ +/*****************************************************************************/ + + + +struct CodeSeg; +struct DataSeg; +struct SymEntry; + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +/* Segment types */ +typedef enum segment_t { + SEG_CODE, + SEG_RODATA, + SEG_DATA, + SEG_BSS, + SEG_COUNT +} segment_t; + +/* A list of all segments used when generating code */ +typedef struct Segments Segments; +struct Segments { + struct CodeSeg* Code; /* Code segment */ + struct DataSeg* Data; /* Data segment */ + struct DataSeg* ROData; /* Readonly data segment */ + struct DataSeg* BSS; /* Segment for uninitialized data */ + segment_t CurDSeg; /* Current data segment */ +}; + +/* Pointer to the current segment list. Output goes here. */ +extern Segments* CS; + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void InitSegNames (void); +/* Initialize the segment names */ + +void NewSegName (segment_t Seg, const char* Name); +/* Set a new name for a segment */ + +int ValidSegName (const char* Name); +/* Return true if the given segment name is valid, return false otherwise */ + +Segments* PushSegments (struct SymEntry* Func); +/* Make the new segment list current but remember the old one */ + +void PopSegments (void); +/* Pop the old segment list (make it current) */ + +void UseDataSeg (segment_t DSeg); +/* For the current segment list, use the data segment DSeg */ + +struct DataSeg* GetDataSeg (void); +/* Return the current data segment */ + +void AddCodeLine (const char* Format, ...) attribute ((format (printf, 1, 2))); +/* Add a line of code to the current code segment */ + +void AddDataLine (const char* Format, ...) attribute ((format (printf, 1, 2))); +/* Add a line of data to the current data segment */ + +void OutputSegments (const Segments* S, FILE* F); +/* Output the given segments to the file */ + + + +/* End of segments.h */ +#endif + + + diff --git a/src/cc65/symentry.h b/src/cc65/symentry.h index ff0b63cea..6fe4ce7f0 100644 --- a/src/cc65/symentry.h +++ b/src/cc65/symentry.h @@ -40,27 +40,38 @@ #include +/* cc65 */ #include "datatype.h" /*****************************************************************************/ -/* struct SymEntry */ +/* Forwards */ +/*****************************************************************************/ + + + +struct Segments; + + + +/*****************************************************************************/ +/* struct SymEntry */ /*****************************************************************************/ /* Storage classes and flags */ -#define SC_AUTO 0x0001U +#define SC_AUTO 0x0001U #define SC_REGISTER 0x0002U /* Register variable, is in static storage */ #define SC_STATIC 0x0004U #define SC_EXTERN 0x0008U #define SC_ENUM 0x0030U /* An enum (numeric constant) */ -#define SC_CONST 0x0020U /* A numeric constant with a type */ +#define SC_CONST 0x0020U /* A numeric constant with a type */ #define SC_LABEL 0x0040U /* A goto label */ #define SC_PARAM 0x0080U /* This is a function parameter */ -#define SC_FUNC 0x0100U /* Function entry */ +#define SC_FUNC 0x0100U /* Function entry */ #define SC_STORAGE 0x0400U /* Symbol with associated storage */ #define SC_DEFAULT 0x0800U /* Flag: default storage class was used */ @@ -83,7 +94,7 @@ struct SymEntry { SymEntry* NextHash; /* Next entry in hash list */ SymEntry* PrevSym; /* Previous symbol in dl list */ SymEntry* NextSym; /* Next symbol double linked list */ - SymEntry* Link; /* General purpose single linked list */ + SymEntry* Link; /* General purpose single linked list */ struct SymTable* Owner; /* Symbol table the symbol is in */ unsigned Flags; /* Symbol flags */ type* Type; /* Symbol type */ @@ -109,18 +120,17 @@ struct SymEntry { /* Data for functions */ struct { struct FuncDesc* Func; /* Function descriptor */ - struct CodeSeg* CS; /* Code for function */ - struct DataSeg* DS; /* Data segment for function */ + struct Segments* Seg; /* Segments for this function */ } F; } V; - char Name[1]; /* Name, dynamically allocated */ + char Name[1]; /* Name, dynamically allocated */ }; /*****************************************************************************/ -/* Code */ +/* Code */ /*****************************************************************************/ diff --git a/src/cc65/symtab.c b/src/cc65/symtab.c index 0fc336dbe..5431cf0dc 100644 --- a/src/cc65/symtab.c +++ b/src/cc65/symtab.c @@ -744,8 +744,7 @@ SymEntry* AddGlobalSym (const char* Name, const type* Type, unsigned Flags) */ if (IsFunc) { Entry->V.F.Func = GetFuncDesc (Entry->Type); - Entry->V.F.CS = 0; - Entry->V.F.DS = 0; + Entry->V.F.Seg = 0; } /* Add the entry to the symbol table */ -- 2.39.5