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);
}
// 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
/// @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.
///
/// @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;
};
}
/// 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
/// 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
/// @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.
///
/// @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
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,
#define LLVM_SUPPORT_STRINGREFMEMORYOBJECT_H
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Compiler.h"
#include "llvm/Support/MemoryObject.h"
namespace llvm {
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;
};
}
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))
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();
current++;
}
- if (copied)
- *copied = current - address;
-
return 0;
}
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 {
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;
}
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;
}
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;
}
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;
}
"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;
}
"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;
}
}
// 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;
}
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.
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;
}
// 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.
}
// 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.
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;
}
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;
}