[Remarks] Add parser for bitstream remarks
The bitstream remark serializer landed in r367372.
This adds a bitstream remark parser that parser bitstream remark files
to llvm::remarks::Remark objects through the RemarkParser interface.
A few interesting things to point out:
* There are parsing helpers to parse the different types of blocks
* The main parsing helper allows us to parse remark metadata and open an
external file containing the encoded remarks
* This adds a dependency from the Remarks library to the BitstreamReader
library
* The testing strategy is to create a remark entry through YAML, parse
it, serialize it to bitstream, parse that back and compare the objects.
* There are close to no tests for malformed bitstream remarks, due to
the lack of textual format for the bitstream format.
* This adds a new C API for parsing bitstream remarks:
LLVMRemarkParserCreateBitstream.
* This bumps the REMARKS_API_VERSION to 1.
Differential Revision: https://reviews.llvm.org/D67134
llvm-svn: 371429
diff --git a/llvm/lib/Remarks/RemarkParser.cpp b/llvm/lib/Remarks/RemarkParser.cpp
index 98f6534..600f415 100644
--- a/llvm/lib/Remarks/RemarkParser.cpp
+++ b/llvm/lib/Remarks/RemarkParser.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Remarks/RemarkParser.h"
+#include "BitstreamRemarkParser.h"
#include "YAMLRemarkParser.h"
#include "llvm-c/Remarks.h"
#include "llvm/ADT/STLExtras.h"
@@ -57,8 +58,7 @@
std::make_error_code(std::errc::invalid_argument),
"The YAML with string table format requires a parsed string table.");
case Format::Bitstream:
- return createStringError(std::make_error_code(std::errc::invalid_argument),
- "Parsing bitstream remarks is not supported.");
+ return std::make_unique<BitstreamRemarkParser>(Buf);
case Format::Unknown:
return createStringError(std::make_error_code(std::errc::invalid_argument),
"Unknown remark parser format.");
@@ -77,8 +77,7 @@
case Format::YAMLStrTab:
return std::make_unique<YAMLStrTabRemarkParser>(Buf, std::move(StrTab));
case Format::Bitstream:
- return createStringError(std::make_error_code(std::errc::invalid_argument),
- "Parsing bitstream remarks is not supported.");
+ return std::make_unique<BitstreamRemarkParser>(Buf, std::move(StrTab));
case Format::Unknown:
return createStringError(std::make_error_code(std::errc::invalid_argument),
"Unknown remark parser format.");
@@ -96,8 +95,7 @@
case Format::YAMLStrTab:
return createYAMLParserFromMeta(Buf, std::move(StrTab));
case Format::Bitstream:
- return createStringError(std::make_error_code(std::errc::invalid_argument),
- "Parsing bitstream remarks is not supported.");
+ return createBitstreamParserFromMeta(Buf, std::move(StrTab));
case Format::Unknown:
return createStringError(std::make_error_code(std::errc::invalid_argument),
"Unknown remark parser format.");
@@ -132,6 +130,12 @@
StringRef(static_cast<const char *>(Buf), Size)));
}
+extern "C" LLVMRemarkParserRef LLVMRemarkParserCreateBitstream(const void *Buf,
+ uint64_t Size) {
+ return wrap(new CParser(Format::Bitstream,
+ StringRef(static_cast<const char *>(Buf), Size)));
+}
+
extern "C" LLVMRemarkEntryRef
LLVMRemarkParserGetNext(LLVMRemarkParserRef Parser) {
CParser &TheCParser = *unwrap(Parser);