LLVM: lib/Remarks/RemarkParser.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
20#include
21
22using namespace llvm;
24
26
28 while (!InBuffer.empty()) {
29
30 std::pair<StringRef, StringRef> Split = InBuffer.split('\0');
31
32 Offsets.push_back(Split.first.data() - Buffer.data());
33 InBuffer = Split.second;
34 }
35}
36
38 if (Index >= Offsets.size())
40 std::make_error_code(std::errc::invalid_argument),
41 "String with index %u is out of bounds (size = %u).", Index,
43
45
46
47 size_t NextOffset =
50}
51
54 auto DetectedFormat = detectFormat(ParserFormat, Buf);
55 if (!DetectedFormat)
56 return DetectedFormat.takeError();
57
58 switch (*DetectedFormat) {
60 return std::make_unique(Buf);
62 return std::make_unique(Buf);
65 break;
66 }
68}
69
73 std::optional ExternalFilePrependPath) {
74 auto DetectedFormat = detectFormat(ParserFormat, Buf);
75 if (!DetectedFormat)
76 return DetectedFormat.takeError();
77
78 switch (*DetectedFormat) {
83 std::move(ExternalFilePrependPath));
86 break;
87 }
89}
90
91namespace {
92
93struct CParser {
94 std::unique_ptr TheParser;
95 std::optionalstd::string Err;
96
99
100 void handleError(Error E) { Err.emplace(toString(std::move(E))); }
101 bool hasError() const { return Err.has_value(); }
102 const char *getMessage() const { return Err ? Err->c_str() : nullptr; };
103};
104}
105
106
108
114
120
123 CParser &TheCParser = *unwrap(Parser);
125
130 return nullptr;
131 }
132
133
134
135 TheCParser.handleError(std::move(E));
136 return nullptr;
137 }
138
139
140 return wrap(MaybeRemark->release());
141}
142
144 return unwrap(Parser)->hasError();
145}
146
147extern "C" const char *
149 return unwrap(Parser)->getMessage();
150}
151
153 delete unwrap(Parser);
154}
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.
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.
constexpr bool empty() const
empty - Check if the string is empty.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
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)
std::string toString(const APInt &I, unsigned Radix, bool Signed, bool formatAsCLiteral=false, bool UpperCase=true, bool InsertSeparators=false)
LLVMAttributeRef wrap(Attribute Attr)
void consumeError(Error Err)
Consume a Error without doing anything.