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

@@ -107,8 +107,8 @@ void DbgInfoFile (void)
void DbgInfoLine (void) void DbgInfoLine (void)
/* Parse and handle LINE subcommand of the .dbg pseudo instruction */ /* Parse and handle LINE subcommand of the .dbg pseudo instruction */
{ {
unsigned Index; long Line;
long LineNum; FilePos Pos = STATIC_FILEPOS_INITIALIZER;
/* If a parameters follow, this is actual line info. If no parameters /* If a parameters follow, this is actual line info. If no parameters
* follow, the last line info is terminated. * follow, the last line info is terminated.
@@ -128,7 +128,7 @@ void DbgInfoLine (void)
} }
/* Get the index in the file table for the name */ /* Get the index in the file table for the name */
Index = GetFileIndex (&CurTok.SVal); Pos.Name = GetFileIndex (&CurTok.SVal);
/* Skip the name */ /* Skip the name */
NextTok (); NextTok ();
@@ -137,14 +137,15 @@ void DbgInfoLine (void)
ConsumeComma (); ConsumeComma ();
/* Line number */ /* Line number */
LineNum = ConstExpression (); Line = ConstExpression ();
if (LineNum < 0) { if (Line < 0) {
ErrorSkip ("Line number is out of valid range"); ErrorSkip ("Line number is out of valid range");
return; return;
} }
Pos.Line = Line;
/* Remember the line info */ /* Remember the line info */
GenLineInfo (LineInfoSlot, Index, LineNum, 0); GenLineInfo (LineInfoSlot, &Pos);
} }

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 <string.h>
#include <limits.h> #include <limits.h>
@@ -92,20 +82,17 @@ static unsigned UsedSlots;
static LineInfo* NewLineInfo (unsigned Type, unsigned File, static LineInfo* NewLineInfo (unsigned Type, const FilePos* Pos)
unsigned long Line, unsigned Col)
/* Create and return a new line info. Usage will be zero. */ /* Create and return a new line info. Usage will be zero. */
{ {
/* Allocate memory */ /* Allocate memory */
LineInfo* LI = xmalloc (sizeof (LineInfo)); LineInfo* LI = xmalloc (sizeof (LineInfo));
/* Initialize the fields */ /* Initialize the fields */
LI->Usage = 0; LI->Usage = 0;
LI->Type = Type; LI->Type = Type;
LI->Index = INV_LINEINFO_INDEX; LI->Index = INV_LINEINFO_INDEX;
LI->Pos.Name = File; LI->Pos = *Pos;
LI->Pos.Line = Line;
LI->Pos.Col = Col;
/* Return the new struct */ /* Return the new struct */
return LI; return LI;
@@ -139,14 +126,19 @@ static void FreeLineInfo (LineInfo* LI)
void InitLineInfo (void) void InitLineInfo (void)
/* Initialize the line infos */ /* Initialize the line infos */
{ {
static const FilePos DefaultPos = STATIC_FILEPOS_INITIALIZER;
/* Allocate 8 slots */ /* Allocate 8 slots */
AllocatedSlots = 8; AllocatedSlots = 8;
CurLineInfo = xmalloc (AllocatedSlots * sizeof (LineInfoSlot)); 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; UsedSlots = 2;
CurLineInfo[LI_SLOT_ASM].Type = LI_TYPE_ASM; CurLineInfo[LI_SLOT_ASM].Type = LI_TYPE_ASM;
CurLineInfo[LI_SLOT_ASM].Info = 0; CurLineInfo[LI_SLOT_ASM].Info = NewLineInfo (LI_TYPE_ASM, &DefaultPos);
CurLineInfo[LI_SLOT_EXT].Type = LI_TYPE_EXT; CurLineInfo[LI_SLOT_EXT].Type = LI_TYPE_EXT;
CurLineInfo[LI_SLOT_EXT].Info = 0; 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 */ /* Generate a new line info in the given slot */
{ {
/* Get a pointer to the 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 */ /* Check if we already have data */
if (S->Info) { if (S->Info) {
/* Generate new data only if it is different from the existing. */ /* Generate new data only if it is different from the existing. */
if (S->Info->Pos.Col == Col && if (CompareFilePos (&S->Info->Pos, Pos) == 0) {
S->Info->Pos.Line == Line &&
S->Info->Pos.Name == File) {
/* Already there */ /* Already there */
return; return;
} }
@@ -215,7 +205,7 @@ void GenLineInfo (unsigned Slot, unsigned File, unsigned long Line, unsigned Col
} }
/* Allocate new data */ /* 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)), static int CmpLineInfo (void* Data attribute ((unused)),
const void* LI1_, const void* LI2_) const void* LI1_, const void* LI2_)
/* Compare function for the sort */ /* Compare function for the sort */
{ {
/* Cast the pointers */ /* Cast the pointers */
@@ -330,7 +320,15 @@ void WriteLineInfo (const Collection* LineInfos)
/* Write the line info indices */ /* Write the line info indices */
for (I = 0; I < CollCount (LineInfos); ++I) { 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; 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 */ /* Sort the collection */
CollSort (&LineInfoColl, CmpLineInfo, 0); CollSort (&LineInfoColl, CmpLineInfo, 0);
@@ -368,30 +371,20 @@ void MakeLineInfoIndex (void)
void WriteLineInfos (void) void WriteLineInfos (void)
/* Write a list of all line infos to the object file. */ /* 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 */ /* Tell the object file module that we're about to write line infos */
ObjStartLineInfos (); ObjStartLineInfos ();
/* Check if debug info is requested */ /* Write the line info count to the list */
if (DbgSyms) { ObjWriteVar (UsedLineInfoCount);
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);
/* 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 */ /* End of line infos */

View File

@@ -2,7 +2,7 @@
/* */ /* */
/* lineinfo.h */ /* lineinfo.h */
/* */ /* */
/* Source file line info structure */ /* Source file line info management */
/* */ /* */
/* */ /* */
/* */ /* */
@@ -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).
*/
#ifndef LINEINFO_H #ifndef LINEINFO_H
#define LINEINFO_H #define LINEINFO_H
@@ -111,7 +101,7 @@ void FreeLineInfoSlot (unsigned Slot);
* FIFO order. * FIFO order.
*/ */
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 */ /* Generate a new line info in the given slot */
void ClearLineInfo (unsigned Slot); void ClearLineInfo (unsigned Slot);

View File

@@ -862,6 +862,11 @@ int main (int argc, char* argv [])
*/ */
SymEnterLevel (&GlobalNameSpace, ST_GLOBAL, ADDR_SIZE_DEFAULT); SymEnterLevel (&GlobalNameSpace, ST_GLOBAL, ADDR_SIZE_DEFAULT);
/* Initialize the line infos. Must be done here, since we need line infos
* for symbol definitions.
*/
InitLineInfo ();
/* Check the parameters */ /* Check the parameters */
I = 1; I = 1;
while (I < ArgCount) { while (I < ArgCount) {
@@ -980,9 +985,6 @@ int main (int argc, char* argv [])
/* Initialize the segments */ /* Initialize the segments */
InitSegments (); InitSegments ();
/* Initialize the line infos */
InitLineInfo ();
/* Initialize the scanner, open the input file */ /* Initialize the scanner, open the input file */
InitScanner (InFile); InitScanner (InFile);

View File

@@ -813,6 +813,9 @@ Again:
/* Clear the string attribute */ /* Clear the string attribute */
SB_Clear (&CurTok.SVal); SB_Clear (&CurTok.SVal);
/* Generate line info for the current token */
GenLineInfo (LI_SLOT_ASM, &CurTok.Pos);
/* Hex number or PC symbol? */ /* Hex number or PC symbol? */
if (C == '$') { if (C == '$') {
NextChar (); NextChar ();