]> git.sur5r.net Git - cc65/blobdiff - src/ld65/lineinfo.c
Typo
[cc65] / src / ld65 / lineinfo.c
index d56bfc3bd58c5d62f46485391ee716e3369354ae..25eca4fcdcf51aeccb1ea6974398d66186e88335 100644 (file)
@@ -1,12 +1,12 @@
 /*****************************************************************************/
 /*                                                                           */
-/*                               lineinfo.h                                 */
+/*                                lineinfo.h                                 */
 /*                                                                           */
-/*                     Source file line info structure                      */
+/*                      Source file line info structure                      */
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2001-2011, Ullrich von Bassewitz                                      */
+/* (C) 2001-2012, Ullrich von Bassewitz                                      */
 /*                Roemerstrasse 52                                           */
 /*                D-70794 Filderstadt                                        */
 /* EMail:         uz@cc65.org                                                */
@@ -49,7 +49,7 @@
 
 
 /*****************************************************************************/
-/*                                          Code                                    */
+/*                                   Code                                    */
 /*****************************************************************************/
 
 
@@ -61,12 +61,13 @@ static LineInfo* NewLineInfo (void)
     LineInfo* LI = xmalloc (sizeof (LineInfo));
 
     /* Initialize the fields */
+    LI->Id         = ~0U;
     LI->File       = 0;
-    LI->Type       = LI_TYPE_ASM;
+    LI->Type       = LI_MAKE_TYPE (LI_TYPE_ASM, 0);
     LI->Pos.Name   = INVALID_STRING_ID;
     LI->Pos.Line   = 0;
     LI->Pos.Col    = 0;
-    LI->Spans      = EmptyCollection;
+    LI->Spans      = 0;
 
     /* Return the new struct */
     return LI;
@@ -77,8 +78,8 @@ static LineInfo* NewLineInfo (void)
 void FreeLineInfo (LineInfo* LI)
 /* Free a LineInfo structure. */
 {
-    /* Free the collections */
-    DoneCollection (&LI->Spans);
+    /* Free the span list */
+    xfree (LI->Spans);
 
     /* Free the structure itself */
     xfree (LI);
@@ -86,6 +87,25 @@ void FreeLineInfo (LineInfo* LI)
 
 
 
+LineInfo* DupLineInfo (const LineInfo* LI)
+/* Creates a duplicate of a line info structure */
+{
+    /* Allocate memory */
+    LineInfo* New = xmalloc (sizeof (LineInfo));
+
+    /* Copy the fields (leave id invalid) */
+    New->Id     = LI->Id;
+    New->File   = LI->File;
+    New->Type   = LI->Type;
+    New->Pos    = LI->Pos;
+    New->Spans  = DupSpanList (LI->Spans);
+
+    /* Return the copy */
+    return New;
+}
+
+
+
 LineInfo* GenLineInfo (const FilePos* Pos)
 /* Generate a new (internally used) line info with the given information */
 {
@@ -113,7 +133,7 @@ LineInfo* ReadLineInfo (FILE* F, ObjData* O)
     LI->File     = CollAt (&O->Files, ReadVar (F));
     LI->Pos.Name = LI->File->Name;
     LI->Type     = ReadVar (F);
-    ReadSpans (&LI->Spans, F, O);
+    LI->Spans    = ReadSpanList (F);
 
     /* Return the struct read */
     return LI;
@@ -123,8 +143,8 @@ LineInfo* ReadLineInfo (FILE* F, ObjData* O)
 
 void ReadLineInfoList (FILE* F, ObjData* O, Collection* LineInfos)
 /* Read a list of line infos stored as a list of indices in the object file,
- * make real line infos from them and place them into the passed collection.
- */
+** make real line infos from them and place them into the passed collection.
+*/
 {
     /* Read the number of line info indices that follow */
     unsigned LineInfoCount = ReadVar (F);
@@ -139,8 +159,8 @@ void ReadLineInfoList (FILE* F, ObjData* O, Collection* LineInfos)
         unsigned LineInfoIndex = ReadVar (F);
 
         /* The line info index was written by the assembler and must
-         * therefore be part of the line infos read from the object file.
-         */
+        ** therefore be part of the line infos read from the object file.
+        */
         if (LineInfoIndex >= CollCount (&O->LineInfos)) {
             Internal ("Invalid line info index %u in module `%s' - max is %u",
                       LineInfoIndex,
@@ -155,13 +175,79 @@ void ReadLineInfoList (FILE* F, ObjData* O, Collection* LineInfos)
 
 
 
+const LineInfo* GetAsmLineInfo (const Collection* LineInfos)
+/* Find a line info of type LI_TYPE_ASM and count zero in the given collection
+** and return it. Return NULL if no such line info was found.
+*/
+{
+    unsigned I;
+
+    /* Search for a line info of LI_TYPE_ASM */
+    for (I = 0; I < CollCount (LineInfos); ++I) {
+        const LineInfo* LI = CollConstAt (LineInfos, I);
+        if (LI->Type == LI_MAKE_TYPE (LI_TYPE_ASM, 0)) {
+            return LI;
+        }
+    }
+
+    /* Not found */
+    return 0;
+}
+
+
+
+unsigned LineInfoCount (void)
+/* Return the total number of line infos */
+{
+    /* Walk over all object files */
+    unsigned I;
+    unsigned Count = 0;
+    for (I = 0; I < CollCount (&ObjDataList); ++I) {
+
+        /* Get this object file */
+        const ObjData* O = CollAtUnchecked (&ObjDataList, I);
+
+        /* Count spans */
+        Count += CollCount (&O->LineInfos);
+    }
+
+    return Count;
+}
+
+
+
+void AssignLineInfoIds (void)
+/* Assign the ids to the line infos */
+{
+    unsigned I, J;
+
+    /* Walk over all line infos */
+    unsigned Id = 0;
+    for (I = 0; I < CollCount (&ObjDataList); ++I) {
+
+        /* Get the object file */
+        ObjData* O = CollAtUnchecked (&ObjDataList, I);
+
+        /* Output the line infos */
+        for (J = 0; J < CollCount (&O->LineInfos); ++J) {
+
+            /* Get this line info */
+            LineInfo* LI = CollAtUnchecked (&O->LineInfos, J);
+
+            /* Assign the id */
+            LI->Id = Id++;
+        }
+    }
+}
+
+
+
 void PrintDbgLineInfo (FILE* F)
 /* Output the line infos to a debug info file */
 {
-    unsigned I, J, K;
+    unsigned I, J;
 
     /* Print line infos from all modules we have linked into the output file */
-    unsigned Id = 0;
     for (I = 0; I < CollCount (&ObjDataList); ++I) {
 
         /* Get the object file */
@@ -177,13 +263,10 @@ void PrintDbgLineInfo (FILE* F)
             unsigned Type  = LI_GET_TYPE (LI->Type);
             unsigned Count = LI_GET_COUNT (LI->Type);
 
-            /* Get a pointer to the spans */
-            const Collection* Spans = &LI->Spans;
-
             /* Print the start of the line */
             fprintf (F,
-                     "line\tid=%u,file=%u,line=%lu",
-                     Id++, LI->File->Id, GetSourceLine (LI));
+                     "line\tid=%u,file=%u,line=%u",
+                     LI->Id, LI->File->Id, GetSourceLine (LI));
 
             /* Print type if not LI_TYPE_ASM and count if not zero */
             if (Type != LI_TYPE_ASM) {
@@ -194,22 +277,10 @@ void PrintDbgLineInfo (FILE* F)
             }
 
             /* Add spans if the line info has it */
-            if (CollCount (Spans) > 0) {
-
-                /* Output the first span */
-                fprintf (F, ",span=%u", SpanId (O, CollConstAt (Spans, 0)));
-
-                /* Output the other spans */
-                for (K = 1; K < CollCount (Spans); ++K) {
-                    fprintf (F, "+%u", SpanId (O, CollConstAt (Spans, K)));
-                }
-            }
+            PrintDbgSpanList (F, O, LI->Spans);
 
             /* Terminate line */
             fputc ('\n', F);
         }
     }
 }
-
-
-