From f8d69f79452a516582e96273583565670c9cb72e Mon Sep 17 00:00:00 2001 From: drmortalwombat <90205530+drmortalwombat@users.noreply.github.com> Date: Wed, 17 May 2023 18:27:09 +0200 Subject: [PATCH] Add "enter" and "leave" attributes to dbj for local variables --- oscar64/Compiler.cpp | 15 ++++++++++++--- oscar64/Declaration.cpp | 10 +++++++++- oscar64/Declaration.h | 4 +++- oscar64/InterCode.h | 1 - oscar64/Parser.cpp | 6 ++++++ 5 files changed, 30 insertions(+), 6 deletions(-) diff --git a/oscar64/Compiler.cpp b/oscar64/Compiler.cpp index f34e865..3e899a1 100644 --- a/oscar64/Compiler.cpp +++ b/oscar64/Compiler.cpp @@ -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)); } } } diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index b0847f9..3446b0f 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -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) diff --git a/oscar64/Declaration.h b/oscar64/Declaration.h index a5cf229..b0e7c39 100644 --- a/oscar64/Declaration.h +++ b/oscar64/Declaration.h @@ -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; diff --git a/oscar64/InterCode.h b/oscar64/InterCode.h index 63e06ab..dd3853c 100644 --- a/oscar64/InterCode.h +++ b/oscar64/InterCode.h @@ -239,7 +239,6 @@ public: class InterVariable { public: - Location mLocation; bool mUsed, mAliased, mTemp; int mIndex, mSize, mOffset, mAddr, mTempIndex; int mNumReferences; diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index efcc14b..1e882a0 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -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;