]> git.sur5r.net Git - cc65/blobdiff - src/cc65/segments.c
Allow any number of optional braces around all initializers as required by the standard
[cc65] / src / cc65 / segments.c
index 2c6f3e3cd704e77387b3f5209e562195c98bb2fa..dd7817b8887149d68ead2401edad3c0b0c411653 100644 (file)
 #include "chartype.h"
 #include "check.h"
 #include "coll.h"
+#include "scanner.h"
+#include "segnames.h"
 #include "xmalloc.h"
 
 /* cc65 */
+#include "codeent.h"
 #include "codeseg.h"
 #include "dataseg.h"
 #include "textseg.h"
@@ -59,6 +62,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];
 
@@ -80,10 +86,10 @@ static Collection SegmentStack = STATIC_COLLECTION_INITIALIZER;
 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");
+    SegmentNames [SEG_BSS]     = xstrdup (SEGNAME_BSS);
+    SegmentNames [SEG_CODE]    = xstrdup (SEGNAME_CODE);
+    SegmentNames [SEG_DATA]    = xstrdup (SEGNAME_DATA);
+    SegmentNames [SEG_RODATA]  = xstrdup (SEGNAME_RODATA);
 }
 
 
@@ -98,27 +104,6 @@ void NewSegName (segment_t Seg, const char* 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;
-}
-
-
-
 static Segments* NewSegments (SymEntry* Func)
 /* Initialize a Segments structure (set all fields to NULL) */
 {
@@ -186,7 +171,9 @@ struct DataSeg* GetDataSeg (void)
        case SEG_BSS:     return CS->BSS;
        case SEG_DATA:    return CS->Data;
        case SEG_RODATA:  return CS->ROData;
-       default:          FAIL ("Invalid data segment");
+       default:
+           FAIL ("Invalid data segment");
+           return 0;
     }
 }
 
@@ -198,7 +185,7 @@ void AddTextLine (const char* Format, ...)
     va_list ap;
     va_start (ap, Format);
     CHECK (CS != 0);
-    AddTextEntry (CS->Text, Format, ap);
+    TS_AddVLine (CS->Text, Format, ap);
     va_end (ap);
 }
 
@@ -210,35 +197,29 @@ void AddCodeLine (const char* Format, ...)
     va_list ap;
     va_start (ap, Format);
     CHECK (CS != 0);
-    AddCodeEntry (CS->Code, Format, ap);
+    CS_AddVLine (CS->Code, CurTok.LI, Format, ap);
     va_end (ap);
 }
 
 
 
-void AddDataLine (const char* Format, ...)
-/* Add a line of data to the current data segment */
+void AddCode (opc_t OPC, am_t AM, const char* Arg, struct CodeLabel* JumpTo)
+/* Add a code entry to the current code segment */
 {
-    va_list ap;
-    va_start (ap, Format);
     CHECK (CS != 0);
-    AddDataEntry (GetDataSeg(), Format, ap);
-    va_end (ap);
+    CS_AddEntry (CS->Code, NewCodeEntry (OPC, AM, Arg, JumpTo, CurTok.LI));
 }
 
 
 
-static void PrintFunctionHeader (const SymEntry* Entry, FILE* F)
+void AddDataLine (const char* Format, ...)
+/* Add a line of data to the current data segment */
 {
-    /* Print a comment with the function signature */
-    fprintf (F,
-            "; ---------------------------------------------------------------\n"
-            "; ");
-    PrintFuncSig (F, Entry->Name, Entry->Type);
-    fprintf (F,
-                    "\n"
-            "; ---------------------------------------------------------------\n"
-            "\n");
+    va_list ap;
+    va_start (ap, Format);
+    CHECK (CS != 0);
+    DS_AddVLine (GetDataSeg(), Format, ap);
+    va_end (ap);
 }
 
 
@@ -246,21 +227,22 @@ static void PrintFunctionHeader (const SymEntry* Entry, FILE* F)
 void OutputSegments (const Segments* S, FILE* F)
 /* Output the given segments to the file */
 {
-    /* If the code segment is associated with a function, print a function header */
-    if (S->Code->Func) {
-       PrintFunctionHeader (S->Code->Func, F);
-    }
+    /* Output the function prologue if the segments came from a function */
+    CS_OutputPrologue (S->Code, F);
 
     /* Output the text segment */
-    OutputTextSeg (S->Text, F);
+    TS_Output (S->Text, F);
 
     /* Output the three data segments */
-    OutputDataSeg (S->Data, F);
-    OutputDataSeg (S->ROData, F);
-    OutputDataSeg (S->BSS, F);
+    DS_Output (S->Data, F);
+    DS_Output (S->ROData, F);
+    DS_Output (S->BSS, F);
 
     /* Output the code segment */
-    OutputCodeSeg (S->Code, F);
+    CS_Output (S->Code, F);
+
+    /* Output the code segment epiloque */
+    CS_OutputEpilogue (S->Code, F);
 }