1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-07-04 23:36:00 +02:00

Added MD5 file hashes to Beef

This commit is contained in:
Brian Fiete 2020-03-23 12:07:05 -07:00
parent 32c09bf94b
commit 61468d818f
33 changed files with 598 additions and 143 deletions

View file

@ -1289,7 +1289,10 @@ void BfDefBuilder::Visit(BfTypeDeclaration* typeDeclaration)
SetAndRestoreValue<HashContext*> prevSignatureHashCtx(mSignatureHashCtx, &signatureHashCtx);
if (bfParser != NULL)
{
mSignatureHashCtx->MixinStr(bfParser->mFileName);
mSignatureHashCtx->Mixin(bfParser->mParserData->mMD5Hash);
}
HashNode(*mSignatureHashCtx, typeDeclaration->mTypeNode);
for (auto& baseClassNode : typeDeclaration->mBaseClasses)
HashNode(*mSignatureHashCtx, baseClassNode);

View file

@ -1651,6 +1651,12 @@ void BfIRBuilder::Write(int64 intVal)
WriteSLEB128(intVal);
}
void BfIRBuilder::Write(Val128 val)
{
WriteSLEB128((int64)val.mLow);
WriteSLEB128((int64)val.mHigh);
}
void BfIRBuilder::Write(const StringImpl&str)
{
WriteSLEB128((int)str.length());
@ -4718,9 +4724,9 @@ BfIRMDNode BfIRBuilder::DbgCreateCompileUnit(int lang, const StringImpl& fileNam
return retVal;
}
BfIRMDNode BfIRBuilder::DbgCreateFile(const StringImpl& fileName, const StringImpl& directory)
BfIRMDNode BfIRBuilder::DbgCreateFile(const StringImpl& fileName, const StringImpl& directory, const Val128& md5Hash)
{
BfIRMDNode retVal = WriteCmd(BfIRCmd_DbgCreateFile, fileName, directory);
BfIRMDNode retVal = WriteCmd(BfIRCmd_DbgCreateFile, fileName, directory, md5Hash);
NEW_CMD_INSERTED_IRMD;
if (mDbgVerifyCodeGen && gDebugDbgLoc)

View file

@ -58,6 +58,7 @@ class BfFieldInstance;
class BfFileInstance;
class BfParser;
class BfParserData;
class Val128;
class BfFilePosition
{
@ -905,6 +906,7 @@ public:
void Write(bool val);
void Write(int val);
void Write(int64 val);
void Write(Val128 val);
void Write(const StringImpl& str);
void Write(const BfIRValue& irValue);
void Write(BfTypeCode typeCode);
@ -1195,7 +1197,7 @@ public:
void DbgAddPrefix(String& name);
BfIRMDNode DbgCreateCompileUnit(int lang, const StringImpl& filename, const StringImpl& directory, const StringImpl& producer, bool isOptimized,
const StringImpl& flags, int runtimeVer, bool linesOnly);
BfIRMDNode DbgCreateFile(const StringImpl& fileName, const StringImpl& directory);
BfIRMDNode DbgCreateFile(const StringImpl& fileName, const StringImpl& directory, const Val128& md5Hash);
BfIRMDNode DbgGetCurrentLocation();
void DbgSetType(BfType * type, BfIRMDNode diType);
void DbgSetInstType(BfType * type, BfIRMDNode diType);

View file

@ -1,6 +1,7 @@
#include "BfIRCodeGen.h"
#include "BfModule.h"
#include "BeefySysLib/util/BeefPerf.h"
#include "BeefySysLib/util/Hash.h"
#pragma warning(push)
#pragma warning(disable:4141)
@ -113,6 +114,7 @@
USING_NS_BF;
#pragma warning(disable:4146)
#pragma warning(disable:4996)
struct BuiltinEntry
{
@ -477,6 +479,12 @@ void BfIRCodeGen::Read(int64& i)
i = ReadSLEB128();
}
void BfIRCodeGen::Read(Val128& i)
{
i.mLow = (uint64)ReadSLEB128();
i.mHigh = (uint64)ReadSLEB128();
}
void BfIRCodeGen::Read(bool& val)
{
val = mStream->Read() != 0;
@ -2741,7 +2749,14 @@ void BfIRCodeGen::HandleNextCmd()
{
CMD_PARAM(String, fileName);
CMD_PARAM(String, directory);
SetResult(curId, mDIBuilder->createFile(fileName.c_str(), directory.c_str()));
CMD_PARAM(Val128, md5Hash);
char hashStr[64];
for (int i = 0; i < 16; i++)
sprintf(&hashStr[i * 2], "%.2x", ((uint8*)&md5Hash)[i]);
SetResult(curId, mDIBuilder->createFile(fileName.c_str(), directory.c_str(),
llvm::DIFile::ChecksumInfo<llvm::StringRef>(llvm::DIFile::CSK_MD5, hashStr)));
}
break;
case BfIRCmd_ConstValueI64:

View file

@ -111,6 +111,7 @@ public:
void Read(StringImpl& str);
void Read(int& i);
void Read(int64& i);
void Read(Val128& i);
void Read(bool& val);
void Read(BfIRTypeEntry*& type);
void Read(llvm::Type*& llvmType);

View file

@ -2168,7 +2168,7 @@ BfFileInstance* BfModule::GetFileFromNode(BfAstNode* astNode)
fileName[i] = DIR_SEP_CHAR;
}
bfFileInstance->mDIFile = mBfIRBuilder->DbgCreateFile(fileName.Substring(slashPos + 1), fileName.Substring(0, slashPos));
bfFileInstance->mDIFile = mBfIRBuilder->DbgCreateFile(fileName.Substring(slashPos + 1), fileName.Substring(0, slashPos), bfParser->mMD5Hash);
}
return bfFileInstance;
}

View file

@ -3382,6 +3382,12 @@ BF_EXPORT void BF_CALLTYPE BfParser_SetCharIdData(BfParser* bfParser, uint8* dat
memcpy(bfParser->mParserData->mCharIdData, data, length);
}
BF_EXPORT void BF_CALLTYPE BfParser_SetHashMD5(BfParser* bfParser, Val128* md5Hash)
{
if (md5Hash != NULL)
bfParser->mParserData->mMD5Hash = *md5Hash;
}
BF_EXPORT void BF_CALLTYPE BfParser_Delete(BfParser* bfParser)
{
if (bfParser->mNextRevision != NULL)

View file

@ -68,6 +68,7 @@ public:
BfParser* mUniqueParser; // For non-cached usage (ie: autocomplete)
String mFileName;
uint8* mCharIdData;
Val128 mMD5Hash;
HashSet<String> mDefines_Def;
HashSet<String> mDefines_NoDef;