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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 : NaClBitcodeParser(Cursor), Translator(Translator), | 59 : NaClBitcodeParser(Cursor), Translator(Translator), |
60 Mod(new Module(InputName, getGlobalContext())), DL(PNaClDataLayout), | 60 Mod(new Module(InputName, getGlobalContext())), DL(PNaClDataLayout), |
61 Header(Header), TypeConverter(getLLVMContext()), | 61 Header(Header), TypeConverter(getLLVMContext()), |
62 ErrorStatus(ErrorStatus), NumErrors(0), NumFunctionIds(0), | 62 ErrorStatus(ErrorStatus), NumErrors(0), NumFunctionIds(0), |
63 NumFunctionBlocks(0), | 63 NumFunctionBlocks(0), |
64 GlobalVarPlaceHolderType(convertToLLVMType(Ice::IceType_i8)) { | 64 GlobalVarPlaceHolderType(convertToLLVMType(Ice::IceType_i8)) { |
65 Mod->setDataLayout(PNaClDataLayout); | 65 Mod->setDataLayout(PNaClDataLayout); |
66 setErrStream(Translator.getContext()->getStrDump()); | 66 setErrStream(Translator.getContext()->getStrDump()); |
67 } | 67 } |
68 | 68 |
69 virtual ~TopLevelParser() {} | 69 ~TopLevelParser() override {} |
70 LLVM_OVERRIDE; | |
71 | 70 |
72 Ice::Translator &getTranslator() { return Translator; } | 71 Ice::Translator &getTranslator() { return Translator; } |
73 | 72 |
74 // Generates error with given Message. Always returns true. | 73 // Generates error with given Message. Always returns true. |
75 virtual bool Error(const std::string &Message) LLVM_OVERRIDE { | 74 bool Error(const std::string &Message) override { |
76 ErrorStatus = true; | 75 ErrorStatus = true; |
77 ++NumErrors; | 76 ++NumErrors; |
78 NaClBitcodeParser::Error(Message); | 77 NaClBitcodeParser::Error(Message); |
79 if (!AllowErrorRecovery) | 78 if (!AllowErrorRecovery) |
80 report_fatal_error("Unable to continue"); | 79 report_fatal_error("Unable to continue"); |
81 return true; | 80 return true; |
82 } | 81 } |
83 | 82 |
84 /// Returns the number of errors found while parsing the bitcode | 83 /// Returns the number of errors found while parsing the bitcode |
85 /// file. | 84 /// file. |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 unsigned NumFunctionIds; | 273 unsigned NumFunctionIds; |
275 // The number of function blocks (processed so far). | 274 // The number of function blocks (processed so far). |
276 unsigned NumFunctionBlocks; | 275 unsigned NumFunctionBlocks; |
277 // The list of value IDs (in the order found) of defining function | 276 // The list of value IDs (in the order found) of defining function |
278 // addresses. | 277 // addresses. |
279 std::vector<unsigned> DefiningFunctionsList; | 278 std::vector<unsigned> DefiningFunctionsList; |
280 // Cached global variable placeholder type. Used for all forward | 279 // Cached global variable placeholder type. Used for all forward |
281 // references to global variable addresses. | 280 // references to global variable addresses. |
282 Type *GlobalVarPlaceHolderType; | 281 Type *GlobalVarPlaceHolderType; |
283 | 282 |
284 virtual bool ParseBlock(unsigned BlockID) LLVM_OVERRIDE; | 283 bool ParseBlock(unsigned BlockID) override; |
285 | 284 |
286 /// Reports that type ID is undefined, and then returns | 285 /// Reports that type ID is undefined, and then returns |
287 /// the void type. | 286 /// the void type. |
288 Type *reportTypeIDAsUndefined(unsigned ID); | 287 Type *reportTypeIDAsUndefined(unsigned ID); |
289 | 288 |
290 /// Reports error about bad call to setTypeID. | 289 /// Reports error about bad call to setTypeID. |
291 void reportBadSetTypeID(unsigned ID, Type *Ty); | 290 void reportBadSetTypeID(unsigned ID, Type *Ty); |
292 | 291 |
293 // Reports that there is no corresponding ICE type for LLVMTy, and | 292 // Reports that there is no corresponding ICE type for LLVMTy, and |
294 // returns ICE::IceType_void. | 293 // returns ICE::IceType_void. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 // Base class for parsing blocks within the bitcode file. Note: | 331 // Base class for parsing blocks within the bitcode file. Note: |
333 // Because this is the base class of block parsers, we generate error | 332 // Because this is the base class of block parsers, we generate error |
334 // messages if ParseBlock or ParseRecord is not overridden in derived | 333 // messages if ParseBlock or ParseRecord is not overridden in derived |
335 // classes. | 334 // classes. |
336 class BlockParserBaseClass : public NaClBitcodeParser { | 335 class BlockParserBaseClass : public NaClBitcodeParser { |
337 public: | 336 public: |
338 // Constructor for the top-level module block parser. | 337 // Constructor for the top-level module block parser. |
339 BlockParserBaseClass(unsigned BlockID, TopLevelParser *Context) | 338 BlockParserBaseClass(unsigned BlockID, TopLevelParser *Context) |
340 : NaClBitcodeParser(BlockID, Context), Context(Context) {} | 339 : NaClBitcodeParser(BlockID, Context), Context(Context) {} |
341 | 340 |
342 virtual ~BlockParserBaseClass() LLVM_OVERRIDE {} | 341 ~BlockParserBaseClass() override {} |
343 | 342 |
344 protected: | 343 protected: |
345 // The context parser that contains the decoded state. | 344 // The context parser that contains the decoded state. |
346 TopLevelParser *Context; | 345 TopLevelParser *Context; |
347 | 346 |
348 // Constructor for nested block parsers. | 347 // Constructor for nested block parsers. |
349 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 348 BlockParserBaseClass(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
350 : NaClBitcodeParser(BlockID, EnclosingParser), | 349 : NaClBitcodeParser(BlockID, EnclosingParser), |
351 Context(EnclosingParser->Context) {} | 350 Context(EnclosingParser->Context) {} |
352 | 351 |
353 // Gets the translator associated with the bitcode parser. | 352 // Gets the translator associated with the bitcode parser. |
354 Ice::Translator &getTranslator() const { return Context->getTranslator(); } | 353 Ice::Translator &getTranslator() const { return Context->getTranslator(); } |
355 | 354 |
356 const Ice::ClFlags &getFlags() const { return getTranslator().getFlags(); } | 355 const Ice::ClFlags &getFlags() const { return getTranslator().getFlags(); } |
357 | 356 |
358 // Generates an error Message with the bit address prefixed to it. | 357 // Generates an error Message with the bit address prefixed to it. |
359 virtual bool Error(const std::string &Message) LLVM_OVERRIDE { | 358 bool Error(const std::string &Message) override { |
360 uint64_t Bit = Record.GetStartBit() + Context->getHeaderSize() * 8; | 359 uint64_t Bit = Record.GetStartBit() + Context->getHeaderSize() * 8; |
361 std::string Buffer; | 360 std::string Buffer; |
362 raw_string_ostream StrBuf(Buffer); | 361 raw_string_ostream StrBuf(Buffer); |
363 StrBuf << "(" << format("%" PRIu64 ":%u", (Bit / 8), | 362 StrBuf << "(" << format("%" PRIu64 ":%u", (Bit / 8), |
364 static_cast<unsigned>(Bit % 8)) << ") " << Message; | 363 static_cast<unsigned>(Bit % 8)) << ") " << Message; |
365 return Context->Error(StrBuf.str()); | 364 return Context->Error(StrBuf.str()); |
366 } | 365 } |
367 | 366 |
368 // Default implementation. Reports that block is unknown and skips | 367 // Default implementation. Reports that block is unknown and skips |
369 // its contents. | 368 // its contents. |
370 virtual bool ParseBlock(unsigned BlockID) LLVM_OVERRIDE; | 369 bool ParseBlock(unsigned BlockID) override; |
371 | 370 |
372 // Default implementation. Reports that the record is not | 371 // Default implementation. Reports that the record is not |
373 // understood. | 372 // understood. |
374 virtual void ProcessRecord() LLVM_OVERRIDE; | 373 void ProcessRecord() override; |
375 | 374 |
376 // Checks if the size of the record is Size. Return true if valid. | 375 // Checks if the size of the record is Size. Return true if valid. |
377 // Otherwise generates an error and returns false. | 376 // Otherwise generates an error and returns false. |
378 bool isValidRecordSize(unsigned Size, const char *RecordName) { | 377 bool isValidRecordSize(unsigned Size, const char *RecordName) { |
379 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 378 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
380 if (Values.size() == Size) | 379 if (Values.size() == Size) |
381 return true; | 380 return true; |
382 ReportRecordSizeError(Size, RecordName, NULL); | 381 ReportRecordSizeError(Size, RecordName, NULL); |
383 return false; | 382 return false; |
384 } | 383 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 StrBuf << "Don't know how to process record: " << Record; | 457 StrBuf << "Don't know how to process record: " << Record; |
459 Error(StrBuf.str()); | 458 Error(StrBuf.str()); |
460 } | 459 } |
461 | 460 |
462 // Class to parse a types block. | 461 // Class to parse a types block. |
463 class TypesParser : public BlockParserBaseClass { | 462 class TypesParser : public BlockParserBaseClass { |
464 public: | 463 public: |
465 TypesParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 464 TypesParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
466 : BlockParserBaseClass(BlockID, EnclosingParser), NextTypeId(0) {} | 465 : BlockParserBaseClass(BlockID, EnclosingParser), NextTypeId(0) {} |
467 | 466 |
468 ~TypesParser() LLVM_OVERRIDE {} | 467 ~TypesParser() override {} |
469 | 468 |
470 private: | 469 private: |
471 // The type ID that will be associated with the next type defining | 470 // The type ID that will be associated with the next type defining |
472 // record in the types block. | 471 // record in the types block. |
473 unsigned NextTypeId; | 472 unsigned NextTypeId; |
474 | 473 |
475 virtual void ProcessRecord() LLVM_OVERRIDE; | 474 void ProcessRecord() override; |
476 }; | 475 }; |
477 | 476 |
478 void TypesParser::ProcessRecord() { | 477 void TypesParser::ProcessRecord() { |
479 Type *Ty = NULL; | 478 Type *Ty = NULL; |
480 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 479 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
481 switch (Record.GetCode()) { | 480 switch (Record.GetCode()) { |
482 case naclbitc::TYPE_CODE_NUMENTRY: | 481 case naclbitc::TYPE_CODE_NUMENTRY: |
483 // NUMENTRY: [numentries] | 482 // NUMENTRY: [numentries] |
484 if (!isValidRecordSize(1, "Type count")) | 483 if (!isValidRecordSize(1, "Type count")) |
485 return; | 484 return; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 | 557 |
559 /// Parses the globals block (i.e. global variables). | 558 /// Parses the globals block (i.e. global variables). |
560 class GlobalsParser : public BlockParserBaseClass { | 559 class GlobalsParser : public BlockParserBaseClass { |
561 public: | 560 public: |
562 GlobalsParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 561 GlobalsParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
563 : BlockParserBaseClass(BlockID, EnclosingParser), InitializersNeeded(0), | 562 : BlockParserBaseClass(BlockID, EnclosingParser), InitializersNeeded(0), |
564 Alignment(1), IsConstant(false) { | 563 Alignment(1), IsConstant(false) { |
565 NextGlobalID = Context->getNumFunctionIDs(); | 564 NextGlobalID = Context->getNumFunctionIDs(); |
566 } | 565 } |
567 | 566 |
568 virtual ~GlobalsParser() LLVM_OVERRIDE {} | 567 ~GlobalsParser() override {} |
569 | 568 |
570 private: | 569 private: |
571 // Holds the sequence of initializers for the global. | 570 // Holds the sequence of initializers for the global. |
572 SmallVector<Constant *, 10> Initializers; | 571 SmallVector<Constant *, 10> Initializers; |
573 | 572 |
574 // Keeps track of how many initializers are expected for | 573 // Keeps track of how many initializers are expected for |
575 // the global variable being built. | 574 // the global variable being built. |
576 unsigned InitializersNeeded; | 575 unsigned InitializersNeeded; |
577 | 576 |
578 // The alignment assumed for the global variable being built. | 577 // The alignment assumed for the global variable being built. |
579 unsigned Alignment; | 578 unsigned Alignment; |
580 | 579 |
581 // True if the global variable being built is a constant. | 580 // True if the global variable being built is a constant. |
582 bool IsConstant; | 581 bool IsConstant; |
583 | 582 |
584 // The index of the next global variable. | 583 // The index of the next global variable. |
585 unsigned NextGlobalID; | 584 unsigned NextGlobalID; |
586 | 585 |
587 virtual void ExitBlock() LLVM_OVERRIDE { | 586 void ExitBlock() override { |
588 verifyNoMissingInitializers(); | 587 verifyNoMissingInitializers(); |
589 unsigned NumIDs = Context->getNumGlobalValueIDs(); | 588 unsigned NumIDs = Context->getNumGlobalValueIDs(); |
590 if (NextGlobalID < NumIDs) { | 589 if (NextGlobalID < NumIDs) { |
591 unsigned NumFcnIDs = Context->getNumFunctionIDs(); | 590 unsigned NumFcnIDs = Context->getNumFunctionIDs(); |
592 std::string Buffer; | 591 std::string Buffer; |
593 raw_string_ostream StrBuf(Buffer); | 592 raw_string_ostream StrBuf(Buffer); |
594 StrBuf << "Globals block expects " << (NumIDs - NumFcnIDs) | 593 StrBuf << "Globals block expects " << (NumIDs - NumFcnIDs) |
595 << " global definitions. Found: " << (NextGlobalID - NumFcnIDs); | 594 << " global definitions. Found: " << (NextGlobalID - NumFcnIDs); |
596 Error(StrBuf.str()); | 595 Error(StrBuf.str()); |
597 } | 596 } |
598 BlockParserBaseClass::ExitBlock(); | 597 BlockParserBaseClass::ExitBlock(); |
599 } | 598 } |
600 | 599 |
601 virtual void ProcessRecord() LLVM_OVERRIDE; | 600 void ProcessRecord() override; |
602 | 601 |
603 // Checks if the number of initializers needed is the same as the | 602 // Checks if the number of initializers needed is the same as the |
604 // number found in the bitcode file. If different, and error message | 603 // number found in the bitcode file. If different, and error message |
605 // is generated, and the internal state of the parser is fixed so | 604 // is generated, and the internal state of the parser is fixed so |
606 // this condition is no longer violated. | 605 // this condition is no longer violated. |
607 void verifyNoMissingInitializers() { | 606 void verifyNoMissingInitializers() { |
608 if (InitializersNeeded != Initializers.size()) { | 607 if (InitializersNeeded != Initializers.size()) { |
609 std::string Buffer; | 608 std::string Buffer; |
610 raw_string_ostream StrBuf(Buffer); | 609 raw_string_ostream StrBuf(Buffer); |
611 StrBuf << "Global variable @g" | 610 StrBuf << "Global variable @g" |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 | 765 |
767 /// Base class for parsing a valuesymtab block in the bitcode file. | 766 /// Base class for parsing a valuesymtab block in the bitcode file. |
768 class ValuesymtabParser : public BlockParserBaseClass { | 767 class ValuesymtabParser : public BlockParserBaseClass { |
769 ValuesymtabParser(const ValuesymtabParser &) LLVM_DELETED_FUNCTION; | 768 ValuesymtabParser(const ValuesymtabParser &) LLVM_DELETED_FUNCTION; |
770 void operator=(const ValuesymtabParser &) LLVM_DELETED_FUNCTION; | 769 void operator=(const ValuesymtabParser &) LLVM_DELETED_FUNCTION; |
771 | 770 |
772 public: | 771 public: |
773 ValuesymtabParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) | 772 ValuesymtabParser(unsigned BlockID, BlockParserBaseClass *EnclosingParser) |
774 : BlockParserBaseClass(BlockID, EnclosingParser) {} | 773 : BlockParserBaseClass(BlockID, EnclosingParser) {} |
775 | 774 |
776 virtual ~ValuesymtabParser() LLVM_OVERRIDE {} | 775 ~ValuesymtabParser() override {} |
777 | 776 |
778 protected: | 777 protected: |
779 typedef SmallString<128> StringType; | 778 typedef SmallString<128> StringType; |
780 | 779 |
781 // Associates Name with the value defined by the given Index. | 780 // Associates Name with the value defined by the given Index. |
782 virtual void setValueName(uint64_t Index, StringType &Name) = 0; | 781 virtual void setValueName(uint64_t Index, StringType &Name) = 0; |
783 | 782 |
784 // Associates Name with the value defined by the given Index; | 783 // Associates Name with the value defined by the given Index; |
785 virtual void setBbName(uint64_t Index, StringType &Name) = 0; | 784 virtual void setBbName(uint64_t Index, StringType &Name) = 0; |
786 | 785 |
787 private: | 786 private: |
788 | 787 |
789 virtual void ProcessRecord() LLVM_OVERRIDE; | 788 void ProcessRecord() override; |
790 | 789 |
791 void ConvertToString(StringType &ConvertedName) { | 790 void ConvertToString(StringType &ConvertedName) { |
792 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); | 791 const NaClBitcodeRecord::RecordVector &Values = Record.GetValues(); |
793 for (size_t i = 1, e = Values.size(); i != e; ++i) { | 792 for (size_t i = 1, e = Values.size(); i != e; ++i) { |
794 ConvertedName += static_cast<char>(Values[i]); | 793 ConvertedName += static_cast<char>(Values[i]); |
795 } | 794 } |
796 } | 795 } |
797 }; | 796 }; |
798 | 797 |
799 void ValuesymtabParser::ProcessRecord() { | 798 void ValuesymtabParser::ProcessRecord() { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 Func->setInternal(LLVMFunc->hasInternalLinkage()); | 845 Func->setInternal(LLVMFunc->hasInternalLinkage()); |
847 CurrentNode = InstallNextBasicBlock(); | 846 CurrentNode = InstallNextBasicBlock(); |
848 Func->setEntryNode(CurrentNode); | 847 Func->setEntryNode(CurrentNode); |
849 for (Function::const_arg_iterator ArgI = LLVMFunc->arg_begin(), | 848 for (Function::const_arg_iterator ArgI = LLVMFunc->arg_begin(), |
850 ArgE = LLVMFunc->arg_end(); | 849 ArgE = LLVMFunc->arg_end(); |
851 ArgI != ArgE; ++ArgI) { | 850 ArgI != ArgE; ++ArgI) { |
852 Func->addArg(getNextInstVar(Context->convertToIceType(ArgI->getType()))); | 851 Func->addArg(getNextInstVar(Context->convertToIceType(ArgI->getType()))); |
853 } | 852 } |
854 } | 853 } |
855 | 854 |
856 ~FunctionParser() LLVM_OVERRIDE; | 855 ~FunctionParser() override; |
857 | 856 |
858 // Set the next constant ID to the given constant C. | 857 // Set the next constant ID to the given constant C. |
859 void setNextConstantID(Ice::Constant *C) { | 858 void setNextConstantID(Ice::Constant *C) { |
860 setOperand(NextLocalInstIndex++, C); | 859 setOperand(NextLocalInstIndex++, C); |
861 } | 860 } |
862 | 861 |
863 private: | 862 private: |
864 // Timer for reading function bitcode and converting to ICE. | 863 // Timer for reading function bitcode and converting to ICE. |
865 Ice::Timer TConvert; | 864 Ice::Timer TConvert; |
866 // The corresponding ICE function defined by the function block. | 865 // The corresponding ICE function defined by the function block. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 } | 897 } |
899 std::string Buffer; | 898 std::string Buffer; |
900 raw_string_ostream StrBuf(Buffer); | 899 raw_string_ostream StrBuf(Buffer); |
901 StrBuf << InstName << " alignment greater than 2**" << AlignPowerLimit | 900 StrBuf << InstName << " alignment greater than 2**" << AlignPowerLimit |
902 << ". Found: 2**" << AlignPower; | 901 << ". Found: 2**" << AlignPower; |
903 Error(StrBuf.str()); | 902 Error(StrBuf.str()); |
904 // Error recover with value that is always acceptable. | 903 // Error recover with value that is always acceptable. |
905 Alignment = 1; | 904 Alignment = 1; |
906 } | 905 } |
907 | 906 |
908 virtual bool ParseBlock(unsigned BlockID) LLVM_OVERRIDE; | 907 bool ParseBlock(unsigned BlockID) override; |
909 | 908 |
910 virtual void ProcessRecord() LLVM_OVERRIDE; | 909 void ProcessRecord() override; |
911 | 910 |
912 virtual void ExitBlock() LLVM_OVERRIDE; | 911 void ExitBlock() override; |
913 | 912 |
914 // Creates and appends a new basic block to the list of basic blocks. | 913 // Creates and appends a new basic block to the list of basic blocks. |
915 Ice::CfgNode *InstallNextBasicBlock() { return Func->makeNode(); } | 914 Ice::CfgNode *InstallNextBasicBlock() { return Func->makeNode(); } |
916 | 915 |
917 // Returns the Index-th basic block in the list of basic blocks. | 916 // Returns the Index-th basic block in the list of basic blocks. |
918 Ice::CfgNode *getBasicBlock(uint32_t Index) { | 917 Ice::CfgNode *getBasicBlock(uint32_t Index) { |
919 const Ice::NodeList &Nodes = Func->getNodes(); | 918 const Ice::NodeList &Nodes = Func->getNodes(); |
920 if (Index >= Nodes.size()) { | 919 if (Index >= Nodes.size()) { |
921 std::string Buffer; | 920 std::string Buffer; |
922 raw_string_ostream StrBuf(Buffer); | 921 raw_string_ostream StrBuf(Buffer); |
(...skipping 1102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2025 /// Parses constants within a function block. | 2024 /// Parses constants within a function block. |
2026 class ConstantsParser : public BlockParserBaseClass { | 2025 class ConstantsParser : public BlockParserBaseClass { |
2027 ConstantsParser(const ConstantsParser &) LLVM_DELETED_FUNCTION; | 2026 ConstantsParser(const ConstantsParser &) LLVM_DELETED_FUNCTION; |
2028 ConstantsParser &operator=(const ConstantsParser &) LLVM_DELETED_FUNCTION; | 2027 ConstantsParser &operator=(const ConstantsParser &) LLVM_DELETED_FUNCTION; |
2029 | 2028 |
2030 public: | 2029 public: |
2031 ConstantsParser(unsigned BlockID, FunctionParser *FuncParser) | 2030 ConstantsParser(unsigned BlockID, FunctionParser *FuncParser) |
2032 : BlockParserBaseClass(BlockID, FuncParser), FuncParser(FuncParser), | 2031 : BlockParserBaseClass(BlockID, FuncParser), FuncParser(FuncParser), |
2033 NextConstantType(Ice::IceType_void) {} | 2032 NextConstantType(Ice::IceType_void) {} |
2034 | 2033 |
2035 ~ConstantsParser() LLVM_OVERRIDE {} | 2034 ~ConstantsParser() override {} |
2036 | 2035 |
2037 private: | 2036 private: |
2038 // The parser of the function block this constants block appears in. | 2037 // The parser of the function block this constants block appears in. |
2039 FunctionParser *FuncParser; | 2038 FunctionParser *FuncParser; |
2040 // The type to use for succeeding constants. | 2039 // The type to use for succeeding constants. |
2041 Ice::Type NextConstantType; | 2040 Ice::Type NextConstantType; |
2042 | 2041 |
2043 virtual void ProcessRecord() LLVM_OVERRIDE; | 2042 void ProcessRecord() override; |
2044 | 2043 |
2045 Ice::GlobalContext *getContext() { return getTranslator().getContext(); } | 2044 Ice::GlobalContext *getContext() { return getTranslator().getContext(); } |
2046 | 2045 |
2047 // Returns true if the type to use for succeeding constants is defined. | 2046 // Returns true if the type to use for succeeding constants is defined. |
2048 // If false, also generates an error message. | 2047 // If false, also generates an error message. |
2049 bool isValidNextConstantType() { | 2048 bool isValidNextConstantType() { |
2050 if (NextConstantType != Ice::IceType_void) | 2049 if (NextConstantType != Ice::IceType_void) |
2051 return true; | 2050 return true; |
2052 Error("Constant record not preceded by set type record"); | 2051 Error("Constant record not preceded by set type record"); |
2053 return false; | 2052 return false; |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2147 public: | 2146 public: |
2148 FunctionValuesymtabParser(unsigned BlockID, FunctionParser *EnclosingParser) | 2147 FunctionValuesymtabParser(unsigned BlockID, FunctionParser *EnclosingParser) |
2149 : ValuesymtabParser(BlockID, EnclosingParser) {} | 2148 : ValuesymtabParser(BlockID, EnclosingParser) {} |
2150 | 2149 |
2151 private: | 2150 private: |
2152 // Returns the enclosing function parser. | 2151 // Returns the enclosing function parser. |
2153 FunctionParser *getFunctionParser() const { | 2152 FunctionParser *getFunctionParser() const { |
2154 return reinterpret_cast<FunctionParser *>(GetEnclosingParser()); | 2153 return reinterpret_cast<FunctionParser *>(GetEnclosingParser()); |
2155 } | 2154 } |
2156 | 2155 |
2157 virtual void setValueName(uint64_t Index, StringType &Name) LLVM_OVERRIDE; | 2156 void setValueName(uint64_t Index, StringType &Name) override; |
2158 virtual void setBbName(uint64_t Index, StringType &Name) LLVM_OVERRIDE; | 2157 void setBbName(uint64_t Index, StringType &Name) override; |
2159 | 2158 |
2160 // Reports that the assignment of Name to the value associated with | 2159 // Reports that the assignment of Name to the value associated with |
2161 // index is not possible, for the given Context. | 2160 // index is not possible, for the given Context. |
2162 void reportUnableToAssign(const char *Context, uint64_t Index, | 2161 void reportUnableToAssign(const char *Context, uint64_t Index, |
2163 StringType &Name) { | 2162 StringType &Name) { |
2164 std::string Buffer; | 2163 std::string Buffer; |
2165 raw_string_ostream StrBuf(Buffer); | 2164 raw_string_ostream StrBuf(Buffer); |
2166 StrBuf << "Function-local " << Context << " name '" << Name | 2165 StrBuf << "Function-local " << Context << " name '" << Name |
2167 << "' can't be associated with index " << Index; | 2166 << "' can't be associated with index " << Index; |
2168 Error(StrBuf.str()); | 2167 Error(StrBuf.str()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2214 return BlockParserBaseClass::ParseBlock(BlockID); | 2213 return BlockParserBaseClass::ParseBlock(BlockID); |
2215 } | 2214 } |
2216 | 2215 |
2217 /// Parses the module block in the bitcode file. | 2216 /// Parses the module block in the bitcode file. |
2218 class ModuleParser : public BlockParserBaseClass { | 2217 class ModuleParser : public BlockParserBaseClass { |
2219 public: | 2218 public: |
2220 ModuleParser(unsigned BlockID, TopLevelParser *Context) | 2219 ModuleParser(unsigned BlockID, TopLevelParser *Context) |
2221 : BlockParserBaseClass(BlockID, Context), | 2220 : BlockParserBaseClass(BlockID, Context), |
2222 GlobalAddressNamesAndInitializersInstalled(false) {} | 2221 GlobalAddressNamesAndInitializersInstalled(false) {} |
2223 | 2222 |
2224 virtual ~ModuleParser() LLVM_OVERRIDE {} | 2223 ~ModuleParser() override {} |
2225 | 2224 |
2226 private: | 2225 private: |
2227 // True if we have already instaledl names for unnamed global addresses, | 2226 // True if we have already instaledl names for unnamed global addresses, |
2228 // and generated global constant initializers. | 2227 // and generated global constant initializers. |
2229 bool GlobalAddressNamesAndInitializersInstalled; | 2228 bool GlobalAddressNamesAndInitializersInstalled; |
2230 | 2229 |
2231 // Temporary hack to generate names for unnamed global addresses, | 2230 // Temporary hack to generate names for unnamed global addresses, |
2232 // and generate global constant initializers. May be called multiple | 2231 // and generate global constant initializers. May be called multiple |
2233 // times. Only the first call will do the installation. | 2232 // times. Only the first call will do the installation. |
2234 // NOTE: Doesn't handle relocations for global constant initializers. | 2233 // NOTE: Doesn't handle relocations for global constant initializers. |
2235 void InstallGlobalAddressNamesAndInitializers() { | 2234 void InstallGlobalAddressNamesAndInitializers() { |
2236 if (!GlobalAddressNamesAndInitializersInstalled) { | 2235 if (!GlobalAddressNamesAndInitializersInstalled) { |
2237 getTranslator().nameUnnamedGlobalAddresses(Context->getModule()); | 2236 getTranslator().nameUnnamedGlobalAddresses(Context->getModule()); |
2238 if (!getFlags().DisableGlobals) | 2237 if (!getFlags().DisableGlobals) |
2239 getTranslator().convertGlobals(Context->getModule()); | 2238 getTranslator().convertGlobals(Context->getModule()); |
2240 GlobalAddressNamesAndInitializersInstalled = true; | 2239 GlobalAddressNamesAndInitializersInstalled = true; |
2241 } | 2240 } |
2242 } | 2241 } |
2243 | 2242 |
2244 virtual bool ParseBlock(unsigned BlockID) LLVM_OVERRIDE; | 2243 bool ParseBlock(unsigned BlockID) override; |
2245 | 2244 |
2246 virtual void ExitBlock() LLVM_OVERRIDE { | 2245 void ExitBlock() override { |
2247 InstallGlobalAddressNamesAndInitializers(); | 2246 InstallGlobalAddressNamesAndInitializers(); |
2248 getTranslator().emitConstants(); | 2247 getTranslator().emitConstants(); |
2249 } | 2248 } |
2250 | 2249 |
2251 virtual void ProcessRecord() LLVM_OVERRIDE; | 2250 void ProcessRecord() override; |
2252 }; | 2251 }; |
2253 | 2252 |
2254 class ModuleValuesymtabParser : public ValuesymtabParser { | 2253 class ModuleValuesymtabParser : public ValuesymtabParser { |
2255 ModuleValuesymtabParser(const ModuleValuesymtabParser &) | 2254 ModuleValuesymtabParser(const ModuleValuesymtabParser &) |
2256 LLVM_DELETED_FUNCTION; | 2255 LLVM_DELETED_FUNCTION; |
2257 void operator=(const ModuleValuesymtabParser &) LLVM_DELETED_FUNCTION; | 2256 void operator=(const ModuleValuesymtabParser &) LLVM_DELETED_FUNCTION; |
2258 | 2257 |
2259 public: | 2258 public: |
2260 ModuleValuesymtabParser(unsigned BlockID, ModuleParser *MP) | 2259 ModuleValuesymtabParser(unsigned BlockID, ModuleParser *MP) |
2261 : ValuesymtabParser(BlockID, MP) {} | 2260 : ValuesymtabParser(BlockID, MP) {} |
2262 | 2261 |
2263 virtual ~ModuleValuesymtabParser() LLVM_OVERRIDE {} | 2262 ~ModuleValuesymtabParser() override {} |
2264 | 2263 |
2265 private: | 2264 private: |
2266 virtual void setValueName(uint64_t Index, StringType &Name) LLVM_OVERRIDE; | 2265 void setValueName(uint64_t Index, StringType &Name) override; |
2267 virtual void setBbName(uint64_t Index, StringType &Name) LLVM_OVERRIDE; | 2266 void setBbName(uint64_t Index, StringType &Name) override; |
2268 }; | 2267 }; |
2269 | 2268 |
2270 void ModuleValuesymtabParser::setValueName(uint64_t Index, StringType &Name) { | 2269 void ModuleValuesymtabParser::setValueName(uint64_t Index, StringType &Name) { |
2271 Value *V = Context->getGlobalValueByID(Index); | 2270 Value *V = Context->getGlobalValueByID(Index); |
2272 if (V == NULL) { | 2271 if (V == NULL) { |
2273 std::string Buffer; | 2272 std::string Buffer; |
2274 raw_string_ostream StrBuf(Buffer); | 2273 raw_string_ostream StrBuf(Buffer); |
2275 StrBuf << "Invalid global address ID in valuesymtab: " << Index; | 2274 StrBuf << "Invalid global address ID in valuesymtab: " << Index; |
2276 Error(StrBuf.str()); | 2275 Error(StrBuf.str()); |
2277 return; | 2276 return; |
2278 } | 2277 } |
2279 V->setName(StringRef(Name.data(), Name.size())); | 2278 V->setName(StringRef(Name.data(), Name.size())); |
2280 } | 2279 } |
2281 | 2280 |
2282 void ModuleValuesymtabParser::setBbName(uint64_t Index, StringType &Name) { | 2281 void ModuleValuesymtabParser::setBbName(uint64_t Index, StringType &Name) { |
2283 std::string Buffer; | 2282 std::string Buffer; |
2284 raw_string_ostream StrBuf(Buffer); | 2283 raw_string_ostream StrBuf(Buffer); |
2285 StrBuf << "Can't define basic block name at global level: '" << Name | 2284 StrBuf << "Can't define basic block name at global level: '" << Name |
2286 << "' -> " << Index; | 2285 << "' -> " << Index; |
2287 Error(StrBuf.str()); | 2286 Error(StrBuf.str()); |
2288 } | 2287 } |
2289 | 2288 |
2290 bool ModuleParser::ParseBlock(unsigned BlockID) LLVM_OVERRIDE { | 2289 bool ModuleParser::ParseBlock(unsigned BlockID) { |
2291 switch (BlockID) { | 2290 switch (BlockID) { |
2292 case naclbitc::BLOCKINFO_BLOCK_ID: | 2291 case naclbitc::BLOCKINFO_BLOCK_ID: |
2293 return NaClBitcodeParser::ParseBlock(BlockID); | 2292 return NaClBitcodeParser::ParseBlock(BlockID); |
2294 case naclbitc::TYPE_BLOCK_ID_NEW: { | 2293 case naclbitc::TYPE_BLOCK_ID_NEW: { |
2295 TypesParser Parser(BlockID, this); | 2294 TypesParser Parser(BlockID, this); |
2296 return Parser.ParseThisBlock(); | 2295 return Parser.ParseThisBlock(); |
2297 } | 2296 } |
2298 case naclbitc::GLOBALVAR_BLOCK_ID: { | 2297 case naclbitc::GLOBALVAR_BLOCK_ID: { |
2299 GlobalsParser Parser(BlockID, this); | 2298 GlobalsParser Parser(BlockID, this); |
2300 return Parser.ParseThisBlock(); | 2299 return Parser.ParseThisBlock(); |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2431 | 2430 |
2432 if (TopLevelBlocks != 1) { | 2431 if (TopLevelBlocks != 1) { |
2433 errs() << IRFilename | 2432 errs() << IRFilename |
2434 << ": Contains more than one module. Found: " << TopLevelBlocks | 2433 << ": Contains more than one module. Found: " << TopLevelBlocks |
2435 << "\n"; | 2434 << "\n"; |
2436 ErrorStatus = true; | 2435 ErrorStatus = true; |
2437 } | 2436 } |
2438 } | 2437 } |
2439 | 2438 |
2440 } // end of namespace Ice | 2439 } // end of namespace Ice |
OLD | NEW |