diff --git a/.gitignore b/.gitignore index ad6600a..463dfbb 100644 --- a/.gitignore +++ b/.gitignore @@ -349,3 +349,5 @@ make/oscar64 *.recipe *.exe *.dbj +*.json +*.mapd diff --git a/oscar64/Compiler.cpp b/oscar64/Compiler.cpp index da66c16..1eae8e1 100644 --- a/oscar64/Compiler.cpp +++ b/oscar64/Compiler.cpp @@ -1321,6 +1321,23 @@ int Compiler::ExecuteCode(bool profile, int trace) return ecode; } +static void DumpReferences(FILE* file, Declaration* dec) +{ + if (dec->mReferences.Size()) + { + fprintf(file, ", \"references\": ["); + for (int i = 0; i < dec->mReferences.Size(); i++) + { + if (i > 0) + fprintf(file, ","); + Expression* exp = dec->mReferences[i]; + fprintf(file, "\n\t\t\t{\"source\": \"%s\", \"line\": %d, \"column\": %d}", exp->mLocation.mFileName, exp->mLocation.mLine, exp->mLocation.mColumn); + } + fprintf(file, "]"); + } + +} + bool Compiler::WriteDbjFile(const char* filename) { FILE* file; @@ -1346,7 +1363,9 @@ bool Compiler::WriteDbjFile(const char* filename) 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)); + DumpReferences(file, v->mDeclaration); + fprintf(file, "}"); } } } @@ -1416,7 +1435,7 @@ bool Compiler::WriteDbjFile(const char* filename) fprintf(file, ",\n"); vfirst = false; - fprintf(file, "\t\t{\"name\": \"%s\", \"start\": %d, \"end\": %d, \"enter\": %d, \"leave\": %d, \"typeid\": %d}", + 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)); @@ -1436,7 +1455,7 @@ bool Compiler::WriteDbjFile(const char* filename) fprintf(file, ",\n"); vfirst = false; - fprintf(file, "\t\t\t{\"name\": \"%s\", \"start\": %d, \"end\": %d, \"base\": %d, \"enter\": %d, \"leave\": %d, \"typeid\": %d}", + 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)); @@ -1447,15 +1466,21 @@ bool Compiler::WriteDbjFile(const char* filename) fprintf(file, ",\n"); vfirst = false; - fprintf(file, "\t\t\t{\"name\": \"%s\", \"start\": %d, \"end\": %d, \"base\": %d, \"enter\": %d, \"leave\": %d, \"typeid\": %d}", + 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)); } + + if (v->mDeclaration) + DumpReferences(file, v->mDeclaration); + fprintf(file, "}"); } } - fprintf(file, "]}\n"); + fprintf(file, "]"); + DumpReferences(file, p->mDeclaration); + fprintf(file, "}\n"); } } fprintf(file, "\t],\n"); diff --git a/oscar64/Declaration.cpp b/oscar64/Declaration.cpp index 2195c9e..04d6a9d 100644 --- a/oscar64/Declaration.cpp +++ b/oscar64/Declaration.cpp @@ -986,7 +986,8 @@ Declaration::Declaration(const Location& loc, DecType type) mVarIndex(-1), mLinkerObject(nullptr), mCallers(nullptr), mCalled(nullptr), mAlignment(1), mFriends(nullptr), mInteger(0), mNumber(0), mMinValue(-0x80000000LL), mMaxValue(0x7fffffffLL), mFastCallBase(0), mFastCallSize(0), mStride(0), mStripe(1), mCompilerOptions(0), mUseCount(0), mTokens(nullptr), mParser(nullptr), - mShift(0), mBits(0), mOptFlags(0), mInlayRegion(nullptr) + mShift(0), mBits(0), mOptFlags(0), mInlayRegion(nullptr), + mReferences(nullptr) {} Declaration::~Declaration(void) diff --git a/oscar64/Declaration.h b/oscar64/Declaration.h index 9521dae..ed6e699 100644 --- a/oscar64/Declaration.h +++ b/oscar64/Declaration.h @@ -290,6 +290,7 @@ public: Parser * mParser; GrowingArray mCallers, mCalled, mFriends; + GrowingArray mReferences; bool CanAssign(const Declaration* fromType) const; bool IsSame(const Declaration* dec) const; diff --git a/oscar64/GlobalAnalyzer.cpp b/oscar64/GlobalAnalyzer.cpp index 9e0704f..bc0ba29 100644 --- a/oscar64/GlobalAnalyzer.cpp +++ b/oscar64/GlobalAnalyzer.cpp @@ -691,6 +691,9 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo case EX_VOID: break; case EX_CONSTANT: + if (mCompilerOptions & COPT_DEBUGINFO) + exp->mDecValue->mReferences.Push(exp); + if (exp->mDecValue->mType == DT_CONST_FUNCTION) AnalyzeProcedure(exp->mDecValue->mValue, exp->mDecValue); else if (exp->mDecValue->mType == DT_CONST_STRUCT) @@ -715,6 +718,9 @@ Declaration * GlobalAnalyzer::Analyze(Expression* exp, Declaration* procDec, boo return exp->mDecValue; case EX_VARIABLE: + if (mCompilerOptions & COPT_DEBUGINFO) + exp->mDecValue->mReferences.Push(exp); + if ((exp->mDecValue->mFlags & DTF_STATIC) || (exp->mDecValue->mFlags & DTF_GLOBAL)) { Declaration* type = exp->mDecValue->mBase; diff --git a/oscar64/Parser.cpp b/oscar64/Parser.cpp index af521dc..f3d0a66 100644 --- a/oscar64/Parser.cpp +++ b/oscar64/Parser.cpp @@ -5209,6 +5209,8 @@ Expression* Parser::ParseSimpleExpression(bool lhs) Declaration* dec = nullptr; Expression* exp = nullptr, * rexp = nullptr; + Location eloc(mScanner->mLocation); + switch (mScanner->mToken) { case TK_INT: @@ -5542,7 +5544,7 @@ Expression* Parser::ParseSimpleExpression(bool lhs) if (dec->mType == DT_CONST_INTEGER || dec->mType == DT_CONST_FLOAT || dec->mType == DT_CONST_FUNCTION || dec->mType == DT_CONST_ASSEMBLER || dec->mType == DT_LABEL || dec->mType == DT_LABEL_REF) { - exp = new Expression(mScanner->mLocation, EX_CONSTANT); + exp = new Expression(eloc, EX_CONSTANT); exp->mDecValue = dec; exp->mDecType = dec->mBase; exp->mConst = true; @@ -5565,7 +5567,7 @@ Expression* Parser::ParseSimpleExpression(bool lhs) if (!exp) { - exp = new Expression(mScanner->mLocation, EX_VARIABLE); + exp = new Expression(eloc, EX_VARIABLE); exp->mDecValue = dec; exp->mDecType = dec->mBase; }