From 305cf64d404046a5848613f3f46d4d3abf90e61e Mon Sep 17 00:00:00 2001 From: uz Date: Mon, 29 Aug 2011 18:55:03 +0000 Subject: [PATCH] Worked on high level language symbol info. git-svn-id: svn://svn.cc65.org/cc65/trunk@5279 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/ca65/dbginfo.c | 116 ++++++++++++++++++++++++++++++-------------- src/ca65/symtab.h | 1 + src/cc65/function.c | 4 +- 3 files changed, 83 insertions(+), 38 deletions(-) diff --git a/src/ca65/dbginfo.c b/src/ca65/dbginfo.c index 7c098aa33..7411e2d15 100644 --- a/src/ca65/dbginfo.c +++ b/src/ca65/dbginfo.c @@ -36,15 +36,18 @@ #include /* common */ +#include "coll.h" +#include "hldbgsym.h" #include "strbuf.h" /* ca65 */ +#include "dbginfo.h" #include "error.h" #include "expr.h" #include "filetab.h" #include "lineinfo.h" #include "nexttok.h" -#include "dbginfo.h" +#include "symtab.h" @@ -57,6 +60,9 @@ /* The current line info */ 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) /* Parse and handle FILE subcommand of the .dbg pseudo instruction */ { @@ -112,10 +138,11 @@ void DbgInfoFunc (void) "STATIC", }; - StrBuf Name = STATIC_STRBUF_INITIALIZER; - StrBuf Type = STATIC_STRBUF_INITIALIZER; - StrBuf AsmName = STATIC_STRBUF_INITIALIZER; - int StorageClass; + unsigned Name; + unsigned Type; + unsigned AsmName; + unsigned Flags; + HLDbgSym* S; /* Parameters are separated by a comma */ @@ -126,7 +153,7 @@ void DbgInfoFunc (void) ErrorSkip ("String constant expected"); return; } - SB_Copy (&Name, &CurTok.SVal); + Name = GetStrBufId (&CurTok.SVal); NextTok (); /* Comma expected */ @@ -137,7 +164,7 @@ void DbgInfoFunc (void) ErrorSkip ("String constant expected"); return; } - SB_Copy (&Type, &CurTok.SVal); + Type = GetStrBufId (&CurTok.SVal); NextTok (); /* Comma expected */ @@ -148,10 +175,10 @@ void DbgInfoFunc (void) ErrorSkip ("Storage class specifier expected"); return; } - StorageClass = GetSubKey (StorageKeys, sizeof (StorageKeys)/sizeof (StorageKeys[0])); - if (StorageClass < 0) { - ErrorSkip ("Storage class specifier expected"); - return; + switch (GetSubKey (StorageKeys, sizeof (StorageKeys)/sizeof (StorageKeys[0]))) { + case 0: Flags = HL_TYPE_FUNC | HL_SC_EXTERN; break; + case 1: Flags = HL_TYPE_FUNC | HL_SC_STATIC; break; + default: ErrorSkip ("Storage class specifier expected"); return; } NextTok (); @@ -163,13 +190,23 @@ void DbgInfoFunc (void) ErrorSkip ("String constant expected"); return; } - SB_Copy (&AsmName, &CurTok.SVal); + AsmName = GetStrBufId (&CurTok.SVal); NextTok (); - /* Free memory used for the strings */ - SB_Done (&AsmName); - SB_Done (&Type); - SB_Done (&Name); + /* There may only be one function per scope */ + if (CurrentScope == RootScope) { + ErrorSkip ("Functions may not be used in the root scope"); + 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", }; - StrBuf Name = STATIC_STRBUF_INITIALIZER; - StrBuf Type = STATIC_STRBUF_INITIALIZER; - StrBuf AsmName = STATIC_STRBUF_INITIALIZER; - int StorageClass; + unsigned Name; + unsigned Type; + unsigned AsmName = EMPTY_STRING_ID; + unsigned Flags; int Offs; + HLDbgSym* S; /* Parameters are separated by a comma */ @@ -250,7 +288,7 @@ void DbgInfoSym (void) ErrorSkip ("String constant expected"); return; } - SB_Copy (&Name, &CurTok.SVal); + Name = GetStrBufId (&CurTok.SVal); NextTok (); /* Comma expected */ @@ -261,7 +299,7 @@ void DbgInfoSym (void) ErrorSkip ("String constant expected"); return; } - SB_Copy (&Type, &CurTok.SVal); + Type = GetStrBufId (&CurTok.SVal); NextTok (); /* Comma expected */ @@ -272,10 +310,12 @@ void DbgInfoSym (void) ErrorSkip ("Storage class specifier expected"); return; } - StorageClass = GetSubKey (StorageKeys, sizeof (StorageKeys)/sizeof (StorageKeys[0])); - if (StorageClass < 0) { - ErrorSkip ("Storage class specifier expected"); - return; + switch (GetSubKey (StorageKeys, sizeof (StorageKeys)/sizeof (StorageKeys[0]))) { + case 0: Flags = HL_SC_AUTO; break; + case 1: Flags = HL_SC_EXTERN; break; + 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 */ @@ -283,26 +323,30 @@ void DbgInfoSym (void) ConsumeComma (); /* The next tokens depend on the storage class */ - if (StorageClass == 0) { + if (Flags == HL_SC_AUTO) { /* Auto: Stack offset follows */ Offs = ConstExpression (); - } else if (StorageClass == 2) { - /* Register: Register bank offset follows */ - Offs = ConstExpression (); } else { - /* Extern or static: Assembler name follows */ + /* Register, extern or static: Assembler name follows */ if (CurTok.Tok != TOK_STRCON) { ErrorSkip ("String constant expected"); return; } - SB_Copy (&AsmName, &CurTok.SVal); + AsmName = GetStrBufId (&CurTok.SVal); NextTok (); + + /* For register, an offset follows */ + if (Flags == HL_SC_REG) { + ConsumeComma (); + Offs = ConstExpression (); + } } - /* Free memory used for the strings */ - SB_Done (&AsmName); - SB_Done (&Type); - SB_Done (&Name); + /* Add the function */ + S = NewHLDbgSym (Flags | HL_TYPE_SYM, Name, Type); + S->AsmName = AsmName; + S->Offs = Offs; + CollAppend (&HLDbgSyms, S); } diff --git a/src/ca65/symtab.h b/src/ca65/symtab.h index ea7e66515..16b126d94 100644 --- a/src/ca65/symtab.h +++ b/src/ca65/symtab.h @@ -58,6 +58,7 @@ /* Symbol table flags */ #define ST_NONE 0x00 /* No flags */ #define ST_DEFINED 0x01 /* Scope has been defined */ +#define ST_EXTFUNC 0x02 /* External debug function assigned */ /* A symbol table */ typedef struct SymTable SymTable; diff --git a/src/cc65/function.c b/src/cc65/function.c index 18f6c42fb..06676a84e 100644 --- a/src/cc65/function.c +++ b/src/cc65/function.c @@ -355,7 +355,7 @@ static void F_RestoreRegVars (Function* F) if (!F_HasVoidReturn (F)) { g_restore (CF_CHAR | CF_FORCECHAR); } -} +} @@ -381,7 +381,7 @@ static void EmitDebugInfo (void) AddTextLine ("\t.dbg\tsym, \"%s\", \"\", auto, %d", Sym->Name, Sym->V.Offs); } 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); } else { -- 2.39.5