Worked on high level language symbol info.

git-svn-id: svn://svn.cc65.org/cc65/trunk@5279 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz
2011-08-29 18:55:03 +00:00
parent 2e7afb6a8d
commit 305cf64d40
3 changed files with 83 additions and 38 deletions

View File

@@ -36,15 +36,18 @@
#include <string.h> #include <string.h>
/* common */ /* common */
#include "coll.h"
#include "hldbgsym.h"
#include "strbuf.h" #include "strbuf.h"
/* ca65 */ /* ca65 */
#include "dbginfo.h"
#include "error.h" #include "error.h"
#include "expr.h" #include "expr.h"
#include "filetab.h" #include "filetab.h"
#include "lineinfo.h" #include "lineinfo.h"
#include "nexttok.h" #include "nexttok.h"
#include "dbginfo.h" #include "symtab.h"
@@ -57,6 +60,9 @@
/* The current line info */ /* The current line info */
static LineInfo* CurLineInfo = 0; static LineInfo* CurLineInfo = 0;
/* List of high level language debug symbols */
static Collection HLDbgSyms = STATIC_COLLECTION_INITIALIZER;
/*****************************************************************************/ /*****************************************************************************/
@@ -65,6 +71,26 @@ static LineInfo* CurLineInfo = 0;
static HLDbgSym* NewHLDbgSym (unsigned Flags, unsigned Name, unsigned Type)
/* Allocate and return a new HLDbgSym structure */
{
/* Allocate memory */
HLDbgSym* S = xmalloc (sizeof (*S));
/* Initialize the fields as necessary */
S->Flags = Flags;
S->Name = Name;
S->AsmName = EMPTY_STRING_ID;
S->Offs = 0;
S->Type = Type;
S->ScopeId = CurrentScope->Id;
/* Return the result */
return S;
}
void DbgInfoFile (void) void DbgInfoFile (void)
/* Parse and handle FILE subcommand of the .dbg pseudo instruction */ /* Parse and handle FILE subcommand of the .dbg pseudo instruction */
{ {
@@ -112,10 +138,11 @@ void DbgInfoFunc (void)
"STATIC", "STATIC",
}; };
StrBuf Name = STATIC_STRBUF_INITIALIZER; unsigned Name;
StrBuf Type = STATIC_STRBUF_INITIALIZER; unsigned Type;
StrBuf AsmName = STATIC_STRBUF_INITIALIZER; unsigned AsmName;
int StorageClass; unsigned Flags;
HLDbgSym* S;
/* Parameters are separated by a comma */ /* Parameters are separated by a comma */
@@ -126,7 +153,7 @@ void DbgInfoFunc (void)
ErrorSkip ("String constant expected"); ErrorSkip ("String constant expected");
return; return;
} }
SB_Copy (&Name, &CurTok.SVal); Name = GetStrBufId (&CurTok.SVal);
NextTok (); NextTok ();
/* Comma expected */ /* Comma expected */
@@ -137,7 +164,7 @@ void DbgInfoFunc (void)
ErrorSkip ("String constant expected"); ErrorSkip ("String constant expected");
return; return;
} }
SB_Copy (&Type, &CurTok.SVal); Type = GetStrBufId (&CurTok.SVal);
NextTok (); NextTok ();
/* Comma expected */ /* Comma expected */
@@ -148,10 +175,10 @@ void DbgInfoFunc (void)
ErrorSkip ("Storage class specifier expected"); ErrorSkip ("Storage class specifier expected");
return; return;
} }
StorageClass = GetSubKey (StorageKeys, sizeof (StorageKeys)/sizeof (StorageKeys[0])); switch (GetSubKey (StorageKeys, sizeof (StorageKeys)/sizeof (StorageKeys[0]))) {
if (StorageClass < 0) { case 0: Flags = HL_TYPE_FUNC | HL_SC_EXTERN; break;
ErrorSkip ("Storage class specifier expected"); case 1: Flags = HL_TYPE_FUNC | HL_SC_STATIC; break;
return; default: ErrorSkip ("Storage class specifier expected"); return;
} }
NextTok (); NextTok ();
@@ -163,13 +190,23 @@ void DbgInfoFunc (void)
ErrorSkip ("String constant expected"); ErrorSkip ("String constant expected");
return; return;
} }
SB_Copy (&AsmName, &CurTok.SVal); AsmName = GetStrBufId (&CurTok.SVal);
NextTok (); NextTok ();
/* Free memory used for the strings */ /* There may only be one function per scope */
SB_Done (&AsmName); if (CurrentScope == RootScope) {
SB_Done (&Type); ErrorSkip ("Functions may not be used in the root scope");
SB_Done (&Name); return;
} else if (CurrentScope->Flags & ST_EXTFUNC) {
ErrorSkip ("Only one function per scope allowed");
return;
}
CurrentScope->Flags |= ST_EXTFUNC;
/* Add the function */
S = NewHLDbgSym (Flags, Name, Type);
S->AsmName = AsmName;
CollAppend (&HLDbgSyms, S);
} }
@@ -235,11 +272,12 @@ void DbgInfoSym (void)
"STATIC", "STATIC",
}; };
StrBuf Name = STATIC_STRBUF_INITIALIZER; unsigned Name;
StrBuf Type = STATIC_STRBUF_INITIALIZER; unsigned Type;
StrBuf AsmName = STATIC_STRBUF_INITIALIZER; unsigned AsmName = EMPTY_STRING_ID;
int StorageClass; unsigned Flags;
int Offs; int Offs;
HLDbgSym* S;
/* Parameters are separated by a comma */ /* Parameters are separated by a comma */
@@ -250,7 +288,7 @@ void DbgInfoSym (void)
ErrorSkip ("String constant expected"); ErrorSkip ("String constant expected");
return; return;
} }
SB_Copy (&Name, &CurTok.SVal); Name = GetStrBufId (&CurTok.SVal);
NextTok (); NextTok ();
/* Comma expected */ /* Comma expected */
@@ -261,7 +299,7 @@ void DbgInfoSym (void)
ErrorSkip ("String constant expected"); ErrorSkip ("String constant expected");
return; return;
} }
SB_Copy (&Type, &CurTok.SVal); Type = GetStrBufId (&CurTok.SVal);
NextTok (); NextTok ();
/* Comma expected */ /* Comma expected */
@@ -272,10 +310,12 @@ void DbgInfoSym (void)
ErrorSkip ("Storage class specifier expected"); ErrorSkip ("Storage class specifier expected");
return; return;
} }
StorageClass = GetSubKey (StorageKeys, sizeof (StorageKeys)/sizeof (StorageKeys[0])); switch (GetSubKey (StorageKeys, sizeof (StorageKeys)/sizeof (StorageKeys[0]))) {
if (StorageClass < 0) { case 0: Flags = HL_SC_AUTO; break;
ErrorSkip ("Storage class specifier expected"); case 1: Flags = HL_SC_EXTERN; break;
return; case 2: Flags = HL_SC_REG; break;
case 3: Flags = HL_SC_STATIC; break;
default: ErrorSkip ("Storage class specifier expected"); return;
} }
/* Skip the storage class token and the following comma */ /* Skip the storage class token and the following comma */
@@ -283,26 +323,30 @@ void DbgInfoSym (void)
ConsumeComma (); ConsumeComma ();
/* The next tokens depend on the storage class */ /* The next tokens depend on the storage class */
if (StorageClass == 0) { if (Flags == HL_SC_AUTO) {
/* Auto: Stack offset follows */ /* Auto: Stack offset follows */
Offs = ConstExpression (); Offs = ConstExpression ();
} else if (StorageClass == 2) {
/* Register: Register bank offset follows */
Offs = ConstExpression ();
} else { } else {
/* Extern or static: Assembler name follows */ /* Register, extern or static: Assembler name follows */
if (CurTok.Tok != TOK_STRCON) { if (CurTok.Tok != TOK_STRCON) {
ErrorSkip ("String constant expected"); ErrorSkip ("String constant expected");
return; return;
} }
SB_Copy (&AsmName, &CurTok.SVal); AsmName = GetStrBufId (&CurTok.SVal);
NextTok (); NextTok ();
/* For register, an offset follows */
if (Flags == HL_SC_REG) {
ConsumeComma ();
Offs = ConstExpression ();
}
} }
/* Free memory used for the strings */ /* Add the function */
SB_Done (&AsmName); S = NewHLDbgSym (Flags | HL_TYPE_SYM, Name, Type);
SB_Done (&Type); S->AsmName = AsmName;
SB_Done (&Name); S->Offs = Offs;
CollAppend (&HLDbgSyms, S);
} }

View File

@@ -58,6 +58,7 @@
/* Symbol table flags */ /* Symbol table flags */
#define ST_NONE 0x00 /* No flags */ #define ST_NONE 0x00 /* No flags */
#define ST_DEFINED 0x01 /* Scope has been defined */ #define ST_DEFINED 0x01 /* Scope has been defined */
#define ST_EXTFUNC 0x02 /* External debug function assigned */
/* A symbol table */ /* A symbol table */
typedef struct SymTable SymTable; typedef struct SymTable SymTable;

View File

@@ -355,7 +355,7 @@ static void F_RestoreRegVars (Function* F)
if (!F_HasVoidReturn (F)) { if (!F_HasVoidReturn (F)) {
g_restore (CF_CHAR | CF_FORCECHAR); g_restore (CF_CHAR | CF_FORCECHAR);
} }
} }
@@ -381,7 +381,7 @@ static void EmitDebugInfo (void)
AddTextLine ("\t.dbg\tsym, \"%s\", \"\", auto, %d", AddTextLine ("\t.dbg\tsym, \"%s\", \"\", auto, %d",
Sym->Name, Sym->V.Offs); Sym->Name, Sym->V.Offs);
} else if (Sym->Flags & SC_REGISTER) { } else if (Sym->Flags & SC_REGISTER) {
AddTextLine ("\t.dbg\tsym, \"%s\", \"\", register, %d", AddTextLine ("\t.dbg\tsym, \"%s\", \"\", register, \"regbank\", %d",
Sym->Name, Sym->V.R.RegOffs); Sym->Name, Sym->V.R.RegOffs);
} else { } else {