diff --git a/llvm/mc/__init__.py b/llvm/mc/__init__.py index 4b75801..da595ae 100644 --- a/llvm/mc/__init__.py +++ b/llvm/mc/__init__.py @@ -93,7 +93,7 @@ class Disassembler: #decode some bytes into instructions. yields each instruction #as it is decoded. def decode(self, bs): - code = api.llvm.BytesMemoryObject.new(bs) + code = api.llvm.StringRefMemoryObject.new(bs, 0) idx = code.getBase() while(idx < code.getExtent()): diff --git a/llvmpy/include/llvm_binding/extra.h b/llvmpy/include/llvm_binding/extra.h index 7911b21..a705d63 100644 --- a/llvmpy/include/llvm_binding/extra.h +++ b/llvmpy/include/llvm_binding/extra.h @@ -35,30 +35,6 @@ #include "auto_pyobject.h" -namespace llvm { - -class BytesMemoryObject : public MemoryObject { -private: - StringRef m_bytes; - -public: - BytesMemoryObject(StringRef bytes) { - m_bytes = bytes; - } - - uint64_t getBase() const { return 0; } - uint64_t getExtent() const { return (uint64_t) m_bytes.size(); } - - int readByte(uint64_t addr, uint8_t *byte) const { - if (addr >= getExtent()) - return -1; - *byte = (uint8_t) m_bytes[(size_t) addr]; - return 0; - } -}; - -} - namespace extra{ using namespace llvm; diff --git a/llvmpy/src/BytesMemoryObject.py b/llvmpy/src/BytesMemoryObject.py deleted file mode 100644 index 051425e..0000000 --- a/llvmpy/src/BytesMemoryObject.py +++ /dev/null @@ -1,17 +0,0 @@ -from binding import * -from .namespace import llvm -from .ADT.StringRef import StringRef - -MemoryObject = llvm.Class() -BytesMemoryObject = llvm.Class(MemoryObject) - -@MemoryObject -class MemoryObject: - pass - -@BytesMemoryObject -class BytesMemoryObject: - new = Constructor(cast(bytes, StringRef)) - - getBase = Method(cast(Uint64, int)) - getExtent = Method(cast(Uint64, int)) diff --git a/llvmpy/src/MC/__init__.py b/llvmpy/src/MC/__init__.py index e2824ba..ca3166a 100644 --- a/llvmpy/src/MC/__init__.py +++ b/llvmpy/src/MC/__init__.py @@ -1,6 +1,6 @@ from binding import * from ..namespace import llvm -from ..BytesMemoryObject import MemoryObject +from ..Support.StringRefMemoryObject import MemoryObject from ..Support.raw_ostream import raw_ostream MCSubtargetInfo = llvm.Class() diff --git a/llvmpy/src/Support/StringRefMemoryObject.py b/llvmpy/src/Support/StringRefMemoryObject.py new file mode 100644 index 0000000..583ef5f --- /dev/null +++ b/llvmpy/src/Support/StringRefMemoryObject.py @@ -0,0 +1,21 @@ +from binding import * +from ..namespace import llvm +from ..ADT.StringRef import StringRef + +MemoryObject = llvm.Class() +if LLVM_VERSION >= (3, 4): + StringRefMemoryObject = llvm.Class(MemoryObject) + +@MemoryObject +class MemoryObject: + pass + +if LLVM_VERSION >= (3, 4): + @StringRefMemoryObject + class StringRefMemoryObject: + _include_ = "llvm/Support/StringRefMemoryObject.h" + + new = Constructor(cast(bytes, StringRef), cast(int, Uint64)) + + getBase = Method(cast(Uint64, int)) + getExtent = Method(cast(Uint64, int))