| OLD | NEW |
| 1 //===- StreamingMemoryObject.h - Streamable data interface -----*- C++ -*-===// | 1 //===- StreamingMemoryObject.h - Streamable data interface -----*- C++ -*-===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 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 #ifndef LLVM_SUPPORT_STREAMINGMEMORYOBJECT_H | 10 #ifndef LLVM_SUPPORT_STREAMINGMEMORYOBJECT_H |
| 11 #define LLVM_SUPPORT_STREAMINGMEMORYOBJECT_H | 11 #define LLVM_SUPPORT_STREAMINGMEMORYOBJECT_H |
| 12 | 12 |
| 13 #include "llvm/Support/Compiler.h" | 13 #include "llvm/Support/Compiler.h" |
| 14 #include "llvm/Support/DataStream.h" | 14 #include "llvm/Support/DataStream.h" |
| 15 #include "llvm/Support/ErrorHandling.h" | 15 #include "llvm/Support/ErrorHandling.h" |
| 16 #include "llvm/Support/MemoryObject.h" | 16 #include "llvm/Support/MemoryObject.h" |
| 17 #include <cassert> | 17 #include <cassert> |
| 18 #include <memory> | 18 #include <memory> |
| 19 #include <vector> | 19 #include <vector> |
| 20 | 20 |
| 21 namespace llvm { | 21 namespace llvm { |
| 22 | 22 |
| 23 /// Interface to data which is actually streamed from a DataStreamer. In | 23 /// Interface to data which is actually streamed from a DataStreamer. In |
| 24 /// addition to inherited members, it has the dropLeadingBytes and | 24 /// addition to inherited members, it has the dropLeadingBytes and |
| 25 /// setKnownObjectSize methods which are not applicable to non-streamed objects. | 25 /// setKnownObjectSize methods which are not applicable to non-streamed objects. |
| 26 /// @LOCALMOD -- Made dropLeadingBytes/setKnownObjectSize virtual. |
| 26 class StreamingMemoryObject : public MemoryObject { | 27 class StreamingMemoryObject : public MemoryObject { |
| 28 public: |
| 29 /// Drop s bytes from the front of the stream, pushing the positions of the |
| 30 /// remaining bytes down by s. This is used to skip past the bitcode header, |
| 31 /// since we don't know a priori if it's present, and we can't put bytes |
| 32 /// back into the stream once we've read them. |
| 33 virtual bool dropLeadingBytes(size_t s) = 0; |
| 34 |
| 35 /// If the data object size is known in advance, many of the operations can |
| 36 /// be made more efficient, so this method should be called before reading |
| 37 /// starts (although it can be called anytime). |
| 38 virtual void setKnownObjectSize(size_t size) = 0; |
| 39 }; |
| 40 |
| 41 /// @LOCALMOD -- split out StreamingMemoryObjectImpl from StreamingMemoryObject. |
| 42 /// StreamingMemoryObjectImpl - an implementation of a StreamingMemoryObject. |
| 43 class StreamingMemoryObjectImpl : public StreamingMemoryObject { |
| 27 public: | 44 public: |
| 28 StreamingMemoryObject(DataStreamer *streamer); | 45 StreamingMemoryObjectImpl(DataStreamer *streamer); |
| 29 uint64_t getExtent() const override; | 46 uint64_t getExtent() const override; |
| 30 uint64_t readBytes(uint8_t *Buf, uint64_t Size, | 47 uint64_t readBytes(uint8_t *Buf, uint64_t Size, |
| 31 uint64_t Address) const override; | 48 uint64_t Address) const override; |
| 32 const uint8_t *getPointer(uint64_t address, uint64_t size) const override { | 49 const uint8_t *getPointer(uint64_t address, uint64_t size) const override { |
| 33 // This could be fixed by ensuring the bytes are fetched and making a copy, | 50 // This could be fixed by ensuring the bytes are fetched and making a copy, |
| 34 // requiring that the bitcode size be known, or otherwise ensuring that | 51 // requiring that the bitcode size be known, or otherwise ensuring that |
| 35 // the memory doesn't go away/get reallocated, but it's | 52 // the memory doesn't go away/get reallocated, but it's |
| 36 // not currently necessary. Users that need the pointer don't stream. | 53 // not currently necessary. Users that need the pointer don't stream. |
| 37 llvm_unreachable("getPointer in streaming memory objects not allowed"); | 54 llvm_unreachable("getPointer in streaming memory objects not allowed"); |
| 38 return nullptr; | 55 return nullptr; |
| 39 } | 56 } |
| 40 bool isValidAddress(uint64_t address) const override; | 57 bool isValidAddress(uint64_t address) const override; |
| 41 | 58 |
| 42 /// Drop s bytes from the front of the stream, pushing the positions of the | 59 /// Drop s bytes from the front of the stream, pushing the positions of the |
| 43 /// remaining bytes down by s. This is used to skip past the bitcode header, | 60 /// remaining bytes down by s. This is used to skip past the bitcode header, |
| 44 /// since we don't know a priori if it's present, and we can't put bytes | 61 /// since we don't know a priori if it's present, and we can't put bytes |
| 45 /// back into the stream once we've read them. | 62 /// back into the stream once we've read them. |
| 46 bool dropLeadingBytes(size_t s); | 63 bool dropLeadingBytes(size_t s) override; |
| 47 | 64 |
| 48 /// If the data object size is known in advance, many of the operations can | 65 /// If the data object size is known in advance, many of the operations can |
| 49 /// be made more efficient, so this method should be called before reading | 66 /// be made more efficient, so this method should be called before reading |
| 50 /// starts (although it can be called anytime). | 67 /// starts (although it can be called anytime). |
| 51 void setKnownObjectSize(size_t size); | 68 void setKnownObjectSize(size_t size) override; |
| 52 | 69 |
| 53 private: | 70 private: |
| 54 const static uint32_t kChunkSize = 4096 * 4; | 71 const static uint32_t kChunkSize = 4096 * 4; |
| 55 mutable std::vector<unsigned char> Bytes; | 72 mutable std::vector<unsigned char> Bytes; |
| 56 std::unique_ptr<DataStreamer> Streamer; | 73 std::unique_ptr<DataStreamer> Streamer; |
| 57 mutable size_t BytesRead; // Bytes read from stream | 74 mutable size_t BytesRead; // Bytes read from stream |
| 58 size_t BytesSkipped;// Bytes skipped at start of stream (e.g. wrapper/header) | 75 size_t BytesSkipped;// Bytes skipped at start of stream (e.g. wrapper/header) |
| 59 mutable size_t ObjectSize; // 0 if unknown, set if wrapper seen or EOF reached | 76 mutable size_t ObjectSize; // 0 if unknown, set if wrapper seen or EOF reached |
| 60 mutable bool EOFReached; | 77 mutable bool EOFReached; |
| 61 | 78 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 74 BytesRead += bytes; | 91 BytesRead += bytes; |
| 75 if (bytes != kChunkSize) { // reached EOF/ran out of bytes | 92 if (bytes != kChunkSize) { // reached EOF/ran out of bytes |
| 76 ObjectSize = BytesRead; | 93 ObjectSize = BytesRead; |
| 77 EOFReached = true; | 94 EOFReached = true; |
| 78 break; | 95 break; |
| 79 } | 96 } |
| 80 } | 97 } |
| 81 return Pos < BytesRead; | 98 return Pos < BytesRead; |
| 82 } | 99 } |
| 83 | 100 |
| 84 StreamingMemoryObject(const StreamingMemoryObject&) LLVM_DELETED_FUNCTION; | 101 StreamingMemoryObjectImpl( |
| 85 void operator=(const StreamingMemoryObject&) LLVM_DELETED_FUNCTION; | 102 const StreamingMemoryObjectImpl&) LLVM_DELETED_FUNCTION; |
| 103 void operator=( |
| 104 const StreamingMemoryObjectImpl&) LLVM_DELETED_FUNCTION; |
| 86 }; | 105 }; |
| 87 | 106 |
| 88 MemoryObject *getNonStreamedMemoryObject( | 107 MemoryObject *getNonStreamedMemoryObject( |
| 89 const unsigned char *Start, const unsigned char *End); | 108 const unsigned char *Start, const unsigned char *End); |
| 90 | 109 |
| 91 } | 110 } |
| 92 #endif // STREAMINGMEMORYOBJECT_H_ | 111 #endif // STREAMINGMEMORYOBJECT_H_ |
| OLD | NEW |