| 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 2967 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2978 void PNaClTranslator::translateBuffer(const std::string &IRFilename, | 2978 void PNaClTranslator::translateBuffer(const std::string &IRFilename, |
| 2979 MemoryBuffer *MemBuf) { | 2979 MemoryBuffer *MemBuf) { |
| 2980 std::unique_ptr<MemoryObject> MemObj(getNonStreamedMemoryObject( | 2980 std::unique_ptr<MemoryObject> MemObj(getNonStreamedMemoryObject( |
| 2981 reinterpret_cast<const unsigned char *>(MemBuf->getBufferStart()), | 2981 reinterpret_cast<const unsigned char *>(MemBuf->getBufferStart()), |
| 2982 reinterpret_cast<const unsigned char *>(MemBuf->getBufferEnd()))); | 2982 reinterpret_cast<const unsigned char *>(MemBuf->getBufferEnd()))); |
| 2983 translate(IRFilename, std::move(MemObj)); | 2983 translate(IRFilename, std::move(MemObj)); |
| 2984 } | 2984 } |
| 2985 | 2985 |
| 2986 void PNaClTranslator::translate(const std::string &IRFilename, | 2986 void PNaClTranslator::translate(const std::string &IRFilename, |
| 2987 std::unique_ptr<MemoryObject> &&MemObj) { | 2987 std::unique_ptr<MemoryObject> &&MemObj) { |
| 2988 | 2988 // On error, we report_fatal_error to avoid destroying the MemObj. |
| 2989 // That may still be in use by IceBrowserCompileServer. Otherwise, |
| 2990 // we need to change the MemObj to be ref-counted, or have a wrapper, |
| 2991 // or simply leak. We also need a hook to tell the IceBrowserCompileServer |
| 2992 // to unblock its QueueStreamer. |
| 2993 // https://code.google.com/p/nativeclient/issues/detail?id=4163 |
| 2994 Ostream &ErrStream = getContext()->getStrError(); |
| 2989 // Read header and verify it is good. | 2995 // Read header and verify it is good. |
| 2990 NaClBitcodeHeader Header; | 2996 NaClBitcodeHeader Header; |
| 2991 if (Header.Read(MemObj.get())) { | 2997 if (Header.Read(MemObj.get())) { |
| 2992 errs() << "Invalid PNaCl bitcode header.\n"; | 2998 llvm::report_fatal_error("Invalid PNaCl bitcode header"); |
| 2993 ErrorStatus.assign(EC_Bitcode); | |
| 2994 return; | |
| 2995 } | 2999 } |
| 2996 if (!Header.IsSupported()) { | 3000 if (!Header.IsSupported()) { |
| 2997 errs() << Header.Unsupported(); | 3001 ErrStream << Header.Unsupported(); |
| 2998 if (!Header.IsReadable()) { | 3002 if (!Header.IsReadable()) { |
| 2999 errs() << "Invalid PNaCl bitcode header.\n"; | 3003 llvm::report_fatal_error("Invalid PNaCl bitcode header"); |
| 3000 ErrorStatus.assign(EC_Bitcode); | |
| 3001 return; | |
| 3002 } | 3004 } |
| 3003 } | 3005 } |
| 3004 | 3006 |
| 3005 // Create a bitstream reader to read the bitcode file. | 3007 // Create a bitstream reader to read the bitcode file. |
| 3006 NaClBitstreamReader InputStreamFile(MemObj.release(), Header); | 3008 NaClBitstreamReader InputStreamFile(MemObj.release(), Header); |
| 3007 NaClBitstreamCursor InputStream(InputStreamFile); | 3009 NaClBitstreamCursor InputStream(InputStreamFile); |
| 3008 | 3010 |
| 3009 TopLevelParser Parser(*this, InputStream, ErrorStatus); | 3011 TopLevelParser Parser(*this, InputStream, ErrorStatus); |
| 3010 int TopLevelBlocks = 0; | 3012 int TopLevelBlocks = 0; |
| 3011 while (!InputStream.AtEndOfStream()) { | 3013 while (!InputStream.AtEndOfStream()) { |
| 3012 if (Parser.Parse()) { | 3014 if (Parser.Parse()) { |
| 3013 ErrorStatus.assign(EC_Bitcode); | 3015 ErrorStatus.assign(EC_Bitcode); |
| 3014 return; | 3016 return; |
| 3015 } | 3017 } |
| 3016 ++TopLevelBlocks; | 3018 ++TopLevelBlocks; |
| 3017 } | 3019 } |
| 3018 | 3020 |
| 3019 if (TopLevelBlocks != 1) { | 3021 if (TopLevelBlocks != 1) { |
| 3020 errs() << IRFilename | 3022 ErrStream << IRFilename |
| 3021 << ": Contains more than one module. Found: " << TopLevelBlocks | 3023 << ": Contains more than one module. Found: " << TopLevelBlocks |
| 3022 << "\n"; | 3024 << "\n"; |
| 3023 ErrorStatus.assign(EC_Bitcode); | 3025 llvm::report_fatal_error("Bitcode has more than one module"); |
| 3024 } | 3026 } |
| 3025 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { | 3027 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) { |
| 3026 errs() << IRFilename | 3028 ErrStream |
| 3027 << ": Bitcode stream should be a multiple of 4 bytes in length.\n"; | 3029 << IRFilename |
| 3028 ErrorStatus.assign(EC_Bitcode); | 3030 << ": Bitcode stream should be a multiple of 4 bytes in length.\n"; |
| 3029 return; | 3031 llvm::report_fatal_error("Bitcode stream should be a multiple of 4 bytes"); |
| 3030 } | 3032 } |
| 3031 } | 3033 } |
| 3032 | 3034 |
| 3033 } // end of namespace Ice | 3035 } // end of namespace Ice |
| OLD | NEW |