From b3af17126c3ac6178e45b090555bed5f34507eaf Mon Sep 17 00:00:00 2001 From: cuz Date: Fri, 24 Aug 2001 15:03:10 +0000 Subject: [PATCH] Allow access to the global segments. Place ".dbg file" statements into the global text segments so they will appear before any of the ".dbg line" statements emitted later. git-svn-id: svn://svn.cc65.org/cc65/trunk@852 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/codegen.c | 22 ++++++++-------------- src/cc65/codeseg.c | 13 ++++++++++++- src/cc65/codeseg.h | 5 ++++- src/cc65/dataseg.c | 13 ++++++++++++- src/cc65/dataseg.h | 5 ++++- src/cc65/segments.c | 9 ++++++--- src/cc65/segments.h | 5 ++++- src/cc65/textseg.c | 13 ++++++++++++- src/cc65/textseg.h | 5 ++++- 9 files changed, 66 insertions(+), 24 deletions(-) diff --git a/src/cc65/codegen.c b/src/cc65/codegen.c index 0a8f46bf2..7732f7f34 100644 --- a/src/cc65/codegen.c +++ b/src/cc65/codegen.c @@ -52,6 +52,7 @@ #include "error.h" #include "global.h" #include "segments.h" +#include "textseg.h" #include "util.h" #include "codegen.h" @@ -139,8 +140,9 @@ static char* GetLabelName (unsigned flags, unsigned long label, unsigned offs) void g_preamble (void) /* Generate the assembler code preamble */ { - /* Create a new segment list */ + /* Create a new (global) segment list and remember it */ PushSegments (0); + GS = CS; /* Identify the compiler version */ AddTextLine (";"); @@ -179,7 +181,10 @@ void g_fileinfo (const char* Name, unsigned long Size, unsigned long MTime) /* If debug info is enabled, place a file info into the source */ { if (DebugInfo) { - AddTextLine ("\t.dbg\t\tfile, \"%s\", %lu, %lu", Name, Size, MTime); + /* We have to place this into the global text segment, so it will + * appear before all .dbg line statements. + */ + TS_AddLine (GS->Text, "\t.dbg\t\tfile, \"%s\", %lu, %lu", Name, Size, MTime); } } @@ -215,17 +220,6 @@ void g_usebss (void) -static void OutputDataLine (DataSeg* S, const char* Format, ...) -/* Add a line to the current data segment */ -{ - va_list ap; - va_start (ap, Format); - DS_AddLine (S, Format, ap); - va_end (ap); -} - - - void g_segname (segment_t Seg, const char* Name) /* Set the name of a segment */ { @@ -242,7 +236,7 @@ void g_segname (segment_t Seg, const char* Name) default: S = 0; break; } if (S) { - OutputDataLine (S, ".segment\t\"%s\"", Name); + DS_AddLine (S, ".segment\t\"%s\"", Name); } } diff --git a/src/cc65/codeseg.c b/src/cc65/codeseg.c index 325eee20f..98bc0c27b 100644 --- a/src/cc65/codeseg.c +++ b/src/cc65/codeseg.c @@ -437,7 +437,7 @@ void CS_AddEntry (CodeSeg* S, struct CodeEntry* E) -void CS_AddLine (CodeSeg* S, LineInfo* LI, const char* Format, va_list ap) +void CS_AddVLine (CodeSeg* S, LineInfo* LI, const char* Format, va_list ap) /* Add a line to the given code segment */ { const char* L; @@ -482,6 +482,17 @@ void CS_AddLine (CodeSeg* S, LineInfo* LI, const char* Format, va_list ap) +void CS_AddLine (CodeSeg* S, LineInfo* LI, const char* Format, ...) +/* Add a line to the given code segment */ +{ + va_list ap; + va_start (ap, Format); + CS_AddVLine (S, LI, Format, ap); + va_end (ap); +} + + + void CS_InsertEntry (CodeSeg* S, struct CodeEntry* E, unsigned Index) /* Insert the code entry at the index given. Following code entries will be * moved to slots with higher indices. diff --git a/src/cc65/codeseg.h b/src/cc65/codeseg.h index f09c0d117..1218634a2 100644 --- a/src/cc65/codeseg.h +++ b/src/cc65/codeseg.h @@ -97,7 +97,10 @@ CodeSeg* NewCodeSeg (const char* SegName, SymEntry* Func); void CS_AddEntry (CodeSeg* S, struct CodeEntry* E); /* Add an entry to the given code segment */ -void CS_AddLine (CodeSeg* S, LineInfo* LI, const char* Format, va_list ap) attribute ((format(printf,3,0))); +void CS_AddVLine (CodeSeg* S, LineInfo* LI, const char* Format, va_list ap) attribute ((format(printf,3,0))); +/* Add a line to the given code segment */ + +void CS_AddLine (CodeSeg* S, LineInfo* LI, const char* Format, ...) attribute ((format(printf,3,4))); /* Add a line to the given code segment */ void CS_InsertEntry (CodeSeg* S, struct CodeEntry* E, unsigned Index); diff --git a/src/cc65/dataseg.c b/src/cc65/dataseg.c index bcc51d2a7..72b22ce76 100644 --- a/src/cc65/dataseg.c +++ b/src/cc65/dataseg.c @@ -81,7 +81,7 @@ void DS_Append (DataSeg* Target, const DataSeg* Source) -void DS_AddLine (DataSeg* S, const char* Format, va_list ap) +void DS_AddVLine (DataSeg* S, const char* Format, va_list ap) /* Add a line to the given data segment */ { /* Format the line */ @@ -94,6 +94,17 @@ void DS_AddLine (DataSeg* S, const char* Format, va_list ap) +void DS_AddLine (DataSeg* S, const char* Format, ...) +/* Add a line to the given data segment */ +{ + va_list ap; + va_start (ap, Format); + DS_AddVLine (S, Format, ap); + va_end (ap); +} + + + void DS_Output (const DataSeg* S, FILE* F) /* Output the data segment data to a file */ { diff --git a/src/cc65/dataseg.h b/src/cc65/dataseg.h index ac1cb4fcc..af1b02448 100644 --- a/src/cc65/dataseg.h +++ b/src/cc65/dataseg.h @@ -77,7 +77,10 @@ DataSeg* NewDataSeg (const char* SegName, SymEntry* Func); void DS_Append (DataSeg* Target, const DataSeg* Source); /* Append the data from Source to Target. */ -void DS_AddLine (DataSeg* S, const char* Format, va_list ap) attribute ((format(printf,2,0))); +void DS_AddVLine (DataSeg* S, const char* Format, va_list ap) attribute ((format(printf,2,0))); +/* Add a line to the given data segment */ + +void DS_AddLine (DataSeg* S, const char* Format, ...) attribute ((format(printf,2,3))); /* Add a line to the given data segment */ void DS_Output (const DataSeg* S, FILE* F); diff --git a/src/cc65/segments.c b/src/cc65/segments.c index 232f9abd8..b4f5ee88b 100644 --- a/src/cc65/segments.c +++ b/src/cc65/segments.c @@ -61,6 +61,9 @@ /* Pointer to the current segment list. Output goes here. */ Segments* CS = 0; +/* Pointer to the global segment list */ +Segments* GS = 0; + /* Actual names for the segments */ static char* SegmentNames[SEG_COUNT]; @@ -202,7 +205,7 @@ void AddTextLine (const char* Format, ...) va_list ap; va_start (ap, Format); CHECK (CS != 0); - TS_AddLine (CS->Text, Format, ap); + TS_AddVLine (CS->Text, Format, ap); va_end (ap); } @@ -214,7 +217,7 @@ void AddCodeLine (const char* Format, ...) va_list ap; va_start (ap, Format); CHECK (CS != 0); - CS_AddLine (CS->Code, CurTok.LI, Format, ap); + CS_AddVLine (CS->Code, CurTok.LI, Format, ap); va_end (ap); } @@ -235,7 +238,7 @@ void AddDataLine (const char* Format, ...) va_list ap; va_start (ap, Format); CHECK (CS != 0); - DS_AddLine (GetDataSeg(), Format, ap); + DS_AddVLine (GetDataSeg(), Format, ap); va_end (ap); } diff --git a/src/cc65/segments.h b/src/cc65/segments.h index 1c9b5fd9a..fde43933d 100644 --- a/src/cc65/segments.h +++ b/src/cc65/segments.h @@ -91,6 +91,9 @@ struct Segments { /* Pointer to the current segment list. Output goes here. */ extern Segments* CS; +/* Pointer to the global segment list */ +extern Segments* GS; + /*****************************************************************************/ @@ -121,7 +124,7 @@ struct DataSeg* GetDataSeg (void); /* Return the current data segment */ void AddTextLine (const char* Format, ...) attribute ((format (printf, 1, 2))); -/* Add a line of code to the current text segment */ +/* Add a line to the current text segment */ void AddCodeLine (const char* Format, ...) attribute ((format (printf, 1, 2))); /* Add a line of code to the current code segment */ diff --git a/src/cc65/textseg.c b/src/cc65/textseg.c index 3ca44990e..f15f13f18 100644 --- a/src/cc65/textseg.c +++ b/src/cc65/textseg.c @@ -70,7 +70,7 @@ TextSeg* NewTextSeg (SymEntry* Func) -void TS_AddLine (TextSeg* S, const char* Format, va_list ap) +void TS_AddVLine (TextSeg* S, const char* Format, va_list ap) /* Add a line to the given text segment */ { /* Format the line */ @@ -83,6 +83,17 @@ void TS_AddLine (TextSeg* S, const char* Format, va_list ap) +void TS_AddLine (TextSeg* S, const char* Format, ...) +/* Add a line to the given text segment */ +{ + va_list ap; + va_start (ap, Format); + TS_AddVLine (S, Format, ap); + va_end (ap); +} + + + void TS_Output (const TextSeg* S, FILE* F) /* Output the text segment data to a file */ { diff --git a/src/cc65/textseg.h b/src/cc65/textseg.h index eeeb4d3fd..568903e12 100644 --- a/src/cc65/textseg.h +++ b/src/cc65/textseg.h @@ -79,7 +79,10 @@ struct TextSeg { TextSeg* NewTextSeg (SymEntry* Func); /* Create a new text segment, initialize and return it */ -void TS_AddLine (TextSeg* S, const char* Format, va_list ap) attribute ((format(printf,2,0))); +void TS_AddVLine (TextSeg* S, const char* Format, va_list ap) attribute ((format(printf,2,0))); +/* Add a line to the given text segment */ + +void TS_AddLine (TextSeg* S, const char* Format, ...) attribute ((format(printf,2,3))); /* Add a line to the given text segment */ void TS_Output (const TextSeg* S, FILE* F); -- 2.39.5