]> git.sur5r.net Git - cc65/commitdiff
Generalized the CodeRange structure used for line infos and renamed it to Span.
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 4 Aug 2011 12:31:37 +0000 (12:31 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 4 Aug 2011 12:31:37 +0000 (12:31 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@5112 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/ld65/dbginfo.c
src/ld65/lineinfo.c
src/ld65/lineinfo.h
src/ld65/make/gcc.mak
src/ld65/make/watcom.mak
src/ld65/span.c [new file with mode: 0644]
src/ld65/span.h [new file with mode: 0644]

index 72363fe7811c2fc247c765837349504f1c202a34..7dca2fef955e303361825465f24288d294a65b47 100644 (file)
@@ -77,20 +77,20 @@ void PrintDbgInfo (ObjData* O, FILE* F)
         unsigned Type  = LI_GET_TYPE (LI->Type);
         unsigned Count = LI_GET_COUNT (LI->Type);
 
-       /* Get a pointer to the code ranges */
-       const Collection* CodeRanges = &LI->CodeRanges;
+       /* Get a pointer to the spans */
+       const Collection* Spans = &LI->Spans;
 
-       /* Code ranges */
-       for (J = 0; J < CollCount (CodeRanges); ++J) {
+       /* Spans */
+       for (J = 0; J < CollCount (Spans); ++J) {
 
            /* Get this code range */
-           const CodeRange* R = CollConstAt (CodeRanges, J);
+           const Span* S = CollConstAt (Spans, J);
 
            /* Print it */
             fprintf (F,
                      "line\tfile=%u,line=%lu,segment=%u,range=0x%lX-0x%lX",
-                     LI->File->Id, GetSourceLine (LI), R->Seg->Id,
-                     R->Offs, R->Offs + R->Size - 1);
+                     LI->File->Id, GetSourceLine (LI), S->Seg->Id,
+                     S->Offs, S->Offs + S->Size - 1);
 
             /* Print type if not LI_TYPE_ASM and count if not zero */
             if (Type != LI_TYPE_ASM) {
@@ -109,4 +109,3 @@ void PrintDbgInfo (ObjData* O, FILE* F)
 
 
 
-
index 2ed4f7a33774c5a0d5bbac79667e3ab472e40dbe..219dcf1ccf57678eb7e145e97d6d527081d83faf 100644 (file)
 
 
 
-static CodeRange* NewCodeRange (Segment* Seg, unsigned long Offs, unsigned long Size)
-/* Create and return a new CodeRange struct */
-{
-    /* Allocate memory */
-    CodeRange* R = xmalloc (sizeof (CodeRange));
-
-    /* Initialize the fields */
-    R->Seg  = Seg;
-    R->Offs = Offs;
-    R->Size = Size;
-
-    /* Return the new struct */
-    return R;
-}
-
-
-
-static void FreeCodeRange (CodeRange* R)
-/* Free a CodeRange structure */
-{
-    /* Just free the memory */
-    xfree (R);
-}
-
-
-
 static LineInfo* NewLineInfo (void)
 /* Create and return a new LineInfo struct with mostly empty fields */
 {
@@ -94,7 +68,7 @@ static LineInfo* NewLineInfo (void)
     LI->Pos.Line   = 0;
     LI->Pos.Col    = 0;
     LI->Fragments  = EmptyCollection;
-    LI->CodeRanges = EmptyCollection;
+    LI->Spans      = EmptyCollection;
 
     /* Return the new struct */
     return LI;
@@ -113,12 +87,12 @@ void FreeLineInfo (LineInfo* LI)
     PRECONDITION (CollCount (&LI->Fragments) == 0);
 
     /* Free all the code ranges */
-    for (I = 0; I < CollCount (&LI->CodeRanges); ++I) {
-        FreeCodeRange (CollAtUnchecked (&LI->CodeRanges, I));
+    for (I = 0; I < CollCount (&LI->Spans); ++I) {
+        FreeSpan (CollAtUnchecked (&LI->Spans, I));
     }
 
     /* Free the collections */
-    DoneCollection (&LI->CodeRanges);
+    DoneCollection (&LI->Spans);
 
     /* Free the structure itself */
     xfree (LI);
@@ -191,55 +165,6 @@ void ReadLineInfoList (FILE* F, ObjData* O, Collection* LineInfos)
 
 
 
-static void AddCodeRange (LineInfo* LI, Segment* Seg, unsigned long Offs,
-                          unsigned long Size)
-/* Add a range of code to this line */
-{
-    unsigned I;
-
-    /* Get a pointer to the collection */
-    Collection* CodeRanges = &LI->CodeRanges;
-
-    /* We will keep the CodeRanges collection sorted by starting offset,
-     * so we have to search for the correct insert position. Since in most
-     * cases, the fragments have increasing order, and there is usually not
-     * more than one or two ranges, we do a linear search.
-     */
-    for (I = 0; I < CollCount (CodeRanges); ++I) {
-       CodeRange* R = CollAtUnchecked (CodeRanges, I);
-        /* Must be same segment */
-        if (R->Seg == Seg) {
-            if (Offs < R->Offs) {
-
-                /* Got the insert position */
-                if (Offs + Size == R->Offs) {
-                    /* Merge the two */
-                    R->Offs = Offs;
-                    R->Size += Size;
-                } else {
-                    /* Insert a new entry */
-                    CollInsert (CodeRanges, NewCodeRange (Seg, Offs, Size), I);
-                }
-
-                /* Done */
-                return;
-
-            } else if (R->Offs + R->Size == Offs) {
-                /* This is the regular case. Merge the two. */
-                R->Size += Size;
-
-                /* Done */
-                return;
-            }
-        }
-    }
-
-    /* We must append an entry */
-    CollAppend (CodeRanges, NewCodeRange (Seg, Offs, Size));
-}
-
-
-
 void RelocLineInfo (Segment* S)
 /* Relocate the line info for a segment. */
 {
@@ -261,7 +186,8 @@ void RelocLineInfo (Segment* S)
 
                    /* Add the range for this fragment to all line infos */
             for (I = 0; I < CollCount (&Frag->LineInfos); ++I) {
-                       AddCodeRange (CollAt (&Frag->LineInfos, I), S, Offs, Frag->Size);
+                LineInfo* LI = CollAtUnchecked (&Frag->LineInfos, I);
+                       AddSpan (&LI->Spans, S, Offs, Frag->Size);
                    }
 
                    /* Update the offset */
index 0c92423fc344dc0f891baff4ddebb7f3806c9236..bc7106effefc33a52f49810231a4bc8256b7c274 100644 (file)
 #include "filepos.h"
 
 /* ld65 */
+#include "span.h"
 #include "spool.h"
 
 
 
 /*****************************************************************************/
-/*                                Forwards                                  */
+/*                                Forwards                                  */
 /*****************************************************************************/
 
 
@@ -66,15 +67,6 @@ struct Segment;
 
 
 
-typedef struct CodeRange CodeRange;
-struct CodeRange {
-    struct Segment*     Seg;            /* Segment of this code range */
-    unsigned long       Offs;           /* Offset of code range */
-    unsigned long       Size;           /* Size of code range */
-};
-
-
-
 /* Structure holding line information. The Pos.Name field is always the
  * global string id of the file name. If the line info was read from the
  * object file, the File pointer is valid, otherwise it is NULL.
@@ -85,7 +77,7 @@ struct LineInfo {
     unsigned            Type;           /* Type of line info */
     FilePos             Pos;            /* Position in file */
     Collection          Fragments;      /* Fragments for this line */
-    Collection          CodeRanges;     /* Code ranges for this line */
+    Collection          Spans;          /* Spans for this line */
 };
 
 
index 1ce5654e58ffe175f0afdd8f1caaed6ff8be82f4..89bce8d4c19d067108cbefc8cc10d517dc50e63f 100644 (file)
@@ -58,6 +58,7 @@ OBJS =        asserts.o       \
        scanner.o       \
         scopes.o        \
        segments.o      \
+        span.o          \
        spool.o         \
        tgtcfg.o
 
index 1020c8142f9e1e5b79abe80c4266c009f97e7966..37a8e6fc6bb5411fd4694dff527193fb4d770191 100644 (file)
@@ -89,6 +89,7 @@ OBJS =        asserts.obj     \
        scanner.obj     \
         scopes.obj      \
        segments.obj    \
+        span.obj        \
         spool.obj       \
        tgtcfg.obj
 
diff --git a/src/ld65/span.c b/src/ld65/span.c
new file mode 100644 (file)
index 0000000..aa6ceda
--- /dev/null
@@ -0,0 +1,128 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                  span.c                                   */
+/*                                                                           */
+/*                      A span of data within a segment                      */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2011,      Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+/* common */
+#include "xmalloc.h"
+                   
+/* ld65 */       
+#include "span.h"
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+Span* NewSpan (struct Segment* Seg, unsigned long Offs, unsigned long Size)
+/* Create and return a new span */                                         
+{
+    /* Allocate memory */
+    Span* S = xmalloc (sizeof (*S));
+
+    /* Initialize the fields */
+    S->Seg      = Seg;
+    S->Offs     = Offs;
+    S->Size     = Size;
+
+    /* Return the result */
+   return S;
+}
+
+
+
+void FreeSpan (Span* S)
+/* Free a span structure */
+{
+    /* Just free the structure */
+    xfree (S);
+}
+
+
+
+void AddSpan (Collection* Spans, struct Segment* Seg, unsigned long Offs,
+              unsigned long Size)
+/* Either add a new span to the ones already in the given collection, or - if
+ * possible - merge it with adjacent ones that already exist.
+ */                              
+{
+    unsigned I;
+
+    /* We don't have many spans in a collection, so we do a linear search here.
+     * The collection is kept sorted which eases our work here.
+     */
+    for (I = 0; I < CollCount (Spans); ++I) {
+
+        /* Get the next span */
+       Span* S = CollAtUnchecked (Spans, I);
+
+        /* Must be same segment, otherwise we cannot merge */
+        if (S->Seg != Seg) {
+            continue;
+        }
+
+        /* Check if we can merge it */
+        if (Offs < S->Offs) {
+
+            /* Got the insert position */
+            if (Offs + Size == S->Offs) {
+                /* Merge the two */
+                S->Offs = Offs;
+                S->Size += Size;
+            } else {
+                /* Insert a new entry */
+                CollInsert (Spans, NewSpan (Seg, Offs, Size), I);
+            }
+
+            /* Done */
+            return;
+
+        } else if (S->Offs + S->Size == Offs) {
+
+            /* This is the regular case. Merge the two. */
+            S->Size += Size;
+
+            /* Done */
+            return;
+        }
+    }
+
+    /* We must append an entry */
+    CollAppend (Spans, NewSpan (Seg, Offs, Size));
+}
+
+
+
diff --git a/src/ld65/span.h b/src/ld65/span.h
new file mode 100644 (file)
index 0000000..cae1cfd
--- /dev/null
@@ -0,0 +1,95 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                  span.h                                   */
+/*                                                                           */
+/*                      A span of data within a segment                      */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2011,      Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+#ifndef SPAN_H
+#define SPAN_H
+
+
+
+/* common */
+#include "coll.h"
+
+
+
+/*****************************************************************************/
+/*                                Forwards                                  */
+/*****************************************************************************/
+
+
+
+struct Segment;
+
+
+
+/*****************************************************************************/
+/*                                  Data                                    */
+/*****************************************************************************/
+
+
+
+typedef struct Span Span;
+struct Span {
+    struct Segment*     Seg;            /* Segment of this span */
+    unsigned long       Offs;           /* Offset of span within segment */
+    unsigned long       Size;           /* Size of span */
+};
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+Span* NewSpan (struct Segment* Seg, unsigned long Offs, unsigned long Size);
+/* Create and return a new span */
+
+void FreeSpan (Span* S);
+/* Free a span structure */
+
+void AddSpan (Collection* Spans, struct Segment* Seg, unsigned long Offs,
+              unsigned long Size);
+/* Either add a new span to the ones already in the given collection, or - if
+ * possible - merge it with adjacent ones that already exist.
+ */
+
+
+
+/* End of span.h */
+#endif
+
+
+