Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: src/PNaClTranslator.cpp

Issue 982403002: Subzero: Switch file reading to be based on a DataStreamer and MemoryObject. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: cleanup Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/PNaClTranslator.h ('k') | src/main.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2974 matching lines...) Expand 10 before | Expand all | Expand 10 after
2985 } 2985 }
2986 // Generate error message by using default block implementation. 2986 // Generate error message by using default block implementation.
2987 BlockParserBaseClass Parser(BlockID, this); 2987 BlockParserBaseClass Parser(BlockID, this);
2988 return Parser.ParseThisBlock(); 2988 return Parser.ParseThisBlock();
2989 } 2989 }
2990 2990
2991 } // end of anonymous namespace 2991 } // end of anonymous namespace
2992 2992
2993 namespace Ice { 2993 namespace Ice {
2994 2994
2995 void PNaClTranslator::translate(const std::string &IRFilename) { 2995 void PNaClTranslator::translateBuffer(const std::string &IRFilename,
Derek Schuff 2015/03/06 21:56:05 so is translatebuffer still used now that it's not
jvoung (off chromium) 2015/03/06 22:34:53 translateBuffer is being used by: subzero/unittes
2996 ErrorOr<std::unique_ptr<MemoryBuffer>> ErrOrFile = 2996 MemoryBuffer *MemBuf) {
2997 MemoryBuffer::getFileOrSTDIN(IRFilename); 2997 std::unique_ptr<MemoryObject> MemObj(getNonStreamedMemoryObject(
2998 if (std::error_code EC = ErrOrFile.getError()) { 2998 reinterpret_cast<const unsigned char *>(MemBuf->getBufferStart()),
2999 errs() << "Error reading '" << IRFilename << "': " << EC.message() << "\n"; 2999 reinterpret_cast<const unsigned char *>(MemBuf->getBufferEnd())));
3000 ErrorStatus.assign(EC.value()); 3000 translate(IRFilename, std::move(MemObj));
3001 return;
3002 }
3003
3004 std::unique_ptr<MemoryBuffer> MemBuf(ErrOrFile.get().release());
3005 translateBuffer(IRFilename, MemBuf.get());
3006 } 3001 }
3007 3002
3008 void PNaClTranslator::translateBuffer(const std::string &IRFilename, 3003 void PNaClTranslator::translate(const std::string &IRFilename,
3009 MemoryBuffer *MemBuf) { 3004 std::unique_ptr<MemoryObject> &&MemObj) {
3010 if (MemBuf->getBufferSize() % 4 != 0) {
3011 errs() << IRFilename
3012 << ": Bitcode stream should be a multiple of 4 bytes in length.\n";
3013 ErrorStatus.assign(EC_Bitcode);
3014 return;
3015 }
3016
3017 const unsigned char *BufPtr = (const unsigned char *)MemBuf->getBufferStart();
3018 const unsigned char *HeaderPtr = BufPtr;
3019 const unsigned char *EndBufPtr = BufPtr + MemBuf->getBufferSize();
3020 3005
3021 // Read header and verify it is good. 3006 // Read header and verify it is good.
3022 NaClBitcodeHeader Header; 3007 NaClBitcodeHeader Header;
3023 if (Header.Read(HeaderPtr, EndBufPtr) || !Header.IsSupported()) { 3008 if (Header.Read(MemObj.get()) || !Header.IsSupported()) {
3024 errs() << "Invalid PNaCl bitcode header.\n"; 3009 errs() << "Invalid PNaCl bitcode header.\n";
3025 ErrorStatus.assign(EC_Bitcode); 3010 ErrorStatus.assign(EC_Bitcode);
3026 return; 3011 return;
3027 } 3012 }
3028 3013
3029 // Create a bitstream reader to read the bitcode file. 3014 // Create a bitstream reader to read the bitcode file.
3030 NaClBitstreamReader InputStreamFile(BufPtr, EndBufPtr, 3015 NaClBitstreamReader InputStreamFile(MemObj.release(), Header.getHeaderSize());
3031 Header.getHeaderSize());
3032 NaClBitstreamCursor InputStream(InputStreamFile); 3016 NaClBitstreamCursor InputStream(InputStreamFile);
3033 3017
3034 TopLevelParser Parser(*this, InputStream, ErrorStatus); 3018 TopLevelParser Parser(*this, InputStream, ErrorStatus);
3035 int TopLevelBlocks = 0; 3019 int TopLevelBlocks = 0;
3036 while (!InputStream.AtEndOfStream()) { 3020 while (!InputStream.AtEndOfStream()) {
3037 if (Parser.Parse()) { 3021 if (Parser.Parse()) {
3038 ErrorStatus.assign(EC_Bitcode); 3022 ErrorStatus.assign(EC_Bitcode);
3039 return; 3023 return;
3040 } 3024 }
3041 ++TopLevelBlocks; 3025 ++TopLevelBlocks;
3042 } 3026 }
3043 3027
3044 if (TopLevelBlocks != 1) { 3028 if (TopLevelBlocks != 1) {
3045 errs() << IRFilename 3029 errs() << IRFilename
3046 << ": Contains more than one module. Found: " << TopLevelBlocks 3030 << ": Contains more than one module. Found: " << TopLevelBlocks
3047 << "\n"; 3031 << "\n";
3048 ErrorStatus.assign(EC_Bitcode); 3032 ErrorStatus.assign(EC_Bitcode);
3049 } 3033 }
3034 if (InputStreamFile.getBitcodeBytes().getExtent() % 4 != 0) {
3035 errs() << IRFilename
3036 << ": Bitcode stream should be a multiple of 4 bytes in length.\n";
3037 ErrorStatus.assign(EC_Bitcode);
3038 return;
3039 }
3050 } 3040 }
3051 3041
3052 } // end of namespace Ice 3042 } // end of namespace Ice
OLDNEW
« no previous file with comments | « src/PNaClTranslator.h ('k') | src/main.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698