From a9fc83d63cd6bc3eaf5aa1045d79fc936ba0207e Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Mon, 20 Nov 2023 17:28:48 +0100 Subject: [PATCH] Add xname attribute to .dbj file --- oscar64/Compiler.cpp | 4 ++-- oscar64/Declaration.cpp | 24 ++++++++++++++++++++++++ oscar64/Declaration.h | 1 + oscar64/Disassembler.cpp | 6 +++--- oscar64/Disassembler.h | 2 +- oscar64/InterCodeGenerator.cpp | 1 + oscar64/Linker.cpp | 11 ++++++----- oscar64/Linker.h | 2 +- 8 files changed, 39 insertions(+), 12 deletions(-) diff --git a/oscar64/Compiler.cpp b/oscar64/Compiler.cpp index 7a73dea..3897627 100644 --- a/oscar64/Compiler.cpp +++ b/oscar64/Compiler.cpp @@ -1357,8 +1357,8 @@ bool Compiler::WriteDbjFile(const char* filename) fprintf(file, ",\n"); first = false; - fprintf(file, "\t\t{\"name\": \"%s\", \"start\": %d, \"end\": %d, \"typeid\": %d, \"source\": \"%s\", \"line\": %d, \"lines\": [\n", - p->mIdent->mString, p->mLinkerObject->mAddress, p->mLinkerObject->mAddress + p->mLinkerObject->mSize, types.IndexOrPush(p->mDeclaration->mBase), + fprintf(file, "\t\t{\"name\": \"%s\", \"xname\": \"%s\", \"start\": %d, \"end\": %d, \"typeid\": %d, \"source\": \"%s\", \"line\": %d, \"lines\": [\n", + p->mIdent->mString, p->mLinkerObject->mFullIdent->mString, p->mLinkerObject->mAddress, p->mLinkerObject->mAddress + p->mLinkerObject->mSize, types.IndexOrPush(p->mDeclaration->mBase), p->mLocation.mFileName, p->mLocation.mLine); bool lfirst = true; diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index 52f2ad3..6b5f01e 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -1176,6 +1176,30 @@ Declaration* Declaration::Last(void) return p; } +const Ident* Declaration::FullIdent(void) +{ + if (!this) + return Ident::Unique("null"); + if (mType == DT_CONST_FUNCTION) + { + const Ident* tident = MangleIdent()->Mangle("("); + Declaration* dec = mBase->mParams; + while (dec) + { + tident = tident->Mangle(dec->mBase->MangleIdent()->mString); + dec = dec->mNext; + if (dec) + tident = tident->Mangle(","); + } + tident = tident->Mangle(")->"); + tident = tident->Mangle(mBase->mBase->MangleIdent()->mString); + return tident; + } + else + return MangleIdent(); + +} + const Ident* Declaration::MangleIdent(void) { if (!this) diff --git a/oscar64/Declaration.h b/oscar64/Declaration.h index c4da608..0c066f2 100644 --- a/oscar64/Declaration.h +++ b/oscar64/Declaration.h @@ -338,6 +338,7 @@ public: Declaration* ExpandTemplate(DeclarationScope* scope); const Ident* MangleIdent(void); + const Ident* FullIdent(void); int Stride(void) const; }; diff --git a/oscar64/Disassembler.cpp b/oscar64/Disassembler.cpp index 10e868b..04db667 100644 --- a/oscar64/Disassembler.cpp +++ b/oscar64/Disassembler.cpp @@ -671,13 +671,13 @@ void NativeCodeDisassembler::DumpMemory(FILE* file, const uint8* memory, int ban } } -void NativeCodeDisassembler::Disassemble(FILE* file, const uint8* memory, int bank, int start, int size, InterCodeProcedure* proc, const Ident * ident, Linker* linker) +void NativeCodeDisassembler::Disassemble(FILE* file, const uint8* memory, int bank, int start, int size, InterCodeProcedure* proc, const Ident * ident, Linker* linker, const Ident * fident) { fprintf(file, "--------------------------------------------------------------------\n"); if (proc && proc->mIdent) - fprintf(file, "%s:\n", proc->mIdent->mString); + fprintf(file, "%s: ; %s\n", proc->mIdent->mString, fident->mString); else if (ident) - fprintf(file, "%s:\n", ident->mString); + fprintf(file, "%s: ; %s\n", ident->mString, fident->mString); char tbuffer[160], abuffer[160]; diff --git a/oscar64/Disassembler.h b/oscar64/Disassembler.h index 846a25e..f7a1e80 100644 --- a/oscar64/Disassembler.h +++ b/oscar64/Disassembler.h @@ -27,7 +27,7 @@ public: NativeCodeDisassembler(void); ~NativeCodeDisassembler(void); - void Disassemble(FILE* file, const uint8* memory, int bank, int start, int size, InterCodeProcedure* proc, const Ident* ident, Linker* linker); + void Disassemble(FILE* file, const uint8* memory, int bank, int start, int size, InterCodeProcedure* proc, const Ident* ident, Linker* linker, const Ident* fident); void DumpMemory(FILE* file, const uint8* memory, int bank, int start, int size, InterCodeProcedure* proc, const Ident* ident, Linker* linker, LinkerObject * lobj); protected: const char* TempName(uint8 tmp, char* buffer, InterCodeProcedure* proc, Linker* linker); diff --git a/oscar64/InterCodeGenerator.cpp b/oscar64/InterCodeGenerator.cpp index 9ec94dd..173c371 100644 --- a/oscar64/InterCodeGenerator.cpp +++ b/oscar64/InterCodeGenerator.cpp @@ -5134,6 +5134,7 @@ void InterCodeGenerator::TranslateLogic(Declaration* procType, InterCodeProcedur InterCodeProcedure* InterCodeGenerator::TranslateProcedure(InterCodeModule * mod, Expression* exp, Declaration * dec) { InterCodeProcedure* proc = new InterCodeProcedure(mod, dec->mLocation, dec->mQualIdent, mLinker->AddObject(dec->mLocation, dec->mQualIdent, dec->mSection, LOT_BYTE_CODE, dec->mAlignment)); + proc->mLinkerObject->mFullIdent = dec->FullIdent(); #if 0 if (proc->mIdent && !strcmp(proc->mIdent->mString, "main")) diff --git a/oscar64/Linker.cpp b/oscar64/Linker.cpp index fb9cf6a..5a6b4c6 100644 --- a/oscar64/Linker.cpp +++ b/oscar64/Linker.cpp @@ -44,7 +44,7 @@ bool LinkerReference::operator!=(const LinkerReference& ref) } LinkerObject::LinkerObject(void) - : mReferences(nullptr), mNumTemporaries(0), mSize(0), mAlignment(1), mStackSection(nullptr) + : mReferences(nullptr), mNumTemporaries(0), mSize(0), mAlignment(1), mStackSection(nullptr), mIdent(nullptr), mFullIdent(nullptr) {} LinkerObject::~LinkerObject(void) @@ -315,6 +315,7 @@ LinkerObject * Linker::AddObject(const Location& location, const Ident* ident, L obj->mData = nullptr; obj->mSize = 0; obj->mIdent = ident; + obj->mFullIdent = ident; obj->mSection = section; obj->mRegion = nullptr; obj->mProc = nullptr; @@ -1435,8 +1436,8 @@ bool Linker::WriteDbjFile(FILE* file) fprintf(file, ",\n"); first = false; - fprintf(file, "\t\t{\"name\": \"%s\", \"start\": %d, \"end\": %d, \"type\": \"%s\", \"source\": \"%s\", \"line\": %d }", - obj->mIdent->mString, obj->mAddress, obj->mAddress + obj->mSize, LinkerObjectTypeNames[obj->mType], + fprintf(file, "\t\t{\"name\": \"%s\", \"xname\": \"%s\", \"start\": %d, \"end\": %d, \"type\": \"%s\", \"source\": \"%s\", \"line\": %d }", + obj->mIdent->mString, obj->mFullIdent->mString, obj->mAddress, obj->mAddress + obj->mSize, LinkerObjectTypeNames[obj->mType], obj->mLocation.mFileName, obj->mLocation.mLine); } } @@ -1496,10 +1497,10 @@ bool Linker::WriteAsmFile(const char* filename) int i = 0; while (!(obj->mRegion->mCartridgeBanks & (1ULL << i))) i++; - mNativeDisassembler.Disassemble(file, mCartridge[i], i, obj->mAddress, obj->mSize, obj->mProc, obj->mIdent, this); + mNativeDisassembler.Disassemble(file, mCartridge[i], i, obj->mAddress, obj->mSize, obj->mProc, obj->mIdent, this, obj->mFullIdent); } else - mNativeDisassembler.Disassemble(file, mMemory, -1, obj->mAddress, obj->mSize, obj->mProc, obj->mIdent, this); + mNativeDisassembler.Disassemble(file, mMemory, -1, obj->mAddress, obj->mSize, obj->mProc, obj->mIdent, this, obj->mFullIdent); break; case LOT_DATA: if (obj->mRegion->mCartridgeBanks) diff --git a/oscar64/Linker.h b/oscar64/Linker.h index c9d9348..cfa308d 100644 --- a/oscar64/Linker.h +++ b/oscar64/Linker.h @@ -179,7 +179,7 @@ class LinkerObject { public: Location mLocation; - const Ident * mIdent; + const Ident * mIdent, * mFullIdent; LinkerObjectType mType; int mID, mMapID; int mAddress, mRefAddress;