/*****************************************************************************/
/* */
-/* lineinfo.h */
+/* lineinfo.h */
/* */
-/* Source file line info structure */
+/* Source file line info structure */
/* */
/* */
/* */
-/* (C) 2001-2011, Ullrich von Bassewitz */
+/* (C) 2001-2012, Ullrich von Bassewitz */
/* Roemerstrasse 52 */
/* D-70794 Filderstadt */
/* EMail: uz@cc65.org */
/*****************************************************************************/
-/* Code */
+/* Code */
/*****************************************************************************/
LineInfo* LI = xmalloc (sizeof (LineInfo));
/* Initialize the fields */
+ LI->Id = ~0U;
LI->File = 0;
- LI->Type = LI_TYPE_ASM;
+ LI->Type = LI_MAKE_TYPE (LI_TYPE_ASM, 0);
LI->Pos.Name = INVALID_STRING_ID;
LI->Pos.Line = 0;
LI->Pos.Col = 0;
- LI->Spans = EmptyCollection;
+ LI->Spans = 0;
/* Return the new struct */
return LI;
void FreeLineInfo (LineInfo* LI)
/* Free a LineInfo structure. */
{
- /* Free the collections */
- DoneCollection (&LI->Spans);
+ /* Free the span list */
+ xfree (LI->Spans);
/* Free the structure itself */
xfree (LI);
+LineInfo* DupLineInfo (const LineInfo* LI)
+/* Creates a duplicate of a line info structure */
+{
+ /* Allocate memory */
+ LineInfo* New = xmalloc (sizeof (LineInfo));
+
+ /* Copy the fields (leave id invalid) */
+ New->Id = LI->Id;
+ New->File = LI->File;
+ New->Type = LI->Type;
+ New->Pos = LI->Pos;
+ New->Spans = DupSpanList (LI->Spans);
+
+ /* Return the copy */
+ return New;
+}
+
+
+
LineInfo* GenLineInfo (const FilePos* Pos)
/* Generate a new (internally used) line info with the given information */
{
LI->File = CollAt (&O->Files, ReadVar (F));
LI->Pos.Name = LI->File->Name;
LI->Type = ReadVar (F);
- ReadSpans (&LI->Spans, F, O);
+ LI->Spans = ReadSpanList (F);
/* Return the struct read */
return LI;
void ReadLineInfoList (FILE* F, ObjData* O, Collection* LineInfos)
/* Read a list of line infos stored as a list of indices in the object file,
- * make real line infos from them and place them into the passed collection.
- */
+** make real line infos from them and place them into the passed collection.
+*/
{
/* Read the number of line info indices that follow */
unsigned LineInfoCount = ReadVar (F);
unsigned LineInfoIndex = ReadVar (F);
/* The line info index was written by the assembler and must
- * therefore be part of the line infos read from the object file.
- */
+ ** therefore be part of the line infos read from the object file.
+ */
if (LineInfoIndex >= CollCount (&O->LineInfos)) {
Internal ("Invalid line info index %u in module `%s' - max is %u",
LineInfoIndex,
+const LineInfo* GetAsmLineInfo (const Collection* LineInfos)
+/* Find a line info of type LI_TYPE_ASM and count zero in the given collection
+** and return it. Return NULL if no such line info was found.
+*/
+{
+ unsigned I;
+
+ /* Search for a line info of LI_TYPE_ASM */
+ for (I = 0; I < CollCount (LineInfos); ++I) {
+ const LineInfo* LI = CollConstAt (LineInfos, I);
+ if (LI->Type == LI_MAKE_TYPE (LI_TYPE_ASM, 0)) {
+ return LI;
+ }
+ }
+
+ /* Not found */
+ return 0;
+}
+
+
+
+unsigned LineInfoCount (void)
+/* Return the total number of line infos */
+{
+ /* Walk over all object files */
+ unsigned I;
+ unsigned Count = 0;
+ for (I = 0; I < CollCount (&ObjDataList); ++I) {
+
+ /* Get this object file */
+ const ObjData* O = CollAtUnchecked (&ObjDataList, I);
+
+ /* Count spans */
+ Count += CollCount (&O->LineInfos);
+ }
+
+ return Count;
+}
+
+
+
+void AssignLineInfoIds (void)
+/* Assign the ids to the line infos */
+{
+ unsigned I, J;
+
+ /* Walk over all line infos */
+ unsigned Id = 0;
+ for (I = 0; I < CollCount (&ObjDataList); ++I) {
+
+ /* Get the object file */
+ ObjData* O = CollAtUnchecked (&ObjDataList, I);
+
+ /* Output the line infos */
+ for (J = 0; J < CollCount (&O->LineInfos); ++J) {
+
+ /* Get this line info */
+ LineInfo* LI = CollAtUnchecked (&O->LineInfos, J);
+
+ /* Assign the id */
+ LI->Id = Id++;
+ }
+ }
+}
+
+
+
void PrintDbgLineInfo (FILE* F)
/* Output the line infos to a debug info file */
{
- unsigned I, J, K;
+ unsigned I, J;
/* Print line infos from all modules we have linked into the output file */
- unsigned Id = 0;
for (I = 0; I < CollCount (&ObjDataList); ++I) {
/* Get the object file */
unsigned Type = LI_GET_TYPE (LI->Type);
unsigned Count = LI_GET_COUNT (LI->Type);
- /* Get a pointer to the spans */
- const Collection* Spans = &LI->Spans;
-
/* Print the start of the line */
fprintf (F,
- "line\tid=%u,file=%u,line=%lu",
- Id++, LI->File->Id, GetSourceLine (LI));
+ "line\tid=%u,file=%u,line=%u",
+ LI->Id, LI->File->Id, GetSourceLine (LI));
/* Print type if not LI_TYPE_ASM and count if not zero */
if (Type != LI_TYPE_ASM) {
}
/* Add spans if the line info has it */
- if (CollCount (Spans) > 0) {
-
- /* Output the first span */
- fprintf (F, ",span=%u", SpanId (O, CollConstAt (Spans, 0)));
-
- /* Output the other spans */
- for (K = 1; K < CollCount (Spans); ++K) {
- fprintf (F, "+%u", SpanId (O, CollConstAt (Spans, K)));
- }
- }
+ PrintDbgSpanList (F, O, LI->Spans);
/* Terminate line */
fputc ('\n', F);
}
}
}
-
-
-