]> git.sur5r.net Git - cc65/blobdiff - src/ld65/objdata.c
Use a string pool to reduce the memory footprint
[cc65] / src / ld65 / objdata.c
index 3b667eace58464e0f4059f2d301b208fac55a248..81320796d4dd03b18dabe5b2e63edd77643252af 100644 (file)
@@ -43,6 +43,7 @@
 #include "error.h"
 #include "fileinfo.h"
 #include "objdata.h"
+#include "spool.h"
 
 
 
@@ -107,13 +108,27 @@ ObjData* NewObjData (void)
 
 
 
-const char* GetObjString (const ObjData* O, unsigned long Index)
+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.
+ */
+{
+    while (O->StringCount) {
+        xfree (O->Strings[--O->StringCount]);
+    }
+    xfree (O->Strings);
+    O->Strings = 0;
+}
+
+
+
+const char* GetObjString (const ObjData* O, unsigned Index)
 /* Get a string from the object file string table. Abort if the string index
  * is invalid.
  */
 {
     if (Index >= O->StringCount) {
-               Error ("Invalid string index (%lu) in module `%s'",
+               Error ("Invalid string index (%u) in module `%s'",
               Index, GetObjFileName (O));
     }
     return O->Strings[Index];
@@ -121,6 +136,18 @@ const char* GetObjString (const ObjData* O, unsigned long Index)
 
 
 
+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));
+    }
+    return GetStringId (O->Strings[Index]);
+}
+
+
+
 const char* GetObjFileName (const ObjData* O)
 /* Get the name of the object file. Return "[linker generated]" if the object
  * file is NULL.