[llvm] r182636 - Remove the Copied parameter from MemoryObject::readBytes.

Ahmed Bougacha ahmed.bougacha at gmail.com
Fri May 24 09:16:35 PDT 2013


Thanks for the welcome change, Benjamin!
-- Ahmed Bougacha


On Fri, May 24, 2013 at 3:54 AM, Benjamin Kramer
<benny.kra at googlemail.com> wrote:
> Author: d0k
> Date: Fri May 24 05:54:58 2013
> New Revision: 182636
>
> URL: http://llvm.org/viewvc/llvm-project?rev=182636&view=rev
> Log:
> 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.
>
> Modified:
>     llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
>     llvm/trunk/include/llvm/Support/MemoryObject.h
>     llvm/trunk/include/llvm/Support/StreamableMemoryObject.h
>     llvm/trunk/include/llvm/Support/StringRefMemoryObject.h
>     llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
>     llvm/trunk/lib/Support/MemoryObject.cpp
>     llvm/trunk/lib/Support/StreamableMemoryObject.cpp
>     llvm/trunk/lib/Support/StringRefMemoryObject.cpp
>     llvm/trunk/lib/Target/AArch64/Disassembler/AArch64Disassembler.cpp
>     llvm/trunk/lib/Target/ARM/Disassembler/ARMDisassembler.cpp
>     llvm/trunk/lib/Target/MBlaze/Disassembler/MBlazeDisassembler.cpp
>     llvm/trunk/lib/Target/Mips/Disassembler/MipsDisassembler.cpp
>     llvm/trunk/lib/Target/SystemZ/Disassembler/SystemZDisassembler.cpp
>     llvm/trunk/lib/Target/XCore/Disassembler/XCoreDisassembler.cpp
>
> Modified: llvm/trunk/include/llvm/Bitcode/BitstreamReader.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Bitcode/BitstreamReader.h?rev=182636&r1=182635&r2=182636&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Bitcode/BitstreamReader.h (original)
> +++ llvm/trunk/include/llvm/Bitcode/BitstreamReader.h Fri May 24 05:54:58 2013
> @@ -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
>
> Modified: llvm/trunk/include/llvm/Support/MemoryObject.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/MemoryObject.h?rev=182636&r1=182635&r2=182636&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Support/MemoryObject.h (original)
> +++ llvm/trunk/include/llvm/Support/MemoryObject.h Fri May 24 05:54:58 2013
> @@ -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;
>  };
>
>  }
>
> Modified: llvm/trunk/include/llvm/Support/StreamableMemoryObject.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/StreamableMemoryObject.h?rev=182636&r1=182635&r2=182636&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Support/StreamableMemoryObject.h (original)
> +++ llvm/trunk/include/llvm/Support/StreamableMemoryObject.h Fri May 24 05:54:58 2013
> @@ -38,7 +38,7 @@ class StreamableMemoryObject : public Me
>    /// 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 Me
>    ///                   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 Me
>    /// @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 Me
>    ///
>    /// @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,
>
> Modified: llvm/trunk/include/llvm/Support/StringRefMemoryObject.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/StringRefMemoryObject.h?rev=182636&r1=182635&r2=182636&view=diff
> ==============================================================================
> --- llvm/trunk/include/llvm/Support/StringRefMemoryObject.h (original)
> +++ llvm/trunk/include/llvm/Support/StringRefMemoryObject.h Fri May 24 05:54:58 2013
> @@ -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;
>  };
>
>  }
>
> Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=182636&r1=182635&r2=182636&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
> +++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Fri May 24 05:54:58 2013
> @@ -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))
>
> Modified: llvm/trunk/lib/Support/MemoryObject.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/MemoryObject.cpp?rev=182636&r1=182635&r2=182636&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/MemoryObject.cpp (original)
> +++ llvm/trunk/lib/Support/MemoryObject.cpp Fri May 24 05:54:58 2013
> @@ -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 add
>      current++;
>    }
>
> -  if (copied)
> -    *copied = current - address;
> -
>    return 0;
>  }
>
> Modified: llvm/trunk/lib/Support/StreamableMemoryObject.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/StreamableMemoryObject.cpp?rev=182636&r1=182635&r2=182636&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/StreamableMemoryObject.cpp (original)
> +++ llvm/trunk/lib/Support/StreamableMemoryObject.cpp Fri May 24 05:54:58 2013
> @@ -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 a
>
>  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(uint
>
>  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;
>  }
>
>
> Modified: llvm/trunk/lib/Support/StringRefMemoryObject.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/StringRefMemoryObject.cpp?rev=182636&r1=182635&r2=182636&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/StringRefMemoryObject.cpp (original)
> +++ llvm/trunk/lib/Support/StringRefMemoryObject.cpp Fri May 24 05:54:58 2013
> @@ -20,15 +20,10 @@ int StringRefMemoryObject::readByte(uint
>
>  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;
>  }
>
> Modified: llvm/trunk/lib/Target/AArch64/Disassembler/AArch64Disassembler.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/Disassembler/AArch64Disassembler.cpp?rev=182636&r1=182635&r2=182636&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/AArch64/Disassembler/AArch64Disassembler.cpp (original)
> +++ llvm/trunk/lib/Target/AArch64/Disassembler/AArch64Disassembler.cpp Fri May 24 05:54:58 2013
> @@ -208,7 +208,7 @@ DecodeStatus AArch64Disassembler::getIns
>    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;
>    }
>
> Modified: llvm/trunk/lib/Target/ARM/Disassembler/ARMDisassembler.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/Disassembler/ARMDisassembler.cpp?rev=182636&r1=182635&r2=182636&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/ARM/Disassembler/ARMDisassembler.cpp (original)
> +++ llvm/trunk/lib/Target/ARM/Disassembler/ARMDisassembler.cpp Fri May 24 05:54:58 2013
> @@ -413,7 +413,7 @@ DecodeStatus ARMDisassembler::getInstruc
>           "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::getInstr
>           "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::getInstr
>    }
>
>    // 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;
>    }
>
> Modified: llvm/trunk/lib/Target/MBlaze/Disassembler/MBlazeDisassembler.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/MBlaze/Disassembler/MBlazeDisassembler.cpp?rev=182636&r1=182635&r2=182636&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/MBlaze/Disassembler/MBlazeDisassembler.cpp (original)
> +++ llvm/trunk/lib/Target/MBlaze/Disassembler/MBlazeDisassembler.cpp Fri May 24 05:54:58 2013
> @@ -501,14 +501,13 @@ MCDisassembler::DecodeStatus MBlazeDisas
>                                          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.
>
> Modified: llvm/trunk/lib/Target/Mips/Disassembler/MipsDisassembler.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/Disassembler/MipsDisassembler.cpp?rev=182636&r1=182635&r2=182636&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/Mips/Disassembler/MipsDisassembler.cpp (original)
> +++ llvm/trunk/lib/Target/Mips/Disassembler/MipsDisassembler.cpp Fri May 24 05:54:58 2013
> @@ -252,7 +252,7 @@ static DecodeStatus readInstruction32(co
>    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;
>    }
>
> Modified: llvm/trunk/lib/Target/SystemZ/Disassembler/SystemZDisassembler.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/SystemZ/Disassembler/SystemZDisassembler.cpp?rev=182636&r1=182635&r2=182636&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/SystemZ/Disassembler/SystemZDisassembler.cpp (original)
> +++ llvm/trunk/lib/Target/SystemZ/Disassembler/SystemZDisassembler.cpp Fri May 24 05:54:58 2013
> @@ -272,7 +272,7 @@ DecodeStatus SystemZDisassembler::getIns
>    // 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::getIns
>    }
>
>    // 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.
>
> Modified: llvm/trunk/lib/Target/XCore/Disassembler/XCoreDisassembler.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/XCore/Disassembler/XCoreDisassembler.cpp?rev=182636&r1=182635&r2=182636&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Target/XCore/Disassembler/XCoreDisassembler.cpp (original)
> +++ llvm/trunk/lib/Target/XCore/Disassembler/XCoreDisassembler.cpp Fri May 24 05:54:58 2013
> @@ -53,7 +53,7 @@ static bool readInstruction16(const Memo
>    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 Memo
>    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;
>    }
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list