-/* 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>
-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;
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;
}
-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 */
/* 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;
}
}
/* Allocate new data */
- S->Info = NewLineInfo (S->Type, File, Line, Col);
+ S->Info = NewLineInfo (S->Type, Pos);
}
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 */
/* 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);
}
}
{
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);
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 */