Remove the Copied parameter from MemoryObject::readBytes.
authorBenjamin Kramer <benny.kra@googlemail.com>
Fri, 24 May 2013 10:54:58 +0000 (10:54 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Fri, 24 May 2013 10:54:58 +0000 (10:54 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182636 91177308-0d34-0410-b5e6-96231b3b80d8

14 files changed:
include/llvm/Bitcode/BitstreamReader.h
include/llvm/Support/MemoryObject.h
include/llvm/Support/StreamableMemoryObject.h
include/llvm/Support/StringRefMemoryObject.h
lib/Bitcode/Reader/BitcodeReader.cpp
lib/Support/MemoryObject.cpp
lib/Support/StreamableMemoryObject.cpp
lib/Support/StringRefMemoryObject.cpp
lib/Target/AArch64/Disassembler/AArch64Disassembler.cpp
lib/Target/ARM/Disassembler/ARMDisassembler.cpp
lib/Target/MBlaze/Disassembler/MBlazeDisassembler.cpp
lib/Target/Mips/Disassembler/MipsDisassembler.cpp
lib/Target/SystemZ/Disassembler/SystemZDisassembler.cpp
lib/Target/XCore/Disassembler/XCoreDisassembler.cpp

index f3139739cd18fd6be789821aa2cbe76e1db49d90..dc5e095155fb92c409e8e34b2da0ffc9b2b8bf6a 100644 (file)
@@ -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
index 732b0f077465d5cb8a8f8157039dc07c21ebbc54..17aa9d2f675a485104b10c76561485c185a38d6b 100644 (file)
@@ -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_tptr) 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;
 };
 
 }
index 385548579b1f20c1317323840f2ed200400f87b5..e823d489d3a81023cd7e12e826889a67c5a2c498 100644 (file)
@@ -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_tptr) 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,
index a0ef35a9e1db49da1689936a9ee3ab4cb74a6726..994fa34b74bb50398ef18f443a6cdcfab197deb1 100644 (file)
@@ -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;
 };
 
 }
index e6ff4b43b13225876fed600425fd8bd9ad095ace..cf827c5d4b08d89012514153d89881ac3813e10b 100644 (file)
@@ -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))
index b20ab8923813215845aa1a517505b95ddc319cd2..02b5b5034fbbe5fef132f1d7128aa0ee87eb39cb 100644 (file)
@@ -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;
 }
index 59e27a263e0605927080103350857e3707966a0b..2ed7c5c100a54b741f94d33c79fe5394607caecb 100644 (file)
@@ -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;
 }
 
index 5db11e918cd634d1e2ab7d319952f11d55230f9c..e035ed1d2ef31fd69a85b3e454a0647eafdca46f 100644 (file)
@@ -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;
 }
index 12c1b8f4c81a7872fa2464d08cc50961c633321f..1c397b5fa9688b56b3d7e6118e26b23d49a19138 100644 (file)
@@ -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;
   }
index 284761cf2950c3b575de6d8ea35957799210bf57..0a7d5eeb8709de2146f5ac55e4f171706a0e73eb 100644 (file)
@@ -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;
   }
index c03ab3803b6060fc0af109600d23e75eec01c267..0acfb3ec2a08ffc7bf80829834b16765bc4b46e2 100644 (file)
@@ -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.
index 0dba33a2767a270a45d53acc40b0d2db05d710f0..4af67037e970ad75b1cef0458143aea6a3dae270 100644 (file)
@@ -252,7 +252,7 @@ static DecodeStatus readInstruction32(const MemoryObject &region,
   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;
   }
index 9a9de7822409e69046d779bb4f8658050e3a366b..4e4816badab6d9df1f211031434d510969189bdd 100644 (file)
@@ -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.
index a2ae40c58a6ecc3ea39e385bdb3f45a968b46897..dcc0955028b2005bb30963efbed9e9080a4c2f9f 100644 (file)
@@ -53,7 +53,7 @@ static bool readInstruction16(const MemoryObject &region,
   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 &region,
   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;
   }