]> git.sur5r.net Git - cc65/blobdiff - src/ld65/objdata.c
Revert "atari5200: fix COLOR defines' names"
[cc65] / src / ld65 / objdata.c
index 1635c14a07fa0263e276ecf3f709fcc03a2be79d..88a7bded4ce10d1105c981863856512b11ccee6b 100644 (file)
@@ -1,8 +1,8 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                                objdata.c                                 */
+/*                                 objdata.c                                 */
 /*                                                                           */
-/*              Handling object file data for the ld65 linker               */
+/*               Handling object file data for the ld65 linker               */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
@@ -50,7 +50,7 @@
 
 
 /*****************************************************************************/
-/*                                          Data                                    */
+/*                                   Data                                    */
 /*****************************************************************************/
 
 
@@ -61,7 +61,7 @@ Collection       ObjDataList = STATIC_COLLECTION_INITIALIZER;
 
 
 /*****************************************************************************/
-/*                                          Code                                    */
+/*                                   Code                                    */
 /*****************************************************************************/
 
 
@@ -73,24 +73,28 @@ ObjData* NewObjData (void)
     ObjData* O = xmalloc (sizeof (ObjData));
 
     /* Initialize the data */
-    O->Next            = 0;
-    O->Name            = INVALID_STRING_ID;
+    O->Next             = 0;
+    O->Name             = INVALID_STRING_ID;
     O->Lib              = 0;
     O->MTime            = 0;
-    O->Start           = 0;
-    O->Flags                   = 0;
+    O->Start            = 0;
+    O->Flags            = 0;
+    O->HLLSymBaseId     = 0;
     O->SymBaseId        = 0;
     O->ScopeBaseId      = 0;
+    O->SpanBaseId       = 0;
     O->Files            = EmptyCollection;
     O->Sections         = EmptyCollection;
-    O->Exports         = EmptyCollection;
-    O->Imports         = EmptyCollection;
-    O->DbgSyms         = EmptyCollection;
+    O->Exports          = EmptyCollection;
+    O->Imports          = EmptyCollection;
+    O->DbgSyms          = EmptyCollection;
+    O->HLLDbgSyms       = EmptyCollection;
     O->LineInfos        = EmptyCollection;
     O->StringCount      = 0;
     O->Strings          = 0;
     O->Assertions       = EmptyCollection;
     O->Scopes           = EmptyCollection;
+    O->Spans            = EmptyCollection;
 
     /* Return the new entry */
     return O;
@@ -100,9 +104,9 @@ ObjData* NewObjData (void)
 
 void FreeObjData (ObjData* O)
 /* Free an ObjData object. NOTE: This function works only for unused object
- * data, that is, ObjData objects that aren't used because they aren't
- * referenced.
- */
+** data, that is, ObjData objects that aren't used because they aren't
+** referenced.
+*/
 {
     unsigned I;
 
@@ -120,6 +124,7 @@ void FreeObjData (ObjData* O)
     }
     DoneCollection (&O->Imports);
     DoneCollection (&O->DbgSyms);
+    DoneCollection (&O->HLLDbgSyms);
 
     for (I = 0; I < CollCount (&O->LineInfos); ++I) {
         FreeLineInfo (CollAtUnchecked (&O->LineInfos, I));
@@ -128,6 +133,11 @@ void FreeObjData (ObjData* O)
     xfree (O->Strings);
     DoneCollection (&O->Assertions);
     DoneCollection (&O->Scopes);
+    for (I = 0; I < CollCount (&O->Spans); ++I) {
+        FreeSpan (CollAtUnchecked (&O->Spans, I));
+    }
+    DoneCollection (&O->Spans);
+
     xfree (O);
 }
 
@@ -135,8 +145,8 @@ void FreeObjData (ObjData* O)
 
 void FreeObjStrings (ObjData* O)
 /* Free the module string data. Used once the object file is loaded completely
- * when all strings are converted to global strings.
- */
+** when all strings are converted to global strings.
+*/
 {
     xfree (O->Strings);
     O->Strings = 0;
@@ -154,8 +164,8 @@ void InsertObjData (ObjData* O)
 
 void InsertObjGlobals (ObjData* O)
 /* Insert imports and exports from the object file into the global import and
- * export lists.
- */
+** export lists.
+*/
 {
     unsigned I;
 
@@ -174,8 +184,8 @@ unsigned MakeGlobalStringId (const ObjData* O, unsigned Index)
 /* Convert a local string id into a global one and return it. */
 {
     if (Index >= O->StringCount) {
-               Error ("Invalid string index (%u) in module `%s'",
-              Index, GetObjFileName (O));
+        Error ("Invalid string index (%u) in module '%s'",
+               Index, GetObjFileName (O));
     }
     return O->Strings[Index];
 }
@@ -184,19 +194,27 @@ unsigned MakeGlobalStringId (const ObjData* O, unsigned Index)
 
 const char* GetObjFileName (const ObjData* O)
 /* Get the name of the object file. Return "[linker generated]" if the object
- * file is NULL.
- */
+** file is NULL.
+*/
 {
     return O? GetString (O->Name) : "[linker generated]";
 }
 
 
 
-struct Section* GetObjSection (ObjData* O, unsigned Id)
+const struct StrBuf* GetObjString (const ObjData* Obj, unsigned Id)
+/* Get a string from an object file checking for an invalid index */
+{
+    return GetStrBuf (MakeGlobalStringId (Obj, Id));
+}
+
+
+
+struct Section* GetObjSection (const ObjData* O, unsigned Id)
 /* Get a section from an object file checking for a valid index */
 {
     if (Id >= CollCount (&O->Sections)) {
-        Error ("Invalid section index (%u) in module `%s'",
+        Error ("Invalid section index (%u) in module '%s'",
                Id, GetObjFileName (O));
     }
     return CollAtUnchecked (&O->Sections, Id);
@@ -204,11 +222,47 @@ struct Section* GetObjSection (ObjData* O, unsigned Id)
 
 
 
-struct Scope* GetObjScope (ObjData* O, unsigned Id)
+struct Import* GetObjImport (const ObjData* O, unsigned Id)
+/* Get an import from an object file checking for a valid index */
+{
+    if (Id >= CollCount (&O->Imports)) {
+        Error ("Invalid import index (%u) in module '%s'",
+               Id, GetObjFileName (O));
+    }
+    return CollAtUnchecked (&O->Imports, Id);
+}
+
+
+
+struct Export* GetObjExport (const ObjData* O, unsigned Id)
+/* Get an export from an object file checking for a valid index */
+{
+    if (Id >= CollCount (&O->Exports)) {
+        Error ("Invalid export index (%u) in module '%s'",
+               Id, GetObjFileName (O));
+    }
+    return CollAtUnchecked (&O->Exports, Id);
+}
+
+
+
+struct DbgSym* GetObjDbgSym (const ObjData* O, unsigned Id)
+/* Get a debug symbol from an object file checking for a valid index */
+{
+    if (Id >= CollCount (&O->DbgSyms)) {
+        Error ("Invalid debug symbol index (%u) in module '%s'",
+               Id, GetObjFileName (O));
+    }
+    return CollAtUnchecked (&O->DbgSyms, Id);
+}
+
+
+
+struct Scope* GetObjScope (const ObjData* O, unsigned Id)
 /* Get a scope from an object file checking for a valid index */
 {
     if (Id >= CollCount (&O->Scopes)) {
-        Error ("Invalid scope index (%u) in module `%s'",
+        Error ("Invalid scope index (%u) in module '%s'",
                Id, GetObjFileName (O));
     }
     return CollAtUnchecked (&O->Scopes, Id);
@@ -216,6 +270,14 @@ struct Scope* GetObjScope (ObjData* O, unsigned Id)
 
 
 
+unsigned ObjDataCount (void)
+/* Return the total number of modules */
+{
+    return CollCount (&ObjDataList);
+}
+
+
+
 void PrintDbgModules (FILE* F)
 /* Output the modules to a debug info file */
 {
@@ -247,6 +309,3 @@ void PrintDbgModules (FILE* F)
     }
 
 }
-
-
-