]> git.sur5r.net Git - cc65/commitdiff
Working on the new backend
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 5 May 2001 14:30:29 +0000 (14:30 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sat, 5 May 2001 14:30:29 +0000 (14:30 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@716 b7a2c559-68d2-44c3-8de9-860c34a00d81

12 files changed:
src/cc65/codegen.c
src/cc65/codeseg.c
src/cc65/codeseg.h
src/cc65/dataseg.c
src/cc65/dataseg.h
src/cc65/make/gcc.mak
src/cc65/segments.c
src/cc65/segments.h
src/cc65/segname.c [deleted file]
src/cc65/segname.h [deleted file]
src/cc65/textseg.c [new file with mode: 0644]
src/cc65/textseg.h [new file with mode: 0644]

index 183a91ce9d3f47c886a6c47bb5e7b202c306b467..a41f9dfa21b8ff16b8eed04c5fcff62fa9a72778 100644 (file)
@@ -143,32 +143,32 @@ void g_preamble (void)
     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");
 }
 
 
@@ -318,9 +318,9 @@ void g_defexport (const char* Name, int ZP)
 /* 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);
     }
 }
 
@@ -330,9 +330,9 @@ void g_defimport (const char* Name, int ZP)
 /* 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);
     }
 }
 
index c0be35a021ce5cec53b9a823cae17dbcbb9fab3c..7b716cdce9c0489213643a0991bf392f0da56da7 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (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       */
@@ -321,14 +321,6 @@ CodeSeg* NewCodeSeg (const char* SegName, SymEntry* Func)
 
 
 
-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 */
 {
index 91b8536ecdff28267399268d3f5a0db31aff63cb..4940f39d2f1ee548c090d67d18fe7920931e6835 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (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       */
@@ -37,7 +37,7 @@
 #define CODESEG_H
 
 
-                 
+
 #include <stdarg.h>
 #include <stdio.h>
 
@@ -81,9 +81,6 @@ struct CodeSeg {
 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 */
 
index 980246a05e48d674520bfbb6cc4f6f235cc531f6..78b10eb7e340b37cc0667162e09beacc65cdb57c 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (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       */
@@ -67,14 +67,6 @@ DataSeg* NewDataSeg (const char* Name, SymEntry* Func)
 
 
 
-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 */
 {
index ab62442d98c61efedb4e1129cc1c2d6e1780ac0e..50d692af781cf291c751cd83575072f6f1f39bd2 100644 (file)
@@ -1,15 +1,15 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                                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       */
@@ -74,9 +74,6 @@ struct DataSeg {
 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. */
 
index d9d374e1bfa2d16bfeb346ec10461745abc190e8..32d7fd766c1b980c03ce3a066501d37b0109fb06 100644 (file)
@@ -62,6 +62,7 @@ OBJS =        anonname.o      \
        stmt.o          \
        symentry.o      \
        symtab.o        \
+       textseg.o       \
        typecmp.o       \
        util.o
 
index 654927908c329124f0b0b3e0dcce2e7bfe1da29b..2c6f3e3cd704e77387b3f5209e562195c98bb2fa 100644 (file)
@@ -45,6 +45,7 @@
 /* cc65 */
 #include "codeseg.h"
 #include "dataseg.h"
+#include "textseg.h"
 #include "segments.h"
 
 
@@ -125,6 +126,7 @@ static Segments* NewSegments (SymEntry* Func)
     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);
@@ -190,6 +192,18 @@ struct DataSeg* GetDataSeg (void)
 
 
 
+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 */
 {
@@ -237,6 +251,9 @@ void OutputSegments (const Segments* S, FILE* F)
        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);
index de66af9d7eba55a9cd1f185dec13bb6598a68c74..06c4ae363562b48f4d897e1b396bb7ed433c3c5f 100644 (file)
 
 struct CodeSeg;
 struct DataSeg;
+struct TextSeg;
 struct SymEntry;
 
 
 
 /*****************************************************************************/
-/*                                  Data                                    */
+/*                                  Data                                    */
 /*****************************************************************************/
 
 
@@ -75,6 +76,7 @@ typedef enum segment_t {
 /* 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 */
@@ -114,6 +116,9 @@ void UseDataSeg (segment_t DSeg);
 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 */
 
diff --git a/src/cc65/segname.c b/src/cc65/segname.c
deleted file mode 100644 (file)
index 422d86e..0000000
+++ /dev/null
@@ -1,109 +0,0 @@
-/*****************************************************************************/
-/*                                                                           */
-/*                                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;
-}
-
-
-
diff --git a/src/cc65/segname.h b/src/cc65/segname.h
deleted file mode 100644 (file)
index b200d21..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*****************************************************************************/
-/*                                                                           */
-/*                                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
-
-
-
diff --git a/src/cc65/textseg.c b/src/cc65/textseg.c
new file mode 100644 (file)
index 0000000..0dd302b
--- /dev/null
@@ -0,0 +1,109 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                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");
+}
+
+
+
diff --git a/src/cc65/textseg.h b/src/cc65/textseg.h
new file mode 100644 (file)
index 0000000..c96a522
--- /dev/null
@@ -0,0 +1,94 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                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
+
+
+