mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 03:02:36 +01:00
Remove the Copied parameter from MemoryObject::readBytes.
There was exactly one caller using this API right, the others were relying on specific behavior of the default implementation. Since it's too hard to use it right just remove it and standardize on the default behavior. Defines away PR16132. llvm-svn: 182636
This commit is contained in:
parent
d428197ca5
commit
fcb0899e18
@ -244,7 +244,7 @@ public:
|
||||
|
||||
uint32_t getWord(size_t pos) {
|
||||
uint8_t buf[4] = { 0xFF, 0xFF, 0xFF, 0xFF };
|
||||
BitStream->getBitcodeBytes().readBytes(pos, sizeof(buf), buf, NULL);
|
||||
BitStream->getBitcodeBytes().readBytes(pos, sizeof(buf), buf);
|
||||
return *reinterpret_cast<support::ulittle32_t *>(buf);
|
||||
}
|
||||
|
||||
@ -366,8 +366,7 @@ public:
|
||||
// Read the next word from the stream.
|
||||
uint8_t Array[sizeof(word_t)] = {0};
|
||||
|
||||
BitStream->getBitcodeBytes().readBytes(NextChar, sizeof(Array),
|
||||
Array, NULL);
|
||||
BitStream->getBitcodeBytes().readBytes(NextChar, sizeof(Array), Array);
|
||||
|
||||
// Handle big-endian byte-swapping if necessary.
|
||||
support::detail::packed_endian_specific_integral
|
||||
|
@ -42,7 +42,7 @@ public:
|
||||
/// @param ptr - A pointer to a byte to be filled in. Must be non-NULL.
|
||||
/// @result - 0 if successful; -1 if not. Failure may be due to a
|
||||
/// bounds violation or an implementation-specific error.
|
||||
virtual int readByte(uint64_t address, uint8_t* ptr) const = 0;
|
||||
virtual int readByte(uint64_t address, uint8_t *ptr) const = 0;
|
||||
|
||||
/// readBytes - Tries to read a contiguous range of bytes from the
|
||||
/// region, up to the end of the region.
|
||||
@ -51,17 +51,12 @@ public:
|
||||
///
|
||||
/// @param address - The address of the first byte, in the same space as
|
||||
/// getBase().
|
||||
/// @param size - The maximum 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
|
||||
/// and large enough to hold size bytes.
|
||||
/// @param copied - A pointer to a nunber that is filled in with the number
|
||||
/// of bytes actually read. May be NULL.
|
||||
/// @result - 0 if successful; -1 if not. Failure may be due to a
|
||||
/// bounds violation or an implementation-specific error.
|
||||
virtual int readBytes(uint64_t address,
|
||||
uint64_t size,
|
||||
uint8_t* buf,
|
||||
uint64_t* copied) const;
|
||||
virtual int readBytes(uint64_t address, uint64_t size, uint8_t *buf) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class StreamableMemoryObject : public MemoryObject {
|
||||
/// getBase - Returns the lowest valid address in the region.
|
||||
///
|
||||
/// @result - The lowest valid address.
|
||||
virtual uint64_t getBase() const = 0;
|
||||
virtual uint64_t getBase() const LLVM_OVERRIDE = 0;
|
||||
|
||||
/// getExtent - Returns the size of the region in bytes. (The region is
|
||||
/// contiguous, so the highest valid address of the region
|
||||
@ -46,7 +46,7 @@ class StreamableMemoryObject : public MemoryObject {
|
||||
/// May block until all bytes in the stream have been read
|
||||
///
|
||||
/// @result - The size of the region.
|
||||
virtual uint64_t getExtent() const = 0;
|
||||
virtual uint64_t getExtent() const LLVM_OVERRIDE = 0;
|
||||
|
||||
/// readByte - Tries to read a single byte from the region.
|
||||
/// May block until (address - base) bytes have been read
|
||||
@ -54,7 +54,7 @@ class StreamableMemoryObject : public MemoryObject {
|
||||
/// @param ptr - A pointer to a byte to be filled in. Must be non-NULL.
|
||||
/// @result - 0 if successful; -1 if not. Failure may be due to a
|
||||
/// bounds violation or an implementation-specific error.
|
||||
virtual int readByte(uint64_t address, uint8_t* ptr) const = 0;
|
||||
virtual int readByte(uint64_t address, uint8_t *ptr) const LLVM_OVERRIDE = 0;
|
||||
|
||||
/// readBytes - Tries to read a contiguous range of bytes from the
|
||||
/// region, up to the end of the region.
|
||||
@ -65,17 +65,14 @@ class StreamableMemoryObject : public MemoryObject {
|
||||
///
|
||||
/// @param address - The address of the first byte, in the same space as
|
||||
/// getBase().
|
||||
/// @param size - The maximum 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
|
||||
/// and large enough to hold size bytes.
|
||||
/// @param copied - A pointer to a nunber that is filled in with the number
|
||||
/// of bytes actually read. May be NULL.
|
||||
/// @result - 0 if successful; -1 if not. Failure may be due to a
|
||||
/// bounds violation or an implementation-specific error.
|
||||
virtual int readBytes(uint64_t address,
|
||||
uint64_t size,
|
||||
uint8_t* buf,
|
||||
uint64_t* copied) const = 0;
|
||||
uint8_t *buf) const LLVM_OVERRIDE = 0;
|
||||
|
||||
/// getPointer - Ensures that the requested data is in memory, and returns
|
||||
/// A pointer to it. More efficient than using readBytes if the
|
||||
@ -110,11 +107,10 @@ public:
|
||||
StreamingMemoryObject(DataStreamer *streamer);
|
||||
virtual uint64_t getBase() const LLVM_OVERRIDE { return 0; }
|
||||
virtual uint64_t getExtent() const LLVM_OVERRIDE;
|
||||
virtual int readByte(uint64_t address, uint8_t* ptr) const LLVM_OVERRIDE;
|
||||
virtual int readByte(uint64_t address, uint8_t *ptr) const LLVM_OVERRIDE;
|
||||
virtual int readBytes(uint64_t address,
|
||||
uint64_t size,
|
||||
uint8_t* buf,
|
||||
uint64_t* copied) const LLVM_OVERRIDE;
|
||||
uint8_t *buf) const LLVM_OVERRIDE;
|
||||
virtual const uint8_t *getPointer(uint64_t address,
|
||||
uint64_t size) const LLVM_OVERRIDE {
|
||||
// This could be fixed by ensuring the bytes are fetched and making a copy,
|
||||
|
@ -16,6 +16,7 @@
|
||||
#define LLVM_SUPPORT_STRINGREFMEMORYOBJECT_H
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
#include "llvm/Support/MemoryObject.h"
|
||||
|
||||
namespace llvm {
|
||||
@ -28,13 +29,11 @@ public:
|
||||
StringRefMemoryObject(StringRef Bytes, uint64_t Base = 0)
|
||||
: Bytes(Bytes), Base(Base) {}
|
||||
|
||||
uint64_t getBase() const { return Base; }
|
||||
uint64_t getExtent() const { return Bytes.size(); }
|
||||
|
||||
int readByte(uint64_t Addr, uint8_t *Byte) const;
|
||||
int readBytes(uint64_t Addr, uint64_t Size,
|
||||
uint8_t *Buf, uint64_t *Copied) const;
|
||||
uint64_t getBase() const LLVM_OVERRIDE { return Base; }
|
||||
uint64_t getExtent() const LLVM_OVERRIDE { return Bytes.size(); }
|
||||
|
||||
int readByte(uint64_t Addr, uint8_t *Byte) const LLVM_OVERRIDE;
|
||||
int readBytes(uint64_t Addr, uint64_t Size, uint8_t *Buf) const LLVM_OVERRIDE;
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -3010,7 +3010,7 @@ bool BitcodeReader::InitLazyStream() {
|
||||
Stream.init(*StreamFile);
|
||||
|
||||
unsigned char buf[16];
|
||||
if (Bytes->readBytes(0, 16, buf, NULL) == -1)
|
||||
if (Bytes->readBytes(0, 16, buf) == -1)
|
||||
return Error("Bitcode stream must be at least 16 bytes in length");
|
||||
|
||||
if (!isBitcode(buf, buf + 16))
|
||||
|
@ -15,8 +15,7 @@ MemoryObject::~MemoryObject() {
|
||||
|
||||
int MemoryObject::readBytes(uint64_t address,
|
||||
uint64_t size,
|
||||
uint8_t* buf,
|
||||
uint64_t* copied) const {
|
||||
uint8_t* buf) const {
|
||||
uint64_t current = address;
|
||||
uint64_t limit = getBase() + getExtent();
|
||||
|
||||
@ -30,8 +29,5 @@ int MemoryObject::readBytes(uint64_t address,
|
||||
current++;
|
||||
}
|
||||
|
||||
if (copied)
|
||||
*copied = current - address;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -31,8 +31,7 @@ public:
|
||||
virtual int readByte(uint64_t address, uint8_t* ptr) const LLVM_OVERRIDE;
|
||||
virtual int readBytes(uint64_t address,
|
||||
uint64_t size,
|
||||
uint8_t* buf,
|
||||
uint64_t* copied) const LLVM_OVERRIDE;
|
||||
uint8_t *buf) const LLVM_OVERRIDE;
|
||||
virtual const uint8_t *getPointer(uint64_t address,
|
||||
uint64_t size) const LLVM_OVERRIDE;
|
||||
virtual bool isValidAddress(uint64_t address) const LLVM_OVERRIDE {
|
||||
@ -67,11 +66,9 @@ int RawMemoryObject::readByte(uint64_t address, uint8_t* ptr) const {
|
||||
|
||||
int RawMemoryObject::readBytes(uint64_t address,
|
||||
uint64_t size,
|
||||
uint8_t* buf,
|
||||
uint64_t* copied) const {
|
||||
uint8_t *buf) const {
|
||||
if (!validAddress(address) || !validAddress(address + size - 1)) return -1;
|
||||
memcpy(buf, (uint8_t *)(uintptr_t)(address + FirstChar), size);
|
||||
if (copied) *copied = size;
|
||||
return size;
|
||||
}
|
||||
|
||||
@ -111,11 +108,9 @@ int StreamingMemoryObject::readByte(uint64_t address, uint8_t* ptr) const {
|
||||
|
||||
int StreamingMemoryObject::readBytes(uint64_t address,
|
||||
uint64_t size,
|
||||
uint8_t* buf,
|
||||
uint64_t* copied) const {
|
||||
uint8_t *buf) const {
|
||||
if (!fetchToPos(address + size - 1)) return -1;
|
||||
memcpy(buf, &Bytes[address + BytesSkipped], size);
|
||||
if (copied) *copied = size;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -20,15 +20,10 @@ int StringRefMemoryObject::readByte(uint64_t Addr, uint8_t *Byte) const {
|
||||
|
||||
int StringRefMemoryObject::readBytes(uint64_t Addr,
|
||||
uint64_t Size,
|
||||
uint8_t *Buf,
|
||||
uint64_t *Copied) const {
|
||||
if (Addr >= Base + getExtent() || Addr < Base)
|
||||
return -1;
|
||||
uint8_t *Buf) const {
|
||||
uint64_t Offset = Addr - Base;
|
||||
if (Size > getExtent() - Offset)
|
||||
Size = getExtent() - Offset;
|
||||
if (Addr >= Base + getExtent() || Offset + Size > getExtent() || Addr < Base)
|
||||
return -1;
|
||||
memcpy(Buf, Bytes.data() + Offset, Size);
|
||||
if (Copied)
|
||||
*Copied = Size;
|
||||
return 0;
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ DecodeStatus AArch64Disassembler::getInstruction(MCInst &MI, uint64_t &Size,
|
||||
uint8_t bytes[4];
|
||||
|
||||
// We want to read exactly 4 bytes of data.
|
||||
if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1) {
|
||||
if (Region.readBytes(Address, 4, bytes) == -1) {
|
||||
Size = 0;
|
||||
return MCDisassembler::Fail;
|
||||
}
|
||||
|
@ -413,7 +413,7 @@ DecodeStatus ARMDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
|
||||
"Asked to disassemble an ARM instruction but Subtarget is in Thumb mode!");
|
||||
|
||||
// We want to read exactly 4 bytes of data.
|
||||
if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1) {
|
||||
if (Region.readBytes(Address, 4, bytes) == -1) {
|
||||
Size = 0;
|
||||
return MCDisassembler::Fail;
|
||||
}
|
||||
@ -659,7 +659,7 @@ DecodeStatus ThumbDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
|
||||
"Asked to disassemble in Thumb mode but Subtarget is in ARM mode!");
|
||||
|
||||
// We want to read exactly 2 bytes of data.
|
||||
if (Region.readBytes(Address, 2, (uint8_t*)bytes, NULL) == -1) {
|
||||
if (Region.readBytes(Address, 2, bytes) == -1) {
|
||||
Size = 0;
|
||||
return MCDisassembler::Fail;
|
||||
}
|
||||
@ -711,7 +711,7 @@ DecodeStatus ThumbDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
|
||||
}
|
||||
|
||||
// We want to read exactly 4 bytes of data.
|
||||
if (Region.readBytes(Address, 4, (uint8_t*)bytes, NULL) == -1) {
|
||||
if (Region.readBytes(Address, 4, bytes) == -1) {
|
||||
Size = 0;
|
||||
return MCDisassembler::Fail;
|
||||
}
|
||||
|
@ -501,14 +501,13 @@ MCDisassembler::DecodeStatus MBlazeDisassembler::getInstruction(MCInst &instr,
|
||||
raw_ostream &cStream) const {
|
||||
// The machine instruction.
|
||||
uint32_t insn;
|
||||
uint64_t read;
|
||||
uint8_t bytes[4];
|
||||
|
||||
// By default we consume 1 byte on failure
|
||||
size = 1;
|
||||
|
||||
// We want to read exactly 4 bytes of data.
|
||||
if (region.readBytes(address, 4, (uint8_t*)bytes, &read) == -1 || read < 4)
|
||||
if (region.readBytes(address, 4, bytes) == -1)
|
||||
return Fail;
|
||||
|
||||
// Encoded as a big-endian 32-bit word in the stream.
|
||||
|
@ -252,7 +252,7 @@ static DecodeStatus readInstruction32(const MemoryObject ®ion,
|
||||
uint8_t Bytes[4];
|
||||
|
||||
// We want to read exactly 4 Bytes of data.
|
||||
if (region.readBytes(address, 4, (uint8_t*)Bytes, NULL) == -1) {
|
||||
if (region.readBytes(address, 4, Bytes) == -1) {
|
||||
size = 0;
|
||||
return MCDisassembler::Fail;
|
||||
}
|
||||
|
@ -272,7 +272,7 @@ DecodeStatus SystemZDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
|
||||
// Get the first two bytes of the instruction.
|
||||
uint8_t Bytes[6];
|
||||
Size = 0;
|
||||
if (Region.readBytes(Address, 2, Bytes, 0) == -1)
|
||||
if (Region.readBytes(Address, 2, Bytes) == -1)
|
||||
return MCDisassembler::Fail;
|
||||
|
||||
// The top 2 bits of the first byte specify the size.
|
||||
@ -289,7 +289,7 @@ DecodeStatus SystemZDisassembler::getInstruction(MCInst &MI, uint64_t &Size,
|
||||
}
|
||||
|
||||
// Read any remaining bytes.
|
||||
if (Size > 2 && Region.readBytes(Address + 2, Size - 2, Bytes + 2, 0) == -1)
|
||||
if (Size > 2 && Region.readBytes(Address + 2, Size - 2, Bytes + 2) == -1)
|
||||
return MCDisassembler::Fail;
|
||||
|
||||
// Construct the instruction.
|
||||
|
@ -53,7 +53,7 @@ static bool readInstruction16(const MemoryObject ®ion,
|
||||
uint8_t Bytes[4];
|
||||
|
||||
// We want to read exactly 2 Bytes of data.
|
||||
if (region.readBytes(address, 2, Bytes, NULL) == -1) {
|
||||
if (region.readBytes(address, 2, Bytes) == -1) {
|
||||
size = 0;
|
||||
return false;
|
||||
}
|
||||
@ -69,7 +69,7 @@ static bool readInstruction32(const MemoryObject ®ion,
|
||||
uint8_t Bytes[4];
|
||||
|
||||
// We want to read exactly 4 Bytes of data.
|
||||
if (region.readBytes(address, 4, Bytes, NULL) == -1) {
|
||||
if (region.readBytes(address, 4, Bytes) == -1) {
|
||||
size = 0;
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user