mirror of
https://github.com/cc65/cc65.git
synced 2024-11-19 06:31:31 +00:00
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:
parent
d7d1ad7fd0
commit
b2b1edc4ab
@ -107,8 +107,8 @@ 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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -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,8 +82,7 @@ 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 */
|
||||
@ -103,9 +92,7 @@ static LineInfo* NewLineInfo (unsigned Type, unsigned File,
|
||||
LI->Usage = 0;
|
||||
LI->Type = Type;
|
||||
LI->Index = INV_LINEINFO_INDEX;
|
||||
LI->Pos.Name = File;
|
||||
LI->Pos.Line = Line;
|
||||
LI->Pos.Col = Col;
|
||||
LI->Pos = *Pos;
|
||||
|
||||
/* Return the new struct */
|
||||
return LI;
|
||||
@ -139,14 +126,19 @@ 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_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);
|
||||
}
|
||||
|
||||
|
||||
@ -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,14 +371,11 @@ 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);
|
||||
|
||||
@ -387,13 +387,6 @@ void WriteLineInfos (void)
|
||||
ObjWritePos (&LI->Pos);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
/* No line infos */
|
||||
ObjWriteVar (0);
|
||||
|
||||
}
|
||||
|
||||
/* End of line infos */
|
||||
ObjEndLineInfos ();
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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 ();
|
||||
|
Loading…
Reference in New Issue
Block a user