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

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 nits. 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
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 2506 matching lines...) Expand 10 before | Expand all | Expand 10 after
2960 void PNaClTranslator::translate(const std::string &IRFilename) { 2954 void PNaClTranslator::translate(const std::string &IRFilename) {
2961 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrOrFile = 2955 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrOrFile =
2962 MemoryBuffer::getFileOrSTDIN(IRFilename); 2956 MemoryBuffer::getFileOrSTDIN(IRFilename);
2963 if (std::error_code EC = ErrOrFile.getError()) { 2957 if (std::error_code EC = ErrOrFile.getError()) {
2964 errs() << "Error reading '" << IRFilename << "': " << EC.message() << "\n"; 2958 errs() << "Error reading '" << IRFilename << "': " << EC.message() << "\n";
2965 ErrorStatus = true; 2959 ErrorStatus = true;
2966 return; 2960 return;
2967 } 2961 }
2968 2962
2969 std::unique_ptr<MemoryBuffer> MemBuf(ErrOrFile.get().release()); 2963 std::unique_ptr<MemoryBuffer> MemBuf(ErrOrFile.get().release());
2964 translateBuffer(IRFilename, MemBuf.get());
2965 }
2966
2967 void PNaClTranslator::translateBuffer(const std::string &IRFilename,
2968 MemoryBuffer *MemBuf) {
2970 if (MemBuf->getBufferSize() % 4 != 0) { 2969 if (MemBuf->getBufferSize() % 4 != 0) {
2971 errs() << IRFilename 2970 errs() << IRFilename
2972 << ": Bitcode stream should be a multiple of 4 bytes in length.\n"; 2971 << ": Bitcode stream should be a multiple of 4 bytes in length.\n";
2973 ErrorStatus = true; 2972 ErrorStatus = true;
2974 return; 2973 return;
2975 } 2974 }
2976 2975
2977 const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart(); 2976 const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart();
2978 const unsigned char *EndBufPtr = BufPtr + MemBuf->getBufferSize(); 2977 const unsigned char *EndBufPtr = BufPtr + MemBuf->getBufferSize();
2979 2978
(...skipping 21 matching lines...) Expand all
3001 3000
3002 if (TopLevelBlocks != 1) { 3001 if (TopLevelBlocks != 1) {
3003 errs() << IRFilename 3002 errs() << IRFilename
3004 << ": Contains more than one module. Found: " << TopLevelBlocks 3003 << ": Contains more than one module. Found: " << TopLevelBlocks
3005 << "\n"; 3004 << "\n";
3006 ErrorStatus = true; 3005 ErrorStatus = true;
3007 } 3006 }
3008 } 3007 }
3009 3008
3010 } // end of namespace Ice 3009 } // end of namespace Ice
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698