From fdd120db4905611e552cadd1bbeca984a3100e0b Mon Sep 17 00:00:00 2001 From: acqn Date: Mon, 3 Aug 2020 01:36:19 +0800 Subject: [PATCH] Enabled to output errors and warnings about tentative definitions. --- src/cc65/compile.c | 52 ++++++++++++++++++++++++++-------------------- src/cc65/compile.h | 2 +- src/cc65/main.c | 2 +- 3 files changed, 32 insertions(+), 24 deletions(-) diff --git a/src/cc65/compile.c b/src/cc65/compile.c index 3d2f82c51..d70e38e00 100644 --- a/src/cc65/compile.c +++ b/src/cc65/compile.c @@ -415,9 +415,36 @@ void Compile (const char* FileName) } else { + /* Used for emitting externals */ + SymEntry* Entry; + /* Ok, start the ball rolling... */ Parse (); + /* Reset the BSS segment name to its default; so that the below strcmp() + ** will work as expected, at the beginning of the list of variables + */ + SetSegName (SEG_BSS, SEGNAME_BSS); + + /* Walk over all global symbols and generate code for uninitialized + ** global variables. + */ + for (Entry = GetGlobalSymTab ()->SymHead; Entry; Entry = Entry->NextSym) { + if ((Entry->Flags & (SC_STORAGE | SC_DEF | SC_STATIC)) == (SC_STORAGE | SC_STATIC)) { + /* Assembly definition of uninitialized global variable */ + + /* Set the segment name only when it changes */ + if (strcmp (GetSegName (SEG_BSS), Entry->V.BssName) != 0) { + SetSegName (SEG_BSS, Entry->V.BssName); + g_segname (SEG_BSS); + } + g_usebss (); + g_defgloblabel (Entry->Name); + g_res (SizeOf (Entry->Type)); + /* Mark as defined; so that it will be exported, not imported */ + Entry->Flags |= SC_DEF; + } + } } if (Debug) { @@ -431,18 +458,12 @@ void Compile (const char* FileName) void FinishCompile (void) -/* Emit literals, externals, debug info, do cleanup and optimizations */ +/* Emit literals, debug info, do cleanup and optimizations */ { SymEntry* Entry; - /* Reset the BSS segment name to its default; so that the below strcmp() - ** will work as expected, at the beginning of the list of variables - */ - SetSegName (SEG_BSS, SEGNAME_BSS); - - /* Walk over all global symbols: - ** - for functions, do clean-up and optimizations - ** - generate code for uninitialized global variables + /* Walk over all global symbols and do clean-up and optimizations for + ** functions. */ for (Entry = GetGlobalSymTab ()->SymHead; Entry; Entry = Entry->NextSym) { if (SymIsOutputFunc (Entry)) { @@ -450,19 +471,6 @@ void FinishCompile (void) MoveLiteralPool (Entry->V.F.LitPool); CS_MergeLabels (Entry->V.F.Seg->Code); RunOpt (Entry->V.F.Seg->Code); - } else if ((Entry->Flags & (SC_STORAGE | SC_DEF | SC_STATIC)) == (SC_STORAGE | SC_STATIC)) { - /* Assembly definition of uninitialized global variable */ - - /* Set the segment name only when it changes */ - if (strcmp (GetSegName (SEG_BSS), Entry->V.BssName) != 0) { - SetSegName (SEG_BSS, Entry->V.BssName); - g_segname (SEG_BSS); - } - g_usebss (); - g_defgloblabel (Entry->Name); - g_res (SizeOf (Entry->Type)); - /* Mark as defined; so that it will be exported, not imported */ - Entry->Flags |= SC_DEF; } } diff --git a/src/cc65/compile.h b/src/cc65/compile.h index 2d15c8200..7af14ef7e 100644 --- a/src/cc65/compile.h +++ b/src/cc65/compile.h @@ -48,7 +48,7 @@ void Compile (const char* FileName); /* Top level compile routine. Will setup things and call the parser. */ void FinishCompile (void); -/* Emit literals, externals, do cleanup and optimizations */ +/* Emit literals, debug info, do cleanup and optimizations */ diff --git a/src/cc65/main.c b/src/cc65/main.c index ed2e9d7ba..3e60bcb95 100644 --- a/src/cc65/main.c +++ b/src/cc65/main.c @@ -1069,7 +1069,7 @@ int main (int argc, char* argv[]) /* Create the output file if we didn't had any errors */ if (PreprocessOnly == 0 && (ErrorCount == 0 || Debug)) { - /* Emit literals, externals, do cleanup and optimizations */ + /* Emit literals, do cleanup and optimizations */ FinishCompile (); /* Open the file */