From b2b1edc4ab581e8af4e021067cab55457868d250 Mon Sep 17 00:00:00 2001 From: uz Date: Thu, 27 Jan 2011 16:39:30 +0000 Subject: [PATCH] Actually generate basic line info. git-svn-id: svn://svn.cc65.org/cc65/trunk@4928 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ca65/dbginfo.c | 17 +++++---- src/ca65/lineinfo.c | 89 +++++++++++++++++++++------------------------ src/ca65/lineinfo.h | 14 +------ src/ca65/main.c | 8 ++-- src/ca65/scanner.c | 3 ++ 5 files changed, 60 insertions(+), 71 deletions(-) diff --git a/src/ca65/dbginfo.c b/src/ca65/dbginfo.c index 15745b3fd..8d53972ef 100644 --- a/src/ca65/dbginfo.c +++ b/src/ca65/dbginfo.c @@ -106,9 +106,9 @@ void DbgInfoFile (void) void DbgInfoLine (void) /* Parse and handle LINE subcommand of the .dbg pseudo instruction */ -{ - unsigned Index; - long LineNum; +{ + long Line; + FilePos Pos = STATIC_FILEPOS_INITIALIZER; /* If a parameters follow, this is actual line info. If no parameters * follow, the last line info is terminated. @@ -128,7 +128,7 @@ void DbgInfoLine (void) } /* Get the index in the file table for the name */ - Index = GetFileIndex (&CurTok.SVal); + Pos.Name = GetFileIndex (&CurTok.SVal); /* Skip the name */ NextTok (); @@ -137,14 +137,15 @@ void DbgInfoLine (void) ConsumeComma (); /* Line number */ - LineNum = ConstExpression (); - if (LineNum < 0) { + Line = ConstExpression (); + if (Line < 0) { ErrorSkip ("Line number is out of valid range"); return; - } + } + Pos.Line = Line; /* Remember the line info */ - GenLineInfo (LineInfoSlot, Index, LineNum, 0); + GenLineInfo (LineInfoSlot, &Pos); } diff --git a/src/ca65/lineinfo.c b/src/ca65/lineinfo.c index 92d7612a5..14ef3b9b0 100644 --- a/src/ca65/lineinfo.c +++ b/src/ca65/lineinfo.c @@ -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 #include @@ -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 */ diff --git a/src/ca65/lineinfo.h b/src/ca65/lineinfo.h index ec654118e..282ad1b79 100644 --- a/src/ca65/lineinfo.h +++ b/src/ca65/lineinfo.h @@ -2,7 +2,7 @@ /* */ /* 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 #define LINEINFO_H @@ -111,7 +101,7 @@ void FreeLineInfoSlot (unsigned Slot); * 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 */ void ClearLineInfo (unsigned Slot); diff --git a/src/ca65/main.c b/src/ca65/main.c index a5db62559..ceadced2e 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -862,6 +862,11 @@ int main (int argc, char* argv []) */ 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 */ I = 1; while (I < ArgCount) { @@ -980,9 +985,6 @@ int main (int argc, char* argv []) /* Initialize the segments */ InitSegments (); - /* Initialize the line infos */ - InitLineInfo (); - /* Initialize the scanner, open the input file */ InitScanner (InFile); diff --git a/src/ca65/scanner.c b/src/ca65/scanner.c index 59fecbd1c..585deec6b 100644 --- a/src/ca65/scanner.c +++ b/src/ca65/scanner.c @@ -813,6 +813,9 @@ Again: /* Clear the string attribute */ SB_Clear (&CurTok.SVal); + /* Generate line info for the current token */ + GenLineInfo (LI_SLOT_ASM, &CurTok.Pos); + /* Hex number or PC symbol? */ if (C == '$') { NextChar (); -- 2.39.5