Skip to content

Commit fb8ee0e

Browse files
committed
extract the MD5Stream utility from IRGen to its own header file.
1 parent 97eb38e commit fb8ee0e

File tree

2 files changed

+46
-25
lines changed

2 files changed

+46
-25
lines changed

include/swift/Basic/MD5Stream.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//===--- MD5Stream.h - raw_ostream that compute MD5 ------------*- C++ -*-===//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2014 - 2022 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
#ifndef SWIFT_MD5STREAM_H
14+
#define SWIFT_MD5STREAM_H
15+
16+
#include "llvm/Support/MD5.h"
17+
#include "llvm/Support/raw_ostream.h"
18+
19+
namespace swift {
20+
21+
/// An output stream which calculates the MD5 hash of the streamed data.
22+
class MD5Stream : public llvm::raw_ostream {
23+
private:
24+
25+
uint64_t Pos = 0;
26+
llvm::MD5 Hash;
27+
28+
void write_impl(const char *Ptr, size_t Size) override {
29+
Hash.update(ArrayRef<uint8_t>(reinterpret_cast<const uint8_t *>(Ptr), Size));
30+
Pos += Size;
31+
}
32+
33+
uint64_t current_pos() const override { return Pos; }
34+
35+
public:
36+
37+
void final(llvm::MD5::MD5Result &Result) {
38+
flush();
39+
Hash.final(Result);
40+
}
41+
};
42+
43+
} // namespace swift
44+
45+
#endif

lib/IRGen/IRGen.cpp

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "swift/AST/TBDGenRequests.h"
2828
#include "swift/Basic/Defer.h"
2929
#include "swift/Basic/Dwarf.h"
30+
#include "swift/Basic/MD5Stream.h"
3031
#include "swift/Basic/Platform.h"
3132
#include "swift/Basic/Statistic.h"
3233
#include "swift/Basic/Version.h"
@@ -69,7 +70,6 @@
6970
#include "llvm/Support/ErrorHandling.h"
7071
#include "llvm/Support/FileSystem.h"
7172
#include "llvm/Support/FormattedStream.h"
72-
#include "llvm/Support/MD5.h"
7373
#include "llvm/Support/Mutex.h"
7474
#include "llvm/Support/Path.h"
7575
#include "llvm/Target/TargetMachine.h"
@@ -376,30 +376,6 @@ void swift::performLLVMOptimizations(const IRGenOptions &Opts,
376376
}
377377
}
378378

379-
namespace {
380-
/// An output stream which calculates the MD5 hash of the streamed data.
381-
class MD5Stream : public llvm::raw_ostream {
382-
private:
383-
384-
uint64_t Pos = 0;
385-
llvm::MD5 Hash;
386-
387-
void write_impl(const char *Ptr, size_t Size) override {
388-
Hash.update(ArrayRef<uint8_t>(reinterpret_cast<const uint8_t *>(Ptr), Size));
389-
Pos += Size;
390-
}
391-
392-
uint64_t current_pos() const override { return Pos; }
393-
394-
public:
395-
396-
void final(MD5::MD5Result &Result) {
397-
flush();
398-
Hash.final(Result);
399-
}
400-
};
401-
} // end anonymous namespace
402-
403379
/// Computes the MD5 hash of the llvm \p Module including the compiler version
404380
/// and options which influence the compilation.
405381
static MD5::MD5Result getHashOfModule(const IRGenOptions &Opts,

0 commit comments

Comments
 (0)