Chromium Code Reviews| 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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 break; | 151 break; |
| 152 } | 152 } |
| 153 case FuncSig: { | 153 case FuncSig: { |
| 154 Stream << " " << Signature; | 154 Stream << " " << Signature; |
| 155 } | 155 } |
| 156 default: | 156 default: |
| 157 break; | 157 break; |
| 158 } | 158 } |
| 159 } | 159 } |
| 160 | 160 |
| 161 class BlockParserBaseClass; | |
| 162 | |
| 161 // Top-level class to read PNaCl bitcode files, and translate to ICE. | 163 // Top-level class to read PNaCl bitcode files, and translate to ICE. |
| 162 class TopLevelParser : public NaClBitcodeParser { | 164 class TopLevelParser : public NaClBitcodeParser { |
| 163 TopLevelParser(const TopLevelParser &) = delete; | 165 TopLevelParser(const TopLevelParser &) = delete; |
| 164 TopLevelParser &operator=(const TopLevelParser &) = delete; | 166 TopLevelParser &operator=(const TopLevelParser &) = delete; |
| 167 friend class BlockParserBaseClass; | |
|
Jim Stichnoth
2014/11/19 19:21:00
Can we avoid resorting to friend declarations this
Karl
2014/11/20 17:32:09
No longer friendly.
| |
| 165 | 168 |
| 166 public: | 169 public: |
| 167 typedef std::vector<Ice::FunctionDeclaration *> FunctionDeclarationListType; | 170 typedef std::vector<Ice::FunctionDeclaration *> FunctionDeclarationListType; |
| 168 | 171 |
| 169 TopLevelParser(Ice::Translator &Translator, const std::string &InputName, | 172 TopLevelParser(Ice::Translator &Translator, const std::string &InputName, |
| 170 NaClBitcodeHeader &Header, NaClBitstreamCursor &Cursor, | 173 NaClBitcodeHeader &Header, NaClBitstreamCursor &Cursor, |
| 171 bool &ErrorStatus) | 174 bool &ErrorStatus) |
| 172 : NaClBitcodeParser(Cursor), Translator(Translator), | 175 : NaClBitcodeParser(Cursor), Translator(Translator), |
| 173 Mod(new Module(InputName, getGlobalContext())), DL(PNaClDataLayout), | 176 Mod(new Module(InputName, getGlobalContext())), DL(PNaClDataLayout), |
| 174 Header(Header), TypeConverter(Mod->getContext()), | 177 Header(Header), TypeConverter(Mod->getContext()), |
| 175 ErrorStatus(ErrorStatus), NumErrors(0), NumFunctionIds(0), | 178 ErrorStatus(ErrorStatus), NumErrors(0), NumFunctionIds(0), |
| 176 NumFunctionBlocks(0) { | 179 NumFunctionBlocks(0), BlockParser(nullptr) { |
| 177 Mod->setDataLayout(PNaClDataLayout); | 180 Mod->setDataLayout(PNaClDataLayout); |
| 178 setErrStream(Translator.getContext()->getStrDump()); | 181 setErrStream(Translator.getContext()->getStrDump()); |
| 179 } | 182 } |
| 180 | 183 |
| 181 ~TopLevelParser() override {} | 184 ~TopLevelParser() override {} |
| 182 | 185 |
| 183 Ice::Translator &getTranslator() { return Translator; } | 186 Ice::Translator &getTranslator() { return Translator; } |
| 184 | 187 |
| 185 // Generates error with given Message. Always returns true. | 188 // Generates error with given Message. Always returns true. |
| 186 bool Error(const std::string &Message) override { | 189 bool Error(const std::string &Message) override; |
| 187 ErrorStatus = true; | 190 |
| 188 ++NumErrors; | 191 // Generates error message with respect to the current block parser. |
| 189 NaClBitcodeParser::Error(Message); | 192 bool BlockError(const std::string &Message); |
| 190 if (!AllowErrorRecovery) | |
| 191 report_fatal_error("Unable to continue"); | |
| 192 return true; | |
| 193 } | |
| 194 | 193 |
| 195 /// Returns the number of errors found while parsing the bitcode | 194 /// Returns the number of errors found while parsing the bitcode |
| 196 /// file. | 195 /// file. |
| 197 unsigned getNumErrors() const { return NumErrors; } | 196 unsigned getNumErrors() const { return NumErrors; } |
| 198 | 197 |
| 199 /// Returns the LLVM module associated with the translation. | 198 /// Returns the LLVM module associated with the translation. |
| 200 Module *getModule() const { return Mod.get(); } | 199 Module *getModule() const { return Mod.get(); } |
| 201 | 200 |
| 202 const DataLayout &getDataLayout() const { return DL; } | 201 const DataLayout &getDataLayout() const { return DL; } |
| 203 | 202 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 } | 311 } |
| 313 std::string Name; | 312 std::string Name; |
| 314 bool SuppressMangling; | 313 bool SuppressMangling; |
| 315 if (Decl) { | 314 if (Decl) { |
| 316 Name = Decl->getName(); | 315 Name = Decl->getName(); |
| 317 SuppressMangling = Decl->getSuppressMangling(); | 316 SuppressMangling = Decl->getSuppressMangling(); |
| 318 } else { | 317 } else { |
| 319 std::string Buffer; | 318 std::string Buffer; |
| 320 raw_string_ostream StrBuf(Buffer); | 319 raw_string_ostream StrBuf(Buffer); |
| 321 StrBuf << "Reference to global not defined: " << ID; | 320 StrBuf << "Reference to global not defined: " << ID; |
| 322 Error(StrBuf.str()); | 321 BlockError(StrBuf.str()); |
| 323 // TODO(kschimpf) Remove error recovery once implementation complete. | 322 // TODO(kschimpf) Remove error recovery once implementation complete. |
| 324 Name = "??"; | 323 Name = "??"; |
| 325 SuppressMangling = false; | 324 SuppressMangling = false; |
| 326 } | 325 } |
| 327 const Ice::RelocOffsetT Offset = 0; | 326 const Ice::RelocOffsetT Offset = 0; |
| 328 C = getTranslator().getContext()->getConstantSym( | 327 C = getTranslator().getContext()->getConstantSym( |
| 329 getIcePointerType(), Offset, Name, SuppressMangling); | 328 getIcePointerType(), Offset, Name, SuppressMangling); |
| 330 ValueIDConstants[ID] = C; | 329 ValueIDConstants[ID] = C; |
| 331 return C; | 330 return C; |
| 332 } | 331 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 422 unsigned NumFunctionIds; | 421 unsigned NumFunctionIds; |
| 423 // The number of function blocks (processed so far). | 422 // The number of function blocks (processed so far). |
| 424 unsigned NumFunctionBlocks; | 423 unsigned NumFunctionBlocks; |
| 425 // The list of function declaration IDs (in the order found) that | 424 // The list of function declaration IDs (in the order found) that |
| 426 // aren't just proto declarations. | 425 // aren't just proto declarations. |
| 427 // TODO(kschimpf): Instead of using this list, just use | 426 // TODO(kschimpf): Instead of using this list, just use |
| 428 // FunctionDeclarationList, and the isProto member function. | 427 // FunctionDeclarationList, and the isProto member function. |
| 429 std::vector<unsigned> DefiningFunctionDeclarationsList; | 428 std::vector<unsigned> DefiningFunctionDeclarationsList; |
| 430 // Error recovery value to use when getFuncSigTypeByID fails. | 429 // Error recovery value to use when getFuncSigTypeByID fails. |
| 431 Ice::FuncSigType UndefinedFuncSigType; | 430 Ice::FuncSigType UndefinedFuncSigType; |
| 431 // The block parser currently being applied. Used for error | |
| 432 // reporting. | |
| 433 BlockParserBaseClass *BlockParser; | |
| 432 | 434 |
| 433 bool ParseBlock(unsigned BlockID) override; | 435 bool ParseBlock(unsigned BlockID) override; |
| 434 | 436 |
| 435 // Gets extended type associated with the given index, assuming the | 437 // Gets extended type associated with the given index, assuming the |
| 436 // extended type is of the WantedKind. Generates error message if | 438 // extended type is of the WantedKind. Generates error message if |
| 437 // corresponding extended type of WantedKind can't be found, and | 439 // corresponding extended type of WantedKind can't be found, and |
| 438 // returns nullptr. | 440 // returns nullptr. |
| 439 ExtendedType *getTypeByIDAsKind(unsigned ID, | 441 ExtendedType *getTypeByIDAsKind(unsigned ID, |
| 440 ExtendedType::TypeKind WantedKind) { | 442 ExtendedType::TypeKind WantedKind) { |
| 441 ExtendedType *Ty = nullptr; | 443 ExtendedType *Ty = nullptr; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 459 | 461 |
| 460 // Reports that there is not global variable declaration for | 462 // Reports that there is not global variable declaration for |
| 461 // ID. Returns an error recovery value to use. | 463 // ID. Returns an error recovery value to use. |
| 462 Ice::VariableDeclaration *reportGetGlobalVariableByIDError(unsigned Index); | 464 Ice::VariableDeclaration *reportGetGlobalVariableByIDError(unsigned Index); |
| 463 | 465 |
| 464 // Reports that there is no corresponding ICE type for LLVMTy, and | 466 // Reports that there is no corresponding ICE type for LLVMTy, and |
| 465 // returns ICE::IceType_void. | 467 // returns ICE::IceType_void. |
| 466 Ice::Type convertToIceTypeError(Type *LLVMTy); | 468 Ice::Type convertToIceTypeError(Type *LLVMTy); |
| 467 }; | 469 }; |
| 468 | 470 |
| 471 bool TopLevelParser::Error(const std::string &Message) { | |
| 472 ErrorStatus = true; | |
| 473 ++NumErrors; | |
| 474 NaClBitcodeParser::Error(Message); | |
| 475 if (!AllowErrorRecovery) | |
| 476 report_fatal_error("Unable to continue"); | |
| 477 return true; | |
| 478 } | |
| 479 | |
| 469 void TopLevelParser::reportBadTypeIDAs(unsigned ID, const ExtendedType *Ty, | 480 void TopLevelParser::reportBadTypeIDAs(unsigned ID, const ExtendedType *Ty, |
| 470 ExtendedType::TypeKind WantedType) { | 481 ExtendedType::TypeKind WantedType) { |
| 471 std::string Buffer; | 482 std::string Buffer; |
| 472 raw_string_ostream StrBuf(Buffer); | 483 raw_string_ostream StrBuf(Buffer); |
| 473 if (Ty == nullptr) { | 484 if (Ty == nullptr) { |
| 474 StrBuf << "Can't find extended type for type id: " << ID; | 485 StrBuf << "Can't find extended type for type id: " << ID; |
| 475 } else { | 486 } else { |
| 476 StrBuf << "Type id " << ID << " not " << WantedType << ". Found: " << *Ty; | 487 StrBuf << "Type id " << ID << " not " << WantedType << ". Found: " << *Ty; |
| 477 } | 488 } |
| 478 Error(StrBuf.str()); | 489 BlockError(StrBuf.str()); |
| 479 } | 490 } |
| 480 | 491 |
| 481 Ice::FunctionDeclaration * | 492 Ice::FunctionDeclaration * |
| 482 TopLevelParser::reportGetFunctionByIDError(unsigned ID) { | 493 TopLevelParser::reportGetFunctionByIDError(unsigned ID) { |
| 483 std::string Buffer; | 494 std::string Buffer; |
| 484 raw_string_ostream StrBuf(Buffer); | 495 raw_string_ostream StrBuf(Buffer); |
| 485 StrBuf << "Function index " << ID | 496 StrBuf << "Function index " << ID |
| 486 << " not allowed. Out of range. Must be less than " | 497 << " not allowed. Out of range. Must be less than " |
| 487 << FunctionDeclarationList.size(); | 498 << FunctionDeclarationList.size(); |
| 488 Error(StrBuf.str()); | 499 BlockError(StrBuf.str()); |
| 489 // TODO(kschimpf) Remove error recovery once implementation complete. | 500 // TODO(kschimpf) Remove error recovery once implementation complete. |
| 490 if (!FunctionDeclarationList.empty()) | 501 if (!FunctionDeclarationList.empty()) |
| 491 return FunctionDeclarationList[0]; | 502 return FunctionDeclarationList[0]; |
| 492 report_fatal_error("Unable to continue"); | 503 report_fatal_error("Unable to continue"); |
| 493 } | 504 } |
| 494 | 505 |
| 495 Ice::VariableDeclaration * | 506 Ice::VariableDeclaration * |
| 496 TopLevelParser::reportGetGlobalVariableByIDError(unsigned Index) { | 507 TopLevelParser::reportGetGlobalVariableByIDError(unsigned Index) { |
| 497 std::string Buffer; | 508 std::string Buffer; |
| 498 raw_string_ostream StrBuf(Buffer); | 509 raw_string_ostream StrBuf(Buffer); |
| 499 StrBuf << "Global index " << Index | 510 StrBuf << "Global index " << Index |
| 500 << " not allowed. Out of range. Must be less than " | 511 << " not allowed. Out of range. Must be less than " |
| 501 << VariableDeclarations.size(); | 512 << VariableDeclarations.size(); |
| 502 Error(StrBuf.str()); | 513 BlockError(StrBuf.str()); |
| 503 // TODO(kschimpf) Remove error recovery once implementation complete. | 514 // TODO(kschimpf) Remove error recovery once implementation complete. |
| 504 if (!VariableDeclarations.empty()) | 515 if (!VariableDeclarations.empty()) |
| 505 return VariableDeclarations[0]; | 516 return VariableDeclarations[0]; |
| 506 report_fatal_error("Unable to continue"); | 517 report_fatal_error("Unable to continue"); |
| 507 } | 518 } |
| 508 | 519 |
| 509 Ice::Type TopLevelParser::convertToIceTypeError(Type *LLVMTy) { | 520 Ice::Type TopLevelParser::convertToIceTypeError(Type *LLVMTy) { |
| 510 std::string Buffer; | 521 std::string Buffer; |
| 511 raw_string_ostream StrBuf(Buffer); | 522 raw_string_ostream StrBuf(Buffer); |
| 512 StrBuf << "Invalid LLVM type: " << *LLVMTy; | 523 StrBuf << "Invalid LLVM type: " << *LLVMTy; |
| 513 Error(StrBuf.str()); | 524 Error(StrBuf.str()); |
| 514 return Ice::IceType_void; | 525 return Ice::IceType_void; |
| 515 } | 526 } |
| 516 | 527 |
| 517 // Base class for parsing blocks within the bitcode file. Note: | 528 // Base class for parsing blocks within the bitcode file. Note: |
| 518 // Because this is the base class of block parsers, we generate error | 529 // Because this is the base class of block parsers, we generate error |
| 519 // messages if ParseBlock or ParseRecord is not overridden in derived | 530 // messages if ParseBlock or ParseRecord is not overridden in derived |
| 520 // classes. | 531 // classes. |
| 521 class BlockParserBaseClass : public NaClBitcodeParser { | 532 class BlockParserBaseClass : public NaClBitcodeParser { |
| 533 BlockParserBaseClass(const BlockParserBaseClass &) = delete; | |
| 534 BlockParserBaseClass &operator=(const BlockParserBaseClass &) = delete; | |
| 535 friend class TopLevelParser; | |
| 536 | |
| 522 public: | 537 public: |
| 523 // Constructor for the top-level module block parser. | 538 // Constructor for the top-level module block parser. |
| 524 BlockParserBaseClass(unsigned BlockID, TopLevelParser *Context) | 539 BlockParserBaseClass(unsigned BlockID, TopLevelParser *Context) |
| 525 : NaClBitcodeParser(BlockID, Context), Context(Context) {} | 540 : NaClBitcodeParser(BlockID, Context), Context(Context) { |
| 541 Context->BlockParser = this; | |
| 542 } | |
| 526 | 543 |
| 527 ~BlockParserBaseClass() override {} | 544 ~BlockParserBaseClass() override { Context->BlockParser = nullptr; } |
| 545 | |
| 546 // Returns the printable name of the type of block being parsed. | |
| 547 virtual const char *getBlockName() const { | |
| 548 // If this class is used, it is parsing an unknown block. | |
| 549 return "unknown"; | |
| 550 } | |
| 528 | 551 |
| 529 protected: | 552 protected: |
| 530 // The context parser that contains the decoded state. | 553 // The context parser that contains the decoded state. |
| 531 TopLevelParser *Context; | 554 TopLevelParser *Context; |
| 532 | 555 |
| 533 // Constructor for nested block parsers. | 556 // Constructor for nested block parsers. |
| 534 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 557 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
| 535 : NaClBitcodeParser(BlockID, EnclosingParser), | 558 : NaClBitcodeParser(BlockID, EnclosingParser), |
| 536 Context(EnclosingParser->Context) {} | 559 Context(EnclosingParser->Context) {} |
| 537 | 560 |
| 538 // Gets the translator associated with the bitcode parser. | 561 // Gets the translator associated with the bitcode parser. |
| 539 Ice::Translator &getTranslator() const { return Context->getTranslator(); } | 562 Ice::Translator &getTranslator() const { return Context->getTranslator(); } |
| 540 | 563 |
| 541 const Ice::ClFlags &getFlags() const { return getTranslator().getFlags(); } | 564 const Ice::ClFlags &getFlags() const { return getTranslator().getFlags(); } |
| 542 | 565 |
| 543 bool isIRGenerationDisabled() const { | 566 bool isIRGenerationDisabled() const { |
| 544 return ALLOW_DISABLE_IR_GEN ? getTranslator().getFlags().DisableIRGeneration | 567 return ALLOW_DISABLE_IR_GEN ? getTranslator().getFlags().DisableIRGeneration |
| 545 : false; | 568 : false; |
| 546 } | 569 } |
| 547 | 570 |
| 548 // Generates an error Message with the bit address prefixed to it. | 571 // Generates an error Message with the bit address prefixed to it. |
| 549 bool Error(const std::string &Message) override { | 572 bool Error(const std::string &Message) override; |
| 550 uint64_t Bit = Record.GetStartBit() + Context->getHeaderSize() * 8; | |
| 551 std::string Buffer; | |
| 552 raw_string_ostream StrBuf(Buffer); | |
| 553 StrBuf << "(" << format("%" PRIu64 ":%u", (Bit / 8), | |
| 554 static_cast<unsigned>(Bit % 8)) << ") "; | |
| 555 // Note: If dump routines have been turned off, the error messages | |
| 556 // will not be readable. Hence, replace with simple error. | |
| 557 if (ALLOW_DUMP) | |
| 558 StrBuf << Message; | |
| 559 else | |
| 560 StrBuf << "Invalid input record"; | |
| 561 return Context->Error(StrBuf.str()); | |
| 562 } | |
| 563 | 573 |
| 564 // Default implementation. Reports that block is unknown and skips | 574 // Default implementation. Reports that block is unknown and skips |
| 565 // its contents. | 575 // its contents. |
| 566 bool ParseBlock(unsigned BlockID) override; | 576 bool ParseBlock(unsigned BlockID) override; |
| 567 | 577 |
| 568 // Default implementation. Reports that the record is not | 578 // Default implementation. Reports that the record is not |
| 569 // understood. | 579 // understood. |
| 570 void ProcessRecord() override; | 580 void ProcessRecord() override; |
| 571 | 581 |
| 572 // Checks if the size of the record is Size. Return true if valid. | 582 // Checks if the size of the record is Size. Return true if valid. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 613 private: | 623 private: |
| 614 /// Generates a record size error. ExpectedSize is the number | 624 /// Generates a record size error. ExpectedSize is the number |
| 615 /// of elements expected. RecordName is the name of the kind of | 625 /// of elements expected. RecordName is the name of the kind of |
| 616 /// record that has incorrect size. ContextMessage (if not nullptr) | 626 /// record that has incorrect size. ContextMessage (if not nullptr) |
| 617 /// is appended to "record expects" to describe how ExpectedSize | 627 /// is appended to "record expects" to describe how ExpectedSize |
| 618 /// should be interpreted. | 628 /// should be interpreted. |
| 619 void ReportRecordSizeError(unsigned ExpectedSize, const char *RecordName, | 629 void ReportRecordSizeError(unsigned ExpectedSize, const char *RecordName, |
| 620 const char *ContextMessage); | 630 const char *ContextMessage); |
| 621 }; | 631 }; |
| 622 | 632 |
| 633 bool TopLevelParser::BlockError(const std::string &Message) { | |
| 634 if (BlockParser) | |
| 635 return BlockParser->Error(Message); | |
| 636 else | |
| 637 return Error(Message); | |
| 638 } | |
| 639 | |
| 640 // Generates an error Message with the bit address prefixed to it. | |
| 641 bool BlockParserBaseClass::Error(const std::string &Message) { | |
| 642 uint64_t Bit = Record.GetStartBit() + Context->getHeaderSize() * 8; | |
| 643 std::string Buffer; | |
| 644 raw_string_ostream StrBuf(Buffer); | |
| 645 StrBuf << "(" << format("%" PRIu64 ":%u", (Bit / 8), | |
| 646 static_cast<unsigned>(Bit % 8)) << ") "; | |
| 647 // Note: If dump routines have been turned off, the error messages | |
| 648 // will not be readable. Hence, replace with simple error. | |
| 649 if (ALLOW_DUMP) | |
| 650 StrBuf << Message; | |
| 651 else { | |
| 652 StrBuf << "Invalid " << getBlockName() << " record: <" << Record.GetCode(); | |
| 653 for (const auto Val : Record.GetValues()) { | |
|
Jim Stichnoth
2014/11/19 23:30:36
Probably better not to use auto here, since one ha
| |
| 654 StrBuf << " " << Val; | |
| 655 } | |
| 656 StrBuf << ">"; | |
| 657 } | |
| 658 return Context->Error(StrBuf.str()); | |
| 659 } | |
| 660 | |
| 623 void BlockParserBaseClass::ReportRecordSizeError(unsigned ExpectedSize, | 661 void BlockParserBaseClass::ReportRecordSizeError(unsigned ExpectedSize, |
| 624 const char *RecordName, | 662 const char *RecordName, |
| 625 const char *ContextMessage) { | 663 const char *ContextMessage) { |
| 626 std::string Buffer; | 664 std::string Buffer; |
| 627 raw_string_ostream StrBuf(Buffer); | 665 raw_string_ostream StrBuf(Buffer); |
| 628 StrBuf << RecordName << " record expects"; | 666 const char *BlockName = getBlockName(); |
| 667 const char FirstChar = toupper(*BlockName); | |
| 668 StrBuf << FirstChar << (BlockName + 1) << " " << RecordName | |
| 669 << " record expects"; | |
| 629 if (ContextMessage) | 670 if (ContextMessage) |
| 630 StrBuf << " " << ContextMessage; | 671 StrBuf << " " << ContextMessage; |
| 631 StrBuf << " " << ExpectedSize << " argument"; | 672 StrBuf << " " << ExpectedSize << " argument"; |
| 632 if (ExpectedSize > 1) | 673 if (ExpectedSize > 1) |
| 633 StrBuf << "s"; | 674 StrBuf << "s"; |
| 634 StrBuf << ". Found: " << Record.GetValues().size(); | 675 StrBuf << ". Found: " << Record.GetValues().size(); |
| 635 Error(StrBuf.str()); | 676 Error(StrBuf.str()); |
| 636 } | 677 } |
| 637 | 678 |
| 638 bool BlockParserBaseClass::ParseBlock(unsigned BlockID) { | 679 bool BlockParserBaseClass::ParseBlock(unsigned BlockID) { |
| 639 // If called, derived class doesn't know how to handle block. | 680 // If called, derived class doesn't know how to handle block. |
| 640 // Report error and skip. | 681 // Report error and skip. |
| 641 std::string Buffer; | 682 std::string Buffer; |
| 642 raw_string_ostream StrBuf(Buffer); | 683 raw_string_ostream StrBuf(Buffer); |
| 643 StrBuf << "Don't know how to parse block id: " << BlockID; | 684 StrBuf << "Don't know how to parse block id: " << BlockID; |
| 644 Error(StrBuf.str()); | 685 Error(StrBuf.str()); |
| 645 // TODO(kschimpf) Remove error recovery once implementation complete. | 686 // TODO(kschimpf) Remove error recovery once implementation complete. |
| 646 SkipBlock(); | 687 SkipBlock(); |
| 647 return false; | 688 return false; |
| 648 } | 689 } |
| 649 | 690 |
| 650 void BlockParserBaseClass::ProcessRecord() { | 691 void BlockParserBaseClass::ProcessRecord() { |
| 651 // If called, derived class doesn't know how to handle. | 692 // If called, derived class doesn't know how to handle. |
| 652 std::string Buffer; | 693 std::string Buffer; |
| 653 raw_string_ostream StrBuf(Buffer); | 694 raw_string_ostream StrBuf(Buffer); |
| 654 StrBuf << "Don't know how to process record: " << Record; | 695 StrBuf << "Don't know how to process " << getBlockName() |
| 696 << " record:" << Record; | |
| 655 Error(StrBuf.str()); | 697 Error(StrBuf.str()); |
| 656 } | 698 } |
| 657 | 699 |
| 658 // Class to parse a types block. | 700 // Class to parse a types block. |
| 659 class TypesParser : public BlockParserBaseClass { | 701 class TypesParser : public BlockParserBaseClass { |
| 660 public: | 702 public: |
| 661 TypesParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 703 TypesParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
| 662 : BlockParserBaseClass(BlockID, EnclosingParser), | 704 : BlockParserBaseClass(BlockID, EnclosingParser), |
| 663 Timer(Ice::TimerStack::TT_parseTypes, getTranslator().getContext()), | 705 Timer(Ice::TimerStack::TT_parseTypes, getTranslator().getContext()), |
| 664 NextTypeId(0) {} | 706 NextTypeId(0) {} |
| 665 | 707 |
| 666 ~TypesParser() override {} | 708 ~TypesParser() override {} |
| 667 | 709 |
| 668 private: | 710 private: |
| 669 Ice::TimerMarker Timer; | 711 Ice::TimerMarker Timer; |
| 670 // The type ID that will be associated with the next type defining | 712 // The type ID that will be associated with the next type defining |
| 671 // record in the types block. | 713 // record in the types block. |
| 672 unsigned NextTypeId; | 714 unsigned NextTypeId; |
| 673 | 715 |
| 674 void ProcessRecord() override; | 716 void ProcessRecord() override; |
| 675 | 717 |
| 718 const char *getBlockName() const override { return "type"; } | |
| 719 | |
| 676 void setNextTypeIDAsSimpleType(Ice::Type Ty) { | 720 void setNextTypeIDAsSimpleType(Ice::Type Ty) { |
| 677 Context->getTypeByIDForDefining(NextTypeId++)->setAsSimpleType(Ty); | 721 Context->getTypeByIDForDefining(NextTypeId++)->setAsSimpleType(Ty); |
| 678 } | 722 } |
| 679 }; | 723 }; |
| 680 | 724 |
| 681 void TypesParser::ProcessRecord() { | 725 void TypesParser::ProcessRecord() { |
| 682 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 726 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
| 683 switch (Record.GetCode()) { | 727 switch (Record.GetCode()) { |
| 684 case naclbitc::TYPE_CODE_NUMENTRY: | 728 case naclbitc::TYPE_CODE_NUMENTRY: |
| 685 // NUMENTRY: [numentries] | 729 // NUMENTRY: [numentries] |
| 686 if (!isValidRecordSize(1, "Type count")) | 730 if (!isValidRecordSize(1, "count")) |
| 687 return; | 731 return; |
| 688 Context->resizeTypeIDValues(Values[0]); | 732 Context->resizeTypeIDValues(Values[0]); |
| 689 return; | 733 return; |
| 690 case naclbitc::TYPE_CODE_VOID: | 734 case naclbitc::TYPE_CODE_VOID: |
| 691 // VOID | 735 // VOID |
| 692 if (!isValidRecordSize(0, "Type void")) | 736 if (!isValidRecordSize(0, "void")) |
| 693 return; | 737 return; |
| 694 setNextTypeIDAsSimpleType(Ice::IceType_void); | 738 setNextTypeIDAsSimpleType(Ice::IceType_void); |
| 695 return; | 739 return; |
| 696 case naclbitc::TYPE_CODE_FLOAT: | 740 case naclbitc::TYPE_CODE_FLOAT: |
| 697 // FLOAT | 741 // FLOAT |
| 698 if (!isValidRecordSize(0, "Type float")) | 742 if (!isValidRecordSize(0, "float")) |
| 699 return; | 743 return; |
| 700 setNextTypeIDAsSimpleType(Ice::IceType_f32); | 744 setNextTypeIDAsSimpleType(Ice::IceType_f32); |
| 701 return; | 745 return; |
| 702 case naclbitc::TYPE_CODE_DOUBLE: | 746 case naclbitc::TYPE_CODE_DOUBLE: |
| 703 // DOUBLE | 747 // DOUBLE |
| 704 if (!isValidRecordSize(0, "Type double")) | 748 if (!isValidRecordSize(0, "double")) |
| 705 return; | 749 return; |
| 706 setNextTypeIDAsSimpleType(Ice::IceType_f64); | 750 setNextTypeIDAsSimpleType(Ice::IceType_f64); |
| 707 return; | 751 return; |
| 708 case naclbitc::TYPE_CODE_INTEGER: | 752 case naclbitc::TYPE_CODE_INTEGER: |
| 709 // INTEGER: [width] | 753 // INTEGER: [width] |
| 710 if (!isValidRecordSize(1, "Type integer")) | 754 if (!isValidRecordSize(1, "integer")) |
| 711 return; | 755 return; |
| 712 switch (Values[0]) { | 756 switch (Values[0]) { |
| 713 case 1: | 757 case 1: |
| 714 setNextTypeIDAsSimpleType(Ice::IceType_i1); | 758 setNextTypeIDAsSimpleType(Ice::IceType_i1); |
| 715 return; | 759 return; |
| 716 case 8: | 760 case 8: |
| 717 setNextTypeIDAsSimpleType(Ice::IceType_i8); | 761 setNextTypeIDAsSimpleType(Ice::IceType_i8); |
| 718 return; | 762 return; |
| 719 case 16: | 763 case 16: |
| 720 setNextTypeIDAsSimpleType(Ice::IceType_i16); | 764 setNextTypeIDAsSimpleType(Ice::IceType_i16); |
| 721 return; | 765 return; |
| 722 case 32: | 766 case 32: |
| 723 setNextTypeIDAsSimpleType(Ice::IceType_i32); | 767 setNextTypeIDAsSimpleType(Ice::IceType_i32); |
| 724 return; | 768 return; |
| 725 case 64: | 769 case 64: |
| 726 setNextTypeIDAsSimpleType(Ice::IceType_i64); | 770 setNextTypeIDAsSimpleType(Ice::IceType_i64); |
| 727 return; | 771 return; |
| 728 default: | 772 default: |
| 729 break; | 773 break; |
| 730 } | 774 } |
| 731 { | 775 { |
| 732 std::string Buffer; | 776 std::string Buffer; |
| 733 raw_string_ostream StrBuf(Buffer); | 777 raw_string_ostream StrBuf(Buffer); |
| 734 StrBuf << "Type integer record with invalid bitsize: " << Values[0]; | 778 StrBuf << "Type integer record with invalid bitsize: " << Values[0]; |
| 735 Error(StrBuf.str()); | 779 Error(StrBuf.str()); |
| 736 } | 780 } |
| 737 return; | 781 return; |
| 738 case naclbitc::TYPE_CODE_VECTOR: { | 782 case naclbitc::TYPE_CODE_VECTOR: { |
| 739 // VECTOR: [numelts, eltty] | 783 // VECTOR: [numelts, eltty] |
| 740 if (!isValidRecordSize(2, "Type vector")) | 784 if (!isValidRecordSize(2, "vector")) |
| 741 return; | 785 return; |
| 742 Ice::Type BaseTy = Context->getSimpleTypeByID(Values[1]); | 786 Ice::Type BaseTy = Context->getSimpleTypeByID(Values[1]); |
| 743 Ice::SizeT Size = Values[0]; | 787 Ice::SizeT Size = Values[0]; |
| 744 switch (BaseTy) { | 788 switch (BaseTy) { |
| 745 case Ice::IceType_i1: | 789 case Ice::IceType_i1: |
| 746 switch (Size) { | 790 switch (Size) { |
| 747 case 4: | 791 case 4: |
| 748 setNextTypeIDAsSimpleType(Ice::IceType_v4i1); | 792 setNextTypeIDAsSimpleType(Ice::IceType_v4i1); |
| 749 return; | 793 return; |
| 750 case 8: | 794 case 8: |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 788 std::string Buffer; | 832 std::string Buffer; |
| 789 raw_string_ostream StrBuf(Buffer); | 833 raw_string_ostream StrBuf(Buffer); |
| 790 StrBuf << "Invalid type vector record: <" << Values[0] << " x " << BaseTy | 834 StrBuf << "Invalid type vector record: <" << Values[0] << " x " << BaseTy |
| 791 << ">"; | 835 << ">"; |
| 792 Error(StrBuf.str()); | 836 Error(StrBuf.str()); |
| 793 } | 837 } |
| 794 return; | 838 return; |
| 795 } | 839 } |
| 796 case naclbitc::TYPE_CODE_FUNCTION: { | 840 case naclbitc::TYPE_CODE_FUNCTION: { |
| 797 // FUNCTION: [vararg, retty, paramty x N] | 841 // FUNCTION: [vararg, retty, paramty x N] |
| 798 if (!isValidRecordSizeAtLeast(2, "Type signature")) | 842 if (!isValidRecordSizeAtLeast(2, "signature")) |
| 799 return; | 843 return; |
| 800 if (Values[0]) | 844 if (Values[0]) |
| 801 Error("Function type can't define varargs"); | 845 Error("Function type can't define varargs"); |
| 802 ExtendedType *Ty = Context->getTypeByIDForDefining(NextTypeId++); | 846 ExtendedType *Ty = Context->getTypeByIDForDefining(NextTypeId++); |
| 803 Ty->setAsFunctionType(); | 847 Ty->setAsFunctionType(); |
| 804 FuncSigExtendedType *FuncTy = cast<FuncSigExtendedType>(Ty); | 848 FuncSigExtendedType *FuncTy = cast<FuncSigExtendedType>(Ty); |
| 805 FuncTy->setReturnType(Context->getSimpleTypeByID(Values[1])); | 849 FuncTy->setReturnType(Context->getSimpleTypeByID(Values[1])); |
| 806 for (unsigned i = 2, e = Values.size(); i != e; ++i) { | 850 for (unsigned i = 2, e = Values.size(); i != e; ++i) { |
| 807 // Check that type void not used as argument type. | 851 // Check that type void not used as argument type. |
| 808 // Note: PNaCl restrictions can't be checked until we | 852 // Note: PNaCl restrictions can't be checked until we |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 834 GlobalsParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 878 GlobalsParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
| 835 : BlockParserBaseClass(BlockID, EnclosingParser), | 879 : BlockParserBaseClass(BlockID, EnclosingParser), |
| 836 Timer(Ice::TimerStack::TT_parseGlobals, getTranslator().getContext()), | 880 Timer(Ice::TimerStack::TT_parseGlobals, getTranslator().getContext()), |
| 837 InitializersNeeded(0), NextGlobalID(0), | 881 InitializersNeeded(0), NextGlobalID(0), |
| 838 DummyGlobalVar( | 882 DummyGlobalVar( |
| 839 Ice::VariableDeclaration::create(getTranslator().getContext())), | 883 Ice::VariableDeclaration::create(getTranslator().getContext())), |
| 840 CurGlobalVar(DummyGlobalVar) {} | 884 CurGlobalVar(DummyGlobalVar) {} |
| 841 | 885 |
| 842 ~GlobalsParser() final {} | 886 ~GlobalsParser() final {} |
| 843 | 887 |
| 888 const char *getBlockName() const override { return "globals"; } | |
| 889 | |
| 844 private: | 890 private: |
| 845 Ice::TimerMarker Timer; | 891 Ice::TimerMarker Timer; |
| 846 // Keeps track of how many initializers are expected for the global variable | 892 // Keeps track of how many initializers are expected for the global variable |
| 847 // declaration being built. | 893 // declaration being built. |
| 848 unsigned InitializersNeeded; | 894 unsigned InitializersNeeded; |
| 849 | 895 |
| 850 // The index of the next global variable declaration. | 896 // The index of the next global variable declaration. |
| 851 unsigned NextGlobalID; | 897 unsigned NextGlobalID; |
| 852 | 898 |
| 853 // Dummy global variable declaration to guarantee CurGlobalVar is | 899 // Dummy global variable declaration to guarantee CurGlobalVar is |
| 854 // always defined (allowing code to not need to check if | 900 // always defined (allowing code to not need to check if |
| 855 // CurGlobalVar is nullptr). | 901 // CurGlobalVar is nullptr). |
| 856 Ice::VariableDeclaration *DummyGlobalVar; | 902 Ice::VariableDeclaration *DummyGlobalVar; |
| 857 | 903 |
| 858 // Holds the current global variable declaration being built. | 904 // Holds the current global variable declaration being built. |
| 859 Ice::VariableDeclaration *CurGlobalVar; | 905 Ice::VariableDeclaration *CurGlobalVar; |
| 860 | 906 |
| 861 void ExitBlock() override { | 907 void ExitBlock() override { |
| 862 verifyNoMissingInitializers(); | 908 verifyNoMissingInitializers(); |
| 863 unsigned NumIDs = Context->getNumGlobalVariables(); | 909 unsigned NumIDs = Context->getNumGlobalVariables(); |
| 864 if (NextGlobalID < NumIDs) { | 910 if (NextGlobalID < NumIDs) { |
| 865 std::string Buffer; | 911 std::string Buffer; |
| 866 raw_string_ostream StrBuf(Buffer); | 912 raw_string_ostream StrBuf(Buffer); |
| 867 StrBuf << "Globals block expects " << NumIDs | 913 StrBuf << getBlockName() << " block expects " << NumIDs |
| 868 << " global variable declarations. Found: " << NextGlobalID; | 914 << " global variable declarations. Found: " << NextGlobalID; |
| 869 Error(StrBuf.str()); | 915 Error(StrBuf.str()); |
| 870 } | 916 } |
| 871 BlockParserBaseClass::ExitBlock(); | 917 BlockParserBaseClass::ExitBlock(); |
| 872 } | 918 } |
| 873 | 919 |
| 874 void ProcessRecord() override; | 920 void ProcessRecord() override; |
| 875 | 921 |
| 876 // Checks if the number of initializers for the CurGlobalVar is the same as | 922 // Checks if the number of initializers for the CurGlobalVar is the same as |
| 877 // the number found in the bitcode file. If different, and error message is | 923 // the number found in the bitcode file. If different, and error message is |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 891 InitializersNeeded = NumInits; | 937 InitializersNeeded = NumInits; |
| 892 } | 938 } |
| 893 } | 939 } |
| 894 }; | 940 }; |
| 895 | 941 |
| 896 void GlobalsParser::ProcessRecord() { | 942 void GlobalsParser::ProcessRecord() { |
| 897 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 943 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
| 898 switch (Record.GetCode()) { | 944 switch (Record.GetCode()) { |
| 899 case naclbitc::GLOBALVAR_COUNT: | 945 case naclbitc::GLOBALVAR_COUNT: |
| 900 // COUNT: [n] | 946 // COUNT: [n] |
| 901 if (!isValidRecordSize(1, "Globals count")) | 947 if (!isValidRecordSize(1, "count")) |
| 902 return; | 948 return; |
| 903 if (NextGlobalID != Context->getNumGlobalVariables()) { | 949 if (NextGlobalID != Context->getNumGlobalVariables()) { |
| 904 Error("Globals count record not first in block."); | 950 Error("Globals count record not first in block."); |
| 905 return; | 951 return; |
| 906 } | 952 } |
| 907 Context->CreateGlobalVariables(Values[0]); | 953 Context->CreateGlobalVariables(Values[0]); |
| 908 return; | 954 return; |
| 909 case naclbitc::GLOBALVAR_VAR: { | 955 case naclbitc::GLOBALVAR_VAR: { |
| 910 // VAR: [align, isconst] | 956 // VAR: [align, isconst] |
| 911 if (!isValidRecordSize(2, "Globals variable")) | 957 if (!isValidRecordSize(2, "variable")) |
| 912 return; | 958 return; |
| 913 verifyNoMissingInitializers(); | 959 verifyNoMissingInitializers(); |
| 914 if (!isIRGenerationDisabled()) { | 960 if (!isIRGenerationDisabled()) { |
| 915 InitializersNeeded = 1; | 961 InitializersNeeded = 1; |
| 916 CurGlobalVar = Context->getGlobalVariableByID(NextGlobalID); | 962 CurGlobalVar = Context->getGlobalVariableByID(NextGlobalID); |
| 917 CurGlobalVar->setAlignment((1 << Values[0]) >> 1); | 963 CurGlobalVar->setAlignment((1 << Values[0]) >> 1); |
| 918 CurGlobalVar->setIsConstant(Values[1] != 0); | 964 CurGlobalVar->setIsConstant(Values[1] != 0); |
| 919 } | 965 } |
| 920 ++NextGlobalID; | 966 ++NextGlobalID; |
| 921 return; | 967 return; |
| 922 } | 968 } |
| 923 case naclbitc::GLOBALVAR_COMPOUND: | 969 case naclbitc::GLOBALVAR_COMPOUND: |
| 924 // COMPOUND: [size] | 970 // COMPOUND: [size] |
| 925 if (!isValidRecordSize(1, "globals compound")) | 971 if (!isValidRecordSize(1, "compound")) |
| 926 return; | 972 return; |
| 927 if (!CurGlobalVar->getInitializers().empty()) { | 973 if (!CurGlobalVar->getInitializers().empty()) { |
| 928 Error("Globals compound record not first initializer"); | 974 Error("Globals compound record not first initializer"); |
| 929 return; | 975 return; |
| 930 } | 976 } |
| 931 if (Values[0] < 2) { | 977 if (Values[0] < 2) { |
| 932 std::string Buffer; | 978 std::string Buffer; |
| 933 raw_string_ostream StrBuf(Buffer); | 979 raw_string_ostream StrBuf(Buffer); |
| 934 StrBuf << "Globals compound record size invalid. Found: " << Values[0]; | 980 StrBuf << getBlockName() |
| 981 << " compound record size invalid. Found: " << Values[0]; | |
| 935 Error(StrBuf.str()); | 982 Error(StrBuf.str()); |
| 936 return; | 983 return; |
| 937 } | 984 } |
| 938 if (isIRGenerationDisabled()) | 985 if (isIRGenerationDisabled()) |
| 939 return; | 986 return; |
| 940 InitializersNeeded = Values[0]; | 987 InitializersNeeded = Values[0]; |
| 941 return; | 988 return; |
| 942 case naclbitc::GLOBALVAR_ZEROFILL: { | 989 case naclbitc::GLOBALVAR_ZEROFILL: { |
| 943 // ZEROFILL: [size] | 990 // ZEROFILL: [size] |
| 944 if (!isValidRecordSize(1, "Globals zerofill")) | 991 if (!isValidRecordSize(1, "zerofill")) |
| 945 return; | 992 return; |
| 946 if (isIRGenerationDisabled()) | 993 if (isIRGenerationDisabled()) |
| 947 return; | 994 return; |
| 948 CurGlobalVar->addInitializer( | 995 CurGlobalVar->addInitializer( |
| 949 new Ice::VariableDeclaration::ZeroInitializer(Values[0])); | 996 new Ice::VariableDeclaration::ZeroInitializer(Values[0])); |
| 950 return; | 997 return; |
| 951 } | 998 } |
| 952 case naclbitc::GLOBALVAR_DATA: { | 999 case naclbitc::GLOBALVAR_DATA: { |
| 953 // DATA: [b0, b1, ...] | 1000 // DATA: [b0, b1, ...] |
| 954 if (!isValidRecordSizeAtLeast(1, "Globals data")) | 1001 if (!isValidRecordSizeAtLeast(1, "data")) |
| 955 return; | 1002 return; |
| 956 if (isIRGenerationDisabled()) | 1003 if (isIRGenerationDisabled()) |
| 957 return; | 1004 return; |
| 958 CurGlobalVar->addInitializer( | 1005 CurGlobalVar->addInitializer( |
| 959 new Ice::VariableDeclaration::DataInitializer(Values)); | 1006 new Ice::VariableDeclaration::DataInitializer(Values)); |
| 960 return; | 1007 return; |
| 961 } | 1008 } |
| 962 case naclbitc::GLOBALVAR_RELOC: { | 1009 case naclbitc::GLOBALVAR_RELOC: { |
| 963 // RELOC: [val, [addend]] | 1010 // RELOC: [val, [addend]] |
| 964 if (!isValidRecordSizeInRange(1, 2, "Globals reloc")) | 1011 if (!isValidRecordSizeInRange(1, 2, "reloc")) |
| 965 return; | 1012 return; |
| 966 if (isIRGenerationDisabled()) | 1013 if (isIRGenerationDisabled()) |
| 967 return; | 1014 return; |
| 968 unsigned Index = Values[0]; | 1015 unsigned Index = Values[0]; |
| 969 Ice::SizeT Offset = 0; | 1016 Ice::SizeT Offset = 0; |
| 970 if (Values.size() == 2) | 1017 if (Values.size() == 2) |
| 971 Offset = Values[1]; | 1018 Offset = Values[1]; |
| 972 CurGlobalVar->addInitializer(new Ice::VariableDeclaration::RelocInitializer( | 1019 CurGlobalVar->addInitializer(new Ice::VariableDeclaration::RelocInitializer( |
| 973 Context->getGlobalDeclarationByID(Index), Offset)); | 1020 Context->getGlobalDeclarationByID(Index), Offset)); |
| 974 return; | 1021 return; |
| 975 } | 1022 } |
| 976 default: | 1023 default: |
| 977 BlockParserBaseClass::ProcessRecord(); | 1024 BlockParserBaseClass::ProcessRecord(); |
| 978 return; | 1025 return; |
| 979 } | 1026 } |
| 980 } | 1027 } |
| 981 | 1028 |
| 982 /// Base class for parsing a valuesymtab block in the bitcode file. | 1029 /// Base class for parsing a valuesymtab block in the bitcode file. |
| 983 class ValuesymtabParser : public BlockParserBaseClass { | 1030 class ValuesymtabParser : public BlockParserBaseClass { |
| 984 ValuesymtabParser(const ValuesymtabParser &) = delete; | 1031 ValuesymtabParser(const ValuesymtabParser &) = delete; |
| 985 void operator=(const ValuesymtabParser &) = delete; | 1032 void operator=(const ValuesymtabParser &) = delete; |
| 986 | 1033 |
| 987 public: | 1034 public: |
| 988 ValuesymtabParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 1035 ValuesymtabParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
| 989 : BlockParserBaseClass(BlockID, EnclosingParser) {} | 1036 : BlockParserBaseClass(BlockID, EnclosingParser) {} |
| 990 | 1037 |
| 991 ~ValuesymtabParser() override {} | 1038 ~ValuesymtabParser() override {} |
| 992 | 1039 |
| 1040 const char *getBlockName() const override { return "valuesymtab"; } | |
| 1041 | |
| 993 protected: | 1042 protected: |
| 994 typedef SmallString<128> StringType; | 1043 typedef SmallString<128> StringType; |
| 995 | 1044 |
| 996 // Associates Name with the value defined by the given Index. | 1045 // Associates Name with the value defined by the given Index. |
| 997 virtual void setValueName(uint64_t Index, StringType &Name) = 0; | 1046 virtual void setValueName(uint64_t Index, StringType &Name) = 0; |
| 998 | 1047 |
| 999 // Associates Name with the value defined by the given Index; | 1048 // Associates Name with the value defined by the given Index; |
| 1000 virtual void setBbName(uint64_t Index, StringType &Name) = 0; | 1049 virtual void setBbName(uint64_t Index, StringType &Name) = 0; |
| 1001 | 1050 |
| 1002 private: | 1051 private: |
| 1003 | 1052 |
| 1004 void ProcessRecord() override; | 1053 void ProcessRecord() override; |
| 1005 | 1054 |
| 1006 void ConvertToString(StringType &ConvertedName) { | 1055 void ConvertToString(StringType &ConvertedName) { |
| 1007 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 1056 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
| 1008 for (size_t i = 1, e = Values.size(); i != e; ++i) { | 1057 for (size_t i = 1, e = Values.size(); i != e; ++i) { |
| 1009 ConvertedName += static_cast<char>(Values[i]); | 1058 ConvertedName += static_cast<char>(Values[i]); |
| 1010 } | 1059 } |
| 1011 } | 1060 } |
| 1012 }; | 1061 }; |
| 1013 | 1062 |
| 1014 void ValuesymtabParser::ProcessRecord() { | 1063 void ValuesymtabParser::ProcessRecord() { |
| 1015 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 1064 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
| 1016 StringType ConvertedName; | 1065 StringType ConvertedName; |
| 1017 switch (Record.GetCode()) { | 1066 switch (Record.GetCode()) { |
| 1018 case naclbitc::VST_CODE_ENTRY: { | 1067 case naclbitc::VST_CODE_ENTRY: { |
| 1019 // VST_ENTRY: [ValueId, namechar x N] | 1068 // VST_ENTRY: [ValueId, namechar x N] |
| 1020 if (!isValidRecordSizeAtLeast(2, "Valuesymtab value entry")) | 1069 if (!isValidRecordSizeAtLeast(2, "value entry")) |
| 1021 return; | 1070 return; |
| 1022 ConvertToString(ConvertedName); | 1071 ConvertToString(ConvertedName); |
| 1023 setValueName(Values[0], ConvertedName); | 1072 setValueName(Values[0], ConvertedName); |
| 1024 return; | 1073 return; |
| 1025 } | 1074 } |
| 1026 case naclbitc::VST_CODE_BBENTRY: { | 1075 case naclbitc::VST_CODE_BBENTRY: { |
| 1027 // VST_BBENTRY: [BbId, namechar x N] | 1076 // VST_BBENTRY: [BbId, namechar x N] |
| 1028 if (!isValidRecordSizeAtLeast(2, "Valuesymtab basic block entry")) | 1077 if (!isValidRecordSizeAtLeast(2, "basic block entry")) |
| 1029 return; | 1078 return; |
| 1030 ConvertToString(ConvertedName); | 1079 ConvertToString(ConvertedName); |
| 1031 setBbName(Values[0], ConvertedName); | 1080 setBbName(Values[0], ConvertedName); |
| 1032 return; | 1081 return; |
| 1033 } | 1082 } |
| 1034 default: | 1083 default: |
| 1035 break; | 1084 break; |
| 1036 } | 1085 } |
| 1037 // If reached, don't know how to handle record. | 1086 // If reached, don't know how to handle record. |
| 1038 BlockParserBaseClass::ProcessRecord(); | 1087 BlockParserBaseClass::ProcessRecord(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1080 CurrentNode = InstallNextBasicBlock(); | 1129 CurrentNode = InstallNextBasicBlock(); |
| 1081 Func->setEntryNode(CurrentNode); | 1130 Func->setEntryNode(CurrentNode); |
| 1082 for (Ice::Type ArgType : Signature.getArgList()) { | 1131 for (Ice::Type ArgType : Signature.getArgList()) { |
| 1083 Func->addArg(getNextInstVar(ArgType)); | 1132 Func->addArg(getNextInstVar(ArgType)); |
| 1084 } | 1133 } |
| 1085 } | 1134 } |
| 1086 } | 1135 } |
| 1087 | 1136 |
| 1088 ~FunctionParser() final {} | 1137 ~FunctionParser() final {} |
| 1089 | 1138 |
| 1139 const char *getBlockName() const override { return "function"; } | |
| 1140 | |
| 1090 void setNextLocalInstIndex(Ice::Operand *Op) { | 1141 void setNextLocalInstIndex(Ice::Operand *Op) { |
| 1091 setOperand(NextLocalInstIndex++, Op); | 1142 setOperand(NextLocalInstIndex++, Op); |
| 1092 } | 1143 } |
| 1093 | 1144 |
| 1094 // Set the next constant ID to the given constant C. | 1145 // Set the next constant ID to the given constant C. |
| 1095 void setNextConstantID(Ice::Constant *C) { setNextLocalInstIndex(C); } | 1146 void setNextConstantID(Ice::Constant *C) { setNextLocalInstIndex(C); } |
| 1096 | 1147 |
| 1097 private: | 1148 private: |
| 1098 Ice::TimerMarker Timer; | 1149 Ice::TimerMarker Timer; |
| 1099 // The corresponding ICE function defined by the function block. | 1150 // The corresponding ICE function defined by the function block. |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1751 if (InstIsTerminating) { | 1802 if (InstIsTerminating) { |
| 1752 InstIsTerminating = false; | 1803 InstIsTerminating = false; |
| 1753 if (!isIRGenerationDisabled()) | 1804 if (!isIRGenerationDisabled()) |
| 1754 CurrentNode = getBasicBlock(++CurrentBbIndex); | 1805 CurrentNode = getBasicBlock(++CurrentBbIndex); |
| 1755 } | 1806 } |
| 1756 // The base index for relative indexing. | 1807 // The base index for relative indexing. |
| 1757 int32_t BaseIndex = getNextInstIndex(); | 1808 int32_t BaseIndex = getNextInstIndex(); |
| 1758 switch (Record.GetCode()) { | 1809 switch (Record.GetCode()) { |
| 1759 case naclbitc::FUNC_CODE_DECLAREBLOCKS: { | 1810 case naclbitc::FUNC_CODE_DECLAREBLOCKS: { |
| 1760 // DECLAREBLOCKS: [n] | 1811 // DECLAREBLOCKS: [n] |
| 1761 if (!isValidRecordSize(1, "function block count")) | 1812 if (!isValidRecordSize(1, "count")) |
| 1762 return; | 1813 return; |
| 1763 uint32_t NumBbs = Values[0]; | 1814 uint32_t NumBbs = Values[0]; |
| 1764 if (NumBbs == 0) { | 1815 if (NumBbs == 0) { |
| 1765 Error("Functions must contain at least one basic block."); | 1816 Error("Functions must contain at least one basic block."); |
| 1766 // TODO(kschimpf) Remove error recovery once implementation complete. | 1817 // TODO(kschimpf) Remove error recovery once implementation complete. |
| 1767 NumBbs = 1; | 1818 NumBbs = 1; |
| 1768 } | 1819 } |
| 1769 if (isIRGenerationDisabled()) | 1820 if (isIRGenerationDisabled()) |
| 1770 return; | 1821 return; |
| 1771 if (Func->getNodes().size() != 1) { | 1822 if (Func->getNodes().size() != 1) { |
| 1772 Error("Duplicate function block count record"); | 1823 Error("Duplicate function block count record"); |
| 1773 return; | 1824 return; |
| 1774 } | 1825 } |
| 1775 // Install the basic blocks, skipping bb0 which was created in the | 1826 // Install the basic blocks, skipping bb0 which was created in the |
| 1776 // constructor. | 1827 // constructor. |
| 1777 for (size_t i = 1; i < NumBbs; ++i) | 1828 for (size_t i = 1; i < NumBbs; ++i) |
| 1778 InstallNextBasicBlock(); | 1829 InstallNextBasicBlock(); |
| 1779 return; | 1830 return; |
| 1780 } | 1831 } |
| 1781 case naclbitc::FUNC_CODE_INST_BINOP: { | 1832 case naclbitc::FUNC_CODE_INST_BINOP: { |
| 1782 // BINOP: [opval, opval, opcode] | 1833 // BINOP: [opval, opval, opcode] |
| 1783 if (!isValidRecordSize(3, "function block binop")) | 1834 if (!isValidRecordSize(3, "binop")) |
| 1784 return; | 1835 return; |
| 1785 Ice::Operand *Op1 = getRelativeOperand(Values[0], BaseIndex); | 1836 Ice::Operand *Op1 = getRelativeOperand(Values[0], BaseIndex); |
| 1786 Ice::Operand *Op2 = getRelativeOperand(Values[1], BaseIndex); | 1837 Ice::Operand *Op2 = getRelativeOperand(Values[1], BaseIndex); |
| 1787 if (isIRGenerationDisabled()) { | 1838 if (isIRGenerationDisabled()) { |
| 1788 assert(Op1 == nullptr && Op2 == nullptr); | 1839 assert(Op1 == nullptr && Op2 == nullptr); |
| 1789 setNextLocalInstIndex(nullptr); | 1840 setNextLocalInstIndex(nullptr); |
| 1790 return; | 1841 return; |
| 1791 } | 1842 } |
| 1792 Ice::Type Type1 = Op1->getType(); | 1843 Ice::Type Type1 = Op1->getType(); |
| 1793 Ice::Type Type2 = Op2->getType(); | 1844 Ice::Type Type2 = Op2->getType(); |
| 1794 if (Type1 != Type2) { | 1845 if (Type1 != Type2) { |
| 1795 std::string Buffer; | 1846 std::string Buffer; |
| 1796 raw_string_ostream StrBuf(Buffer); | 1847 raw_string_ostream StrBuf(Buffer); |
| 1797 StrBuf << "Binop argument types differ: " << Type1 << " and " << Type2; | 1848 StrBuf << "Binop argument types differ: " << Type1 << " and " << Type2; |
| 1798 Error(StrBuf.str()); | 1849 Error(StrBuf.str()); |
| 1799 appendErrorInstruction(Type1); | 1850 appendErrorInstruction(Type1); |
| 1800 return; | 1851 return; |
| 1801 } | 1852 } |
| 1802 | 1853 |
| 1803 Ice::InstArithmetic::OpKind Opcode; | 1854 Ice::InstArithmetic::OpKind Opcode; |
| 1804 if (!convertBinopOpcode(Values[2], Type1, Opcode)) | 1855 if (!convertBinopOpcode(Values[2], Type1, Opcode)) |
| 1805 return; | 1856 return; |
| 1806 CurrentNode->appendInst(Ice::InstArithmetic::create( | 1857 CurrentNode->appendInst(Ice::InstArithmetic::create( |
| 1807 Func, Opcode, getNextInstVar(Type1), Op1, Op2)); | 1858 Func, Opcode, getNextInstVar(Type1), Op1, Op2)); |
| 1808 return; | 1859 return; |
| 1809 } | 1860 } |
| 1810 case naclbitc::FUNC_CODE_INST_CAST: { | 1861 case naclbitc::FUNC_CODE_INST_CAST: { |
| 1811 // CAST: [opval, destty, castopc] | 1862 // CAST: [opval, destty, castopc] |
| 1812 if (!isValidRecordSize(3, "function block cast")) | 1863 if (!isValidRecordSize(3, "cast")) |
| 1813 return; | 1864 return; |
| 1814 Ice::Operand *Src = getRelativeOperand(Values[0], BaseIndex); | 1865 Ice::Operand *Src = getRelativeOperand(Values[0], BaseIndex); |
| 1815 Ice::Type CastType = Context->getSimpleTypeByID(Values[1]); | 1866 Ice::Type CastType = Context->getSimpleTypeByID(Values[1]); |
| 1816 Instruction::CastOps LLVMCastOp; | 1867 Instruction::CastOps LLVMCastOp; |
| 1817 Ice::InstCast::OpKind CastKind; | 1868 Ice::InstCast::OpKind CastKind; |
| 1818 if (!naclbitc::DecodeCastOpcode(Values[2], LLVMCastOp) || | 1869 if (!naclbitc::DecodeCastOpcode(Values[2], LLVMCastOp) || |
| 1819 !convertLLVMCastOpToIceOp(LLVMCastOp, CastKind)) { | 1870 !convertLLVMCastOpToIceOp(LLVMCastOp, CastKind)) { |
| 1820 std::string Buffer; | 1871 std::string Buffer; |
| 1821 raw_string_ostream StrBuf(Buffer); | 1872 raw_string_ostream StrBuf(Buffer); |
| 1822 StrBuf << "Cast opcode not understood: " << Values[2]; | 1873 StrBuf << "Cast opcode not understood: " << Values[2]; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1839 Error(StrBuf.str()); | 1890 Error(StrBuf.str()); |
| 1840 appendErrorInstruction(CastType); | 1891 appendErrorInstruction(CastType); |
| 1841 return; | 1892 return; |
| 1842 } | 1893 } |
| 1843 CurrentNode->appendInst( | 1894 CurrentNode->appendInst( |
| 1844 Ice::InstCast::create(Func, CastKind, getNextInstVar(CastType), Src)); | 1895 Ice::InstCast::create(Func, CastKind, getNextInstVar(CastType), Src)); |
| 1845 return; | 1896 return; |
| 1846 } | 1897 } |
| 1847 case naclbitc::FUNC_CODE_INST_VSELECT: { | 1898 case naclbitc::FUNC_CODE_INST_VSELECT: { |
| 1848 // VSELECT: [opval, opval, pred] | 1899 // VSELECT: [opval, opval, pred] |
| 1849 if (!isValidRecordSize(3, "function block select")) | 1900 if (!isValidRecordSize(3, "select")) |
| 1850 return; | 1901 return; |
| 1851 Ice::Operand *ThenVal = getRelativeOperand(Values[0], BaseIndex); | 1902 Ice::Operand *ThenVal = getRelativeOperand(Values[0], BaseIndex); |
| 1852 Ice::Operand *ElseVal = getRelativeOperand(Values[1], BaseIndex); | 1903 Ice::Operand *ElseVal = getRelativeOperand(Values[1], BaseIndex); |
| 1853 Ice::Operand *CondVal = getRelativeOperand(Values[2], BaseIndex); | 1904 Ice::Operand *CondVal = getRelativeOperand(Values[2], BaseIndex); |
| 1854 if (isIRGenerationDisabled()) { | 1905 if (isIRGenerationDisabled()) { |
| 1855 assert(ThenVal == nullptr && ElseVal == nullptr && CondVal == nullptr); | 1906 assert(ThenVal == nullptr && ElseVal == nullptr && CondVal == nullptr); |
| 1856 setNextLocalInstIndex(nullptr); | 1907 setNextLocalInstIndex(nullptr); |
| 1857 return; | 1908 return; |
| 1858 } | 1909 } |
| 1859 Ice::Type ThenType = ThenVal->getType(); | 1910 Ice::Type ThenType = ThenVal->getType(); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 1888 Error(StrBuf.str()); | 1939 Error(StrBuf.str()); |
| 1889 appendErrorInstruction(ThenType); | 1940 appendErrorInstruction(ThenType); |
| 1890 return; | 1941 return; |
| 1891 } | 1942 } |
| 1892 CurrentNode->appendInst(Ice::InstSelect::create( | 1943 CurrentNode->appendInst(Ice::InstSelect::create( |
| 1893 Func, getNextInstVar(ThenType), CondVal, ThenVal, ElseVal)); | 1944 Func, getNextInstVar(ThenType), CondVal, ThenVal, ElseVal)); |
| 1894 return; | 1945 return; |
| 1895 } | 1946 } |
| 1896 case naclbitc::FUNC_CODE_INST_EXTRACTELT: { | 1947 case naclbitc::FUNC_CODE_INST_EXTRACTELT: { |
| 1897 // EXTRACTELT: [opval, opval] | 1948 // EXTRACTELT: [opval, opval] |
| 1898 if (!isValidRecordSize(2, "function block extract element")) | 1949 if (!isValidRecordSize(2, "extract element")) |
| 1899 return; | 1950 return; |
| 1900 Ice::Operand *Vec = getRelativeOperand(Values[0], BaseIndex); | 1951 Ice::Operand *Vec = getRelativeOperand(Values[0], BaseIndex); |
| 1901 Ice::Operand *Index = getRelativeOperand(Values[1], BaseIndex); | 1952 Ice::Operand *Index = getRelativeOperand(Values[1], BaseIndex); |
| 1902 if (isIRGenerationDisabled()) { | 1953 if (isIRGenerationDisabled()) { |
| 1903 assert(Vec == nullptr && Index == nullptr); | 1954 assert(Vec == nullptr && Index == nullptr); |
| 1904 setNextLocalInstIndex(nullptr); | 1955 setNextLocalInstIndex(nullptr); |
| 1905 return; | 1956 return; |
| 1906 } | 1957 } |
| 1907 Ice::Type VecType = Vec->getType(); | 1958 Ice::Type VecType = Vec->getType(); |
| 1908 VectorIndexCheckValue IndexCheckValue = validateVectorIndex(Vec, Index); | 1959 VectorIndexCheckValue IndexCheckValue = validateVectorIndex(Vec, Index); |
| 1909 if (IndexCheckValue != VectorIndexValid) { | 1960 if (IndexCheckValue != VectorIndexValid) { |
| 1910 std::string Buffer; | 1961 std::string Buffer; |
| 1911 raw_string_ostream StrBuf(Buffer); | 1962 raw_string_ostream StrBuf(Buffer); |
| 1912 dumpVectorIndexCheckValue(StrBuf, IndexCheckValue); | 1963 dumpVectorIndexCheckValue(StrBuf, IndexCheckValue); |
| 1913 StrBuf << ": extractelement " << VecType << " " << *Vec << ", " | 1964 StrBuf << ": extractelement " << VecType << " " << *Vec << ", " |
| 1914 << Index->getType() << " " << *Index; | 1965 << Index->getType() << " " << *Index; |
| 1915 Error(StrBuf.str()); | 1966 Error(StrBuf.str()); |
| 1916 appendErrorInstruction(VecType); | 1967 appendErrorInstruction(VecType); |
| 1917 return; | 1968 return; |
| 1918 } | 1969 } |
| 1919 CurrentNode->appendInst(Ice::InstExtractElement::create( | 1970 CurrentNode->appendInst(Ice::InstExtractElement::create( |
| 1920 Func, getNextInstVar(typeElementType(VecType)), Vec, Index)); | 1971 Func, getNextInstVar(typeElementType(VecType)), Vec, Index)); |
| 1921 return; | 1972 return; |
| 1922 } | 1973 } |
| 1923 case naclbitc::FUNC_CODE_INST_INSERTELT: { | 1974 case naclbitc::FUNC_CODE_INST_INSERTELT: { |
| 1924 // INSERTELT: [opval, opval, opval] | 1975 // INSERTELT: [opval, opval, opval] |
| 1925 if (!isValidRecordSize(3, "function block insert element")) | 1976 if (!isValidRecordSize(3, "insert element")) |
| 1926 return; | 1977 return; |
| 1927 Ice::Operand *Vec = getRelativeOperand(Values[0], BaseIndex); | 1978 Ice::Operand *Vec = getRelativeOperand(Values[0], BaseIndex); |
| 1928 Ice::Operand *Elt = getRelativeOperand(Values[1], BaseIndex); | 1979 Ice::Operand *Elt = getRelativeOperand(Values[1], BaseIndex); |
| 1929 Ice::Operand *Index = getRelativeOperand(Values[2], BaseIndex); | 1980 Ice::Operand *Index = getRelativeOperand(Values[2], BaseIndex); |
| 1930 if (isIRGenerationDisabled()) { | 1981 if (isIRGenerationDisabled()) { |
| 1931 assert(Vec == nullptr && Elt == nullptr && Index == nullptr); | 1982 assert(Vec == nullptr && Elt == nullptr && Index == nullptr); |
| 1932 setNextLocalInstIndex(nullptr); | 1983 setNextLocalInstIndex(nullptr); |
| 1933 return; | 1984 return; |
| 1934 } | 1985 } |
| 1935 Ice::Type VecType = Vec->getType(); | 1986 Ice::Type VecType = Vec->getType(); |
| 1936 VectorIndexCheckValue IndexCheckValue = validateVectorIndex(Vec, Index); | 1987 VectorIndexCheckValue IndexCheckValue = validateVectorIndex(Vec, Index); |
| 1937 if (IndexCheckValue != VectorIndexValid) { | 1988 if (IndexCheckValue != VectorIndexValid) { |
| 1938 std::string Buffer; | 1989 std::string Buffer; |
| 1939 raw_string_ostream StrBuf(Buffer); | 1990 raw_string_ostream StrBuf(Buffer); |
| 1940 dumpVectorIndexCheckValue(StrBuf, IndexCheckValue); | 1991 dumpVectorIndexCheckValue(StrBuf, IndexCheckValue); |
| 1941 StrBuf << ": insertelement " << VecType << " " << *Vec << ", " | 1992 StrBuf << ": insertelement " << VecType << " " << *Vec << ", " |
| 1942 << Elt->getType() << " " << *Elt << ", " << Index->getType() << " " | 1993 << Elt->getType() << " " << *Elt << ", " << Index->getType() << " " |
| 1943 << *Index; | 1994 << *Index; |
| 1944 Error(StrBuf.str()); | 1995 Error(StrBuf.str()); |
| 1945 appendErrorInstruction(Elt->getType()); | 1996 appendErrorInstruction(Elt->getType()); |
| 1946 return; | 1997 return; |
| 1947 } | 1998 } |
| 1948 CurrentNode->appendInst(Ice::InstInsertElement::create( | 1999 CurrentNode->appendInst(Ice::InstInsertElement::create( |
| 1949 Func, getNextInstVar(VecType), Vec, Elt, Index)); | 2000 Func, getNextInstVar(VecType), Vec, Elt, Index)); |
| 1950 return; | 2001 return; |
| 1951 } | 2002 } |
| 1952 case naclbitc::FUNC_CODE_INST_CMP2: { | 2003 case naclbitc::FUNC_CODE_INST_CMP2: { |
| 1953 // CMP2: [opval, opval, pred] | 2004 // CMP2: [opval, opval, pred] |
| 1954 if (!isValidRecordSize(3, "function block compare")) | 2005 if (!isValidRecordSize(3, "compare")) |
| 1955 return; | 2006 return; |
| 1956 Ice::Operand *Op1 = getRelativeOperand(Values[0], BaseIndex); | 2007 Ice::Operand *Op1 = getRelativeOperand(Values[0], BaseIndex); |
| 1957 Ice::Operand *Op2 = getRelativeOperand(Values[1], BaseIndex); | 2008 Ice::Operand *Op2 = getRelativeOperand(Values[1], BaseIndex); |
| 1958 if (isIRGenerationDisabled()) { | 2009 if (isIRGenerationDisabled()) { |
| 1959 assert(Op1 == nullptr && Op2 == nullptr); | 2010 assert(Op1 == nullptr && Op2 == nullptr); |
| 1960 setNextLocalInstIndex(nullptr); | 2011 setNextLocalInstIndex(nullptr); |
| 1961 return; | 2012 return; |
| 1962 } | 2013 } |
| 1963 Ice::Type Op1Type = Op1->getType(); | 2014 Ice::Type Op1Type = Op1->getType(); |
| 1964 Ice::Type Op2Type = Op2->getType(); | 2015 Ice::Type Op2Type = Op2->getType(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2010 raw_string_ostream StrBuf(Buffer); | 2061 raw_string_ostream StrBuf(Buffer); |
| 2011 StrBuf << "Compare on type not understood: " << Op1Type; | 2062 StrBuf << "Compare on type not understood: " << Op1Type; |
| 2012 Error(StrBuf.str()); | 2063 Error(StrBuf.str()); |
| 2013 appendErrorInstruction(DestType); | 2064 appendErrorInstruction(DestType); |
| 2014 return; | 2065 return; |
| 2015 } | 2066 } |
| 2016 return; | 2067 return; |
| 2017 } | 2068 } |
| 2018 case naclbitc::FUNC_CODE_INST_RET: { | 2069 case naclbitc::FUNC_CODE_INST_RET: { |
| 2019 // RET: [opval?] | 2070 // RET: [opval?] |
| 2020 if (!isValidRecordSizeInRange(0, 1, "function block ret")) | 2071 if (!isValidRecordSizeInRange(0, 1, "return")) |
| 2021 return; | 2072 return; |
| 2022 if (Values.empty()) { | 2073 if (Values.empty()) { |
| 2023 if (isIRGenerationDisabled()) | 2074 if (isIRGenerationDisabled()) |
| 2024 return; | 2075 return; |
| 2025 CurrentNode->appendInst(Ice::InstRet::create(Func)); | 2076 CurrentNode->appendInst(Ice::InstRet::create(Func)); |
| 2026 } else { | 2077 } else { |
| 2027 Ice::Operand *RetVal = getRelativeOperand(Values[0], BaseIndex); | 2078 Ice::Operand *RetVal = getRelativeOperand(Values[0], BaseIndex); |
| 2028 if (isIRGenerationDisabled()) { | 2079 if (isIRGenerationDisabled()) { |
| 2029 assert(RetVal == nullptr); | 2080 assert(RetVal == nullptr); |
| 2030 return; | 2081 return; |
| 2031 } | 2082 } |
| 2032 CurrentNode->appendInst(Ice::InstRet::create(Func, RetVal)); | 2083 CurrentNode->appendInst(Ice::InstRet::create(Func, RetVal)); |
| 2033 } | 2084 } |
| 2034 InstIsTerminating = true; | 2085 InstIsTerminating = true; |
| 2035 return; | 2086 return; |
| 2036 } | 2087 } |
| 2037 case naclbitc::FUNC_CODE_INST_BR: { | 2088 case naclbitc::FUNC_CODE_INST_BR: { |
| 2038 if (Values.size() == 1) { | 2089 if (Values.size() == 1) { |
| 2039 // BR: [bb#] | 2090 // BR: [bb#] |
| 2040 if (isIRGenerationDisabled()) | 2091 if (isIRGenerationDisabled()) |
| 2041 return; | 2092 return; |
| 2042 Ice::CfgNode *Block = getBranchBasicBlock(Values[0]); | 2093 Ice::CfgNode *Block = getBranchBasicBlock(Values[0]); |
| 2043 if (Block == nullptr) | 2094 if (Block == nullptr) |
| 2044 return; | 2095 return; |
| 2045 CurrentNode->appendInst(Ice::InstBr::create(Func, Block)); | 2096 CurrentNode->appendInst(Ice::InstBr::create(Func, Block)); |
| 2046 } else { | 2097 } else { |
| 2047 // BR: [bb#, bb#, opval] | 2098 // BR: [bb#, bb#, opval] |
| 2048 if (!isValidRecordSize(3, "function block branch")) | 2099 if (!isValidRecordSize(3, "branch")) |
| 2049 return; | 2100 return; |
| 2050 Ice::Operand *Cond = getRelativeOperand(Values[2], BaseIndex); | 2101 Ice::Operand *Cond = getRelativeOperand(Values[2], BaseIndex); |
| 2051 if (isIRGenerationDisabled()) { | 2102 if (isIRGenerationDisabled()) { |
| 2052 assert(Cond == nullptr); | 2103 assert(Cond == nullptr); |
| 2053 return; | 2104 return; |
| 2054 } | 2105 } |
| 2055 if (Cond->getType() != Ice::IceType_i1) { | 2106 if (Cond->getType() != Ice::IceType_i1) { |
| 2056 std::string Buffer; | 2107 std::string Buffer; |
| 2057 raw_string_ostream StrBuf(Buffer); | 2108 raw_string_ostream StrBuf(Buffer); |
| 2058 StrBuf << "Branch condition " << *Cond << " not i1. Found: " | 2109 StrBuf << "Branch condition " << *Cond << " not i1. Found: " |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 2072 } | 2123 } |
| 2073 case naclbitc::FUNC_CODE_INST_SWITCH: { | 2124 case naclbitc::FUNC_CODE_INST_SWITCH: { |
| 2074 // SWITCH: [Condty, Cond, BbIndex, NumCases Case ...] | 2125 // SWITCH: [Condty, Cond, BbIndex, NumCases Case ...] |
| 2075 // where Case = [1, 1, Value, BbIndex]. | 2126 // where Case = [1, 1, Value, BbIndex]. |
| 2076 // | 2127 // |
| 2077 // Note: Unlike most instructions, we don't infer the type of | 2128 // Note: Unlike most instructions, we don't infer the type of |
| 2078 // Cond, but provide it as a separate field. There are also | 2129 // Cond, but provide it as a separate field. There are also |
| 2079 // unnecesary data fields (i.e. constants 1). These were not | 2130 // unnecesary data fields (i.e. constants 1). These were not |
| 2080 // cleaned up in PNaCl bitcode because the bitcode format was | 2131 // cleaned up in PNaCl bitcode because the bitcode format was |
| 2081 // already frozen when the problem was noticed. | 2132 // already frozen when the problem was noticed. |
| 2082 if (!isValidRecordSizeAtLeast(4, "function block switch")) | 2133 if (!isValidRecordSizeAtLeast(4, "switch")) |
| 2083 return; | 2134 return; |
| 2084 | 2135 |
| 2085 Ice::Type CondTy = Context->getSimpleTypeByID(Values[0]); | 2136 Ice::Type CondTy = Context->getSimpleTypeByID(Values[0]); |
| 2086 if (!Ice::isScalarIntegerType(CondTy)) { | 2137 if (!Ice::isScalarIntegerType(CondTy)) { |
| 2087 std::string Buffer; | 2138 std::string Buffer; |
| 2088 raw_string_ostream StrBuf(Buffer); | 2139 raw_string_ostream StrBuf(Buffer); |
| 2089 StrBuf << "Case condition must be non-wide integer. Found: " << CondTy; | 2140 StrBuf << "Case condition must be non-wide integer. Found: " << CondTy; |
| 2090 Error(StrBuf.str()); | 2141 Error(StrBuf.str()); |
| 2091 return; | 2142 return; |
| 2092 } | 2143 } |
| 2093 Ice::SizeT BitWidth = Ice::getScalarIntBitWidth(CondTy); | 2144 Ice::SizeT BitWidth = Ice::getScalarIntBitWidth(CondTy); |
| 2094 Ice::Operand *Cond = getRelativeOperand(Values[1], BaseIndex); | 2145 Ice::Operand *Cond = getRelativeOperand(Values[1], BaseIndex); |
| 2095 | 2146 |
| 2096 const bool isIRGenDisabled = isIRGenerationDisabled(); | 2147 const bool isIRGenDisabled = isIRGenerationDisabled(); |
| 2097 if (isIRGenDisabled) { | 2148 if (isIRGenDisabled) { |
| 2098 assert(Cond == nullptr); | 2149 assert(Cond == nullptr); |
| 2099 } else if (CondTy != Cond->getType()) { | 2150 } else if (CondTy != Cond->getType()) { |
| 2100 std::string Buffer; | 2151 std::string Buffer; |
| 2101 raw_string_ostream StrBuf(Buffer); | 2152 raw_string_ostream StrBuf(Buffer); |
| 2102 StrBuf << "Case condition expects type " << CondTy | 2153 StrBuf << "Case condition expects type " << CondTy |
| 2103 << ". Found: " << Cond->getType(); | 2154 << ". Found: " << Cond->getType(); |
| 2104 Error(StrBuf.str()); | 2155 Error(StrBuf.str()); |
| 2105 return; | 2156 return; |
| 2106 } | 2157 } |
| 2107 Ice::CfgNode *DefaultLabel = | 2158 Ice::CfgNode *DefaultLabel = |
| 2108 isIRGenDisabled ? nullptr : getBranchBasicBlock(Values[2]); | 2159 isIRGenDisabled ? nullptr : getBranchBasicBlock(Values[2]); |
| 2109 unsigned NumCases = Values[3]; | 2160 unsigned NumCases = Values[3]; |
| 2110 | 2161 |
| 2111 // Now recognize each of the cases. | 2162 // Now recognize each of the cases. |
| 2112 if (!isValidRecordSize(4 + NumCases * 4, "Function block switch")) | 2163 if (!isValidRecordSize(4 + NumCases * 4, "switch")) |
| 2113 return; | 2164 return; |
| 2114 Ice::InstSwitch *Switch = | 2165 Ice::InstSwitch *Switch = |
| 2115 isIRGenDisabled ? nullptr : Ice::InstSwitch::create(Func, NumCases, | 2166 isIRGenDisabled ? nullptr : Ice::InstSwitch::create(Func, NumCases, |
| 2116 Cond, DefaultLabel); | 2167 Cond, DefaultLabel); |
| 2117 unsigned ValCaseIndex = 4; // index to beginning of case entry. | 2168 unsigned ValCaseIndex = 4; // index to beginning of case entry. |
| 2118 for (unsigned CaseIndex = 0; CaseIndex < NumCases; | 2169 for (unsigned CaseIndex = 0; CaseIndex < NumCases; |
| 2119 ++CaseIndex, ValCaseIndex += 4) { | 2170 ++CaseIndex, ValCaseIndex += 4) { |
| 2120 if (Values[ValCaseIndex] != 1 || Values[ValCaseIndex+1] != 1) { | 2171 if (Values[ValCaseIndex] != 1 || Values[ValCaseIndex+1] != 1) { |
| 2121 std::string Buffer; | 2172 std::string Buffer; |
| 2122 raw_string_ostream StrBuf(Buffer); | 2173 raw_string_ostream StrBuf(Buffer); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 2134 Switch->addBranch(CaseIndex, Value.getSExtValue(), Label); | 2185 Switch->addBranch(CaseIndex, Value.getSExtValue(), Label); |
| 2135 } | 2186 } |
| 2136 if (isIRGenDisabled) | 2187 if (isIRGenDisabled) |
| 2137 return; | 2188 return; |
| 2138 CurrentNode->appendInst(Switch); | 2189 CurrentNode->appendInst(Switch); |
| 2139 InstIsTerminating = true; | 2190 InstIsTerminating = true; |
| 2140 return; | 2191 return; |
| 2141 } | 2192 } |
| 2142 case naclbitc::FUNC_CODE_INST_UNREACHABLE: { | 2193 case naclbitc::FUNC_CODE_INST_UNREACHABLE: { |
| 2143 // UNREACHABLE: [] | 2194 // UNREACHABLE: [] |
| 2144 if (!isValidRecordSize(0, "function block unreachable")) | 2195 if (!isValidRecordSize(0, "unreachable")) |
| 2145 return; | 2196 return; |
| 2146 if (isIRGenerationDisabled()) | 2197 if (isIRGenerationDisabled()) |
| 2147 return; | 2198 return; |
| 2148 CurrentNode->appendInst( | 2199 CurrentNode->appendInst( |
| 2149 Ice::InstUnreachable::create(Func)); | 2200 Ice::InstUnreachable::create(Func)); |
| 2150 InstIsTerminating = true; | 2201 InstIsTerminating = true; |
| 2151 return; | 2202 return; |
| 2152 } | 2203 } |
| 2153 case naclbitc::FUNC_CODE_INST_PHI: { | 2204 case naclbitc::FUNC_CODE_INST_PHI: { |
| 2154 // PHI: [ty, val1, bb1, ..., valN, bbN] for n >= 2. | 2205 // PHI: [ty, val1, bb1, ..., valN, bbN] for n >= 2. |
| 2155 if (!isValidRecordSizeAtLeast(3, "function block phi")) | 2206 if (!isValidRecordSizeAtLeast(3, "phi")) |
| 2156 return; | 2207 return; |
| 2157 Ice::Type Ty = Context->getSimpleTypeByID(Values[0]); | 2208 Ice::Type Ty = Context->getSimpleTypeByID(Values[0]); |
| 2158 if ((Values.size() & 0x1) == 0) { | 2209 if ((Values.size() & 0x1) == 0) { |
| 2159 // Not an odd number of values. | 2210 // Not an odd number of values. |
| 2160 std::string Buffer; | 2211 std::string Buffer; |
| 2161 raw_string_ostream StrBuf(Buffer); | 2212 raw_string_ostream StrBuf(Buffer); |
| 2162 StrBuf << "function block phi record size not valid: " << Values.size(); | 2213 StrBuf << "function block phi record size not valid: " << Values.size(); |
| 2163 Error(StrBuf.str()); | 2214 Error(StrBuf.str()); |
| 2164 appendErrorInstruction(Ty); | 2215 appendErrorInstruction(Ty); |
| 2165 return; | 2216 return; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 2191 appendErrorInstruction(Ty); | 2242 appendErrorInstruction(Ty); |
| 2192 return; | 2243 return; |
| 2193 } | 2244 } |
| 2194 Phi->addArgument(Op, getBasicBlock(Values[i + 1])); | 2245 Phi->addArgument(Op, getBasicBlock(Values[i + 1])); |
| 2195 } | 2246 } |
| 2196 CurrentNode->appendInst(Phi); | 2247 CurrentNode->appendInst(Phi); |
| 2197 return; | 2248 return; |
| 2198 } | 2249 } |
| 2199 case naclbitc::FUNC_CODE_INST_ALLOCA: { | 2250 case naclbitc::FUNC_CODE_INST_ALLOCA: { |
| 2200 // ALLOCA: [Size, align] | 2251 // ALLOCA: [Size, align] |
| 2201 if (!isValidRecordSize(2, "function block alloca")) | 2252 if (!isValidRecordSize(2, "alloca")) |
| 2202 return; | 2253 return; |
| 2203 Ice::Operand *ByteCount = getRelativeOperand(Values[0], BaseIndex); | 2254 Ice::Operand *ByteCount = getRelativeOperand(Values[0], BaseIndex); |
| 2204 unsigned Alignment; | 2255 unsigned Alignment; |
| 2205 extractAlignment("Alloca", Values[1], Alignment); | 2256 extractAlignment("Alloca", Values[1], Alignment); |
| 2206 if (isIRGenerationDisabled()) { | 2257 if (isIRGenerationDisabled()) { |
| 2207 assert(ByteCount == nullptr); | 2258 assert(ByteCount == nullptr); |
| 2208 setNextLocalInstIndex(nullptr); | 2259 setNextLocalInstIndex(nullptr); |
| 2209 return; | 2260 return; |
| 2210 } | 2261 } |
| 2211 Ice::Type PtrTy = Context->getIcePointerType(); | 2262 Ice::Type PtrTy = Context->getIcePointerType(); |
| 2212 if (ByteCount->getType() != Ice::IceType_i32) { | 2263 if (ByteCount->getType() != Ice::IceType_i32) { |
| 2213 std::string Buffer; | 2264 std::string Buffer; |
| 2214 raw_string_ostream StrBuf(Buffer); | 2265 raw_string_ostream StrBuf(Buffer); |
| 2215 StrBuf << "Alloca on non-i32 value. Found: " << *ByteCount; | 2266 StrBuf << "Alloca on non-i32 value. Found: " << *ByteCount; |
| 2216 Error(StrBuf.str()); | 2267 Error(StrBuf.str()); |
| 2217 appendErrorInstruction(PtrTy); | 2268 appendErrorInstruction(PtrTy); |
| 2218 return; | 2269 return; |
| 2219 } | 2270 } |
| 2220 CurrentNode->appendInst(Ice::InstAlloca::create(Func, ByteCount, Alignment, | 2271 CurrentNode->appendInst(Ice::InstAlloca::create(Func, ByteCount, Alignment, |
| 2221 getNextInstVar(PtrTy))); | 2272 getNextInstVar(PtrTy))); |
| 2222 return; | 2273 return; |
| 2223 } | 2274 } |
| 2224 case naclbitc::FUNC_CODE_INST_LOAD: { | 2275 case naclbitc::FUNC_CODE_INST_LOAD: { |
| 2225 // LOAD: [address, align, ty] | 2276 // LOAD: [address, align, ty] |
| 2226 if (!isValidRecordSize(3, "function block load")) | 2277 if (!isValidRecordSize(3, "load")) |
| 2227 return; | 2278 return; |
| 2228 Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex); | 2279 Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex); |
| 2229 Ice::Type Ty = Context->getSimpleTypeByID(Values[2]); | 2280 Ice::Type Ty = Context->getSimpleTypeByID(Values[2]); |
| 2230 unsigned Alignment; | 2281 unsigned Alignment; |
| 2231 extractAlignment("Load", Values[1], Alignment); | 2282 extractAlignment("Load", Values[1], Alignment); |
| 2232 if (isIRGenerationDisabled()) { | 2283 if (isIRGenerationDisabled()) { |
| 2233 assert(Address == nullptr); | 2284 assert(Address == nullptr); |
| 2234 setNextLocalInstIndex(nullptr); | 2285 setNextLocalInstIndex(nullptr); |
| 2235 return; | 2286 return; |
| 2236 } | 2287 } |
| 2237 if (!isValidPointerType(Address, "Load")) { | 2288 if (!isValidPointerType(Address, "Load")) { |
| 2238 appendErrorInstruction(Ty); | 2289 appendErrorInstruction(Ty); |
| 2239 return; | 2290 return; |
| 2240 } | 2291 } |
| 2241 if (!isValidLoadStoreAlignment(Alignment, Ty, "Load")) { | 2292 if (!isValidLoadStoreAlignment(Alignment, Ty, "Load")) { |
| 2242 appendErrorInstruction(Ty); | 2293 appendErrorInstruction(Ty); |
| 2243 return; | 2294 return; |
| 2244 } | 2295 } |
| 2245 CurrentNode->appendInst( | 2296 CurrentNode->appendInst( |
| 2246 Ice::InstLoad::create(Func, getNextInstVar(Ty), Address, Alignment)); | 2297 Ice::InstLoad::create(Func, getNextInstVar(Ty), Address, Alignment)); |
| 2247 return; | 2298 return; |
| 2248 } | 2299 } |
| 2249 case naclbitc::FUNC_CODE_INST_STORE: { | 2300 case naclbitc::FUNC_CODE_INST_STORE: { |
| 2250 // STORE: [address, value, align] | 2301 // STORE: [address, value, align] |
| 2251 if (!isValidRecordSize(3, "function block store")) | 2302 if (!isValidRecordSize(3, "store")) |
| 2252 return; | 2303 return; |
| 2253 Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex); | 2304 Ice::Operand *Address = getRelativeOperand(Values[0], BaseIndex); |
| 2254 Ice::Operand *Value = getRelativeOperand(Values[1], BaseIndex); | 2305 Ice::Operand *Value = getRelativeOperand(Values[1], BaseIndex); |
| 2255 unsigned Alignment; | 2306 unsigned Alignment; |
| 2256 extractAlignment("Store", Values[2], Alignment); | 2307 extractAlignment("Store", Values[2], Alignment); |
| 2257 if (isIRGenerationDisabled()) { | 2308 if (isIRGenerationDisabled()) { |
| 2258 assert(Address == nullptr && Value == nullptr); | 2309 assert(Address == nullptr && Value == nullptr); |
| 2259 return; | 2310 return; |
| 2260 } | 2311 } |
| 2261 if (!isValidPointerType(Address, "Store")) | 2312 if (!isValidPointerType(Address, "Store")) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 2273 // | 2324 // |
| 2274 // Note: The difference between CALL and CALL_INDIRECT is that | 2325 // Note: The difference between CALL and CALL_INDIRECT is that |
| 2275 // CALL has a reference to an explicit function declaration, while | 2326 // CALL has a reference to an explicit function declaration, while |
| 2276 // the CALL_INDIRECT is just an address. For CALL, we can infer | 2327 // the CALL_INDIRECT is just an address. For CALL, we can infer |
| 2277 // the return type by looking up the type signature associated | 2328 // the return type by looking up the type signature associated |
| 2278 // with the function declaration. For CALL_INDIRECT we can only | 2329 // with the function declaration. For CALL_INDIRECT we can only |
| 2279 // infer the type signature via argument types, and the | 2330 // infer the type signature via argument types, and the |
| 2280 // corresponding return type stored in CALL_INDIRECT record. | 2331 // corresponding return type stored in CALL_INDIRECT record. |
| 2281 Ice::SizeT ParamsStartIndex = 2; | 2332 Ice::SizeT ParamsStartIndex = 2; |
| 2282 if (Record.GetCode() == naclbitc::FUNC_CODE_INST_CALL) { | 2333 if (Record.GetCode() == naclbitc::FUNC_CODE_INST_CALL) { |
| 2283 if (!isValidRecordSizeAtLeast(2, "function block call")) | 2334 if (!isValidRecordSizeAtLeast(2, "call")) |
| 2284 return; | 2335 return; |
| 2285 } else { | 2336 } else { |
| 2286 if (!isValidRecordSizeAtLeast(3, "function block call indirect")) | 2337 if (!isValidRecordSizeAtLeast(3, "call indirect")) |
| 2287 return; | 2338 return; |
| 2288 ParamsStartIndex = 3; | 2339 ParamsStartIndex = 3; |
| 2289 } | 2340 } |
| 2290 | 2341 |
| 2291 // Extract out the called function and its return type. | 2342 // Extract out the called function and its return type. |
| 2292 uint32_t CalleeIndex = convertRelativeToAbsIndex(Values[1], BaseIndex); | 2343 uint32_t CalleeIndex = convertRelativeToAbsIndex(Values[1], BaseIndex); |
| 2293 Ice::Operand *Callee = getOperand(CalleeIndex); | 2344 Ice::Operand *Callee = getOperand(CalleeIndex); |
| 2294 Ice::Type ReturnType = Ice::IceType_void; | 2345 Ice::Type ReturnType = Ice::IceType_void; |
| 2295 const Ice::Intrinsics::FullIntrinsicInfo *IntrinsicInfo = nullptr; | 2346 const Ice::Intrinsics::FullIntrinsicInfo *IntrinsicInfo = nullptr; |
| 2296 if (Record.GetCode() == naclbitc::FUNC_CODE_INST_CALL) { | 2347 if (Record.GetCode() == naclbitc::FUNC_CODE_INST_CALL) { |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2405 break; | 2456 break; |
| 2406 } | 2457 } |
| 2407 } | 2458 } |
| 2408 } | 2459 } |
| 2409 | 2460 |
| 2410 CurrentNode->appendInst(Inst); | 2461 CurrentNode->appendInst(Inst); |
| 2411 return; | 2462 return; |
| 2412 } | 2463 } |
| 2413 case naclbitc::FUNC_CODE_INST_FORWARDTYPEREF: { | 2464 case naclbitc::FUNC_CODE_INST_FORWARDTYPEREF: { |
| 2414 // FORWARDTYPEREF: [opval, ty] | 2465 // FORWARDTYPEREF: [opval, ty] |
| 2415 if (!isValidRecordSize(2, "function block forward type ref")) | 2466 if (!isValidRecordSize(2, "forward type ref")) |
| 2416 return; | 2467 return; |
| 2417 Ice::Type OpType = Context->getSimpleTypeByID(Values[1]); | 2468 Ice::Type OpType = Context->getSimpleTypeByID(Values[1]); |
| 2418 setOperand(Values[0], | 2469 setOperand(Values[0], |
| 2419 isIRGenerationDisabled() ? nullptr : createInstVar(OpType)); | 2470 isIRGenerationDisabled() ? nullptr : createInstVar(OpType)); |
| 2420 return; | 2471 return; |
| 2421 } | 2472 } |
| 2422 default: | 2473 default: |
| 2423 // Generate error message! | 2474 // Generate error message! |
| 2424 BlockParserBaseClass::ProcessRecord(); | 2475 BlockParserBaseClass::ProcessRecord(); |
| 2425 return; | 2476 return; |
| 2426 } | 2477 } |
| 2427 } | 2478 } |
| 2428 | 2479 |
| 2429 /// Parses constants within a function block. | 2480 /// Parses constants within a function block. |
| 2430 class ConstantsParser : public BlockParserBaseClass { | 2481 class ConstantsParser : public BlockParserBaseClass { |
| 2431 ConstantsParser(const ConstantsParser &) = delete; | 2482 ConstantsParser(const ConstantsParser &) = delete; |
| 2432 ConstantsParser &operator=(const ConstantsParser &) = delete; | 2483 ConstantsParser &operator=(const ConstantsParser &) = delete; |
| 2433 | 2484 |
| 2434 public: | 2485 public: |
| 2435 ConstantsParser(unsigned BlockID, FunctionParser *FuncParser) | 2486 ConstantsParser(unsigned BlockID, FunctionParser *FuncParser) |
| 2436 : BlockParserBaseClass(BlockID, FuncParser), | 2487 : BlockParserBaseClass(BlockID, FuncParser), |
| 2437 Timer(Ice::TimerStack::TT_parseConstants, getTranslator().getContext()), | 2488 Timer(Ice::TimerStack::TT_parseConstants, getTranslator().getContext()), |
| 2438 FuncParser(FuncParser), NextConstantType(Ice::IceType_void) {} | 2489 FuncParser(FuncParser), NextConstantType(Ice::IceType_void) {} |
| 2439 | 2490 |
| 2440 ~ConstantsParser() override {} | 2491 ~ConstantsParser() override {} |
| 2441 | 2492 |
| 2493 const char *getBlockName() const override { return "constants"; } | |
| 2494 | |
| 2442 private: | 2495 private: |
| 2443 Ice::TimerMarker Timer; | 2496 Ice::TimerMarker Timer; |
| 2444 // The parser of the function block this constants block appears in. | 2497 // The parser of the function block this constants block appears in. |
| 2445 FunctionParser *FuncParser; | 2498 FunctionParser *FuncParser; |
| 2446 // The type to use for succeeding constants. | 2499 // The type to use for succeeding constants. |
| 2447 Ice::Type NextConstantType; | 2500 Ice::Type NextConstantType; |
| 2448 | 2501 |
| 2449 void ProcessRecord() override; | 2502 void ProcessRecord() override; |
| 2450 | 2503 |
| 2451 Ice::GlobalContext *getContext() { return getTranslator().getContext(); } | 2504 Ice::GlobalContext *getContext() { return getTranslator().getContext(); } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 2467 // SETTYPE: [typeid] | 2520 // SETTYPE: [typeid] |
| 2468 if (!isValidRecordSize(1, "constants block set type")) | 2521 if (!isValidRecordSize(1, "constants block set type")) |
| 2469 return; | 2522 return; |
| 2470 NextConstantType = Context->getSimpleTypeByID(Values[0]); | 2523 NextConstantType = Context->getSimpleTypeByID(Values[0]); |
| 2471 if (NextConstantType == Ice::IceType_void) | 2524 if (NextConstantType == Ice::IceType_void) |
| 2472 Error("constants block set type not allowed for void type"); | 2525 Error("constants block set type not allowed for void type"); |
| 2473 return; | 2526 return; |
| 2474 } | 2527 } |
| 2475 case naclbitc::CST_CODE_UNDEF: { | 2528 case naclbitc::CST_CODE_UNDEF: { |
| 2476 // UNDEF | 2529 // UNDEF |
| 2477 if (!isValidRecordSize(0, "constants block undef")) | 2530 if (!isValidRecordSize(0, "undef")) |
| 2478 return; | 2531 return; |
| 2479 if (!isValidNextConstantType()) | 2532 if (!isValidNextConstantType()) |
| 2480 return; | 2533 return; |
| 2481 if (isIRGenerationDisabled()) { | 2534 if (isIRGenerationDisabled()) { |
| 2482 FuncParser->setNextConstantID(nullptr); | 2535 FuncParser->setNextConstantID(nullptr); |
| 2483 return; | 2536 return; |
| 2484 } | 2537 } |
| 2485 FuncParser->setNextConstantID( | 2538 FuncParser->setNextConstantID( |
| 2486 getContext()->getConstantUndef(NextConstantType)); | 2539 getContext()->getConstantUndef(NextConstantType)); |
| 2487 return; | 2540 return; |
| 2488 } | 2541 } |
| 2489 case naclbitc::CST_CODE_INTEGER: { | 2542 case naclbitc::CST_CODE_INTEGER: { |
| 2490 // INTEGER: [intval] | 2543 // INTEGER: [intval] |
| 2491 if (!isValidRecordSize(1, "constants block integer")) | 2544 if (!isValidRecordSize(1, "integer")) |
| 2492 return; | 2545 return; |
| 2493 if (!isValidNextConstantType()) | 2546 if (!isValidNextConstantType()) |
| 2494 return; | 2547 return; |
| 2495 if (isIRGenerationDisabled()) { | 2548 if (isIRGenerationDisabled()) { |
| 2496 FuncParser->setNextConstantID(nullptr); | 2549 FuncParser->setNextConstantID(nullptr); |
| 2497 return; | 2550 return; |
| 2498 } | 2551 } |
| 2499 if (IntegerType *IType = dyn_cast<IntegerType>( | 2552 if (IntegerType *IType = dyn_cast<IntegerType>( |
| 2500 Context->convertToLLVMType(NextConstantType))) { | 2553 Context->convertToLLVMType(NextConstantType))) { |
| 2501 APInt Value(IType->getBitWidth(), NaClDecodeSignRotatedValue(Values[0])); | 2554 APInt Value(IType->getBitWidth(), NaClDecodeSignRotatedValue(Values[0])); |
| 2502 Ice::Constant *C = (NextConstantType == Ice::IceType_i64) | 2555 Ice::Constant *C = (NextConstantType == Ice::IceType_i64) |
| 2503 ? getContext()->getConstantInt64( | 2556 ? getContext()->getConstantInt64( |
| 2504 NextConstantType, Value.getSExtValue()) | 2557 NextConstantType, Value.getSExtValue()) |
| 2505 : getContext()->getConstantInt32( | 2558 : getContext()->getConstantInt32( |
| 2506 NextConstantType, Value.getSExtValue()); | 2559 NextConstantType, Value.getSExtValue()); |
| 2507 FuncParser->setNextConstantID(C); | 2560 FuncParser->setNextConstantID(C); |
| 2508 return; | 2561 return; |
| 2509 } | 2562 } |
| 2510 std::string Buffer; | 2563 std::string Buffer; |
| 2511 raw_string_ostream StrBuf(Buffer); | 2564 raw_string_ostream StrBuf(Buffer); |
| 2512 StrBuf << "constant block integer record for non-integer type " | 2565 StrBuf << "constant block integer record for non-integer type " |
| 2513 << NextConstantType; | 2566 << NextConstantType; |
| 2514 Error(StrBuf.str()); | 2567 Error(StrBuf.str()); |
| 2515 return; | 2568 return; |
| 2516 } | 2569 } |
| 2517 case naclbitc::CST_CODE_FLOAT: { | 2570 case naclbitc::CST_CODE_FLOAT: { |
| 2518 // FLOAT: [fpval] | 2571 // FLOAT: [fpval] |
| 2519 if (!isValidRecordSize(1, "constants block float")) | 2572 if (!isValidRecordSize(1, "float")) |
| 2520 return; | 2573 return; |
| 2521 if (!isValidNextConstantType()) | 2574 if (!isValidNextConstantType()) |
| 2522 return; | 2575 return; |
| 2523 if (isIRGenerationDisabled()) { | 2576 if (isIRGenerationDisabled()) { |
| 2524 FuncParser->setNextConstantID(nullptr); | 2577 FuncParser->setNextConstantID(nullptr); |
| 2525 return; | 2578 return; |
| 2526 } | 2579 } |
| 2527 switch (NextConstantType) { | 2580 switch (NextConstantType) { |
| 2528 case Ice::IceType_f32: { | 2581 case Ice::IceType_f32: { |
| 2529 APFloat Value(APFloat::IEEEsingle, | 2582 APFloat Value(APFloat::IEEEsingle, |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2641 class ModuleParser : public BlockParserBaseClass { | 2694 class ModuleParser : public BlockParserBaseClass { |
| 2642 public: | 2695 public: |
| 2643 ModuleParser(unsigned BlockID, TopLevelParser *Context) | 2696 ModuleParser(unsigned BlockID, TopLevelParser *Context) |
| 2644 : BlockParserBaseClass(BlockID, Context), | 2697 : BlockParserBaseClass(BlockID, Context), |
| 2645 Timer(Ice::TimerStack::TT_parseModule, | 2698 Timer(Ice::TimerStack::TT_parseModule, |
| 2646 Context->getTranslator().getContext()), | 2699 Context->getTranslator().getContext()), |
| 2647 GlobalDeclarationNamesAndInitializersInstalled(false) {} | 2700 GlobalDeclarationNamesAndInitializersInstalled(false) {} |
| 2648 | 2701 |
| 2649 ~ModuleParser() override {} | 2702 ~ModuleParser() override {} |
| 2650 | 2703 |
| 2704 const char *getBlockName() const override { return "module"; } | |
| 2705 | |
| 2651 private: | 2706 private: |
| 2652 Ice::TimerMarker Timer; | 2707 Ice::TimerMarker Timer; |
| 2653 // True if we have already installed names for unnamed global declarations, | 2708 // True if we have already installed names for unnamed global declarations, |
| 2654 // and have generated global constant initializers. | 2709 // and have generated global constant initializers. |
| 2655 bool GlobalDeclarationNamesAndInitializersInstalled; | 2710 bool GlobalDeclarationNamesAndInitializersInstalled; |
| 2656 | 2711 |
| 2657 // Generates names for unnamed global addresses (i.e. functions and | 2712 // Generates names for unnamed global addresses (i.e. functions and |
| 2658 // global variables). Then lowers global variable declaration | 2713 // global variables). Then lowers global variable declaration |
| 2659 // initializers to the target. May be called multiple times. Only | 2714 // initializers to the target. May be called multiple times. Only |
| 2660 // the first call will do the installation. | 2715 // the first call will do the installation. |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2760 default: | 2815 default: |
| 2761 return BlockParserBaseClass::ParseBlock(BlockID); | 2816 return BlockParserBaseClass::ParseBlock(BlockID); |
| 2762 } | 2817 } |
| 2763 } | 2818 } |
| 2764 | 2819 |
| 2765 void ModuleParser::ProcessRecord() { | 2820 void ModuleParser::ProcessRecord() { |
| 2766 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 2821 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
| 2767 switch (Record.GetCode()) { | 2822 switch (Record.GetCode()) { |
| 2768 case naclbitc::MODULE_CODE_VERSION: { | 2823 case naclbitc::MODULE_CODE_VERSION: { |
| 2769 // VERSION: [version#] | 2824 // VERSION: [version#] |
| 2770 if (!isValidRecordSize(1, "Module version")) | 2825 if (!isValidRecordSize(1, "version")) |
| 2771 return; | 2826 return; |
| 2772 unsigned Version = Values[0]; | 2827 unsigned Version = Values[0]; |
| 2773 if (Version != 1) { | 2828 if (Version != 1) { |
| 2774 std::string Buffer; | 2829 std::string Buffer; |
| 2775 raw_string_ostream StrBuf(Buffer); | 2830 raw_string_ostream StrBuf(Buffer); |
| 2776 StrBuf << "Unknown bitstream version: " << Version; | 2831 StrBuf << "Unknown bitstream version: " << Version; |
| 2777 Error(StrBuf.str()); | 2832 Error(StrBuf.str()); |
| 2778 } | 2833 } |
| 2779 return; | 2834 return; |
| 2780 } | 2835 } |
| 2781 case naclbitc::MODULE_CODE_FUNCTION: { | 2836 case naclbitc::MODULE_CODE_FUNCTION: { |
| 2782 // FUNCTION: [type, callingconv, isproto, linkage] | 2837 // FUNCTION: [type, callingconv, isproto, linkage] |
| 2783 if (!isValidRecordSize(4, "Function heading")) | 2838 if (!isValidRecordSize(4, "address")) |
| 2784 return; | 2839 return; |
| 2785 const Ice::FuncSigType &Signature = Context->getFuncSigTypeByID(Values[0]); | 2840 const Ice::FuncSigType &Signature = Context->getFuncSigTypeByID(Values[0]); |
| 2786 CallingConv::ID CallingConv; | 2841 CallingConv::ID CallingConv; |
| 2787 if (!naclbitc::DecodeCallingConv(Values[1], CallingConv)) { | 2842 if (!naclbitc::DecodeCallingConv(Values[1], CallingConv)) { |
| 2788 std::string Buffer; | 2843 std::string Buffer; |
| 2789 raw_string_ostream StrBuf(Buffer); | 2844 raw_string_ostream StrBuf(Buffer); |
| 2790 StrBuf << "Function heading has unknown calling convention: " | 2845 StrBuf << "Function address has unknown calling convention: " |
| 2791 << Values[1]; | 2846 << Values[1]; |
| 2792 Error(StrBuf.str()); | 2847 Error(StrBuf.str()); |
| 2793 return; | 2848 return; |
| 2794 } | 2849 } |
| 2795 GlobalValue::LinkageTypes Linkage; | 2850 GlobalValue::LinkageTypes Linkage; |
| 2796 if (!naclbitc::DecodeLinkage(Values[3], Linkage)) { | 2851 if (!naclbitc::DecodeLinkage(Values[3], Linkage)) { |
| 2797 std::string Buffer; | 2852 std::string Buffer; |
| 2798 raw_string_ostream StrBuf(Buffer); | 2853 raw_string_ostream StrBuf(Buffer); |
| 2799 StrBuf << "Function heading has unknown linkage. Found " << Values[3]; | 2854 StrBuf << "Function address has unknown linkage. Found " << Values[3]; |
| 2800 Error(StrBuf.str()); | 2855 Error(StrBuf.str()); |
| 2801 return; | 2856 return; |
| 2802 } | 2857 } |
| 2803 Ice::FunctionDeclaration *Func = Ice::FunctionDeclaration::create( | 2858 Ice::FunctionDeclaration *Func = Ice::FunctionDeclaration::create( |
| 2804 getTranslator().getContext(), Signature, CallingConv, Linkage, | 2859 getTranslator().getContext(), Signature, CallingConv, Linkage, |
| 2805 Values[2] == 0); | 2860 Values[2] == 0); |
| 2806 if (Values[2] == 0) | 2861 if (Values[2] == 0) |
| 2807 Context->setNextValueIDAsImplementedFunction(); | 2862 Context->setNextValueIDAsImplementedFunction(); |
| 2808 Context->setNextFunctionID(Func); | 2863 Context->setNextFunctionID(Func); |
| 2809 return; | 2864 return; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2872 | 2927 |
| 2873 if (TopLevelBlocks != 1) { | 2928 if (TopLevelBlocks != 1) { |
| 2874 errs() << IRFilename | 2929 errs() << IRFilename |
| 2875 << ": Contains more than one module. Found: " << TopLevelBlocks | 2930 << ": Contains more than one module. Found: " << TopLevelBlocks |
| 2876 << "\n"; | 2931 << "\n"; |
| 2877 ErrorStatus = true; | 2932 ErrorStatus = true; |
| 2878 } | 2933 } |
| 2879 } | 2934 } |
| 2880 | 2935 |
| 2881 } // end of namespace Ice | 2936 } // end of namespace Ice |
| OLD | NEW |