Add "enter" and "leave" attributes to dbj for local variables

This commit is contained in:
drmortalwombat 2023-05-17 18:27:09 +02:00
parent d4caa6bb71
commit f8d69f7945
5 changed files with 30 additions and 6 deletions

View File

@ -1103,7 +1103,10 @@ bool Compiler::WriteDbjFile(const char* filename)
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));
fprintf(file, "\t\t{\"name\": \"%s\", \"start\": %d, \"end\": %d, \"enter\": %d, \"leave\": %d, \"typeid\": %d}",
v->mIdent->mString, v->mLinkerObject->mAddress, v->mLinkerObject->mAddress + v->mLinkerObject->mSize,
v->mDeclaration->mLocation.mLine, v->mDeclaration->mEndLocation.mLine,
types.IndexOrPush(v->mDeclaration->mBase));
}
else
{
@ -1120,7 +1123,10 @@ bool Compiler::WriteDbjFile(const char* filename)
fprintf(file, ",\n");
vfirst = false;
fprintf(file, "\t\t\t{\"name\": \"%s\", \"start\": %d, \"end\": %d, \"base\": %d, \"typeid\": %d}", v->mIdent->mString, v->mOffset, v->mOffset + v->mSize, BC_REG_LOCALS, types.IndexOrPush(v->mDeclaration->mBase));
fprintf(file, "\t\t\t{\"name\": \"%s\", \"start\": %d, \"end\": %d, \"base\": %d, \"enter\": %d, \"leave\": %d, \"typeid\": %d}",
v->mIdent->mString, v->mOffset, v->mOffset + v->mSize, BC_REG_LOCALS,
v->mDeclaration->mLocation.mLine, v->mDeclaration->mEndLocation.mLine,
types.IndexOrPush(v->mDeclaration->mBase));
}
else
{
@ -1128,7 +1134,10 @@ bool Compiler::WriteDbjFile(const char* filename)
fprintf(file, ",\n");
vfirst = false;
fprintf(file, "\t\t\t{\"name\": \"%s\", \"start\": %d, \"end\": %d, \"base\": %d, \"typeid\": %d}", v->mIdent->mString, v->mOffset, v->mOffset + v->mSize, BC_REG_STACK, types.IndexOrPush(v->mDeclaration->mBase));
fprintf(file, "\t\t\t{\"name\": \"%s\", \"start\": %d, \"end\": %d, \"base\": %d, \"enter\": %d, \"leave\": %d, \"typeid\": %d}",
v->mIdent->mString, v->mOffset, v->mOffset + v->mSize, BC_REG_STACK,
v->mDeclaration->mLocation.mLine, v->mDeclaration->mEndLocation.mLine,
types.IndexOrPush(v->mDeclaration->mBase));
}
}
}

View File

@ -82,6 +82,14 @@ Declaration* DeclarationScope::Lookup(const Ident* ident)
return mParent ? mParent->Lookup(ident) : nullptr;
}
void DeclarationScope::End(const Location& loc)
{
for (int i = 0; i < mHashSize; i++)
{
if (mHash[i].mDec)
mHash[i].mDec->mEndLocation = loc;
}
}
Expression::Expression(const Location& loc, ExpressionType type)
: mLocation(loc), mType(type), mLeft(nullptr), mRight(nullptr), mConst(false)
@ -594,7 +602,7 @@ Expression* Expression::ConstantFold(Errors * errors)
}
Declaration::Declaration(const Location& loc, DecType type)
: mLocation(loc), mType(type), mScope(nullptr), mData(nullptr), mIdent(nullptr), mSize(0), mOffset(0), mFlags(0), mComplexity(0), mLocalSize(0),
: mLocation(loc), mEndLocation(loc), mType(type), mScope(nullptr), mData(nullptr), mIdent(nullptr), mSize(0), mOffset(0), mFlags(0), mComplexity(0), mLocalSize(0),
mBase(nullptr), mParams(nullptr), mValue(nullptr), mNext(nullptr), mVarIndex(-1), mLinkerObject(nullptr), mCallers(nullptr), mCalled(nullptr), mAlignment(1),
mInteger(0), mNumber(0), mMinValue(-0x80000000LL), mMaxValue(0x7fffffffLL), mFastCallBase(0), mFastCallSize(0), mStride(0), mStripe(1),
mCompilerOptions(0), mUseCount(0)

View File

@ -101,6 +101,8 @@ public:
Declaration* Insert(const Ident* ident, Declaration* dec);
Declaration* Lookup(const Ident* ident);
void End(const Location & loc);
DeclarationScope* mParent;
protected:
struct Entry
@ -183,7 +185,7 @@ public:
Declaration(const Location & loc, DecType type);
~Declaration(void);
Location mLocation;
Location mLocation, mEndLocation;
DecType mType;
Token mToken;
Declaration* mBase, *mParams, * mNext;

View File

@ -239,7 +239,6 @@ public:
class InterVariable
{
public:
Location mLocation;
bool mUsed, mAliased, mTemp;
int mIndex, mSize, mOffset, mAddr, mTempIndex;
int mNumReferences;

View File

@ -2137,6 +2137,7 @@ Expression* Parser::ParseFunction(Declaration * dec)
Expression * exp = ParseStatement();
mScope->End(mScanner->mLocation);
mScope = mScope->mParent;
return exp;
@ -2183,6 +2184,8 @@ Expression* Parser::ParseStatement(void)
} while (mScanner->mToken != TK_CLOSE_BRACE && mScanner->mToken != TK_EOF);
if (mScanner->mToken != TK_CLOSE_BRACE)
mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "'}' expected");
mScope->End(mScanner->mLocation);
mScanner->NextToken();
}
else
@ -2222,6 +2225,7 @@ Expression* Parser::ParseStatement(void)
exp->mLeft = ParseParenthesisExpression();
exp->mRight = ParseStatement();
mScope->End(mScanner->mLocation);
mScope = mScope->mParent;
}
break;
@ -2281,6 +2285,7 @@ Expression* Parser::ParseStatement(void)
else
mErrors->Error(mScanner->mLocation, EERR_SYNTAX, "')' expected");
bodyExp = ParseStatement();
mScope->End(mScanner->mLocation);
exp->mLeft = new Expression(mScanner->mLocation, EX_SEQUENCE);
exp->mLeft->mLeft = new Expression(mScanner->mLocation, EX_SEQUENCE);
@ -3222,6 +3227,7 @@ Expression* Parser::ParseAssembler(void)
}
#endif
mScope->End(mScanner->mLocation);
mScope = mScope->mParent;
dassm->mSize = offset;
dassm->mScope->mParent = nullptr;