[llvm] r221503 - Use a StringRefMemoryObject. NFC.

Rafael Avila de Espindola rafael.espindola at gmail.com
Thu Nov 6 18:50:45 PST 2014



Sent from my iPhone

> On Nov 6, 2014, at 20:24, Eric Christopher <echristo at gmail.com> wrote:
> 
> Out of curiosity, where are you going with this?
> 


Not sure yet.

I was trying to read 64 bits at a time in the bitcode reader.

I found that an issue was that we can have files that are not multiple of 64 bits. The existing api will not return the number of bytes read as a sane read method should.

Trying to change that I found quiet a few peculiar implementations and started removing them.

The use in getinstruction is also pretty odd. Even x86 has a maximum instruction size. We could probably pass a StringRef.

Any thoughts on it?



> -eric
> 
>> On Thu Nov 06 2014 at 5:23:12 PM Rafael Espindola <rafael.espindola at gmail.com> wrote:
>> Author: rafael
>> Date: Thu Nov  6 19:09:51 2014
>> New Revision: 221503
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=221503&view=rev
>> Log:
>> Use a StringRefMemoryObject. NFC.
>> 
>> Modified:
>>     llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp
>> 
>> Modified: llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp?rev=221503&r1=221502&r2=221503&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp (original)
>> +++ llvm/trunk/lib/MC/MCDisassembler/Disassembler.cpp Thu Nov  6 19:09:51 2014
>> @@ -21,7 +21,7 @@
>>  #include "llvm/MC/MCSymbolizer.h"
>>  #include "llvm/Support/ErrorHandling.h"
>>  #include "llvm/Support/FormattedStream.h"
>> -#include "llvm/Support/MemoryObject.h"
>> +#include "llvm/Support/StringRefMemoryObject.h"
>>  #include "llvm/Support/TargetRegistry.h"
>> 
>>  using namespace llvm;
>> @@ -122,30 +122,6 @@ void LLVMDisasmDispose(LLVMDisasmContext
>>    delete DC;
>>  }
>> 
>> -namespace {
>> -//
>> -// The memory object created by LLVMDisasmInstruction().
>> -//
>> -class DisasmMemoryObject : public MemoryObject {
>> -  uint8_t *Bytes;
>> -  uint64_t Size;
>> -  uint64_t BasePC;
>> -public:
>> -  DisasmMemoryObject(uint8_t *bytes, uint64_t size, uint64_t basePC) :
>> -                     Bytes(bytes), Size(size), BasePC(basePC) {}
>> -
>> -  uint64_t getBase() const override { return BasePC; }
>> -  uint64_t getExtent() const override { return Size; }
>> -
>> -  int readByte(uint64_t Addr, uint8_t *Byte) const override {
>> -    if (Addr - BasePC >= Size)
>> -      return -1;
>> -    *Byte = Bytes[Addr - BasePC];
>> -    return 0;
>> -  }
>> -};
>> -} // end anonymous namespace
>> -
>>  /// \brief Emits the comments that are stored in \p DC comment stream.
>>  /// Each comment in the comment stream must end with a newline.
>>  static void emitComments(LLVMDisasmContext *DC,
>> @@ -269,7 +245,8 @@ size_t LLVMDisasmInstruction(LLVMDisasmC
>>                               size_t OutStringSize){
>>    LLVMDisasmContext *DC = (LLVMDisasmContext *)DCR;
>>    // Wrap the pointer to the Bytes, BytesSize and PC in a MemoryObject.
>> -  DisasmMemoryObject MemoryObject(Bytes, BytesSize, PC);
>> +  StringRef Data((const char*) Bytes, BytesSize);
>> +  StringRefMemoryObject MemoryObject(Data, PC);
>> 
>>    uint64_t Size;
>>    MCInst Inst;
>> 
>> 
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141106/c4d78a5a/attachment.html>


More information about the llvm-commits mailing list