LLVM: lib/Remarks/RemarkParser.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13

15#include "BitstreamRemarkParser.h"

19#include

20

21using namespace llvm;

23

25

27 while (!InBuffer.empty()) {

28

29 std::pair<StringRef, StringRef> Split = InBuffer.split('\0');

30

32 InBuffer = Split.second;

33 }

34}

35

37 if (Index >= Offsets.size())

39 std::make_error_code(std::errc::invalid_argument),

40 "String with index %u is out of bounds (size = %u).", Index,

42

44

45

46 size_t NextOffset =

49}

50

53 switch (ParserFormat) {

55 return std::make_unique(Buf);

58 std::make_error_code(std::errc::invalid_argument),

59 "The YAML with string table format requires a parsed string table.");

61 return std::make_unique(Buf);

63 return createStringError(std::make_error_code(std::errc::invalid_argument),

64 "Unknown remark parser format.");

65 }

67}

68

72 switch (ParserFormat) {

74 return createStringError(std::make_error_code(std::errc::invalid_argument),

75 "The YAML format can't be used with a string "

76 "table. Use yaml-strtab instead.");

78 return std::make_unique(Buf, std::move(StrTab));

80 return std::make_unique(Buf, std::move(StrTab));

82 return createStringError(std::make_error_code(std::errc::invalid_argument),

83 "Unknown remark parser format.");

84 }

86}

87

90 Format ParserFormat, StringRef Buf, std::optional StrTab,

91 std::optional ExternalFilePrependPath) {

92 switch (ParserFormat) {

93

94

98 std::move(ExternalFilePrependPath));

101 std::move(ExternalFilePrependPath));

103 return createStringError(std::make_error_code(std::errc::invalid_argument),

104 "Unknown remark parser format.");

105 }

107}

108

109namespace {

110

111struct CParser {

112 std::unique_ptr TheParser;

113 std::optionalstd::string Err;

114

116 std::optional StrTab = std::nullopt)

120

121 void handleError(Error E) { Err.emplace(toString(std::move(E))); }

122 bool hasError() const { return Err.has_value(); }

123 const char *getMessage() const { return Err ? Err->c_str() : nullptr; };

124};

125}

126

127

129

133 StringRef(static_cast<const char *>(Buf), Size)));

134}

135

139 StringRef(static_cast<const char *>(Buf), Size)));

140}

141

144 CParser &TheCParser = *unwrap(Parser);

146

151 return nullptr;

152 }

153

154

155

156 TheCParser.handleError(std::move(E));

157 return nullptr;

158 }

159

160

161 return wrap(MaybeRemark->release());

162}

163

165 return unwrap(Parser)->hasError();

166}

167

168extern "C" const char *

170 return unwrap(Parser)->getMessage();

171}

172

174 delete unwrap(Parser);

175}

static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")

#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)

Lightweight error class with error context and mandatory checking.

bool isA() const

Check whether one error is a subclass of another.

Tagged union holding either a T or a Error.

Error takeError()

Take ownership of the stored error.

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

std::pair< StringRef, StringRef > split(char Separator) const

Split into two substrings around the first occurrence of a separator character.

constexpr bool empty() const

empty - Check if the string is empty.

constexpr size_t size() const

size - Get the string size.

constexpr const char * data() const

data - Get a pointer to the start of the string (which may not be null terminated).

#define llvm_unreachable(msg)

Marks that the current location is not supposed to be reachable.

@ C

The default llvm calling convention, compatible with C.

This is an optimization pass for GlobalISel generic memory operations.

Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)

Create formatted StringError object.

void cantFail(Error Err, const char *Msg=nullptr)

Report a fatal error if Err is a failure value.

Attribute unwrap(LLVMAttributeRef Attr)

OutputIt move(R &&Range, OutputIt Out)

Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.

LLVMAttributeRef wrap(Attribute Attr)

const char * toString(DWARFSectionKind Kind)

void consumeError(Error Err)

Consume a Error without doing anything.

Implement std::hash so that hash_code can be used in STL containers.