| 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 namespace { | 34 namespace { |
| 35 | 35 |
| 36 // Top-level class to read PNaCl bitcode files, and translate to ICE. | 36 // Top-level class to read PNaCl bitcode files, and translate to ICE. |
| 37 class TopLevelParser : public NaClBitcodeParser { | 37 class TopLevelParser : public NaClBitcodeParser { |
| 38 TopLevelParser(const TopLevelParser &) LLVM_DELETED_FUNCTION; | 38 TopLevelParser(const TopLevelParser &) LLVM_DELETED_FUNCTION; |
| 39 TopLevelParser &operator=(const TopLevelParser &) LLVM_DELETED_FUNCTION; | 39 TopLevelParser &operator=(const TopLevelParser &) LLVM_DELETED_FUNCTION; |
| 40 | 40 |
| 41 public: | 41 public: |
| 42 TopLevelParser(const std::string &InputName, NaClBitcodeHeader &Header, | 42 TopLevelParser(const std::string &InputName, NaClBitcodeHeader &Header, |
| 43 NaClBitstreamCursor &Cursor, int &ExitStatusFlag) | 43 NaClBitstreamCursor &Cursor, bool &ErrorStatus) |
| 44 : NaClBitcodeParser(Cursor), | 44 : NaClBitcodeParser(Cursor), |
| 45 Mod(new Module(InputName, getGlobalContext())), Header(Header), | 45 Mod(new Module(InputName, getGlobalContext())), Header(Header), |
| 46 ExitStatusFlag(ExitStatusFlag), NumErrors(0), NumFunctionIds(0), | 46 ErrorStatus(ErrorStatus), NumErrors(0), NumFunctionIds(0), |
| 47 GlobalVarPlaceHolderType(Type::getInt8Ty(getLLVMContext())) { | 47 GlobalVarPlaceHolderType(Type::getInt8Ty(getLLVMContext())) { |
| 48 Mod->setDataLayout(PNaClDataLayout); | 48 Mod->setDataLayout(PNaClDataLayout); |
| 49 } | 49 } |
| 50 | 50 |
| 51 virtual ~TopLevelParser() {} | 51 virtual ~TopLevelParser() {} |
| 52 LLVM_OVERRIDE; | 52 LLVM_OVERRIDE; |
| 53 | 53 |
| 54 virtual bool Error(const std::string &Message) LLVM_OVERRIDE { | 54 virtual bool Error(const std::string &Message) LLVM_OVERRIDE { |
| 55 ExitStatusFlag = 1; | 55 ErrorStatus = true; |
| 56 ++NumErrors; | 56 ++NumErrors; |
| 57 return NaClBitcodeParser::Error(Message); | 57 return NaClBitcodeParser::Error(Message); |
| 58 } | 58 } |
| 59 | 59 |
| 60 /// Returns the number of errors found while parsing the bitcode | 60 /// Returns the number of errors found while parsing the bitcode |
| 61 /// file. | 61 /// file. |
| 62 unsigned getNumErrors() const { return NumErrors; } | 62 unsigned getNumErrors() const { return NumErrors; } |
| 63 | 63 |
| 64 /// Returns the LLVM module associated with the translation. | 64 /// Returns the LLVM module associated with the translation. |
| 65 Module *getModule() const { return Mod.get(); } | 65 Module *getModule() const { return Mod.get(); } |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 Placeholder->eraseFromParent(); | 160 Placeholder->eraseFromParent(); |
| 161 ValueIDValues[ID] = GV; | 161 ValueIDValues[ID] = GV; |
| 162 return true; | 162 return true; |
| 163 } | 163 } |
| 164 | 164 |
| 165 private: | 165 private: |
| 166 // The parsed module. | 166 // The parsed module. |
| 167 OwningPtr<Module> Mod; | 167 OwningPtr<Module> Mod; |
| 168 // The bitcode header. | 168 // The bitcode header. |
| 169 NaClBitcodeHeader &Header; | 169 NaClBitcodeHeader &Header; |
| 170 // The exit status flag that should be set to 1 if an error occurs. | 170 // The exit status that should be set to true if an error occurs. |
| 171 int &ExitStatusFlag; | 171 bool &ErrorStatus; |
| 172 // The number of errors reported. | 172 // The number of errors reported. |
| 173 unsigned NumErrors; | 173 unsigned NumErrors; |
| 174 // The types associated with each type ID. | 174 // The types associated with each type ID. |
| 175 std::vector<Type *> TypeIDValues; | 175 std::vector<Type *> TypeIDValues; |
| 176 // The (global) value IDs. | 176 // The (global) value IDs. |
| 177 std::vector<WeakVH> ValueIDValues; | 177 std::vector<WeakVH> ValueIDValues; |
| 178 // The number of function IDs. | 178 // The number of function IDs. |
| 179 unsigned NumFunctionIds; | 179 unsigned NumFunctionIds; |
| 180 // The list of value IDs (in the order found) of defining function | 180 // The list of value IDs (in the order found) of defining function |
| 181 // addresses. | 181 // addresses. |
| (...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 803 | 803 |
| 804 } // end of anonymous namespace. | 804 } // end of anonymous namespace. |
| 805 | 805 |
| 806 namespace Ice { | 806 namespace Ice { |
| 807 | 807 |
| 808 void PNaClTranslator::translate(const std::string &IRFilename) { | 808 void PNaClTranslator::translate(const std::string &IRFilename) { |
| 809 OwningPtr<MemoryBuffer> MemBuf; | 809 OwningPtr<MemoryBuffer> MemBuf; |
| 810 if (error_code ec = | 810 if (error_code ec = |
| 811 MemoryBuffer::getFileOrSTDIN(IRFilename.c_str(), MemBuf)) { | 811 MemoryBuffer::getFileOrSTDIN(IRFilename.c_str(), MemBuf)) { |
| 812 errs() << "Error reading '" << IRFilename << "': " << ec.message() << "\n"; | 812 errs() << "Error reading '" << IRFilename << "': " << ec.message() << "\n"; |
| 813 ExitStatus = 1; | 813 ErrorStatus = true; |
| 814 return; | 814 return; |
| 815 } | 815 } |
| 816 | 816 |
| 817 if (MemBuf->getBufferSize() % 4 != 0) { | 817 if (MemBuf->getBufferSize() % 4 != 0) { |
| 818 errs() << IRFilename | 818 errs() << IRFilename |
| 819 << ": Bitcode stream should be a multiple of 4 bytes in length.\n"; | 819 << ": Bitcode stream should be a multiple of 4 bytes in length.\n"; |
| 820 ExitStatus = 1; | 820 ErrorStatus = true; |
| 821 return; | 821 return; |
| 822 } | 822 } |
| 823 | 823 |
| 824 const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart(); | 824 const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart(); |
| 825 const unsigned char *EndBufPtr = BufPtr + MemBuf->getBufferSize(); | 825 const unsigned char *EndBufPtr = BufPtr + MemBuf->getBufferSize(); |
| 826 | 826 |
| 827 // Read header and verify it is good. | 827 // Read header and verify it is good. |
| 828 NaClBitcodeHeader Header; | 828 NaClBitcodeHeader Header; |
| 829 if (Header.Read(BufPtr, EndBufPtr) || !Header.IsSupported()) { | 829 if (Header.Read(BufPtr, EndBufPtr) || !Header.IsSupported()) { |
| 830 errs() << "Invalid PNaCl bitcode header.\n"; | 830 errs() << "Invalid PNaCl bitcode header.\n"; |
| 831 ExitStatus = 1; | 831 ErrorStatus = true; |
| 832 return; | 832 return; |
| 833 } | 833 } |
| 834 | 834 |
| 835 // Create a bitstream reader to read the bitcode file. | 835 // Create a bitstream reader to read the bitcode file. |
| 836 NaClBitstreamReader InputStreamFile(BufPtr, EndBufPtr); | 836 NaClBitstreamReader InputStreamFile(BufPtr, EndBufPtr); |
| 837 NaClBitstreamCursor InputStream(InputStreamFile); | 837 NaClBitstreamCursor InputStream(InputStreamFile); |
| 838 | 838 |
| 839 TopLevelParser Parser(MemBuf->getBufferIdentifier(), Header, InputStream, | 839 TopLevelParser Parser(MemBuf->getBufferIdentifier(), Header, InputStream, |
| 840 ExitStatus); | 840 ErrorStatus); |
| 841 int TopLevelBlocks = 0; | 841 int TopLevelBlocks = 0; |
| 842 while (!InputStream.AtEndOfStream()) { | 842 while (!InputStream.AtEndOfStream()) { |
| 843 if (Parser.Parse()) { | 843 if (Parser.Parse()) { |
| 844 ExitStatus = 1; | 844 ErrorStatus = true; |
| 845 return; | 845 return; |
| 846 } | 846 } |
| 847 ++TopLevelBlocks; | 847 ++TopLevelBlocks; |
| 848 } | 848 } |
| 849 | 849 |
| 850 if (TopLevelBlocks != 1) { | 850 if (TopLevelBlocks != 1) { |
| 851 errs() << IRFilename | 851 errs() << IRFilename |
| 852 << ": Contains more than one module. Found: " << TopLevelBlocks | 852 << ": Contains more than one module. Found: " << TopLevelBlocks |
| 853 << "\n"; | 853 << "\n"; |
| 854 ExitStatus = 1; | 854 ErrorStatus = true; |
| 855 } | 855 } |
| 856 return; | 856 return; |
| 857 } | 857 } |
| 858 | 858 |
| 859 } // end of anonymous namespace. | 859 } // end of anonymous namespace. |
| OLD | NEW |