PushSegments (0);
/* Identify the compiler version */
- AddDataLine ("; File generated by cc65 v %u.%u.%u",
- VER_MAJOR, VER_MINOR, VER_PATCH);
+ AddTextLine ("; File generated by cc65 v %u.%u.%u",
+ VER_MAJOR, VER_MINOR, VER_PATCH);
/* Insert some object file options */
- AddDataLine (".fopt\t\tcompiler,\"cc65 v %u.%u.%u\"",
- VER_MAJOR, VER_MINOR, VER_PATCH);
+ AddTextLine (".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) {
- AddDataLine (".pc02");
+ AddTextLine (".pc02");
}
/* Allow auto import for runtime library routines */
- AddDataLine (".autoimport\ton");
+ AddTextLine (".autoimport\ton");
/* Switch the assembler into case sensitive mode */
- AddDataLine (".case\t\ton");
+ AddTextLine (".case\t\ton");
/* Tell the assembler if we want to generate debug info */
- AddDataLine (".debuginfo\t%s", (DebugInfo != 0)? "on" : "off");
+ AddTextLine (".debuginfo\t%s", (DebugInfo != 0)? "on" : "off");
/* Import the stack pointer for direct auto variable access */
- AddDataLine (".importzp\tsp, sreg, regsave, regbank, tmp1, ptr1");
+ AddTextLine (".importzp\tsp, sreg, regsave, regbank, tmp1, ptr1");
/* Define long branch macros */
- AddDataLine (".macpack\tlongbranch");
+ AddTextLine (".macpack\tlongbranch");
}
/* Export the given label */
{
if (ZP) {
- AddDataLine ("\t.exportzp\t_%s", Name);
+ AddTextLine ("\t.exportzp\t_%s", Name);
} else {
- AddDataLine ("\t.export\t\t_%s", Name);
+ AddTextLine ("\t.export\t\t_%s", Name);
}
}
/* Import the given label */
{
if (ZP) {
- AddDataLine ("\t.importzp\t_%s", Name);
+ AddTextLine ("\t.importzp\t_%s", Name);
} else {
- AddDataLine ("\t.import\t\t_%s", Name);
+ AddTextLine ("\t.import\t\t_%s", Name);
}
}
/* */
/* */
/* */
-/* (C) 2001 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (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 */
-void FreeCodeSeg (CodeSeg* S)
-/* Free a code segment including all code entries */
-{
- Internal ("Not implemented");
-}
-
-
-
void AddCodeEntry (CodeSeg* S, const char* Format, va_list ap)
/* Add a line to the given code segment */
{
/* */
/* */
/* */
-/* (C) 2001 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (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 */
#define CODESEG_H
-
+
#include <stdarg.h>
#include <stdio.h>
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 AddCodeEntry (CodeSeg* S, const char* Format, va_list ap) attribute ((format(printf,2,0)));
/* Add a line to the given code segment */
/* */
/* */
/* */
-/* (C) 2001 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (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 */
-void FreeDataSeg (DataSeg* S)
-/* Free a data segment including all line entries */
-{
- Internal ("Not implemented");
-}
-
-
-
void AppendDataSeg (DataSeg* Target, const DataSeg* Source)
/* Append the data from Source to Target */
{
/*****************************************************************************/
/* */
-/* dataseg.h */
+/* dataseg.h */
/* */
-/* Data segment structure */
+/* Data segment structure */
/* */
/* */
/* */
-/* (C) 2001 Ullrich von Bassewitz */
-/* Wacholderweg 14 */
-/* D-70597 Stuttgart */
-/* EMail: uz@musoftware.de */
+/* (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 */
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 AppendDataSeg (DataSeg* Target, const DataSeg* Source);
/* Append the data from Source to Target. */
stmt.o \
symentry.o \
symtab.o \
+ textseg.o \
typecmp.o \
util.o
/* cc65 */
#include "codeseg.h"
#include "dataseg.h"
+#include "textseg.h"
#include "segments.h"
Segments* S = xmalloc (sizeof (Segments));
/* Initialize the fields */
+ S->Text = NewTextSeg (Func);
S->Code = NewCodeSeg (SegmentNames[SEG_CODE], Func);
S->Data = NewDataSeg (SegmentNames[SEG_DATA], Func);
S->ROData = NewDataSeg (SegmentNames[SEG_RODATA], Func);
+void AddTextLine (const char* Format, ...)
+/* Add a line of code to the current text segment */
+{
+ va_list ap;
+ va_start (ap, Format);
+ CHECK (CS != 0);
+ AddTextEntry (CS->Text, Format, ap);
+ va_end (ap);
+}
+
+
+
void AddCodeLine (const char* Format, ...)
/* Add a line of code to the current code segment */
{
PrintFunctionHeader (S->Code->Func, F);
}
+ /* Output the text segment */
+ OutputTextSeg (S->Text, F);
+
/* Output the three data segments */
OutputDataSeg (S->Data, F);
OutputDataSeg (S->ROData, F);
struct CodeSeg;
struct DataSeg;
+struct TextSeg;
struct SymEntry;
/*****************************************************************************/
-/* Data */
+/* Data */
/*****************************************************************************/
/* A list of all segments used when generating code */
typedef struct Segments Segments;
struct Segments {
+ struct TextSeg* Text; /* Text segment */
struct CodeSeg* Code; /* Code segment */
struct DataSeg* Data; /* Data segment */
struct DataSeg* ROData; /* Readonly data segment */
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 */
+
void AddCodeLine (const char* Format, ...) attribute ((format (printf, 1, 2)));
/* Add a line of code to the current code segment */
+++ /dev/null
-/*****************************************************************************/
-/* */
-/* segname.c */
-/* */
-/* Segment name management */
-/* */
-/* */
-/* */
-/* (C) 2000 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 <string.h>
-
-/* common */
-#include "chartype.h"
-#include "check.h"
-#include "xmalloc.h"
-
-/* cc65 */
-#include "segname.h"
-
-
-
-/*****************************************************************************/
-/* Data */
-/*****************************************************************************/
-
-
-
-/* Actual names for the segments */
-char* SegmentNames[SEG_COUNT];
-
-
-
-/*****************************************************************************/
-/* 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 */
-{
- /* Check the parameter */
- CHECK (Seg != SEG_INV);
-
- /* 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;
-}
-
-
-
+++ /dev/null
-/*****************************************************************************/
-/* */
-/* segname.h */
-/* */
-/* Segment name management */
-/* */
-/* */
-/* */
-/* (C) 2000 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 SEGNAME_H
-#define SEGNAME_H
-
-
-
-/*****************************************************************************/
-/* Data */
-/*****************************************************************************/
-
-
-
-/* Current segment */
-typedef enum segment_t {
- SEG_INV = -1, /* Invalid segment */
- SEG_CODE,
- SEG_RODATA,
- SEG_DATA,
- SEG_BSS,
- SEG_COUNT
-} segment_t;
-
-/* Actual names for the segments */
-extern char* SegmentNames[SEG_COUNT];
-
-
-
-/*****************************************************************************/
-/* 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 */
-
-
-
-/* End of segname.h */
-
-#endif
-
-
-
--- /dev/null
+/*****************************************************************************/
+/* */
+/* textseg.c */
+/* */
+/* Text segment structure */
+/* */
+/* */
+/* */
+/* (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. */
+/* */
+/*****************************************************************************/
+
+
+
+/* Note: This is NOT some sort of code segment, it is used to store lines of
+ * output that are textual (not real code) instead.
+ */
+
+
+
+/* common */
+#include "xmalloc.h"
+#include "xsprintf.h"
+
+/* cc65 */
+#include "textseg.h"
+
+
+
+/*****************************************************************************/
+/* Code */
+/*****************************************************************************/
+
+
+
+TextSeg* NewTextSeg (SymEntry* Func)
+/* Create a new text segment, initialize and return it */
+{
+ /* Allocate memory for the structure */
+ TextSeg* S = xmalloc (sizeof (TextSeg));
+
+ /* Initialize the fields */
+ S->Func = Func;
+ InitCollection (&S->Lines);
+
+ /* Return the new struct */
+ return S;
+}
+
+
+
+void AddTextEntry (TextSeg* S, const char* Format, va_list ap)
+/* Add a line to the given text segment */
+{
+ /* Format the line */
+ char Buf [256];
+ xvsprintf (Buf, sizeof (Buf), Format, ap);
+
+ /* Add a copy to the data segment */
+ CollAppend (&S->Lines, xstrdup (Buf));
+}
+
+
+
+void OutputTextSeg (const TextSeg* S, FILE* F)
+/* Output the text segment data to a file */
+{
+ unsigned I;
+
+ /* 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 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");
+}
+
+
+
--- /dev/null
+/*****************************************************************************/
+/* */
+/* textseg.h */
+/* */
+/* Text segment structure */
+/* */
+/* */
+/* */
+/* (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. */
+/* */
+/*****************************************************************************/
+
+
+
+/* Note: This is NOT some sort of code segment, it is used to store lines of
+ * output that are textual (not real code) instead.
+ */
+
+
+
+#ifndef TEXTSEG_H
+#define TEXTSEG_H
+
+
+
+#include <stdarg.h>
+#include <stdio.h>
+
+/* common */
+#include "attrib.h"
+#include "coll.h"
+
+/* cc65 */
+#include "symentry.h"
+
+
+
+/*****************************************************************************/
+/* Data */
+/*****************************************************************************/
+
+
+
+typedef struct TextSeg TextSeg;
+struct TextSeg {
+ SymEntry* Func; /* Owner function */
+ Collection Lines; /* List of text lines */
+};
+
+
+
+/*****************************************************************************/
+/* Code */
+/*****************************************************************************/
+
+
+
+TextSeg* NewTextSeg (SymEntry* Func);
+/* Create a new text segment, initialize and return it */
+
+void AddTextEntry (TextSeg* S, const char* Format, va_list ap) attribute ((format(printf,2,0)));
+/* Add a line to the given text segment */
+
+void OutputTextSeg (const TextSeg* S, FILE* F);
+/* Output the text segment data to a file */
+
+
+
+/* End of textseg.h */
+#endif
+
+
+