]> git.sur5r.net Git - cc65/commitdiff
Rename SegRange to span. Write out the size instead of the end offset so we
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 4 Aug 2011 12:49:59 +0000 (12:49 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Thu, 4 Aug 2011 12:49:59 +0000 (12:49 +0000)
can save some bytes in the object file.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5113 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/ca65/make/gcc.mak
src/ca65/make/watcom.mak
src/ca65/segrange.c [deleted file]
src/ca65/segrange.h [deleted file]
src/ca65/span.c [new file with mode: 0644]
src/ca65/span.h [new file with mode: 0644]
src/ca65/symtab.c
src/ca65/symtab.h

index b82923bafe3a7116ef8ddf3c25536696dd91c1e5..46d432bbd6bb0422ef0b286fbfe609ffbc4c4bd8 100644 (file)
@@ -56,8 +56,8 @@ OBJS =  anonname.o      \
        repeat.o        \
        scanner.o       \
        segment.o       \
-       segrange.o      \
        sizeof.o        \
+       span.o          \
        spool.o         \
        struct.o        \
        studyexpr.o     \
index 74795cc49ab781ab467a33868c1de671bf89c9f8..8760b0691a7f011f4def187114cfd70021d7ad22 100644 (file)
@@ -89,8 +89,8 @@ OBJS =        anonname.obj    \
        repeat.obj      \
        scanner.obj     \
         segment.obj     \
-        segrange.obj    \
         sizeof.obj      \
+        span.obj        \
         spool.obj       \
         struct.obj      \
         studyexpr.obj   \
@@ -119,7 +119,7 @@ $(EXE):     $(OBJS) $(LIBS)
        @echo "OPTION QUIET" >> $(LNKCFG)
        @echo "OPTION MAP" >> $(LNKCFG)
        @echo "OPTION STACK=65536" >> $(LNKCFG)
-       @echo "NAME $@" >> $(LNKCFG)          
+       @echo "NAME $@" >> $(LNKCFG)
        @for i in $(OBJS); do echo "FILE $${i}"; done >> $(LNKCFG)
        @for i in $(LIBS); do echo "LIBRARY $${i}"; done >> $(LNKCFG)
        @$(LD) system $(SYSTEM) @$(LNKCFG)
diff --git a/src/ca65/segrange.c b/src/ca65/segrange.c
deleted file mode 100644 (file)
index e51c621..0000000
+++ /dev/null
@@ -1,154 +0,0 @@
-/*****************************************************************************/
-/*                                                                           */
-/*                                segrange.c                                 */
-/*                                                                           */
-/*                              A segment range                              */
-/*                                                                           */
-/*                                                                           */
-/*                                                                           */
-/* (C) 2003-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"
-
-/* ca65 */
-#include "objfile.h"
-#include "segment.h"
-#include "segrange.h"
-
-
-
-/*****************************************************************************/
-/*                                          Code                                    */
-/*****************************************************************************/
-
-
-
-SegRange* NewSegRange (struct Segment* Seg)
-/* Create a new segment range. The segment is set to Seg, Start and End are
- * set to the current PC of the segment.
- */
-{
-    /* Allocate memory */
-    SegRange* R = xmalloc (sizeof (SegRange));
-
-    /* Initialize the struct */
-    R->Seg      = Seg;
-    R->Start    = Seg->PC;
-    R->End      = Seg->PC;
-
-    /* Return the new struct */
-    return R;
-}
-
-
-
-void AddSegRanges (Collection* Ranges)
-/* Add a segment range for all existing segments to the given collection of
- * ranges. The currently active segment will be inserted first with all others
- * following.
- */
-{
-    Segment* Seg;
-
-    /* Add the currently active segment */
-    CollAppend (Ranges, NewSegRange (ActiveSeg));
-
-    /* Walk through the segment list and add all other segments */
-    Seg = SegmentList;
-    while (Seg) {
-        /* Be sure to skip the active segment, since it was already added */
-        if (Seg != ActiveSeg) {
-            CollAppend (Ranges, NewSegRange (Seg));
-        }
-        Seg = Seg->List;
-    }
-}
-
-
-
-void CloseSegRanges (Collection* Ranges)
-/* Close all open segment ranges by setting PC to the current PC for the
- * segment.
- */
-{
-    unsigned I;
-
-    /* Walk over the segment list */
-    for (I = 0; I < CollCount (Ranges); ++I) {
-
-        /* Get the next segment range */
-        SegRange* R = CollAtUnchecked (Ranges, I);
-
-        /* Set the end offset */
-        R->End = R->Seg->PC;
-    }
-}
-
-
-
-void WriteSegRanges (const Collection* Ranges)
-/* Write a list of segment ranges to the output file */
-{
-    unsigned I;
-    unsigned Count;
-
-    /* Determine how many of the segments contain actual data */
-    Count = 0;
-    for (I = 0; I < CollCount (Ranges); ++I) {
-
-        /* Get next range */
-        const SegRange* R = CollConstAt (Ranges, I);
-
-        /* Is this segment range empty? */
-        if (R->Start != R->End) {
-            ++Count;
-        }
-    }
-
-    /* Write the number of ranges with data */
-    ObjWriteVar (Count);
-
-    /* Write the ranges */
-    for (I = 0; I < CollCount (Ranges); ++I) {
-
-        /* Get next range */
-        const SegRange* R = CollConstAt (Ranges, I);
-
-        /* Write data for non empty ranges */
-        if (R->Start != R->End) {
-            ObjWriteVar (R->Seg->Num);
-            ObjWriteVar (R->Start);
-            ObjWriteVar (R->End);
-        }
-    }
-}
-
-
-
-
diff --git a/src/ca65/segrange.h b/src/ca65/segrange.h
deleted file mode 100644 (file)
index 369207c..0000000
+++ /dev/null
@@ -1,106 +0,0 @@
-/*****************************************************************************/
-/*                                                                           */
-/*                                segrange.h                                 */
-/*                                                                           */
-/*                              A segment range                              */
-/*                                                                           */
-/*                                                                           */
-/*                                                                           */
-/* (C) 2003-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 SEGRANGE_H
-#define SEGRANGE_H
-
-
-
-/* common */
-#include "coll.h"
-#include "inline.h"
-
-
-
-/*****************************************************************************/
-/*                                  Data                                    */
-/*****************************************************************************/
-
-
-
-/* Segment range definition */
-typedef struct SegRange SegRange;
-struct SegRange{
-    struct Segment* Seg;                       /* Pointer to segment */
-    unsigned long   Start;              /* Start of range */
-    unsigned long   End;                /* End of range */
-};
-
-
-
-/*****************************************************************************/
-/*                                          Code                                    */
-/*****************************************************************************/
-
-
-
-SegRange* NewSegRange (struct Segment* Seg);
-/* Create a new segment range. The segment is set to Seg, Start and End are
- * set to the current PC of the segment.
- */
-
-#if defined(HAVE_INLINE)
-INLINE unsigned long GetSegRangeSize (const SegRange* R)
-/* Return the segment range size in bytes */
-{
-    return (R->End - R->Start);
-}
-#else
-#  define GetSegRangeSize(R)   ((R)->End - (R)->Start)
-#endif
-
-void AddSegRanges (Collection* Ranges);
-/* Add a segment range for all existing segments to the given collection of
- * ranges. The currently active segment will be inserted first with all others
- * following.
- */
-
-void CloseSegRanges (Collection* Ranges);
-/* Close all open segment ranges by setting PC to the current PC for the
- * segment.
- */
-
-void WriteSegRanges (const Collection* Ranges);
-/* Write a list of segment ranges to the output file */
-
-
-
-/* End of segrange.h */
-
-#endif
-
-
-
-
diff --git a/src/ca65/span.c b/src/ca65/span.c
new file mode 100644 (file)
index 0000000..9c29b0f
--- /dev/null
@@ -0,0 +1,154 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                  span.c                                   */
+/*                                                                           */
+/*                      A span of data within a segment                      */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2003-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"
+
+/* ca65 */
+#include "objfile.h"
+#include "segment.h"
+#include "span.h"
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+Span* NewSpan (struct Segment* Seg)
+/* Create a new span. The segment is set to Seg, Start and End are set to the 
+ * current PC of the segment.
+ */
+{
+    /* Allocate memory */
+    Span* S = xmalloc (sizeof (Span));
+
+    /* Initialize the struct */
+    S->Seg      = Seg;
+    S->Start    = Seg->PC;
+    S->End      = Seg->PC;
+
+    /* Return the new struct */
+    return S;
+}
+
+
+
+void AddSpans (Collection* Spans)
+/* Add a span for all existing segments to the given collection of spans. The
+ * currently active segment will be inserted first with all others following.
+ */
+{
+    Segment* Seg;
+
+    /* Add the currently active segment */
+    CollAppend (Spans, NewSpan (ActiveSeg));
+
+    /* Walk through the segment list and add all other segments */
+    Seg = SegmentList;
+    while (Seg) {
+        /* Be sure to skip the active segment, since it was already added */
+        if (Seg != ActiveSeg) {
+            CollAppend (Spans, NewSpan (Seg));
+        }
+        Seg = Seg->List;
+    }
+}
+
+
+
+void CloseSpans (Collection* Spans)
+/* Close all open spans by setting PC to the current PC for the segment. */
+{
+    unsigned I;
+
+    /* Walk over the segment list */
+    for (I = 0; I < CollCount (Spans); ++I) {
+
+        /* Get the next segment range */
+        Span* S = CollAtUnchecked (Spans, I);
+
+        /* Set the end offset */
+        S->End = S->Seg->PC;
+    }
+}
+
+
+
+void WriteSpans (const Collection* Spans)
+/* Write a list of spans to the output file */
+{
+    unsigned I;
+    unsigned Count;
+
+    /* Determine how many of the segments contain actual data */
+    Count = 0;
+    for (I = 0; I < CollCount (Spans); ++I) {
+
+        /* Get next range */
+        const Span* S = CollConstAt (Spans, I);
+
+        /* Is this segment range empty? */
+        if (S->Start != S->End) {
+            ++Count;
+        }
+    }
+
+    /* Write the number of spans with data */
+    ObjWriteVar (Count);
+
+    /* Write the spans */
+    for (I = 0; I < CollCount (Spans); ++I) {
+
+        /* Get next range */
+        const Span* S = CollConstAt (Spans, I);
+
+        /* Write data for non empty spans. We will write the size instead of
+         * the end offset to save some bytes, since most spans are expected
+         * to be rather small.
+         */
+        if (S->Start != S->End) {
+            ObjWriteVar (S->Seg->Num);
+            ObjWriteVar (S->Start);
+            ObjWriteVar (S->End - S->Start);
+        }
+    }
+}
+
+
+
+
diff --git a/src/ca65/span.h b/src/ca65/span.h
new file mode 100644 (file)
index 0000000..8bbc7c1
--- /dev/null
@@ -0,0 +1,102 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                  span.h                                   */
+/*                                                                           */
+/*                      A span of data within a segment                      */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2003-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"
+#include "inline.h"
+
+
+
+/*****************************************************************************/
+/*                                  Data                                    */
+/*****************************************************************************/
+
+
+
+/* Span definition */
+typedef struct Span Span;
+struct Span{
+    struct Segment* Seg;                       /* Pointer to segment */
+    unsigned long   Start;              /* Start of range */
+    unsigned long   End;                /* End of range */
+};
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+Span* NewSpan (struct Segment* Seg);
+/* Create a new span. The segment is set to Seg, Start and End are set to the
+ * current PC of the segment.
+ */
+
+#if defined(HAVE_INLINE)
+INLINE unsigned long GetSpanSize (const Span* R)
+/* Return the span size in bytes */
+{
+    return (R->End - R->Start);
+}
+#else
+#  define GetSpanSize(R)   ((R)->End - (R)->Start)
+#endif
+
+void AddSpans (Collection* Spans);
+/* Add a span for all existing segments to the given collection of spans. The
+ * currently active segment will be inserted first with all others following.
+ */
+
+void CloseSpans (Collection* Spans);
+/* Close all open spans by setting PC to the current PC for the segment. */
+
+void WriteSpans (const Collection* Spans);
+/* Write a list of spans to the output file */
+
+
+
+/* End of span.h */
+
+#endif
+
+
+
index 5b92538e1483c8577447ce3225ccd8fd2f162870..fb48de223bded6689e20f0e335f2ae26b5278c9f 100644 (file)
@@ -52,6 +52,7 @@
 #include "scanner.h"
 #include "segment.h"
 #include "sizeof.h"
+#include "span.h"
 #include "spool.h"
 #include "studyexpr.h"
 #include "symtab.h"
@@ -116,7 +117,7 @@ static SymTable* NewSymTable (SymTable* Parent, const StrBuf* Name)
     S->Right        = 0;
     S->Childs       = 0;
     S->OwnerSym     = 0;
-    S->SegRanges    = AUTO_COLLECTION_INITIALIZER;
+    S->Spans        = AUTO_COLLECTION_INITIALIZER;
     S->Id           = ScopeCount++;
     S->Flags        = ST_NONE;
     S->AddrSize     = ADDR_SIZE_DEFAULT;
@@ -215,14 +216,14 @@ void SymEnterLevel (const StrBuf* ScopeName, unsigned char Type,
     CurrentScope->Type     = Type;
     CurrentScope->OwnerSym = OwnerSym;
 
-    /* If this is a scope that allows to emit data into segments, add segment
-     * ranges for all currently existing segments. Doing this for just a few
-     * scope types is not really necessary but an optimization, because it
-     * does not allocate memory for useless data (unhandled types here don't
-     * occupy space in any segment).
+    /* If this is a scope that allows to emit data into segments, add spans
+     * for all currently existing segments. Doing this for just a few scope 
+     * types is not really necessary but an optimization, because it does not 
+     * allocate memory for useless data (unhandled types here don't occupy 
+     * space in any segment).
      */
     if (CurrentScope->Type <= SCOPE_HAS_DATA) {
-        AddSegRanges (&CurrentScope->SegRanges);
+        AddSpans (&CurrentScope->Spans);
     }
 }
 
@@ -231,23 +232,23 @@ void SymEnterLevel (const StrBuf* ScopeName, unsigned char Type,
 void SymLeaveLevel (void)
 /* Leave the current lexical level */
 {
-    /* Close the segment ranges. We don't care about the scope type here,
-     * since types without segment ranges will just have an empty list.
+    /* Close the spans. We don't care about the scope type here, since types 
+     * without spans will just have an empty list.
      */
-    CloseSegRanges (&CurrentScope->SegRanges);
+    CloseSpans (&CurrentScope->Spans);
 
-    /* If we have segment ranges, the first one is the segment that was
-     * active, when the scope was opened. Set the size of the scope to the
-     * number of data bytes emitted into this segment. If we have an owner
-     * symbol set the size of this symbol, too.
+    /* If we have spans, the first one is the segment that was active, when the 
+     * scope was opened. Set the size of the scope to the number of data bytes 
+     * emitted into this segment. If we have an owner symbol set the size of 
+     * this symbol, too.
      */
-    if (CollCount (&CurrentScope->SegRanges) > 0) {
-        const SegRange* R = CollAtUnchecked (&CurrentScope->SegRanges, 0);
-        unsigned long Size = GetSegRangeSize (R);
+    if (CollCount (&CurrentScope->Spans) > 0) {
+        const Span* S = CollAtUnchecked (&CurrentScope->Spans, 0);
+        unsigned long Size = GetSpanSize (S);
         DefSizeOfScope (CurrentScope, Size);
         if (CurrentScope->OwnerSym) {
             DefSizeOfSymbol (CurrentScope->OwnerSym, Size);
-        }
+        }                                  
     }
 
     /* Leave the scope */
@@ -940,8 +941,8 @@ void WriteScopes (void)
                 ObjWriteVar (Size);
             }
 
-            /* Segment ranges for this scope */
-            WriteSegRanges (&S->SegRanges);
+            /* Spans for this scope */
+            WriteSpans (&S->Spans);
 
             /* Next scope */
             S = S->Next;
index 36d37133b26e892acef841e4e243e88f8e7782b6..eef2587038642aeb8c3d0e008eb99a07527aee22 100644 (file)
@@ -45,7 +45,6 @@
 #include "inline.h"
 
 /* ca65 */
-#include "segrange.h"
 #include "symentry.h"
 
 
@@ -69,7 +68,7 @@ struct SymTable {
     SymTable*                  Parent;         /* Link to enclosing scope if any */
     SymTable*           Childs;         /* Pointer to child scopes */
     SymEntry*           OwnerSym;       /* Symbol that "owns" the scope */
-    Collection          SegRanges;      /* Segment ranges for this scope */
+    Collection          Spans;          /* Spans for this scope */
     unsigned            Id;             /* Scope id */
     unsigned short      Flags;          /* Symbol table flags */
     unsigned char      AddrSize;       /* Address size */