#include "error.h"
#include "global.h"
#include "segments.h"
+#include "textseg.h"
#include "util.h"
#include "codegen.h"
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 (";");
/* 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);
}
}
-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 */
{
default: S = 0; break;
}
if (S) {
- OutputDataLine (S, ".segment\t\"%s\"", Name);
+ DS_AddLine (S, ".segment\t\"%s\"", Name);
}
}
-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;
+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.
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);
-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 */
+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 */
{
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);
/* 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];
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);
}
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);
}
va_list ap;
va_start (ap, Format);
CHECK (CS != 0);
- DS_AddLine (GetDataSeg(), Format, ap);
+ DS_AddVLine (GetDataSeg(), Format, ap);
va_end (ap);
}
/* Pointer to the current segment list. Output goes here. */
extern Segments* CS;
+/* Pointer to the global segment list */
+extern Segments* GS;
+
/*****************************************************************************/
/* 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 */
-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 */
+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 */
{
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);