mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-09 11:25:55 +00:00
Return the number of read bytes in MemoryObject::readBytes.
Returning more information will allow BitstreamReader to be simplified a bit and changed to read 64 bits at a time. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@221794 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -341,7 +341,7 @@ public:
|
|||||||
// Read the next word from the stream.
|
// Read the next word from the stream.
|
||||||
uint8_t Array[sizeof(word_t)] = {0};
|
uint8_t Array[sizeof(word_t)] = {0};
|
||||||
|
|
||||||
BitStream->getBitcodeBytes().readBytes(NextChar, sizeof(Array), Array);
|
BitStream->getBitcodeBytes().readBytes(Array, sizeof(Array), NextChar);
|
||||||
|
|
||||||
// Handle big-endian byte-swapping if necessary.
|
// Handle big-endian byte-swapping if necessary.
|
||||||
support::detail::packed_endian_specific_integral
|
support::detail::packed_endian_specific_integral
|
||||||
|
@@ -36,18 +36,16 @@ public:
|
|||||||
virtual uint64_t getExtent() const = 0;
|
virtual uint64_t getExtent() const = 0;
|
||||||
|
|
||||||
/// Tries to read a contiguous range of bytes from the region, up to the end
|
/// Tries to read a contiguous range of bytes from the region, up to the end
|
||||||
/// of the region. You should override this function if there is a quicker way
|
/// of the region.
|
||||||
/// than going back and forth with individual bytes.
|
|
||||||
///
|
///
|
||||||
/// @param address - The address of the first byte, in the same space as
|
/// @param address - The address of the first byte, in the same space as
|
||||||
/// getBase().
|
/// getBase().
|
||||||
/// @param size - The number of bytes to copy.
|
/// @param size - The number of bytes to copy.
|
||||||
/// @param buf - A pointer to a buffer to be filled in. Must be non-NULL
|
/// @param buf - A pointer to a buffer to be filled in. Must be non-NULL
|
||||||
/// and large enough to hold size bytes.
|
/// and large enough to hold size bytes.
|
||||||
/// @result - 0 if successful; -1 if not. Failure may be due to a
|
/// @result - The number of bytes read.
|
||||||
/// bounds violation or an implementation-specific error.
|
virtual uint64_t readBytes(uint8_t *Buf, uint64_t Size,
|
||||||
virtual int readBytes(uint64_t address, uint64_t size,
|
uint64_t Address) const = 0;
|
||||||
uint8_t *buf) const = 0;
|
|
||||||
|
|
||||||
/// Ensures that the requested data is in memory, and returns a pointer to it.
|
/// Ensures that the requested data is in memory, and returns a pointer to it.
|
||||||
/// More efficient than using readBytes if the data is already in memory. May
|
/// More efficient than using readBytes if the data is already in memory. May
|
||||||
|
@@ -27,8 +27,8 @@ class StreamingMemoryObject : public MemoryObject {
|
|||||||
public:
|
public:
|
||||||
StreamingMemoryObject(DataStreamer *streamer);
|
StreamingMemoryObject(DataStreamer *streamer);
|
||||||
uint64_t getExtent() const override;
|
uint64_t getExtent() const override;
|
||||||
int readBytes(uint64_t address, uint64_t size,
|
uint64_t readBytes(uint8_t *Buf, uint64_t Size,
|
||||||
uint8_t *buf) const override;
|
uint64_t Address) const override;
|
||||||
const uint8_t *getPointer(uint64_t address, uint64_t size) const override {
|
const uint8_t *getPointer(uint64_t address, uint64_t size) const override {
|
||||||
// This could be fixed by ensuring the bytes are fetched and making a copy,
|
// This could be fixed by ensuring the bytes are fetched and making a copy,
|
||||||
// requiring that the bitcode size be known, or otherwise ensuring that
|
// requiring that the bitcode size be known, or otherwise ensuring that
|
||||||
|
@@ -3430,7 +3430,7 @@ std::error_code BitcodeReader::InitLazyStream() {
|
|||||||
Stream.init(&*StreamFile);
|
Stream.init(&*StreamFile);
|
||||||
|
|
||||||
unsigned char buf[16];
|
unsigned char buf[16];
|
||||||
if (Bytes->readBytes(0, 16, buf) == -1)
|
if (Bytes->readBytes(buf, 16, 0) != 16)
|
||||||
return Error(BitcodeError::InvalidBitcodeSignature);
|
return Error(BitcodeError::InvalidBitcodeSignature);
|
||||||
|
|
||||||
if (!isBitcode(buf, buf + 16))
|
if (!isBitcode(buf, buf + 16))
|
||||||
|
@@ -28,8 +28,8 @@ public:
|
|||||||
uint64_t getExtent() const override {
|
uint64_t getExtent() const override {
|
||||||
return LastChar - FirstChar;
|
return LastChar - FirstChar;
|
||||||
}
|
}
|
||||||
int readBytes(uint64_t address, uint64_t size,
|
uint64_t readBytes(uint8_t *Buf, uint64_t Size,
|
||||||
uint8_t *buf) const override;
|
uint64_t Address) const override;
|
||||||
const uint8_t *getPointer(uint64_t address, uint64_t size) const override;
|
const uint8_t *getPointer(uint64_t address, uint64_t size) const override;
|
||||||
bool isValidAddress(uint64_t address) const override {
|
bool isValidAddress(uint64_t address) const override {
|
||||||
return validAddress(address);
|
return validAddress(address);
|
||||||
@@ -55,12 +55,20 @@ private:
|
|||||||
void operator=(const RawMemoryObject&) LLVM_DELETED_FUNCTION;
|
void operator=(const RawMemoryObject&) LLVM_DELETED_FUNCTION;
|
||||||
};
|
};
|
||||||
|
|
||||||
int RawMemoryObject::readBytes(uint64_t address,
|
uint64_t RawMemoryObject::readBytes(uint8_t *Buf, uint64_t Size,
|
||||||
uint64_t size,
|
uint64_t Address) const {
|
||||||
uint8_t *buf) const {
|
uint64_t BufferSize = LastChar - FirstChar;
|
||||||
if (!validAddress(address) || !validAddress(address + size - 1)) return -1;
|
if (Address >= BufferSize)
|
||||||
memcpy(buf, (uint8_t *)(uintptr_t)(address + FirstChar), size);
|
return 0;
|
||||||
return size;
|
|
||||||
|
uint64_t End = Address + Size;
|
||||||
|
if (End > BufferSize)
|
||||||
|
End = BufferSize;
|
||||||
|
|
||||||
|
Size = End - Address;
|
||||||
|
assert(Size >= 0);
|
||||||
|
memcpy(Buf, (uint8_t *)(Address + FirstChar), Size);
|
||||||
|
return Size;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint8_t *RawMemoryObject::getPointer(uint64_t address,
|
const uint8_t *RawMemoryObject::getPointer(uint64_t address,
|
||||||
@@ -91,12 +99,20 @@ uint64_t StreamingMemoryObject::getExtent() const {
|
|||||||
return ObjectSize;
|
return ObjectSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
int StreamingMemoryObject::readBytes(uint64_t address,
|
uint64_t StreamingMemoryObject::readBytes(uint8_t *Buf, uint64_t Size,
|
||||||
uint64_t size,
|
uint64_t Address) const {
|
||||||
uint8_t *buf) const {
|
fetchToPos(Address + Size - 1);
|
||||||
if (!fetchToPos(address + size - 1)) return -1;
|
uint64_t BufferSize = Bytes.size() - BytesSkipped;
|
||||||
memcpy(buf, &Bytes[address + BytesSkipped], size);
|
if (Address >= BufferSize)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
uint64_t End = Address + Size;
|
||||||
|
if (End > BufferSize)
|
||||||
|
End = BufferSize;
|
||||||
|
Size = End - Address;
|
||||||
|
assert(Size >= 0);
|
||||||
|
memcpy(Buf, &Bytes[Address + BytesSkipped], Size);
|
||||||
|
return Size;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StreamingMemoryObject::dropLeadingBytes(size_t s) {
|
bool StreamingMemoryObject::dropLeadingBytes(size_t s) {
|
||||||
|
Reference in New Issue
Block a user