]> git.sur5r.net Git - cc65/commitdiff
Read scopes from the object files.
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Mon, 1 Aug 2011 20:54:42 +0000 (20:54 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Mon, 1 Aug 2011 20:54:42 +0000 (20:54 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@5103 b7a2c559-68d2-44c3-8de9-860c34a00d81

src/ld65/make/gcc.mak
src/ld65/make/watcom.mak
src/ld65/objfile.c
src/ld65/scopes.c [new file with mode: 0644]
src/ld65/scopes.h [new file with mode: 0644]

index 292bd1e8b3558e3ca8d75647e787c01f3aa87bd8..1ce5654e58ffe175f0afdd8f1caaed6ff8be82f4 100644 (file)
@@ -56,6 +56,7 @@ OBJS =        asserts.o       \
        objdata.o       \
        objfile.o       \
        scanner.o       \
+        scopes.o        \
        segments.o      \
        spool.o         \
        tgtcfg.o
index b54e1a3b041a31fe7a3d161cde5474fe80caba03..1020c8142f9e1e5b79abe80c4266c009f97e7966 100644 (file)
@@ -87,6 +87,7 @@ OBJS =        asserts.obj     \
        objdata.obj     \
        objfile.obj     \
        scanner.obj     \
+        scopes.obj      \
        segments.obj    \
         spool.obj       \
        tgtcfg.obj
index a81927704c3062051ee3779258f1e4eacfdf891a..8f7fbe9d67f868e0c7432883cc4fe803afa65e1a 100644 (file)
@@ -53,6 +53,7 @@
 #include "lineinfo.h"
 #include "objdata.h"
 #include "objfile.h"
+#include "scopes.h"
 #include "segments.h"
 #include "spool.h"
 
@@ -274,7 +275,7 @@ void ObjReadScopes (FILE* F, unsigned long Pos, ObjData* O)
     ScopeCount = ReadVar (F);
     CollGrow (&O->Scopes, ScopeCount);
     for (I = 0; I < ScopeCount; ++I) {
-        CollAppend (&O->Scopes, 0);     /* ReadScope (F, O); ### not implemented */
+        CollAppend (&O->Scopes,  ReadScope (F, O, I));
     }
 }
 
diff --git a/src/ld65/scopes.c b/src/ld65/scopes.c
new file mode 100644 (file)
index 0000000..994011f
--- /dev/null
@@ -0,0 +1,169 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                 scopes.c                                  */
+/*                                                                           */
+/*                    Scope handling for the ld65 linker                     */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (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 "error.h"
+#include "fileio.h"
+#include "scopes.h"
+
+
+
+/*****************************************************************************/
+/*                                          Data                                    */
+/*****************************************************************************/
+
+
+
+typedef struct SegRange SegRange;
+struct SegRange {
+    unsigned        SegId;              /* Id of segment */
+    unsigned long   Start;              /* Start of range */
+    unsigned long   End;                /* End of range */
+};
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+static Scope* NewScope (ObjData* Obj, unsigned Id)
+/* Create a new Scope and return it */
+{
+    /* Allocate memory */
+    Scope* S     = xmalloc (sizeof (Scope));
+
+    /* Initialize the fields where necessary */
+    S->Id        = Id;
+    S->Obj       = Obj;
+    S->Size      = 0;
+    S->SegRanges = EmptyCollection;
+
+    /* Return the new entry */
+    return S;
+}
+
+
+
+static SegRange* NewSegRange (void)
+/* Create a new SegRange and return it */
+{
+    /* Allocate memory and return it */
+    return xmalloc (sizeof (SegRange));
+}
+
+
+
+static SegRange* ReadSegRange (FILE* F)
+/* Read a SegRange from a file and return it */
+{
+    /* Create a new SegRange */
+    SegRange* S = NewSegRange ();
+
+    /* Read data */
+    S->SegId    = ReadVar (F);
+    S->Start    = ReadVar (F);
+    S->End      = ReadVar (F);
+
+    /* Return the SegRange read */
+    return S;
+}
+
+
+
+Scope* ReadScope (FILE* F, ObjData* Obj, unsigned Id)
+/* Read a scope from a file and return it */
+{
+    unsigned Count;
+
+    /* Create a new scope */
+    Scope* S = NewScope (Obj, Id);
+
+    /* Read the data from file */
+    S->Parent.Id    = ReadVar (F);
+    S->LexicalLevel = ReadVar (F);
+    S->Flags        = ReadVar (F);
+    S->Type         = ReadVar (F);
+    S->Name         = MakeGlobalStringId (Obj, ReadVar (F));
+    if (SCOPE_HAS_SIZE (S->Flags)) {
+        S->Size     = ReadVar (F);
+    }
+
+    /* Read the segment ranges for this scope */
+    Count = ReadVar (F);
+    while (Count--) {
+        CollAppend (&S->SegRanges, ReadSegRange (F));
+    }
+
+    /* Return the new Scope */
+    return S;
+}
+
+
+
+void ResolveScopes (ObjData* Obj)
+/* Resolve a scope list. */
+{
+    unsigned I;
+
+    /* Walk over the list and resolve the parent ids. */
+    for (I = 0; I < CollCount (&Obj->Scopes); ++I) {
+
+        /* Get the scope */
+        Scope* S = CollAtUnchecked (&Obj->Scopes, I);
+
+        /* Resolve the parent id. The root scope doesn't have a parent */
+        if (S->Id == 0) {
+            /* Root scope */
+            S->Parent.Scope = 0;
+        } else {
+            /* Check the data */
+            unsigned ParentId = S->Parent.Id;
+            if (ParentId >= CollCount (&Obj->Scopes)) {
+                Error ("Invalid scope index (%u) in module `%s'",
+                       ParentId, GetObjFileName (Obj));
+            }
+            S->Parent.Scope = CollAtUnchecked (&Obj->Scopes, S->Parent.Id);
+        }
+    }
+}
+
+
+
diff --git a/src/ld65/scopes.h b/src/ld65/scopes.h
new file mode 100644 (file)
index 0000000..2217a8d
--- /dev/null
@@ -0,0 +1,96 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                 scopes.h                                  */
+/*                                                                           */
+/*                    Scope handling for the ld65 linker                     */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (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 SCOPES_H
+#define SCOPES_H
+
+
+
+#include <stdio.h>
+
+/* common */
+#include "coll.h"
+#include "scopedefs.h"
+
+/* ld65 */
+#include "objdata.h"
+
+
+
+/*****************************************************************************/
+/*                                          Data                                    */
+/*****************************************************************************/
+
+
+
+/* Debug symbol structure */
+typedef struct Scope Scope;
+struct Scope {
+    unsigned            Id;             /* Id of scope */
+    ObjData*                   Obj;            /* Object file that exports the name */
+    union {
+        unsigned        Id;             /* Id of parent scope */
+        Scope*          Scope;          /* Pointer to parent scope */
+    } Parent;
+    unsigned            LexicalLevel;   /* Lexical level */
+    unsigned            Flags;
+    unsigned            Type;           /* Type of scope */
+    unsigned            Name;           /* Name of scope */
+    unsigned long       Size;           /* Size of scope */
+    Collection          SegRanges;      /* Segment ranges for this scope */
+};
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+Scope* ReadScope (FILE* F, ObjData* Obj, unsigned Id);
+/* Read a scope from a file, insert and return it */
+
+void ResolveScopes (ObjData* Obj);
+/* Resolve a scope list. */
+
+
+
+/* End of scopes.h */
+
+#endif
+
+
+