Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(529)

Unified Diff: lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp

Issue 986453002: Additional clean ups on errors in bitcode parsing. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix comment. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp ('k') | unittests/Bitcode/NaClAbbrevErrorTests.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp
diff --git a/lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp b/lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp
index 195fd81fc820012acfedbf3f733c692823593bfb..9d48f4b6a1cdf0691cf1c28dd6459da5c9fb6763 100644
--- a/lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp
+++ b/lib/Bitcode/NaCl/Reader/NaClBitstreamReader.cpp
@@ -8,26 +8,37 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/ADT/STLExtras.h"
#include "llvm/Bitcode/NaCl/NaClBitstreamReader.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
-std::string NaClBitstreamReader::getBitAddress(uint64_t Bit,
- unsigned MinByteWidth) {
+namespace {
+
+static const char *ErrorLevelName[] = {
+ "Warning",
+ "Error",
+ "Fatal"
+};
+
+} // End of anonymous namespace.
+
+std::string llvm::naclbitc::getBitAddress(uint64_t Bit) {
std::string Buffer;
raw_string_ostream Stream(Buffer);
- Stream << '%' << MinByteWidth << PRIu64 << ":%u";
- Stream.flush();
- std::string FormatString(Buffer);
- Buffer.clear();
- Stream << format(FormatString.c_str(),
- (Bit / 8),
- static_cast<unsigned>(Bit % 8));
+ Stream << (Bit / 8) << ":" << (Bit % 8);
return Stream.str();
}
+raw_ostream &llvm::naclbitc::ErrorAt(
+ raw_ostream &Out, ErrorLevel Level, uint64_t BitPosition) {
+ assert(Level < array_lengthof(::ErrorLevelName));
+ return Out << ErrorLevelName[Level] << "("
+ << naclbitc::getBitAddress(BitPosition) << "): ";
+}
+
//===----------------------------------------------------------------------===//
// NaClBitstreamCursor implementation
//===----------------------------------------------------------------------===//
@@ -38,9 +49,8 @@ Fatal(const std::string &ErrorMessage) const {
// the error occurred.
std::string Buffer;
raw_string_ostream StrBuf(Buffer);
- StrBuf << "Error("
- << NaClBitstreamReader::getBitAddress(Cursor.GetCurrentBitNo())
- << "): " << ErrorMessage;
+ naclbitc::ErrorAt(StrBuf, naclbitc::Fatal, Cursor.GetCurrentBitNo())
+ << ErrorMessage;
report_fatal_error(StrBuf.str());
}
« no previous file with comments | « lib/Bitcode/NaCl/Reader/NaClBitcodeReader.cpp ('k') | unittests/Bitcode/NaClAbbrevErrorTests.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698