Commit 94561463 authored by Christian Dietrich's avatar Christian Dietrich
Browse files

hash: report number of processed bytes

parent d36930d1
......@@ -12,6 +12,7 @@ struct Hash : protected MurMurHash3 {
struct digest {
enum { DIGEST_WORDS = algorithm::DIGEST_WORDS };
uint32_t value[algorithm::DIGEST_WORDS];
uint32_t length;
bool operator==(const digest &other) const {
for (unsigned i = 0; i < DIGEST_WORDS; i++) {
......@@ -55,7 +56,7 @@ struct Hash : protected MurMurHash3 {
const digest getDigest() const {
Hash copy = *this;
digest ret;
copy.finalize(ret.value);
ret.length = copy.finalize(ret.value);
return ret;
}
......@@ -99,6 +100,7 @@ struct Hash : protected MurMurHash3 {
}
Hash& operator<<(const digest & x) {
m_byteCount += x.length;
return processBytes(x.value, sizeof(x.value));
}
......
......@@ -152,11 +152,12 @@ public:
return *this;
}
void finalize(uint32_t *digest) {
uint32_t finalize(uint32_t *digest) {
//----------
// tail
uint64_t k1 = 0;
uint64_t k2 = 0;
// We use m_byteCount NOT here. On Purpose.
switch(m_blockByteIndex & 15)
{
case 15: k2 ^= ((uint64_t)m_block[14]) << 48;
......@@ -194,9 +195,11 @@ public:
((uint64_t*)digest)[0] = h1;
((uint64_t*)digest)[1] = h2;
return m_byteCount;
}
private:
protected:
void processBlock() {
uint64_t k1 = getblock64((uint64_t*)m_block, 0);
uint64_t k2 = getblock64((uint64_t*)m_block, 1);
......
......@@ -70,7 +70,7 @@ public:
return *this;
}
void finalize(uint32_t *digest) {
uint32_t finalize(uint32_t *digest) {
size_t bitCount = m_byteCount * 8;
processByte(0x80);
if (m_blockByteIndex > 56) {
......@@ -95,6 +95,8 @@ public:
processByte( static_cast<unsigned char>((bitCount) & 0xFF));
memcpy(digest, m_digest, sizeof(m_digest));
return m_byteCount;
}
private:
......
......@@ -20,13 +20,16 @@ public:
Visitor.hashDecl(Context.getTranslationUnitDecl());
// Context.getTranslationUnitDecl()->dump();
unsigned processed_bytes;
std::string hash = Visitor.GetHash(&processed_bytes);
if (toplevel_hash_stream) {
std::string hash = Visitor.GetHash();
toplevel_hash_stream->write(hash.c_str(), hash.length());
delete toplevel_hash_stream;
}
llvm::errs() << "top-level-hash: " << Visitor.GetHash() << "\n";
llvm::errs() << "top-level-hash: " << hash << "\n";
llvm::errs() << "processed bytes: " << processed_bytes << "\n";
}
private:
raw_ostream *toplevel_hash_stream;
......
......@@ -10,8 +10,12 @@ using namespace std;
typedef TranslationUnitHashVisitor HashVisitor;
string HashVisitor::GetHash() {
return toplevel_hash.getDigest().getHexDigest();
string HashVisitor::GetHash(unsigned *processed_bytes) {
auto hash = toplevel_hash.getDigest();
if (processed_bytes) {
*processed_bytes = hash.length;
}
return hash.getHexDigest();
}
/// Declarations
......
......@@ -107,7 +107,7 @@ public:
bool VisitAdjustedType(const AdjustedType *T);
bool VisitElaboratedType(const ElaboratedType *T);
std::string GetHash();
std::string GetHash(unsigned *processed_bytes = nullptr);
//C Exprs (no clang-builtins, ...)
/*bool VisitExpr(const Expr *Node);*/
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment