]> git.sur5r.net Git - cc65/blobdiff - src/ld65/condes.c
Removed (pretty inconsistently used) tab chars from source code base.
[cc65] / src / ld65 / condes.c
index cbe03f4cf5e6e3150b46a09dd0270c53d3849ccd..dc8383767fa54b8e0d1a005c7d28a4dbef19c470 100644 (file)
@@ -1,15 +1,15 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                                condes.h                                  */
+/*                                 condes.c                                  */
 /*                                                                           */
-/*                  Module constructor/destructor support                   */
+/*                   Module constructor/destructor support                   */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000      Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 2000-2012, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
 #include <string.h>
 
 /* common */
+#include "addrsize.h"
 #include "check.h"
 #include "coll.h"
-#include "segdefs.h"
+#include "filepos.h"
+#include "fragdefs.h"
 #include "xmalloc.h"
 
 /* ld65 */
+#include "condes.h"
 #include "exports.h"
 #include "fragment.h"
 #include "segments.h"
-#include "condes.h"
+#include "spool.h"
 
 
 
 /*****************************************************************************/
-/*                                          Data                                    */
+/*                                   Data                                    */
 /*****************************************************************************/
 
 
 /* Struct describing one condes type */
 typedef struct ConDesDesc ConDesDesc;
 struct ConDesDesc {
-    Collection         ExpList;        /* List of exported symbols */
-    char*              SegName;        /* Name of segment the table is in */
-    char*              Label;          /* Name of table label */
-    char*              CountSym;       /* Name of symbol for entry count */
-    unsigned char      Order;          /* Table order (increasing/decreasing) */
+    Collection          ExpList;        /* List of exported symbols */
+    unsigned            SegName;        /* Name of segment the table is in */
+    unsigned            Label;          /* Name of table label */
+    unsigned            CountSym;       /* Name of symbol for entry count */
+    unsigned char       Order;          /* Table order (increasing/decreasing) */
+    ConDesImport        Import;         /* Forced import if any */
 };
 
 /* Array for all types */
 static ConDesDesc ConDes[CD_TYPE_COUNT] = {
-    { STATIC_COLLECTION_INITIALIZER, 0, 0, 0, cdIncreasing },
-    { STATIC_COLLECTION_INITIALIZER, 0, 0, 0, cdIncreasing },
-    { STATIC_COLLECTION_INITIALIZER, 0, 0, 0, cdIncreasing },
-    { STATIC_COLLECTION_INITIALIZER, 0, 0, 0, cdIncreasing },
-    { STATIC_COLLECTION_INITIALIZER, 0, 0, 0, cdIncreasing },
-    { STATIC_COLLECTION_INITIALIZER, 0, 0, 0, cdIncreasing },
-    { STATIC_COLLECTION_INITIALIZER, 0, 0, 0, cdIncreasing },
+    {
+        STATIC_COLLECTION_INITIALIZER,
+        INVALID_STRING_ID,
+        INVALID_STRING_ID,
+        INVALID_STRING_ID,
+        cdIncreasing,
+        { INVALID_STRING_ID, STATIC_FILEPOS_INITIALIZER, ADDR_SIZE_DEFAULT },
+    },{
+        STATIC_COLLECTION_INITIALIZER,
+        INVALID_STRING_ID,
+        INVALID_STRING_ID,
+        INVALID_STRING_ID,
+        cdIncreasing,
+        { INVALID_STRING_ID, STATIC_FILEPOS_INITIALIZER, ADDR_SIZE_DEFAULT },
+    },{
+        STATIC_COLLECTION_INITIALIZER,
+        INVALID_STRING_ID,
+        INVALID_STRING_ID,
+        INVALID_STRING_ID,
+        cdIncreasing,
+        { INVALID_STRING_ID, STATIC_FILEPOS_INITIALIZER, ADDR_SIZE_DEFAULT },
+    },{
+        STATIC_COLLECTION_INITIALIZER,
+        INVALID_STRING_ID,
+        INVALID_STRING_ID,
+        INVALID_STRING_ID,
+        cdIncreasing,
+        { INVALID_STRING_ID, STATIC_FILEPOS_INITIALIZER, ADDR_SIZE_DEFAULT },
+    },{
+        STATIC_COLLECTION_INITIALIZER,
+        INVALID_STRING_ID,
+        INVALID_STRING_ID,
+        INVALID_STRING_ID,
+        cdIncreasing,
+        { INVALID_STRING_ID, STATIC_FILEPOS_INITIALIZER, ADDR_SIZE_DEFAULT },
+    },{
+        STATIC_COLLECTION_INITIALIZER,
+        INVALID_STRING_ID,
+        INVALID_STRING_ID,
+        INVALID_STRING_ID,
+        cdIncreasing,
+        { INVALID_STRING_ID, STATIC_FILEPOS_INITIALIZER, ADDR_SIZE_DEFAULT },
+    },{
+        STATIC_COLLECTION_INITIALIZER,
+        INVALID_STRING_ID,
+        INVALID_STRING_ID,
+        INVALID_STRING_ID,
+        cdIncreasing,
+        { INVALID_STRING_ID, STATIC_FILEPOS_INITIALIZER, ADDR_SIZE_DEFAULT },
+    },
 };
 
 
 
 /*****************************************************************************/
-/*          Internally used function to create the condes tables            */
+/*           Internally used function to create the condes tables            */
 /*****************************************************************************/
 
 
@@ -104,19 +151,19 @@ static int ConDesCompare (void* Data, const void* E1, const void* E2)
 
     /* Compare the priorities for this condes type */
     if (Prio1 < Prio2) {
-               Cmp = -1;
+        Cmp = -1;
     } else if (Prio1 > Prio2) {
-       Cmp = 1;
+        Cmp = 1;
     } else {
-       /* Use the name in this case */
-               Cmp = strcmp (Exp1->Name, Exp2->Name);
+        /* Use the name in this case */
+        Cmp = SB_Compare (GetStrBuf (Exp1->Name), GetStrBuf (Exp2->Name));
     }
 
     /* Reverse the result for decreasing order */
     if (CD->Order == cdIncreasing) {
-       return Cmp;
+        return Cmp;
     } else {
-       return -Cmp;
+        return -Cmp;
     }
 }
 
@@ -125,16 +172,16 @@ static int ConDesCompare (void* Data, const void* E1, const void* E2)
 static void ConDesCreateOne (ConDesDesc* CD)
 /* Create one table if requested */
 {
-    Segment*   Seg;            /* Segment for table */
-    Section*   Sec;            /* Section for table */
-    unsigned   Count;          /* Number of exports */
-    unsigned   I;
+    Segment*    Seg;            /* Segment for table */
+    Section*    Sec;            /* Section for table */
+    unsigned    Count;          /* Number of exports */
+    unsigned    I;
 
     /* Check if this table has a segment and table label defined. If not,
      * creation was not requested in the config file - ignore it.
      */
-    if (CD->SegName == 0 || CD->Label == 0) {
-       return;
+    if (CD->SegName == INVALID_STRING_ID || CD->Label == INVALID_STRING_ID) {
+        return;
     }
 
     /* Check if there is an import for the table label. If not, there is no
@@ -142,17 +189,17 @@ static void ConDesCreateOne (ConDesDesc* CD)
      * table.
      */
     if (!IsUnresolved (CD->Label)) {
-       return;
+        return;
     }
 
     /* Sort the collection of exports according to priority */
     CollSort (&CD->ExpList, ConDesCompare, CD);
 
     /* Get the segment for the table, create it if needed */
-    Seg = GetSegment (CD->SegName, SEGTYPE_ABS, 0);
+    Seg = GetSegment (CD->SegName, ADDR_SIZE_ABS, 0);
 
     /* Create a new section for the table */
-    Sec = NewSection (Seg, 1, SEGTYPE_ABS);
+    Sec = NewSection (Seg, 1, ADDR_SIZE_ABS);
 
     /* Walk over the exports and create a fragment for each one. We will use
      * the exported expression without copying it, since it's cheap and there
@@ -162,33 +209,33 @@ static void ConDesCreateOne (ConDesDesc* CD)
     Count = CollCount (&CD->ExpList);
     for (I = 0; I < Count; ++I) {
 
-       /* Get the export */
-       Export* E = CollAt (&CD->ExpList, I);
+        /* Get the export */
+        Export* E = CollAt (&CD->ExpList, I);
 
-       /* Create the fragment */
-       Fragment* F = NewFragment (FRAG_EXPR, 2, Sec);
+        /* Create the fragment */
+        Fragment* F = NewFragment (FRAG_EXPR, 2, Sec);
 
-       /* Set the expression pointer */
-       F->Expr = E->Expr;
+        /* Set the expression pointer */
+        F->Expr = E->Expr;
     }
 
     /* Define the table start as an export, offset into section is zero
      * (the section only contains the table).
      */
-    CreateSectionExport (CD->Label,    Sec, 0);
+    CreateSectionExport (CD->Label, Sec, 0);
 
     /* If we have a CountSym name given AND if it is referenced, define it
      * with the number of elements in the table.
      */
     if (CD->CountSym) {
-       CreateConstExport (CD->CountSym, Count);
+        CreateConstExport (CD->CountSym, Count);
     }
 }
 
 
 
 /*****************************************************************************/
-/*                                          Code                                    */
+/*                                   Code                                    */
 /*****************************************************************************/
 
 
@@ -200,56 +247,88 @@ void ConDesAddExport (struct Export* E)
 
     /* Insert the export into all tables for which declarations exist */
     for (Type = 0; Type < CD_TYPE_COUNT; ++Type) {
-       unsigned Prio = E->ConDes[Type];
-       if (Prio != CD_PRIO_NONE) {
-                   CollAppend (&ConDes[Type].ExpList, E);
-       }
+        unsigned Prio = E->ConDes[Type];
+        if (Prio != CD_PRIO_NONE) {
+            CollAppend (&ConDes[Type].ExpList, E);
+        }
     }
 }
 
 
 
-void ConDesSetSegName (unsigned Type, const char* SegName)
+void ConDesSetSegName (unsigned Type, unsigned SegName)
 /* Set the segment name where the table should go */
 {
     /* Check the parameters */
     PRECONDITION (Type <= CD_TYPE_MAX && SegName != 0);
 
     /* Setting the segment name twice is bad */
-    CHECK (ConDes[Type].SegName == 0);
+    CHECK (ConDes[Type].SegName == INVALID_STRING_ID);
 
     /* Set the name */
-    ConDes[Type].SegName = xstrdup (SegName);
+    ConDes[Type].SegName = SegName;
+}
+
+
+
+const ConDesImport* ConDesGetImport (unsigned Type)
+/* Get the forced import for the given ConDes type. Returns NULL if there is
+ * no forced import for this type.
+ */
+{
+    const ConDesImport* Import;
+
+    /* Check the parameters */
+    PRECONDITION (Type <= CD_TYPE_MAX);
+
+    /* Return the import */    
+    Import = &ConDes[Type].Import;
+    return (Import->Name != INVALID_STRING_ID)? Import : 0;
 }
 
 
 
-void ConDesSetLabel (unsigned Type, const char* Name)
+void ConDesSetImport (unsigned Type, const ConDesImport* Import)
+/* Set the forced import for the given ConDes type */
+{
+    /* Check the parameters */
+    PRECONDITION (Type <= CD_TYPE_MAX && Import != 0);
+
+    /* Setting the import twice is bad */
+    CHECK (ConDes[Type].Import.Name == INVALID_STRING_ID);
+
+    /* Set the import and its position */
+    ConDes[Type].Import = *Import;
+}
+
+
+
+void ConDesSetLabel (unsigned Type, unsigned Name)
 /* Set the label for the given ConDes type */
 {
     /* Check the parameters */
     PRECONDITION (Type <= CD_TYPE_MAX && Name != 0);
 
     /* Setting the label twice is bad */
-    CHECK (ConDes[Type].Label == 0);
+    CHECK (ConDes[Type].Label == INVALID_STRING_ID);
 
     /* Set the name */
-    ConDes[Type].Label = xstrdup (Name);
+    ConDes[Type].Label = Name;
 }
 
 
 
-void ConDesSetCountSym (unsigned Type, const char* Name)
+void ConDesSetCountSym (unsigned Type, unsigned Name)
 /* Set the name for the given ConDes count symbol */
 {
     /* Check the parameters */
     PRECONDITION (Type <= CD_TYPE_MAX && Name != 0);
 
     /* Setting the symbol twice is bad */
-    CHECK (ConDes[Type].CountSym == 0);
+    CHECK (ConDes[Type].CountSym == INVALID_STRING_ID);
 
     /* Set the name */
-    ConDes[Type].CountSym = xstrdup (Name);
+    ConDes[Type].CountSym = Name;
 }
 
 
@@ -272,7 +351,7 @@ int ConDesHasSegName (unsigned Type)
     /* Check the parameters */
     PRECONDITION (Type <= CD_TYPE_MAX);
 
-    return (ConDes[Type].SegName != 0);
+    return (ConDes[Type].SegName != INVALID_STRING_ID);
 }
 
 
@@ -283,7 +362,7 @@ int ConDesHasLabel (unsigned Type)
     /* Check the parameters */
     PRECONDITION (Type <= CD_TYPE_MAX);
 
-    return (ConDes[Type].Label != 0);
+    return (ConDes[Type].Label != INVALID_STRING_ID);
 }
 
 
@@ -295,7 +374,7 @@ void ConDesCreate (void)
 
     /* Walk over the descriptor array and create a table for each entry */
     for (Type = 0; Type < CD_TYPE_COUNT; ++Type) {
-       ConDesCreateOne (ConDes + Type);
+        ConDesCreateOne (ConDes + Type);
     }
 }
 
@@ -306,12 +385,10 @@ void ConDesDump (void)
 {
     unsigned Type;
     for (Type = 0; Type < CD_TYPE_COUNT; ++Type) {
-               Collection* ExpList = &ConDes[Type].ExpList;
-       printf ("CONDES(%u): %u symbols\n", Type, CollCount (ExpList));
+        Collection* ExpList = &ConDes[Type].ExpList;
+        printf ("CONDES(%u): %u symbols\n", Type, CollCount (ExpList));
     }
 }
 
 
 
-
-