| OLD | NEW |
| 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 ~TopLevelParser() override {} | 172 ~TopLevelParser() override {} |
| 173 | 173 |
| 174 Ice::Translator &getTranslator() const { return Translator; } | 174 Ice::Translator &getTranslator() const { return Translator; } |
| 175 | 175 |
| 176 void setBlockParser(BlockParserBaseClass *NewBlockParser) { | 176 void setBlockParser(BlockParserBaseClass *NewBlockParser) { |
| 177 BlockParser = NewBlockParser; | 177 BlockParser = NewBlockParser; |
| 178 } | 178 } |
| 179 | 179 |
| 180 /// Generates error with given Message, occurring at BitPosition | 180 /// Generates error with given Message, occurring at BitPosition |
| 181 /// within the bitcode file. Always returns true. | 181 /// within the bitcode file. Always returns true. |
| 182 bool ErrorAt(uint64_t BitPosition, const std::string &Message) final; | 182 bool ErrorAt(naclbitc::ErrorLevel Level, uint64_t BitPosition, |
| 183 const std::string &Message) final; |
| 183 | 184 |
| 184 /// Generates error message with respect to the current block parser. | 185 /// Generates error message with respect to the current block parser. |
| 185 bool BlockError(const std::string &Message); | 186 bool BlockError(const std::string &Message); |
| 186 | 187 |
| 187 /// Returns the number of errors found while parsing the bitcode | 188 /// Returns the number of errors found while parsing the bitcode |
| 188 /// file. | 189 /// file. |
| 189 unsigned getNumErrors() const { return NumErrors; } | 190 unsigned getNumErrors() const { return NumErrors; } |
| 190 | 191 |
| 191 /// Changes the size of the type list to the given size. | 192 /// Changes the size of the type list to the given size. |
| 192 void resizeTypeIDValues(unsigned NewSize) { TypeIDValues.resize(NewSize); } | 193 void resizeTypeIDValues(unsigned NewSize) { TypeIDValues.resize(NewSize); } |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 | 494 |
| 494 // Reports that there is not global variable declaration for | 495 // Reports that there is not global variable declaration for |
| 495 // ID. Returns an error recovery value to use. | 496 // ID. Returns an error recovery value to use. |
| 496 Ice::VariableDeclaration *reportGetGlobalVariableByIDError(unsigned Index); | 497 Ice::VariableDeclaration *reportGetGlobalVariableByIDError(unsigned Index); |
| 497 | 498 |
| 498 // Reports that there is no corresponding ICE type for LLVMTy, and | 499 // Reports that there is no corresponding ICE type for LLVMTy, and |
| 499 // returns ICE::IceType_void. | 500 // returns ICE::IceType_void. |
| 500 Ice::Type convertToIceTypeError(Type *LLVMTy); | 501 Ice::Type convertToIceTypeError(Type *LLVMTy); |
| 501 }; | 502 }; |
| 502 | 503 |
| 503 bool TopLevelParser::ErrorAt(uint64_t Bit, const std::string &Message) { | 504 bool TopLevelParser::ErrorAt(naclbitc::ErrorLevel Level, uint64_t Bit, |
| 505 const std::string &Message) { |
| 504 ErrorStatus.assign(Ice::EC_Bitcode); | 506 ErrorStatus.assign(Ice::EC_Bitcode); |
| 505 ++NumErrors; | 507 ++NumErrors; |
| 506 Ice::GlobalContext *Context = Translator.getContext(); | 508 Ice::GlobalContext *Context = Translator.getContext(); |
| 507 Ice::OstreamLocker L(Context); | 509 Ice::OstreamLocker L(Context); |
| 508 raw_ostream &OldErrStream = setErrStream(Context->getStrDump()); | 510 raw_ostream &OldErrStream = setErrStream(Context->getStrDump()); |
| 509 NaClBitcodeParser::ErrorAt(Bit, Message); | 511 NaClBitcodeParser::ErrorAt(Level, Bit, Message); |
| 510 setErrStream(OldErrStream); | 512 setErrStream(OldErrStream); |
| 511 if (!Translator.getFlags().getAllowErrorRecovery()) | 513 if (Level >= naclbitc::Error |
| 514 && !Translator.getFlags().getAllowErrorRecovery()) |
| 512 Fatal(); | 515 Fatal(); |
| 513 return true; | 516 return true; |
| 514 } | 517 } |
| 515 | 518 |
| 516 void TopLevelParser::reportBadTypeIDAs(unsigned ID, const ExtendedType *Ty, | 519 void TopLevelParser::reportBadTypeIDAs(unsigned ID, const ExtendedType *Ty, |
| 517 ExtendedType::TypeKind WantedType) { | 520 ExtendedType::TypeKind WantedType) { |
| 518 std::string Buffer; | 521 std::string Buffer; |
| 519 raw_string_ostream StrBuf(Buffer); | 522 raw_string_ostream StrBuf(Buffer); |
| 520 if (Ty == nullptr) { | 523 if (Ty == nullptr) { |
| 521 StrBuf << "Can't find extended type for type id: " << ID; | 524 StrBuf << "Can't find extended type for type id: " << ID; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 | 582 |
| 580 ~BlockParserBaseClass() override { Context->setBlockParser(nullptr); } | 583 ~BlockParserBaseClass() override { Context->setBlockParser(nullptr); } |
| 581 | 584 |
| 582 // Returns the printable name of the type of block being parsed. | 585 // Returns the printable name of the type of block being parsed. |
| 583 virtual const char *getBlockName() const { | 586 virtual const char *getBlockName() const { |
| 584 // If this class is used, it is parsing an unknown block. | 587 // If this class is used, it is parsing an unknown block. |
| 585 return "unknown"; | 588 return "unknown"; |
| 586 } | 589 } |
| 587 | 590 |
| 588 // Generates an error Message with the Bit address prefixed to it. | 591 // Generates an error Message with the Bit address prefixed to it. |
| 589 bool ErrorAt(uint64_t Bit, const std::string &Message) final; | 592 bool ErrorAt(naclbitc::ErrorLevel Level, uint64_t Bit, |
| 593 const std::string &Message) final; |
| 590 | 594 |
| 591 protected: | 595 protected: |
| 592 // The context parser that contains the decoded state. | 596 // The context parser that contains the decoded state. |
| 593 TopLevelParser *Context; | 597 TopLevelParser *Context; |
| 594 | 598 |
| 595 // Constructor for nested block parsers. | 599 // Constructor for nested block parsers. |
| 596 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 600 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
| 597 : NaClBitcodeParser(BlockID, EnclosingParser), | 601 : NaClBitcodeParser(BlockID, EnclosingParser), |
| 598 Context(EnclosingParser->Context) {} | 602 Context(EnclosingParser->Context) {} |
| 599 | 603 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 666 }; | 670 }; |
| 667 | 671 |
| 668 bool TopLevelParser::BlockError(const std::string &Message) { | 672 bool TopLevelParser::BlockError(const std::string &Message) { |
| 669 if (BlockParser) | 673 if (BlockParser) |
| 670 return BlockParser->Error(Message); | 674 return BlockParser->Error(Message); |
| 671 else | 675 else |
| 672 return Error(Message); | 676 return Error(Message); |
| 673 } | 677 } |
| 674 | 678 |
| 675 // Generates an error Message with the bit address prefixed to it. | 679 // Generates an error Message with the bit address prefixed to it. |
| 676 bool BlockParserBaseClass::ErrorAt(uint64_t Bit, const std::string &Message) { | 680 bool BlockParserBaseClass::ErrorAt( |
| 681 naclbitc::ErrorLevel Level, uint64_t Bit, const std::string &Message) { |
| 677 std::string Buffer; | 682 std::string Buffer; |
| 678 raw_string_ostream StrBuf(Buffer); | 683 raw_string_ostream StrBuf(Buffer); |
| 679 // Note: If dump routines have been turned off, the error messages | 684 // Note: If dump routines have been turned off, the error messages |
| 680 // will not be readable. Hence, replace with simple error. We also | 685 // will not be readable. Hence, replace with simple error. We also |
| 681 // use the simple form for unit tests. | 686 // use the simple form for unit tests. |
| 682 if (getFlags().getGenerateUnitTestMessages()) { | 687 if (getFlags().getGenerateUnitTestMessages()) { |
| 683 StrBuf << "Invalid " << getBlockName() << " record: <" << Record.GetCode(); | 688 StrBuf << "Invalid " << getBlockName() << " record: <" << Record.GetCode(); |
| 684 for (const uint64_t Val : Record.GetValues()) { | 689 for (const uint64_t Val : Record.GetValues()) { |
| 685 StrBuf << " " << Val; | 690 StrBuf << " " << Val; |
| 686 } | 691 } |
| 687 StrBuf << ">"; | 692 StrBuf << ">"; |
| 688 } else { | 693 } else { |
| 689 StrBuf << Message; | 694 StrBuf << Message; |
| 690 } | 695 } |
| 691 return Context->ErrorAt(Bit, StrBuf.str()); | 696 return Context->ErrorAt(Level, Bit, StrBuf.str()); |
| 692 } | 697 } |
| 693 | 698 |
| 694 void BlockParserBaseClass::ReportRecordSizeError(unsigned ExpectedSize, | 699 void BlockParserBaseClass::ReportRecordSizeError(unsigned ExpectedSize, |
| 695 const char *RecordName, | 700 const char *RecordName, |
| 696 const char *ContextMessage) { | 701 const char *ContextMessage) { |
| 697 std::string Buffer; | 702 std::string Buffer; |
| 698 raw_string_ostream StrBuf(Buffer); | 703 raw_string_ostream StrBuf(Buffer); |
| 699 const char *BlockName = getBlockName(); | 704 const char *BlockName = getBlockName(); |
| 700 const char FirstChar = toupper(*BlockName); | 705 const char FirstChar = toupper(*BlockName); |
| 701 StrBuf << FirstChar << (BlockName + 1) << " " << RecordName | 706 StrBuf << FirstChar << (BlockName + 1) << " " << RecordName |
| (...skipping 2341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3043 | 3048 |
| 3044 if (TopLevelBlocks != 1) { | 3049 if (TopLevelBlocks != 1) { |
| 3045 errs() << IRFilename | 3050 errs() << IRFilename |
| 3046 << ": Contains more than one module. Found: " << TopLevelBlocks | 3051 << ": Contains more than one module. Found: " << TopLevelBlocks |
| 3047 << "\n"; | 3052 << "\n"; |
| 3048 ErrorStatus.assign(EC_Bitcode); | 3053 ErrorStatus.assign(EC_Bitcode); |
| 3049 } | 3054 } |
| 3050 } | 3055 } |
| 3051 | 3056 |
| 3052 } // end of namespace Ice | 3057 } // end of namespace Ice |
| OLD | NEW |