1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-21 20:29:24 +00:00

Fragment cleanup, more string pool use

git-svn-id: svn://svn.cc65.org/cc65/trunk@2201 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2003-06-06 06:50:27 +00:00
parent c5255302db
commit 0aa75f12d6
11 changed files with 64 additions and 140 deletions

View File

@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1998-2000 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* (C) 1998-2003 Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@ -41,6 +41,7 @@
/* ld65 */
#include "error.h"
#include "fileio.h"
#include "spool.h"
@ -253,19 +254,43 @@ unsigned long ReadVar (FILE* F)
char* ReadStr (FILE* F)
/* Read a string from the file (the memory will be malloc'ed) */
unsigned ReadStr (FILE* F)
/* Read a string from the file, place it into the global string pool, and
* return its string id.
*/
{
unsigned Id;
char* B;
char Buf[256];
/* Read the length */
unsigned Len = ReadVar (F);
/* Allocate memory and read the string itself */
char* S = xmalloc (Len + 1);
ReadData (F, S, Len);
/* If the string is short enough, use our buffer on the stack, otherwise
* allocate space on the heap.
*/
if (Len < sizeof (Buf)) {
B = Buf;
} else {
B = xmalloc (Len + 1);
}
/* Terminate the string and return it */
S [Len] = '\0';
return S;
/* Read the string */
ReadData (F, B, Len);
/* Terminate the string */
B[Len] = '\0';
/* Insert it into the string pool and remember the id */
Id = GetStringId (B);
/* If we had allocated memory before, free it now */
if (B != Buf) {
xfree (B);
}
/* Return the string id */
return Id;
}
@ -284,7 +309,7 @@ FilePos* ReadFilePos (FILE* F, FilePos* Pos)
void* ReadData (FILE* F, void* Data, unsigned Size)
/* Read data from the file */
{
{
/* Explicitly allow reading zero bytes */
if (Size > 0) {
if (fread (Data, 1, Size, F) != Size) {

View File

@ -6,10 +6,10 @@
/* */
/* */
/* */
/* (C) 1998-2000 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* EMail: uz@musoftware.de */
/* (C) 1998-2003 Ullrich von Bassewitz */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
/* This software is provided 'as-is', without any expressed or implied */
@ -96,8 +96,10 @@ long Read32Signed (FILE* F);
unsigned long ReadVar (FILE* F);
/* Read a variable size value from the file */
char* ReadStr (FILE* F);
/* Read a string from the file into a malloced area */
unsigned ReadStr (FILE* F);
/* Read a string from the file, place it into the global string pool, and
* return its string id.
*/
FilePos* ReadFilePos (FILE* F, FilePos* Pos);
/* Read a file position from the file */

View File

@ -39,11 +39,8 @@
/* ld65 */
#include "error.h"
#include "expr.h"
#include "fragment.h"
#include "fileio.h"
#include "segments.h"
#include "spool.h"
@ -53,56 +50,6 @@
static FragCheck* NewFragCheck (unsigned Action)
/* Allocate a new FragCheck struct and return it */
{
/* Allocate memory */
FragCheck* FC = xmalloc (sizeof (FragCheck));
/* Initialize the fields */
FC->Next = 0;
FC->Expr = 0;
FC->Action = Action;
FC->Message = INVALID_STRING_ID;
/* Return the new struct */
return FC;
}
FragCheck* ReadFragCheck (FILE* F, Fragment* Frag)
/* Read a fragment check expression from the given file */
{
/* Get the object file pointer from the fragment */
ObjData* O = Frag->Obj;
/* Read the action and create a new struct */
FragCheck* FC = NewFragCheck (ReadVar (F));
/* Determine the remaining data from the action */
switch (FC->Action) {
case FRAG_ACT_WARN:
case FRAG_ACT_ERROR:
FC->Expr = ReadExpr (F, O);
FC->Message = MakeGlobalStringId (O, ReadVar (F));
break;
default:
Internal ("In module `%s', file `%s', line %lu: Invalid fragment "
"check action: %u",
GetObjFileName (O),
GetSourceFileName (O, Frag->Pos.Name),
Frag->Pos.Line, FC->Action);
}
/* Return the new fragment check */
return FC;
}
Fragment* NewFragment (unsigned char Type, unsigned Size, Section* S)
/* Create a new fragment and insert it into the section S */
{
@ -126,7 +73,6 @@ Fragment* NewFragment (unsigned char Type, unsigned Size, Section* S)
F->Expr = 0;
InitFilePos (&F->Pos);
F->LI = 0;
F->Check = 0;
F->Type = Type;
/* Insert the code fragment into the section */

View File

@ -61,15 +61,6 @@ struct Section;
/* Fragment check expression */
typedef struct FragCheck FragCheck;
struct FragCheck {
struct FragCheck* Next; /* Next check expression */
struct ExprNode* Expr; /* The expression itself */
unsigned Action; /* Action to take if the check fails */
unsigned Message; /* Message number */
};
/* Fragment structure */
typedef struct Fragment Fragment;
struct Fragment {
@ -79,7 +70,6 @@ struct Fragment {
struct ExprNode* Expr; /* Expression if FRAG_EXPR */
FilePos Pos; /* File position in source */
struct LineInfo* LI; /* Additional line info */
FragCheck* Check; /* Single linked list of checks */
unsigned char Type; /* Type of fragment */
unsigned char LitBuf [1]; /* Dynamically alloc'ed literal buffer */
};
@ -92,9 +82,6 @@ struct Fragment {
FragCheck* ReadFragCheck (FILE* F, Fragment* Frag);
/* Read a fragment check expression from the given file */
Fragment* NewFragment (unsigned char Type, unsigned Size, struct Section* S);
/* Create a new fragment and insert it into the section S */

View File

@ -118,13 +118,11 @@ static ObjData* ReadIndexEntry (void)
ObjData* O = NewObjData ();
/* Module name */
char* Name = ReadStr (Lib);
O->Name = GetStringId (Name);
xfree (Name);
O->Name = ReadStr (Lib);
/* Module flags/MTime/Start/Size */
O->Flags = Read16 (Lib);
O->MTime = Read32 (Lib);
O->MTime = Read32 (Lib);
O->Start = Read32 (Lib);
Read32 (Lib); /* Skip Size */

View File

@ -7,8 +7,8 @@
/* */
/* */
/* (C) 2001 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */
@ -151,7 +151,7 @@ static void AddCodeRange (LineInfo* LI, unsigned long Offs, unsigned long Size)
void RelocLineInfo (struct Segment* S)
void RelocLineInfo (Segment* S)
/* Relocate the line info for a segment. */
{
unsigned long Offs = 0;

View File

@ -7,8 +7,8 @@
/* */
/* */
/* (C) 2001 Ullrich von Bassewitz */
/* Wacholderweg 14 */
/* D-70597 Stuttgart */
/* Römerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/* */
/* */

View File

@ -110,7 +110,7 @@ void FreeObjData (ObjData* O)
FreeImport (O->Imports[--O->ImportCount]);
}
xfree (O->Imports);
FreeObjStrings (O);
xfree (O->Strings);
xfree (O);
}
@ -121,9 +121,6 @@ void FreeObjStrings (ObjData* O)
* when all strings are converted to global strings.
*/
{
while (O->StringCount) {
xfree (O->Strings[--O->StringCount]);
}
xfree (O->Strings);
O->Strings = 0;
}
@ -138,20 +135,6 @@ void InsertObjData (ObjData* O)
const char* GetObjString (const ObjData* O, unsigned Index)
/* Get a string from the object file string table. Abort if the string index
* is invalid.
*/
{
if (Index >= O->StringCount) {
Error ("Invalid string index (%u) in module `%s'",
Index, GetObjFileName (O));
}
return O->Strings[Index];
}
unsigned MakeGlobalStringId (const ObjData* O, unsigned Index)
/* Convert a local string id into a global one and return it. */
{
@ -159,7 +142,7 @@ unsigned MakeGlobalStringId (const ObjData* O, unsigned Index)
Error ("Invalid string index (%u) in module `%s'",
Index, GetObjFileName (O));
}
return GetStringId (O->Strings[Index]);
return O->Strings[Index];
}

View File

@ -76,7 +76,7 @@ struct ObjData {
unsigned LineInfoCount; /* Count of additional line infos */
struct LineInfo** LineInfos; /* List of additional line infos */
unsigned StringCount; /* Count of strings */
char** Strings; /* List of strings used */
unsigned* Strings; /* List of global string indices */
};
@ -109,11 +109,6 @@ void FreeObjStrings (ObjData* O);
void InsertObjData (ObjData* O);
/* Insert the ObjData object into the collection of used ObjData objects. */
const char* GetObjString (const ObjData* O, unsigned Index);
/* Get a string from the object file string table. Abort if the string index
* is invalid.
*/
unsigned MakeGlobalStringId (const ObjData* O, unsigned Index);
/* Convert a local string id into a global one and return it. */

View File

@ -111,7 +111,7 @@ void ObjReadFiles (FILE* F, ObjData* O)
unsigned I;
O->FileCount = ReadVar (F);
O->Files = xmalloc (O->FileCount * sizeof (FileInfo*));
O->Files = xmalloc (O->FileCount * sizeof (O->Files[0]));
for (I = 0; I < O->FileCount; ++I) {
O->Files[I] = ReadFileInfo (F, O);
}
@ -125,7 +125,7 @@ void ObjReadImports (FILE* F, ObjData* O)
unsigned I;
O->ImportCount = ReadVar (F);
O->Imports = xmalloc (O->ImportCount * sizeof (Import*));
O->Imports = xmalloc (O->ImportCount * sizeof (O->Imports[0]));
for (I = 0; I < O->ImportCount; ++I) {
O->Imports [I] = ReadImport (F, O);
InsertImport (O->Imports [I]);
@ -140,7 +140,7 @@ void ObjReadExports (FILE* F, ObjData* O)
unsigned I;
O->ExportCount = ReadVar (F);
O->Exports = xmalloc (O->ExportCount * sizeof (Export*));
O->Exports = xmalloc (O->ExportCount * sizeof (O->Exports[0]));
for (I = 0; I < O->ExportCount; ++I) {
O->Exports [I] = ReadExport (F, O);
InsertExport (O->Exports [I]);
@ -155,7 +155,7 @@ void ObjReadDbgSyms (FILE* F, ObjData* O)
unsigned I;
O->DbgSymCount = ReadVar (F);
O->DbgSyms = xmalloc (O->DbgSymCount * sizeof (DbgSym*));
O->DbgSyms = xmalloc (O->DbgSymCount * sizeof (O->DbgSyms[0]));
for (I = 0; I < O->DbgSymCount; ++I) {
O->DbgSyms [I] = ReadDbgSym (F, O);
}
@ -169,7 +169,7 @@ void ObjReadLineInfos (FILE* F, ObjData* O)
unsigned I;
O->LineInfoCount = ReadVar (F);
O->LineInfos = xmalloc (O->LineInfoCount * sizeof (LineInfo*));
O->LineInfos = xmalloc (O->LineInfoCount * sizeof (O->LineInfos[0]));
for (I = 0; I < O->LineInfoCount; ++I) {
O->LineInfos[I] = ReadLineInfo (F, O);
}
@ -181,8 +181,9 @@ void ObjReadStrPool (FILE* F, ObjData* O)
/* Read the string pool from a file at the current position */
{
unsigned I;
O->StringCount = ReadVar (F);
O->Strings = xmalloc (O->StringCount * sizeof (char*));
O->Strings = xmalloc (O->StringCount * sizeof (O->Strings[0]));
for (I = 0; I < O->StringCount; ++I) {
O->Strings[I] = ReadStr (F);
}
@ -196,7 +197,7 @@ void ObjReadSections (FILE* F, ObjData* O)
unsigned I;
O->SectionCount = ReadVar (F);
O->Sections = xmalloc (O->SectionCount * sizeof (Section*));
O->Sections = xmalloc (O->SectionCount * sizeof (O->Sections[0]));
for (I = 0; I < O->SectionCount; ++I) {
O->Sections [I] = ReadSection (F, O);
}

View File

@ -238,7 +238,6 @@ Section* ReadSection (FILE* F, ObjData* O)
unsigned char Type = Read8 (F);
/* Extract the check mask from the type */
unsigned char Check = Type & FRAG_CHECKMASK;
unsigned char Bytes = Type & FRAG_BYTEMASK;
Type &= FRAG_TYPEMASK;
@ -268,18 +267,6 @@ Section* ReadSection (FILE* F, ObjData* O)
return 0;
}
/* A list of check expressions may follow */
if (Check) {
/* Read the number of expressions that follow */
unsigned Count = ReadVar (F);
/* Read the expressions */
while (Count--) {
/* ### */
}
}
/* Read the file position of the fragment */
ReadFilePos (F, &Frag->Pos);