Skip to content

Commit

Permalink
Add local variables to .dbj files
Browse files Browse the repository at this point in the history
  • Loading branch information
drmortalwombat committed Apr 9, 2023
1 parent 85df217 commit 373ef6c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
56 changes: 51 additions & 5 deletions oscar64/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,11 +997,14 @@ bool Compiler::WriteDbjFile(const char* filename)
InterVariable* v(mInterCodeModule->mGlobalVars[i]);
if (v->mLinkerObject && v->mIdent && v->mDeclaration)
{
if (!first)
fprintf(file, ",\n");
first = false;
if (v->mLinkerObject->mSection->mType != LST_STATIC_STACK && v->mLinkerObject->mFlags & LOBJF_PLACED)
{
if (!first)
fprintf(file, ",\n");
first = false;

fprintf(file, "\t\t{\"name\": \"%s\", \"start\": %d, \"end\": %d, \"typeid\": %d}", v->mIdent->mString, v->mLinkerObject->mAddress, v->mLinkerObject->mAddress + v->mLinkerObject->mSize, types.IndexOrPush(v->mDeclaration->mBase));
fprintf(file, "\t\t{\"name\": \"%s\", \"start\": %d, \"end\": %d, \"typeid\": %d}", v->mIdent->mString, v->mLinkerObject->mAddress, v->mLinkerObject->mAddress + v->mLinkerObject->mSize, types.IndexOrPush(v->mDeclaration->mBase));
}
}
}
fprintf(file, "\t],\n");
Expand Down Expand Up @@ -1037,7 +1040,50 @@ bool Compiler::WriteDbjFile(const char* filename)
lo->mCodeLocations[j].mLocation.mLine);
}

fprintf(file, "]}");
fprintf(file, "], \n\t\t\t\"variables\":[\n");

bool vfirst = true;
for (int i = 0; i < p->mParamVars.Size(); i++)
{
InterVariable* v(p->mParamVars[i]);
if (v && v->mIdent)
{
if (v->mLinkerObject)
{
}
else
{
if (!vfirst)
fprintf(file, ",\n");
vfirst = false;

fprintf(file, "\t\t\t{\"name\": \"%s\", \"start\": %d, \"end\": %d, \"typeid\": %d}", v->mIdent->mString, i + BC_REG_FPARAMS, i + BC_REG_FPARAMS + v->mSize, types.IndexOrPush(v->mDeclaration->mBase));
}
}
}
for (int i = 0; i < p->mLocalVars.Size(); i++)
{
InterVariable* v(p->mLocalVars[i]);
if (v && v->mIdent)
{
if (v->mLinkerObject)
{
if (v->mLinkerObject->mFlags & LOBJF_PLACED)
{
if (!vfirst)
fprintf(file, ",\n");
vfirst = false;

fprintf(file, "\t\t{\"name\": \"%s\", \"start\": %d, \"end\": %d, \"typeid\": %d}", v->mIdent->mString, v->mLinkerObject->mAddress, v->mLinkerObject->mAddress + v->mLinkerObject->mSize, types.IndexOrPush(v->mDeclaration->mBase));
}
}
else
{
}
}
}

fprintf(file, "]}\n");
}
}
fprintf(file, "\t],\n");
Expand Down
2 changes: 2 additions & 0 deletions oscar64/InterCodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ void InterCodeGenerator::InitParameter(InterCodeProcedure* proc, Declaration* de
{
proc->mParamVars[index] = new InterVariable();
proc->mParamVars[index]->mIdent = dec->mIdent;
proc->mParamVars[index]->mDeclaration = dec;
}
}

Expand All @@ -288,6 +289,7 @@ void InterCodeGenerator::InitLocalVariable(InterCodeProcedure* proc, Declaration
{
proc->mLocalVars[index] = new InterVariable();
proc->mLocalVars[index]->mIdent = dec->mIdent;
proc->mLocalVars[index]->mDeclaration = dec;
}
}
static const Ident* StructIdent(const Ident* base, const Ident* item)
Expand Down

0 comments on commit 373ef6c

Please sign in to comment.