From: uz Date: Mon, 1 Aug 2011 20:54:42 +0000 (+0000) Subject: Read scopes from the object files. X-Git-Tag: V2.13.3~359 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=1f95085ffe4e7a3c76b42db714080ae377e2445e;p=cc65 Read scopes from the object files. git-svn-id: svn://svn.cc65.org/cc65/trunk@5103 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/src/ld65/make/gcc.mak b/src/ld65/make/gcc.mak index 292bd1e8b..1ce5654e5 100644 --- a/src/ld65/make/gcc.mak +++ b/src/ld65/make/gcc.mak @@ -56,6 +56,7 @@ OBJS = asserts.o \ objdata.o \ objfile.o \ scanner.o \ + scopes.o \ segments.o \ spool.o \ tgtcfg.o diff --git a/src/ld65/make/watcom.mak b/src/ld65/make/watcom.mak index b54e1a3b0..1020c8142 100644 --- a/src/ld65/make/watcom.mak +++ b/src/ld65/make/watcom.mak @@ -87,6 +87,7 @@ OBJS = asserts.obj \ objdata.obj \ objfile.obj \ scanner.obj \ + scopes.obj \ segments.obj \ spool.obj \ tgtcfg.obj diff --git a/src/ld65/objfile.c b/src/ld65/objfile.c index a81927704..8f7fbe9d6 100644 --- a/src/ld65/objfile.c +++ b/src/ld65/objfile.c @@ -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 index 000000000..994011f8b --- /dev/null +++ b/src/ld65/scopes.c @@ -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 index 000000000..2217a8d1b --- /dev/null +++ b/src/ld65/scopes.h @@ -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 + +/* 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 + + +