1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 03:28:20 +02:00

Order-independent hash fixes

This commit is contained in:
Brian Fiete 2019-09-27 13:04:33 -07:00
parent 2ea5d31c37
commit d41a8c5683
3 changed files with 97 additions and 6 deletions

View file

@ -241,6 +241,12 @@ BeIRCodeGen::~BeIRCodeGen()
void BeIRCodeGen::Hash(BeHashContext& hashCtx)
{
// if (mBeModule->mModuleName == "IDE_IDEApp")
// {
// hashCtx.mDbgViz = true;
// NOP;
// }
hashCtx.Mixin(mPtrSize);
hashCtx.Mixin(mIsOptimized);
if (mBeModule != NULL)
@ -2782,6 +2788,7 @@ void BeIRCodeGen::HandleNextCmd()
if (dbgFunc->mValue != NULL)
dbgFunc->mValue->mDbgFunction = dbgFunc;
dbgFunc->mIdx = (int)mBeModule->mDbgModule->mFuncs.size();
mBeModule->mDbgModule->mFuncs.push_back(dbgFunc);
SetResult(curId, dbgFunc);
@ -2823,6 +2830,7 @@ void BeIRCodeGen::HandleNextCmd()
}*/
if (dbgFunc->mValue != NULL)
dbgFunc->mValue->mDbgFunction = dbgFunc;
dbgFunc->mIdx = (int)mBeModule->mDbgModule->mFuncs.size();
mBeModule->mDbgModule->mFuncs.push_back(dbgFunc);
SetResult(curId, dbgFunc);

View file

@ -3264,9 +3264,89 @@ void BeDbgModule::HashContent(BeHashContext & hashCtx)
hashCtx.MixinStr(mDirectory);
hashCtx.MixinStr(mProducer);
for (auto dbgFunc : mFuncs)
dbgFunc->HashReference(hashCtx);
BeDumpContext dc;
dc.mModule = mBeModule;
String lhsName;
String rhsName;
for (auto globalVar : mGlobalVariables)
globalVar->HashReference(hashCtx);
if (!mFuncs.IsEmpty())
{
auto _GetName = [&](BeDbgFunction* func, String& str)
{
if (!func->mLinkageName.IsEmpty())
str.Append(func->mLinkageName);
else
dc.ToString(str, func);
};
Array<BeDbgFunction*> unrefFuncs;
for (auto dbgFunc : mFuncs)
{
if ((!dbgFunc->mIncludedAsMember) && (dbgFunc->mHashId == -1))
unrefFuncs.Add(dbgFunc);
}
std::sort(unrefFuncs.begin(), unrefFuncs.end(), [&](BeDbgFunction* lhs, BeDbgFunction* rhs)
{
lhsName.Clear();
_GetName(lhs, lhsName);
rhsName.Clear();
_GetName(rhs, rhsName);
int cmp = String::Compare(lhsName, rhsName, false);
if (cmp != 0)
return cmp < 0;
if (lhs->mFile != rhs->mFile)
{
lhsName.Clear();
rhsName.Clear();
if (lhs->mFile != NULL)
lhs->mFile->ToString(lhsName);
if (rhs->mFile != NULL)
rhs->mFile->ToString(rhsName);
cmp = String::Compare(lhsName, rhsName, false);
if (cmp != 0)
return cmp < 0;
}
if (lhs->mLine != rhs->mLine)
return lhs->mLine < rhs->mLine;
return lhs->mIdx < rhs->mIdx;
});
hashCtx.Mixin(unrefFuncs.size());
for (auto dbgFunc : unrefFuncs)
{
if (dbgFunc->mHashId == -1)
dbgFunc->HashReference(hashCtx);
}
}
if (!mGlobalVariables.IsEmpty())
{
auto _GetName = [&](BeDbgGlobalVariable* func, String& str)
{
if (!func->mLinkageName.IsEmpty())
str.Append(func->mLinkageName);
else
dc.ToString(str, func);
};
std::sort(mGlobalVariables.begin(), mGlobalVariables.end(), [&](BeDbgGlobalVariable* lhs, BeDbgGlobalVariable* rhs)
{
lhsName.Clear();
_GetName(lhs, lhsName);
rhsName.Clear();
_GetName(rhs, rhsName);
return (lhsName < rhsName);
});
for (auto globalVar : mGlobalVariables)
globalVar->HashReference(hashCtx);
}
}

View file

@ -1764,6 +1764,8 @@ public:
BE_VALUE_TYPE(BeDbgFunction, BeMDNode);
public:
int mIdx;
BeMDNode* mScope;
BeDbgFile* mFile;
int mLine;
@ -1793,6 +1795,7 @@ public:
public:
BeDbgFunction()
{
mIdx = -1;
mScope = NULL;
mFile = NULL;
mLine = -1;
@ -2009,8 +2012,8 @@ public:
virtual void HashContent(BeHashContext& hashCtx) override
{
hashCtx.Mixin(TypeId);
hashCtx.Mixin(mName);
hashCtx.Mixin(mLinkageName);
hashCtx.MixinStr(mName);
hashCtx.MixinStr(mLinkageName);
if (mFile != NULL)
mFile->HashReference(hashCtx);
hashCtx.Mixin(mLineNum);