Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Christian Dietrich
clang-hash
Commits
94561463
Commit
94561463
authored
Mar 22, 2016
by
Christian Dietrich
Browse files
hash: report number of processed bytes
parent
d36930d1
Changes
6
Hide whitespace changes
Inline
Side-by-side
src/Hash.h
View file @
94561463
...
...
@@ -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
));
}
...
...
src/MurMurHash3.h
View file @
94561463
...
...
@@ -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
;
}
pr
ivate
:
pr
otected
:
void
processBlock
()
{
uint64_t
k1
=
getblock64
((
uint64_t
*
)
m_block
,
0
);
uint64_t
k2
=
getblock64
((
uint64_t
*
)
m_block
,
1
);
...
...
src/SHA1.h
View file @
94561463
...
...
@@ -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:
...
...
src/clang-hash.cc
View file @
94561463
...
...
@@ -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
;
...
...
src/hash-visitor.cc
View file @
94561463
...
...
@@ -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
...
...
src/hash-visitor.h
View file @
94561463
...
...
@@ -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);*/
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment