================
@@ -12,35 +12,74 @@
//===----------------------------------------------------------------------===//
#include "BitstreamRemarkParser.h"
-#include "llvm/Remarks/Remark.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Path.h"
#include <optional>
using namespace llvm;
using namespace llvm::remarks;
-static Error unknownRecord(const char *BlockName, unsigned RecordID) {
- return createStringError(
- std::make_error_code(std::errc::illegal_byte_sequence),
- "Error while parsing %s: unknown record entry (%lu).", BlockName,
- RecordID);
+namespace {
+
+template <typename... Ts> Error error(char const *Fmt, const Ts &...Vals) {
+ std::string Buffer;
+ raw_string_ostream OS(Buffer);
+ OS << formatv(Fmt, Vals...);
+ return make_error<StringError>(
+ std::move(Buffer),
+ std::make_error_code(std::errc::illegal_byte_sequence));
+}
+
+} // namespace
+
+Error BitstreamBlockParserHelperBase::unknownRecord(unsigned AbbrevID) {
+ return error("Unknown record entry ({}).", AbbrevID);
}
-static Error malformedRecord(const char *BlockName, const char *RecordName) {
- return createStringError(
- std::make_error_code(std::errc::illegal_byte_sequence),
- "Error while parsing %s: malformed record entry (%s).", BlockName,
- RecordName);
+Error BitstreamBlockParserHelperBase::unexpectedRecord(StringRef RecordName) {
+ return error("Unexpected record entry ({}).", RecordName);
}
-BitstreamMetaParserHelper::BitstreamMetaParserHelper(
- BitstreamCursor &Stream, BitstreamBlockInfo &BlockInfo)
- : Stream(Stream), BlockInfo(BlockInfo) {}
+Error BitstreamBlockParserHelperBase::malformedRecord(StringRef RecordName) {
+ return error("Malformed record entry ({}).", RecordName);
+}
-/// Parse a record and fill in the fields in the parser.
-static Error parseRecord(BitstreamMetaParserHelper &Parser, unsigned Code) {
- BitstreamCursor &Stream = Parser.Stream;
+Error BitstreamBlockParserHelperBase::unexpectedBlock(unsigned Code) {
+ return error("Unexpected subblock ({}).", Code);
+}
+
+static Expected<unsigned> expectSubBlock(BitstreamCursor &Stream) {
+ Expected<BitstreamEntry> Next = Stream.advance();
+ if (!Next)
+ return Next.takeError();
+ switch (Next->Kind) {
+ case BitstreamEntry::SubBlock:
+ return Next->ID;
+ case BitstreamEntry::Record:
+ case BitstreamEntry::EndBlock:
+ return error("Expected subblock, but got unexpected record.");
+ case BitstreamEntry::Error:
+ return error("Expected subblock, but got unexpected end of bitstream.");
+ }
+}
----------------
jroelofs wrote:
Is this switch fully covered? If so, there should be an `llvm_unreachable("some
message");` at the end of the scope.
https://github.com/llvm/llvm-project/pull/156511
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits