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

Side by Side Diff: lib/Bitcode/NaCl/Analysis/NaClObjDumpStream.cpp

Issue 932953002: Fix the NaCl bitstream reader to report fatal errors. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix formatting. Created 5 years, 10 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 unified diff | Download patch
OLDNEW
1 //===-- NaClObjDumpStream.cpp --------------------------------------------===// 1 //===-- NaClObjDumpStream.cpp --------------------------------------------===//
2 // Implements an objdump stream (bitcode records/assembly code). 2 // Implements an objdump stream (bitcode records/assembly code).
3 // 3 //
4 // The LLVM Compiler Infrastructure 4 // The LLVM Compiler Infrastructure
5 // 5 //
6 // This file is distributed under the University of Illinois Open Source 6 // This file is distributed under the University of Illinois Open Source
7 // License. See LICENSE.TXT for details. 7 // License. See LICENSE.TXT for details.
8 // 8 //
9 //===----------------------------------------------------------------------===// 9 //===----------------------------------------------------------------------===//
10 10
11 #include "llvm/Bitcode/NaCl/NaClObjDumpStream.h" 11 #include "llvm/Bitcode/NaCl/NaClObjDumpStream.h"
12 #include "llvm/ADT/STLExtras.h" 12 #include "llvm/ADT/STLExtras.h"
13 #include "llvm/Support/ErrorHandling.h" 13 #include "llvm/Support/ErrorHandling.h"
14 #include "llvm/Support/Format.h" 14 #include "llvm/Support/Format.h"
jvoung (off chromium) 2015/02/20 00:12:42 No longer need Format.h?
Karl 2015/02/20 21:41:17 Done.
15 15
16 #include <inttypes.h> 16 #include <inttypes.h>
17 17
18 namespace llvm { 18 namespace llvm {
19 namespace naclbitc { 19 namespace naclbitc {
20 20
21 TextFormatter::TextFormatter(raw_ostream &BaseStream, 21 TextFormatter::TextFormatter(raw_ostream &BaseStream,
22 unsigned LineWidth, 22 unsigned LineWidth,
23 const char *Tab) 23 const char *Tab)
24 : TextIndenter(Tab), 24 : TextIndenter(Tab),
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 Endline(this), 164 Endline(this),
165 StartCluster(this), 165 StartCluster(this),
166 FinishCluster(this) { 166 FinishCluster(this) {
167 // Handle fact that 64-bit values can take up to 21 characters. 167 // Handle fact that 64-bit values can take up to 21 characters.
168 MinLineWidth = 21; 168 MinLineWidth = 21;
169 Label = RecordAddress(0); 169 Label = RecordAddress(0);
170 } 170 }
171 171
172 std::string RecordTextFormatter::RecordAddress(uint64_t Bit, 172 std::string RecordTextFormatter::RecordAddress(uint64_t Bit,
173 unsigned MinByteWidth) { 173 unsigned MinByteWidth) {
174 std::string Buffer; 174 return NaClBitstreamReader::getBitAddress(Bit, MinByteWidth);
jvoung (off chromium) 2015/02/20 00:12:42 Can this variant of RecordAddress be removed and N
Karl 2015/02/20 21:41:17 Removed all instances of RecordAddress and ObjDump
175 raw_string_ostream Stream(Buffer);
176 Stream << '%' << MinByteWidth << PRIu64 << ":%u";
177 Stream.flush();
178 std::string FormatString(Buffer);
179 Buffer.clear();
180 Stream << format(FormatString.c_str(),
181 (Bit / 8),
182 static_cast<unsigned>(Bit % 8));
183 return Stream.str();
184 } 175 }
185 176
186 std::string RecordTextFormatter::GetEmptyLabelColumn() { 177 std::string RecordTextFormatter::GetEmptyLabelColumn() {
187 std::string Buffer; 178 std::string Buffer;
188 raw_string_ostream StrmBuffer(Buffer); 179 raw_string_ostream StrmBuffer(Buffer);
189 for (size_t i = 0; i < Label.size(); ++i) { 180 for (size_t i = 0; i < Label.size(); ++i) {
190 StrmBuffer << ' '; 181 StrmBuffer << ' ';
191 } 182 }
192 StrmBuffer << '|'; 183 StrmBuffer << '|';
193 return StrmBuffer.str(); 184 return StrmBuffer.str();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 Flush(); 260 Flush();
270 llvm::report_fatal_error("Unable to continue"); 261 llvm::report_fatal_error("Unable to continue");
271 } 262 }
272 263
273 void ObjDumpStream::Fatal(uint64_t Bit, 264 void ObjDumpStream::Fatal(uint64_t Bit,
274 const llvm::NaClBitcodeRecordData &Record, 265 const llvm::NaClBitcodeRecordData &Record,
275 const std::string &Message) { 266 const std::string &Message) {
276 LastKnownBit = Bit; 267 LastKnownBit = Bit;
277 PrintMessagePrefix("Error", Bit) << Message; 268 PrintMessagePrefix("Error", Bit) << Message;
278 Write(Bit, Record); 269 Write(Bit, Record);
270 Flush();
279 llvm::report_fatal_error("Unable to continue"); 271 llvm::report_fatal_error("Unable to continue");
280 } 272 }
281 273
282 // Dumps the next line of text in the buffer. Returns the number of characters 274 // Dumps the next line of text in the buffer. Returns the number of characters
283 // printed. 275 // printed.
284 static size_t DumpLine(raw_ostream &Stream, 276 static size_t DumpLine(raw_ostream &Stream,
285 const std::string &Buffer, 277 const std::string &Buffer,
286 size_t &Index, 278 size_t &Index,
287 size_t Size) { 279 size_t Size) {
288 size_t Count = 0; 280 size_t Count = 0;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 // an infinite loop. 338 // an infinite loop.
347 Stream << "Error(" << ObjDumpAddress(LastKnownBit) 339 Stream << "Error(" << ObjDumpAddress(LastKnownBit)
348 << "): Too many errors\n"; 340 << "): Too many errors\n";
349 llvm::report_fatal_error("Unable to continue"); 341 llvm::report_fatal_error("Unable to continue");
350 } 342 }
351 Stream.flush(); 343 Stream.flush();
352 } 344 }
353 345
354 } 346 }
355 } 347 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698