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

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

Issue 1122423005: Add (unsupported experimental) feature allowing byte aligned bitcode. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-llvm.git@master
Patch Set: Fix nits. Created 5 years, 7 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 //===-- NaClBitcodeAnalyzer.cpp - Bitcode Analyzer ------------------------===// 1 //===-- NaClBitcodeAnalyzer.cpp - Bitcode Analyzer ------------------------===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 9
10 #define DEBUG_TYPE "nacl-bitcode-analyzer" 10 #define DEBUG_TYPE "nacl-bitcode-analyzer"
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 int AnalyzeBitcodeInBuffer(const std::unique_ptr<MemoryBuffer> &Buf, 401 int AnalyzeBitcodeInBuffer(const std::unique_ptr<MemoryBuffer> &Buf,
402 raw_ostream &OS, 402 raw_ostream &OS,
403 const AnalysisDumpOptions &DumpOptions) { 403 const AnalysisDumpOptions &DumpOptions) {
404 DEBUG(dbgs() << "-> AnalyzeBitcodeInBuffer\n"); 404 DEBUG(dbgs() << "-> AnalyzeBitcodeInBuffer\n");
405 405
406 if (Buf->getBufferSize() & 3) 406 if (Buf->getBufferSize() & 3)
407 return Error("Bitcode stream should be a multiple of 4 bytes in length"); 407 return Error("Bitcode stream should be a multiple of 4 bytes in length");
408 408
409 const unsigned char *BufPtr = (const unsigned char *)Buf->getBufferStart(); 409 const unsigned char *BufPtr = (const unsigned char *)Buf->getBufferStart();
410 const unsigned char *EndBufPtr = BufPtr + Buf->getBufferSize(); 410 const unsigned char *EndBufPtr = BufPtr + Buf->getBufferSize();
411 const unsigned char *HeaderPtr = BufPtr;
411 412
412 NaClBitcodeHeader Header; 413 NaClBitcodeHeader Header;
413 if (Header.Read(BufPtr, EndBufPtr)) 414 if (Header.Read(HeaderPtr, EndBufPtr))
414 return Error("Invalid PNaCl bitcode header"); 415 return Error("Invalid PNaCl bitcode header");
415 416
416 if (!Header.IsSupported()) 417 if (!Header.IsSupported())
417 errs() << "Warning: " << Header.Unsupported() << "\n"; 418 errs() << "Warning: " << Header.Unsupported() << "\n";
418 419
419 if (!Header.IsReadable()) 420 if (!Header.IsReadable())
420 Error("Bitcode file is not readable"); 421 Error("Bitcode file is not readable");
421 422
422 NaClBitstreamReader StreamFile(BufPtr, EndBufPtr); 423 NaClBitstreamReader StreamFile(BufPtr, EndBufPtr, Header);
423 NaClBitstreamCursor Stream(StreamFile); 424 NaClBitstreamCursor Stream(StreamFile);
424 425
425 unsigned NumTopBlocks = 0; 426 unsigned NumTopBlocks = 0;
426 427
427 // Print out header information. 428 // Print out header information.
428 for (size_t i = 0, limit = Header.NumberFields(); i < limit; ++i) { 429 for (size_t i = 0, limit = Header.NumberFields(); i < limit; ++i) {
429 OS << Header.GetField(i)->Contents() << "\n"; 430 OS << Header.GetField(i)->Contents() << "\n";
430 } 431 }
431 if (Header.NumberFields()) OS << "\n"; 432 if (Header.NumberFields()) OS << "\n";
432 433
(...skipping 27 matching lines...) Expand all
460 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrOrFile = 461 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrOrFile =
461 MemoryBuffer::getFileOrSTDIN(InputFilename); 462 MemoryBuffer::getFileOrSTDIN(InputFilename);
462 if (std::error_code EC = ErrOrFile.getError()) 463 if (std::error_code EC = ErrOrFile.getError())
463 return Error(Twine("Error reading '") + InputFilename + "': " + 464 return Error(Twine("Error reading '") + InputFilename + "': " +
464 EC.message()); 465 EC.message());
465 466
466 return AnalyzeBitcodeInBuffer(ErrOrFile.get(), OS, DumpOptions); 467 return AnalyzeBitcodeInBuffer(ErrOrFile.get(), OS, DumpOptions);
467 } 468 }
468 469
469 } // namespace llvm 470 } // namespace llvm
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698