| OLD | NEW |
| 1 //===- StreamingMemoryObject.cpp - Streamable data interface -------------===// | 1 //===- StreamingMemoryObject.cpp - Streamable data interface -------------===// |
| 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 #include "llvm/Support/StreamingMemoryObject.h" | 10 #include "llvm/Support/StreamingMemoryObject.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 const uint8_t *RawMemoryObject::getPointer(uint64_t address, | 68 const uint8_t *RawMemoryObject::getPointer(uint64_t address, |
| 69 uint64_t size) const { | 69 uint64_t size) const { |
| 70 return FirstChar + address; | 70 return FirstChar + address; |
| 71 } | 71 } |
| 72 } // anonymous namespace | 72 } // anonymous namespace |
| 73 | 73 |
| 74 namespace llvm { | 74 namespace llvm { |
| 75 // If the bitcode has a header, then its size is known, and we don't have to | 75 // If the bitcode has a header, then its size is known, and we don't have to |
| 76 // block until we actually want to read it. | 76 // block until we actually want to read it. |
| 77 bool StreamingMemoryObject::isValidAddress(uint64_t address) const { | 77 // @LOCALMOD -- separated into Impl (revisit after merge) |
| 78 bool StreamingMemoryObjectImpl::isValidAddress(uint64_t address) const { |
| 78 if (ObjectSize && address < ObjectSize) return true; | 79 if (ObjectSize && address < ObjectSize) return true; |
| 79 return fetchToPos(address); | 80 return fetchToPos(address); |
| 80 } | 81 } |
| 81 | 82 |
| 82 uint64_t StreamingMemoryObject::getExtent() const { | 83 // @LOCALMOD -- separated into Impl |
| 84 uint64_t StreamingMemoryObjectImpl::getExtent() const { |
| 83 if (ObjectSize) return ObjectSize; | 85 if (ObjectSize) return ObjectSize; |
| 84 size_t pos = BytesRead + kChunkSize; | 86 size_t pos = BytesRead + kChunkSize; |
| 85 // keep fetching until we run out of bytes | 87 // keep fetching until we run out of bytes |
| 86 while (fetchToPos(pos)) pos += kChunkSize; | 88 while (fetchToPos(pos)) pos += kChunkSize; |
| 87 return ObjectSize; | 89 return ObjectSize; |
| 88 } | 90 } |
| 89 | 91 |
| 90 uint64_t StreamingMemoryObject::readBytes(uint8_t *Buf, uint64_t Size, | 92 // @LOCALMOD --separated into Impl |
| 93 uint64_t StreamingMemoryObjectImpl::readBytes(uint8_t *Buf, uint64_t Size, |
| 91 uint64_t Address) const { | 94 uint64_t Address) const { |
| 92 fetchToPos(Address + Size - 1); | 95 fetchToPos(Address + Size - 1); |
| 93 if (Address >= BytesRead) | 96 if (Address >= BytesRead) |
| 94 return 0; | 97 return 0; |
| 95 | 98 |
| 96 uint64_t End = Address + Size; | 99 uint64_t End = Address + Size; |
| 97 if (End > BytesRead) | 100 if (End > BytesRead) |
| 98 End = BytesRead; | 101 End = BytesRead; |
| 99 assert(static_cast<int64_t>(End - Address) >= 0); | 102 assert(static_cast<int64_t>(End - Address) >= 0); |
| 100 Size = End - Address; | 103 Size = End - Address; |
| 101 memcpy(Buf, &Bytes[Address + BytesSkipped], Size); | 104 memcpy(Buf, &Bytes[Address + BytesSkipped], Size); |
| 102 return Size; | 105 return Size; |
| 103 } | 106 } |
| 104 | 107 |
| 105 bool StreamingMemoryObject::dropLeadingBytes(size_t s) { | 108 // @LOCALMOD -- separated into Impl |
| 109 bool StreamingMemoryObjectImpl::dropLeadingBytes(size_t s) { |
| 106 if (BytesRead < s) return true; | 110 if (BytesRead < s) return true; |
| 107 BytesSkipped = s; | 111 BytesSkipped = s; |
| 108 BytesRead -= s; | 112 BytesRead -= s; |
| 109 return false; | 113 return false; |
| 110 } | 114 } |
| 111 | 115 |
| 112 void StreamingMemoryObject::setKnownObjectSize(size_t size) { | 116 // @LOCALMOD -- separated into Impl |
| 117 void StreamingMemoryObjectImpl::setKnownObjectSize(size_t size) { |
| 113 ObjectSize = size; | 118 ObjectSize = size; |
| 114 Bytes.reserve(size); | 119 Bytes.reserve(size); |
| 115 } | 120 } |
| 116 | 121 |
| 117 MemoryObject *getNonStreamedMemoryObject(const unsigned char *Start, | 122 MemoryObject *getNonStreamedMemoryObject(const unsigned char *Start, |
| 118 const unsigned char *End) { | 123 const unsigned char *End) { |
| 119 return new RawMemoryObject(Start, End); | 124 return new RawMemoryObject(Start, End); |
| 120 } | 125 } |
| 121 | 126 |
| 122 StreamingMemoryObject::StreamingMemoryObject(DataStreamer *streamer) : | 127 // @LOCALMOD -- separated into Impl |
| 128 StreamingMemoryObjectImpl::StreamingMemoryObjectImpl( |
| 129 DataStreamer *streamer) : |
| 123 Bytes(kChunkSize), Streamer(streamer), BytesRead(0), BytesSkipped(0), | 130 Bytes(kChunkSize), Streamer(streamer), BytesRead(0), BytesSkipped(0), |
| 124 ObjectSize(0), EOFReached(false) { | 131 ObjectSize(0), EOFReached(false) { |
| 125 BytesRead = streamer->GetBytes(&Bytes[0], kChunkSize); | 132 BytesRead = streamer->GetBytes(&Bytes[0], kChunkSize); |
| 126 } | 133 } |
| 127 } | 134 } |
| OLD | NEW |