Actually generate basic line info.

git-svn-id: svn://svn.cc65.org/cc65/trunk@4928 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz
2011-01-27 16:39:30 +00:00
parent d7d1ad7fd0
commit b2b1edc4ab
5 changed files with 60 additions and 71 deletions

View File

@@ -33,16 +33,6 @@
/* Note: The line infos kept here are additional line infos supplied by the
* ".dbg line" command. The native line infos are always kept in the fragments
* itself (because one fragment always originates from one line). The
* additional line infos (which may not exist if none are supplied in the
* source) may have several fragments attached (as is the case with sources
* generated by the C compiler).
*/
#include <string.h>
#include <limits.h>
@@ -92,20 +82,17 @@ static unsigned UsedSlots;
static LineInfo* NewLineInfo (unsigned Type, unsigned File,
unsigned long Line, unsigned Col)
static LineInfo* NewLineInfo (unsigned Type, const FilePos* Pos)
/* Create and return a new line info. Usage will be zero. */
{
/* Allocate memory */
LineInfo* LI = xmalloc (sizeof (LineInfo));
/* Initialize the fields */
LI->Usage = 0;
LI->Type = Type;
LI->Index = INV_LINEINFO_INDEX;
LI->Pos.Name = File;
LI->Pos.Line = Line;
LI->Pos.Col = Col;
LI->Usage = 0;
LI->Type = Type;
LI->Index = INV_LINEINFO_INDEX;
LI->Pos = *Pos;
/* Return the new struct */
return LI;
@@ -139,15 +126,20 @@ static void FreeLineInfo (LineInfo* LI)
void InitLineInfo (void)
/* Initialize the line infos */
{
static const FilePos DefaultPos = STATIC_FILEPOS_INITIALIZER;
/* Allocate 8 slots */
AllocatedSlots = 8;
CurLineInfo = xmalloc (AllocatedSlots * sizeof (LineInfoSlot));
/* Initalize the predefined slots */
/* Initalize the predefined slots. Be sure to ccreate a new LineInfo for
* the default source. This is necessary to allow error message to be
* generated without any input file open.
*/
UsedSlots = 2;
CurLineInfo[LI_SLOT_ASM].Type = LI_TYPE_ASM;
CurLineInfo[LI_SLOT_ASM].Info = 0;
CurLineInfo[LI_SLOT_EXT].Type = LI_TYPE_EXT;
CurLineInfo[LI_SLOT_ASM].Info = NewLineInfo (LI_TYPE_ASM, &DefaultPos);
CurLineInfo[LI_SLOT_EXT].Type = LI_TYPE_EXT;
CurLineInfo[LI_SLOT_EXT].Info = 0;
}
@@ -191,7 +183,7 @@ void FreeLineInfoSlot (unsigned Slot)
void GenLineInfo (unsigned Slot, unsigned File, unsigned long Line, unsigned Col)
void GenLineInfo (unsigned Slot, const FilePos* Pos)
/* Generate a new line info in the given slot */
{
/* Get a pointer to the slot */
@@ -200,9 +192,7 @@ void GenLineInfo (unsigned Slot, unsigned File, unsigned long Line, unsigned Col
/* Check if we already have data */
if (S->Info) {
/* Generate new data only if it is different from the existing. */
if (S->Info->Pos.Col == Col &&
S->Info->Pos.Line == Line &&
S->Info->Pos.Name == File) {
if (CompareFilePos (&S->Info->Pos, Pos) == 0) {
/* Already there */
return;
}
@@ -215,7 +205,7 @@ void GenLineInfo (unsigned Slot, unsigned File, unsigned long Line, unsigned Col
}
/* Allocate new data */
S->Info = NewLineInfo (S->Type, File, Line, Col);
S->Info = NewLineInfo (S->Type, Pos);
}
@@ -294,7 +284,7 @@ LineInfo* ReleaseLineInfo (LineInfo* LI)
static int CmpLineInfo (void* Data attribute ((unused)),
const void* LI1_, const void* LI2_)
const void* LI1_, const void* LI2_)
/* Compare function for the sort */
{
/* Cast the pointers */
@@ -330,7 +320,15 @@ void WriteLineInfo (const Collection* LineInfos)
/* Write the line info indices */
for (I = 0; I < CollCount (LineInfos); ++I) {
ObjWriteVar (((const LineInfo*) CollConstAt (LineInfos, I))->Index);
/* Get a pointer to the line info */
const LineInfo* LI = CollConstAt (LineInfos, I);
/* Check the index */
CHECK (LI->Index != INV_LINEINFO_INDEX);
/* Write the index to the file */
ObjWriteVar (LI->Index);
}
}
@@ -341,6 +339,11 @@ void MakeLineInfoIndex (void)
{
unsigned I;
/* Be sure to move pending line infos to the global list */
for (I = 0; I < UsedSlots; ++I) {
FreeLineInfo (CurLineInfo[I].Info);
}
/* Sort the collection */
CollSort (&LineInfoColl, CmpLineInfo, 0);
@@ -368,30 +371,20 @@ void MakeLineInfoIndex (void)
void WriteLineInfos (void)
/* Write a list of all line infos to the object file. */
{
unsigned I;
/* Tell the object file module that we're about to write line infos */
ObjStartLineInfos ();
/* Check if debug info is requested */
if (DbgSyms) {
unsigned I;
/* Write the line info count to the list */
ObjWriteVar (UsedLineInfoCount);
/* Walk over the list and write all line infos */
for (I = 0; I < UsedLineInfoCount; ++I) {
/* Get a pointer to this line info */
LineInfo* LI = CollAt (&LineInfoColl, I);
/* Write the source file position */
ObjWritePos (&LI->Pos);
}
} else {
/* No line infos */
ObjWriteVar (0);
/* Write the line info count to the list */
ObjWriteVar (UsedLineInfoCount);
/* Walk over the list and write all line infos */
for (I = 0; I < UsedLineInfoCount; ++I) {
/* Get a pointer to this line info */
LineInfo* LI = CollAt (&LineInfoColl, I);
/* Write the source file position */
ObjWritePos (&LI->Pos);
}
/* End of line infos */