1
0
mirror of https://github.com/cc65/cc65.git synced 2025-08-08 22:25:28 +00:00

Use a separate structure for file infos instead of just the name.

git-svn-id: svn://svn.cc65.org/cc65/trunk@749 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2001-05-23 21:32:57 +00:00
parent bfbedfa54b
commit 275da22a66
9 changed files with 181 additions and 12 deletions

79
src/ld65/fileinfo.c Normal file
View File

@@ -0,0 +1,79 @@
/*****************************************************************************/
/* */
/* fileinfo.c */
/* */
/* sOURCE FILE INFO STRUCTURE */
/* */
/* */
/* */
/* (C) 2001 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* 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 "fileio.h"
#include "fileinfo.h"
/*****************************************************************************/
/* Code */
/*****************************************************************************/
static FileInfo* NewFileInfo (void)
/* Allocate and initialize a new FileInfo struct and return it */
{
/* Allocate memory */
FileInfo* FI = xmalloc (sizeof (FileInfo));
/* Return the new struct */
return FI;
}
FileInfo* ReadFileInfo (FILE* F, ObjData* O)
/* Read a file info from a file and return it */
{
/* Allocate a new FileInfo structure */
FileInfo* FI = NewFileInfo ();
/* Read the fields from the file */
FI->MTime = Read32 (F);
FI->Size = Read32 (F);
FI->Name = ReadStr (F);
/* Return the new struct */
return FI;
}

82
src/ld65/fileinfo.h Normal file
View File

@@ -0,0 +1,82 @@
/*****************************************************************************/
/* */
/* fileinfo.h */
/* */
/* Source file info structure */
/* */
/* */
/* */
/* (C) 2001 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* 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 FILEINFO_H
#define FILEINFO_H
#include <stdio.h>
/* common */
#include "coll.h"
#include "filepos.h"
/* ld65 */
#include "objdata.h"
/*****************************************************************************/
/* Data */
/*****************************************************************************/
typedef struct FileInfo FileInfo;
struct FileInfo {
unsigned long MTime; /* Time of last modification */
unsigned long Size; /* Size of the file */
char* Name; /* File name */
};
/*****************************************************************************/
/* Code */
/*****************************************************************************/
FileInfo* ReadFileInfo (FILE* F, ObjData* O);
/* Read a file info from a file and return it */
/* End of fileinfo.h */
#endif

View File

@@ -34,6 +34,7 @@
/* common */ /* common */
#include "check.h"
#include "xmalloc.h" #include "xmalloc.h"
/* ld65 */ /* ld65 */
@@ -55,6 +56,7 @@ static LineInfo* NewLineInfo (void)
LineInfo* LI = xmalloc (sizeof (LineInfo)); LineInfo* LI = xmalloc (sizeof (LineInfo));
/* Initialize the fields */ /* Initialize the fields */
LI->File = 0;
InitFilePos (&LI->Pos); InitFilePos (&LI->Pos);
InitCollection (&LI->Fragments); InitCollection (&LI->Fragments);
@@ -73,6 +75,10 @@ LineInfo* ReadLineInfo (FILE* F, ObjData* O)
/* Read the file position */ /* Read the file position */
ReadFilePos (F, &LI->Pos); ReadFilePos (F, &LI->Pos);
/* Resolve the file index to a pointer to FileInfo struct */
CHECK (LI->Pos.Name < O->FileCount);
LI->File = O->Files[LI->Pos.Name];
/* Return the new LineInfo */ /* Return the new LineInfo */
return LI; return LI;
} }

View File

@@ -55,8 +55,9 @@
typedef struct LineInfo LineInfo; typedef struct LineInfo LineInfo;
struct LineInfo { struct LineInfo {
FilePos Pos; /* File position */ struct FileInfo* File; /* File struct for this line */
Collection Fragments; /* Fragments for this line */ FilePos Pos; /* File position */
Collection Fragments; /* Fragments for this line */
}; };

View File

@@ -27,6 +27,7 @@ OBJS = bin.o \
exports.o \ exports.o \
expr.o \ expr.o \
extsyms.o \ extsyms.o \
fileinfo.o \
fileio.o \ fileio.o \
fragment.o \ fragment.o \
global.o \ global.o \

View File

@@ -76,10 +76,12 @@ OBJS = bin.obj \
exports.obj \ exports.obj \
expr.obj \ expr.obj \
extsyms.obj \ extsyms.obj \
fileinfo.obj \
fileio.obj \ fileio.obj \
fragment.obj \ fragment.obj \
global.obj \ global.obj \
library.obj \ library.obj \
lineinfo.obj \
main.obj \ main.obj \
mapfile.obj \ mapfile.obj \
o65.obj \ o65.obj \

View File

@@ -41,6 +41,7 @@
/* ld65 */ /* ld65 */
#include "error.h" #include "error.h"
#include "fileinfo.h"
#include "objdata.h" #include "objdata.h"
@@ -110,7 +111,7 @@ void FreeObjData (ObjData* O)
xfree (O->Name); xfree (O->Name);
xfree (O->Imports); xfree (O->Imports);
xfree (O->Exports); xfree (O->Exports);
xfree (O->DbgSyms); xfree (O->DbgSyms);
xfree (O->LineInfos); xfree (O->LineInfos);
xfree (O); xfree (O);
} }
@@ -144,7 +145,7 @@ const char* GetSourceFileName (const ObjData* O, unsigned Index)
PRECONDITION (Index < O->FileCount); PRECONDITION (Index < O->FileCount);
/* Return the name */ /* Return the name */
return O->Files[Index]; return O->Files[Index]->Name;
} }
} }

View File

@@ -65,7 +65,7 @@ struct ObjData {
unsigned long Start; /* Start offset of data in library */ unsigned long Start; /* Start offset of data in library */
unsigned Flags; unsigned Flags;
unsigned FileCount; /* Input file count */ unsigned FileCount; /* Input file count */
char** Files; /* List of input files */ struct FileInfo** Files; /* List of input files */
unsigned SectionCount; /* Count of sections in this object */ unsigned SectionCount; /* Count of sections in this object */
struct Section** Sections; /* List of all sections */ struct Section** Sections; /* List of all sections */
unsigned ExportCount; /* Count of exports */ unsigned ExportCount; /* Count of exports */

View File

@@ -46,6 +46,7 @@
#include "dbgsyms.h" #include "dbgsyms.h"
#include "error.h" #include "error.h"
#include "exports.h" #include "exports.h"
#include "fileinfo.h"
#include "fileio.h" #include "fileio.h"
#include "lineinfo.h" #include "lineinfo.h"
#include "objdata.h" #include "objdata.h"
@@ -112,13 +113,9 @@ void ObjReadFiles (FILE* F, ObjData* O)
unsigned I; unsigned I;
O->FileCount = ReadVar (F); O->FileCount = ReadVar (F);
O->Files = xmalloc (O->FileCount * sizeof (char*)); O->Files = xmalloc (O->FileCount * sizeof (FileInfo*));
for (I = 0; I < O->FileCount; ++I) { for (I = 0; I < O->FileCount; ++I) {
/* Skip MTime and size */ O->Files[I] = ReadFileInfo (F, O);
Read32 (F);
Read32 (F);
/* Read the filename */
O->Files [I] = ReadStr (F);
} }
} }
@@ -158,7 +155,7 @@ void ObjReadDbgSyms (FILE* F, ObjData* O)
/* Read the debug symbols from a file at the current position */ /* Read the debug symbols from a file at the current position */
{ {
unsigned I; unsigned I;
O->DbgSymCount = ReadVar (F); O->DbgSymCount = ReadVar (F);
O->DbgSyms = xmalloc (O->DbgSymCount * sizeof (DbgSym*)); O->DbgSyms = xmalloc (O->DbgSymCount * sizeof (DbgSym*));
for (I = 0; I < O->DbgSymCount; ++I) { for (I = 0; I < O->DbgSymCount; ++I) {