Add xname attribute to .dbj file

This commit is contained in:
drmortalwombat 2023-11-20 17:28:48 +01:00
parent a5f4cf3252
commit a9fc83d63c
8 changed files with 39 additions and 12 deletions

View File

@ -1357,8 +1357,8 @@ bool Compiler::WriteDbjFile(const char* filename)
fprintf(file, ",\n"); fprintf(file, ",\n");
first = false; first = false;
fprintf(file, "\t\t{\"name\": \"%s\", \"start\": %d, \"end\": %d, \"typeid\": %d, \"source\": \"%s\", \"line\": %d, \"lines\": [\n", 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->mAddress, p->mLinkerObject->mAddress + p->mLinkerObject->mSize, types.IndexOrPush(p->mDeclaration->mBase), 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); p->mLocation.mFileName, p->mLocation.mLine);
bool lfirst = true; bool lfirst = true;

View File

@ -1176,6 +1176,30 @@ Declaration* Declaration::Last(void)
return p; 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) const Ident* Declaration::MangleIdent(void)
{ {
if (!this) if (!this)

View File

@ -338,6 +338,7 @@ public:
Declaration* ExpandTemplate(DeclarationScope* scope); Declaration* ExpandTemplate(DeclarationScope* scope);
const Ident* MangleIdent(void); const Ident* MangleIdent(void);
const Ident* FullIdent(void);
int Stride(void) const; int Stride(void) const;
}; };

View File

@ -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"); fprintf(file, "--------------------------------------------------------------------\n");
if (proc && proc->mIdent) if (proc && proc->mIdent)
fprintf(file, "%s:\n", proc->mIdent->mString); fprintf(file, "%s: ; %s\n", proc->mIdent->mString, fident->mString);
else if (ident) else if (ident)
fprintf(file, "%s:\n", ident->mString); fprintf(file, "%s: ; %s\n", ident->mString, fident->mString);
char tbuffer[160], abuffer[160]; char tbuffer[160], abuffer[160];

View File

@ -27,7 +27,7 @@ public:
NativeCodeDisassembler(void); NativeCodeDisassembler(void);
~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); void DumpMemory(FILE* file, const uint8* memory, int bank, int start, int size, InterCodeProcedure* proc, const Ident* ident, Linker* linker, LinkerObject * lobj);
protected: protected:
const char* TempName(uint8 tmp, char* buffer, InterCodeProcedure* proc, Linker* linker); const char* TempName(uint8 tmp, char* buffer, InterCodeProcedure* proc, Linker* linker);

View File

@ -5134,6 +5134,7 @@ void InterCodeGenerator::TranslateLogic(Declaration* procType, InterCodeProcedur
InterCodeProcedure* InterCodeGenerator::TranslateProcedure(InterCodeModule * mod, Expression* exp, Declaration * dec) 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)); 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 0
if (proc->mIdent && !strcmp(proc->mIdent->mString, "main")) if (proc->mIdent && !strcmp(proc->mIdent->mString, "main"))

View File

@ -44,7 +44,7 @@ bool LinkerReference::operator!=(const LinkerReference& ref)
} }
LinkerObject::LinkerObject(void) 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) LinkerObject::~LinkerObject(void)
@ -315,6 +315,7 @@ LinkerObject * Linker::AddObject(const Location& location, const Ident* ident, L
obj->mData = nullptr; obj->mData = nullptr;
obj->mSize = 0; obj->mSize = 0;
obj->mIdent = ident; obj->mIdent = ident;
obj->mFullIdent = ident;
obj->mSection = section; obj->mSection = section;
obj->mRegion = nullptr; obj->mRegion = nullptr;
obj->mProc = nullptr; obj->mProc = nullptr;
@ -1435,8 +1436,8 @@ bool Linker::WriteDbjFile(FILE* file)
fprintf(file, ",\n"); fprintf(file, ",\n");
first = false; first = false;
fprintf(file, "\t\t{\"name\": \"%s\", \"start\": %d, \"end\": %d, \"type\": \"%s\", \"source\": \"%s\", \"line\": %d }", fprintf(file, "\t\t{\"name\": \"%s\", \"xname\": \"%s\", \"start\": %d, \"end\": %d, \"type\": \"%s\", \"source\": \"%s\", \"line\": %d }",
obj->mIdent->mString, obj->mAddress, obj->mAddress + obj->mSize, LinkerObjectTypeNames[obj->mType], obj->mIdent->mString, obj->mFullIdent->mString, obj->mAddress, obj->mAddress + obj->mSize, LinkerObjectTypeNames[obj->mType],
obj->mLocation.mFileName, obj->mLocation.mLine); obj->mLocation.mFileName, obj->mLocation.mLine);
} }
} }
@ -1496,10 +1497,10 @@ bool Linker::WriteAsmFile(const char* filename)
int i = 0; int i = 0;
while (!(obj->mRegion->mCartridgeBanks & (1ULL << i))) while (!(obj->mRegion->mCartridgeBanks & (1ULL << i)))
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 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; break;
case LOT_DATA: case LOT_DATA:
if (obj->mRegion->mCartridgeBanks) if (obj->mRegion->mCartridgeBanks)

View File

@ -179,7 +179,7 @@ class LinkerObject
{ {
public: public:
Location mLocation; Location mLocation;
const Ident * mIdent; const Ident * mIdent, * mFullIdent;
LinkerObjectType mType; LinkerObjectType mType;
int mID, mMapID; int mID, mMapID;
int mAddress, mRefAddress; int mAddress, mRefAddress;