1
0
mirror of https://github.com/cc65/cc65.git synced 2025-02-04 13:32:54 +00:00

Read scopes from the object files.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5103 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2011-08-01 20:54:42 +00:00
parent 67692e51f1
commit 1f95085ffe
5 changed files with 269 additions and 1 deletions

View File

@ -56,6 +56,7 @@ OBJS = asserts.o \
objdata.o \
objfile.o \
scanner.o \
scopes.o \
segments.o \
spool.o \
tgtcfg.o

View File

@ -87,6 +87,7 @@ OBJS = asserts.obj \
objdata.obj \
objfile.obj \
scanner.obj \
scopes.obj \
segments.obj \
spool.obj \
tgtcfg.obj

View 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));
}
}

169
src/ld65/scopes.c Normal file
View File

@ -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);
}
}
}

96
src/ld65/scopes.h Normal file
View File

@ -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