LLVM: include/llvm/Support/HashingOutputBackend.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17#ifndef LLVM_SUPPORT_HASHINGOUTPUTBACKEND_H

18#define LLVM_SUPPORT_HASHINGOUTPUTBACKEND_H

19

26#include

27

29

30

31template

33private:

36

38 HashBuilderT Builder;

39

40 void write_impl(const char *Ptr, size_t Size) override {

41 OS.write(Ptr, Size);

42 }

43

44 void pwrite_impl(const char *Ptr, size_t Size, uint64_t Offset) override {

46 }

47

48 uint64_t current_pos() const override { return OS.str().size(); }

49

50public:

52

53 auto final() {

54 Builder.update(OS.str());

55 return Builder.final();

56 }

57};

58

59template class HashingOutputFile;

60

61

63private:

66 std::lock_guardstd::mutex Lock(OutputHashLock);

67 OutputHashes[Path] = Hash.str();

68 }

69

70protected:

74

77 return std::make_unique<HashingOutputFile>(Path, *this);

78 }

79

80public:

81

82

83

84 auto outputFiles() const { return OutputHashes.keys(); }

85

86

87

88

89

91 auto F = OutputHashes.find(Path);

92 if (F == OutputHashes.end())

93 return std::nullopt;

94 return toHex(F->second);

95 }

96

97private:

98 std::mutex OutputHashLock;

100};

101

102

103template

105public:

107 auto Result = OS.final();

108 Backend.addOutputFile(OutputPath, toStringRef(Result));

110 }

113

116 : OutputPath(OutputPath.str()), Backend(Backend) {}

117

118private:

119 const std::string OutputPath;

122};

123

124}

125

126#endif

This file defines the StringMap class.

This file contains the declarations of the VirtualOutputBackend class, which can be used to virtualiz...

This file contains the declarations of the OutputConfig class.

Lightweight error class with error context and mandatory checking.

static ErrorSuccess success()

Create a success value.

Tagged union holding either a T or a Error.

Interface to help hash various types through a hasher type.

A smart pointer to a reference-counted object that inherits from RefCountedBase or ThreadSafeRefCount...

This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.

StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...

StringRef - Represent a constant reference to a string, i.e.

std::string str() const

str - Get the contents as an std::string.

void SetUnbuffered()

Set the stream to be unbuffered.

An abstract base class for streams implementations that also support a pwrite operation.

A raw_ostream that writes to an SmallVector or SmallString.

An output backend that only generates the hash for outputs.

Definition HashingOutputBackend.h:62

std::optional< std::string > getHashValueForFile(StringRef Path)

Get hash value for the output files in hex representation.

Definition HashingOutputBackend.h:90

IntrusiveRefCntPtr< OutputBackend > cloneImpl() const override

Must be thread-safe.

Definition HashingOutputBackend.h:71

Expected< std::unique_ptr< OutputFileImpl > > createFileImpl(StringRef Path, std::optional< OutputConfig > Config) override

Create a file for Path.

Definition HashingOutputBackend.h:76

auto outputFiles() const

Iterator for all the output file names.

Definition HashingOutputBackend.h:84

HashingOutputFile.

Definition HashingOutputBackend.h:104

Error discard() override

Definition HashingOutputBackend.h:111

HashingOutputFile(StringRef OutputPath, HashingOutputBackend< HasherT > &Backend)

Definition HashingOutputBackend.h:114

Error keep() override

Definition HashingOutputBackend.h:106

raw_pwrite_stream & getOS() override

Definition HashingOutputBackend.h:112

raw_pwrite_stream that writes to a hasher.

Definition HashingOutputBackend.h:32

HashingStream()

Definition HashingOutputBackend.h:51

void toHex(ArrayRef< uint8_t > Input, bool LowerCase, SmallVectorImpl< char > &Output)

Convert buffer Input to its hexadecimal representation. The returned string is double the size of Inp...

StringRef toStringRef(bool B)

Construct a string ref from a boolean.