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

Side by Side Diff: src/PNaClTranslator.cpp

Issue 800883006: Add ability to test parsing of bitcode records in Subzero. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix issues in last patch set. Created 5 years, 11 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
« no previous file with comments | « src/PNaClTranslator.h ('k') | src/llvm2ice.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===// 1 //===- subzero/src/PNaClTranslator.cpp - ICE from bitcode -----------------===//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
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 // This file implements the PNaCl bitcode file to Ice, to machine code 10 // This file implements the PNaCl bitcode file to Ice, to machine code
(...skipping 19 matching lines...) Expand all
30 #include "IceGlobalInits.h" 30 #include "IceGlobalInits.h"
31 #include "IceInst.h" 31 #include "IceInst.h"
32 #include "IceOperand.h" 32 #include "IceOperand.h"
33 #include "PNaClTranslator.h" 33 #include "PNaClTranslator.h"
34 34
35 #include <memory> 35 #include <memory>
36 36
37 namespace { 37 namespace {
38 using namespace llvm; 38 using namespace llvm;
39 39
40 // TODO(kschimpf) Remove error recovery once implementation complete.
41 static cl::opt<bool> AllowErrorRecovery(
42 "allow-pnacl-reader-error-recovery",
43 cl::desc("Allow error recovery when reading PNaCl bitcode."),
44 cl::init(false));
45
46 // Models elements in the list of types defined in the types block. 40 // Models elements in the list of types defined in the types block.
47 // These elements can be undefined, a (simple) type, or a function type 41 // These elements can be undefined, a (simple) type, or a function type
48 // signature. Note that an extended type is undefined on construction. 42 // signature. Note that an extended type is undefined on construction.
49 // Use methods setAsSimpleType and setAsFuncSigType to define 43 // Use methods setAsSimpleType and setAsFuncSigType to define
50 // the extended type. 44 // the extended type.
51 class ExtendedType { 45 class ExtendedType {
52 // ExtendedType(const ExtendedType &Ty) = delete; 46 // ExtendedType(const ExtendedType &Ty) = delete;
53 ExtendedType &operator=(const ExtendedType &Ty) = delete; 47 ExtendedType &operator=(const ExtendedType &Ty) = delete;
54 public: 48 public:
55 /// Discriminator for LLVM-style RTTI. 49 /// Discriminator for LLVM-style RTTI.
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 427
434 // Reports that there is no corresponding ICE type for LLVMTy, and 428 // Reports that there is no corresponding ICE type for LLVMTy, and
435 // returns ICE::IceType_void. 429 // returns ICE::IceType_void.
436 Ice::Type convertToIceTypeError(Type *LLVMTy); 430 Ice::Type convertToIceTypeError(Type *LLVMTy);
437 }; 431 };
438 432
439 bool TopLevelParser::Error(const std::string &Message) { 433 bool TopLevelParser::Error(const std::string &Message) {
440 ErrorStatus = true; 434 ErrorStatus = true;
441 ++NumErrors; 435 ++NumErrors;
442 NaClBitcodeParser::Error(Message); 436 NaClBitcodeParser::Error(Message);
443 if (!AllowErrorRecovery) 437 if (!Translator.getFlags().AllowErrorRecovery)
444 report_fatal_error("Unable to continue"); 438 report_fatal_error("Unable to continue");
445 return true; 439 return true;
446 } 440 }
447 441
448 void TopLevelParser::reportBadTypeIDAs(unsigned ID, const ExtendedType *Ty, 442 void TopLevelParser::reportBadTypeIDAs(unsigned ID, const ExtendedType *Ty,
449 ExtendedType::TypeKind WantedType) { 443 ExtendedType::TypeKind WantedType) {
450 std::string Buffer; 444 std::string Buffer;
451 raw_string_ostream StrBuf(Buffer); 445 raw_string_ostream StrBuf(Buffer);
452 if (Ty == nullptr) { 446 if (Ty == nullptr) {
453 StrBuf << "Can't find extended type for type id: " << ID; 447 StrBuf << "Can't find extended type for type id: " << ID;
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 } 599 }
606 600
607 // Generates an error Message with the bit address prefixed to it. 601 // Generates an error Message with the bit address prefixed to it.
608 bool BlockParserBaseClass::Error(const std::string &Message) { 602 bool BlockParserBaseClass::Error(const std::string &Message) {
609 uint64_t Bit = Record.GetStartBit() + Context->getHeaderSize() * 8; 603 uint64_t Bit = Record.GetStartBit() + Context->getHeaderSize() * 8;
610 std::string Buffer; 604 std::string Buffer;
611 raw_string_ostream StrBuf(Buffer); 605 raw_string_ostream StrBuf(Buffer);
612 StrBuf << "(" << format("%" PRIu64 ":%u", (Bit / 8), 606 StrBuf << "(" << format("%" PRIu64 ":%u", (Bit / 8),
613 static_cast<unsigned>(Bit % 8)) << ") "; 607 static_cast<unsigned>(Bit % 8)) << ") ";
614 // Note: If dump routines have been turned off, the error messages 608 // Note: If dump routines have been turned off, the error messages
615 // will not be readable. Hence, replace with simple error. 609 // will not be readable. Hence, replace with simple error. We also
616 if (ALLOW_DUMP) 610 // use the simple form for unit tests.
611 if (ALLOW_DUMP && !getFlags().GenerateUnitTestMessages) {
617 StrBuf << Message; 612 StrBuf << Message;
618 else { 613 } else {
619 StrBuf << "Invalid " << getBlockName() << " record: <" << Record.GetCode(); 614 StrBuf << "Invalid " << getBlockName() << " record: <" << Record.GetCode();
620 for (const uint64_t Val : Record.GetValues()) { 615 for (const uint64_t Val : Record.GetValues()) {
621 StrBuf << " " << Val; 616 StrBuf << " " << Val;
622 } 617 }
623 StrBuf << ">"; 618 StrBuf << ">";
624 } 619 }
625 return Context->Error(StrBuf.str()); 620 return Context->Error(StrBuf.str());
626 } 621 }
627 622
628 void BlockParserBaseClass::ReportRecordSizeError(unsigned ExpectedSize, 623 void BlockParserBaseClass::ReportRecordSizeError(unsigned ExpectedSize,
(...skipping 2331 matching lines...) Expand 10 before | Expand all | Expand 10 after
2960 void PNaClTranslator::translate(const std::string &IRFilename) { 2955 void PNaClTranslator::translate(const std::string &IRFilename) {
2961 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrOrFile = 2956 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrOrFile =
2962 MemoryBuffer::getFileOrSTDIN(IRFilename); 2957 MemoryBuffer::getFileOrSTDIN(IRFilename);
2963 if (std::error_code EC = ErrOrFile.getError()) { 2958 if (std::error_code EC = ErrOrFile.getError()) {
2964 errs() << "Error reading '" << IRFilename << "': " << EC.message() << "\n"; 2959 errs() << "Error reading '" << IRFilename << "': " << EC.message() << "\n";
2965 ErrorStatus = true; 2960 ErrorStatus = true;
2966 return; 2961 return;
2967 } 2962 }
2968 2963
2969 std::unique_ptr<MemoryBuffer> MemBuf(ErrOrFile.get().release()); 2964 std::unique_ptr<MemoryBuffer> MemBuf(ErrOrFile.get().release());
2965 translateBuffer(IRFilename, MemBuf.get());
2966 }
2967
2968 void PNaClTranslator::translateBuffer(const std::string &IRFilename,
2969 MemoryBuffer *MemBuf) {
2970 if (MemBuf->getBufferSize() % 4 != 0) { 2970 if (MemBuf->getBufferSize() % 4 != 0) {
2971 errs() << IRFilename 2971 errs() << IRFilename
2972 << ": Bitcode stream should be a multiple of 4 bytes in length.\n"; 2972 << ": Bitcode stream should be a multiple of 4 bytes in length.\n";
2973 ErrorStatus = true; 2973 ErrorStatus = true;
2974 return; 2974 return;
2975 } 2975 }
2976 2976
2977 const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart(); 2977 const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart();
2978 const unsigned char *EndBufPtr = BufPtr + MemBuf->getBufferSize(); 2978 const unsigned char *EndBufPtr = BufPtr + MemBuf->getBufferSize();
2979 2979
(...skipping 21 matching lines...) Expand all
3001 3001
3002 if (TopLevelBlocks != 1) { 3002 if (TopLevelBlocks != 1) {
3003 errs() << IRFilename 3003 errs() << IRFilename
3004 << ": Contains more than one module. Found: " << TopLevelBlocks 3004 << ": Contains more than one module. Found: " << TopLevelBlocks
3005 << "\n"; 3005 << "\n";
3006 ErrorStatus = true; 3006 ErrorStatus = true;
3007 } 3007 }
3008 } 3008 }
3009 3009
3010 } // end of namespace Ice 3010 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/PNaClTranslator.h ('k') | src/llvm2ice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698