add BytesMemoryObject to extra.h and a binding for it in llvmpy/src
This commit is contained in:
parent
09d9dbba1e
commit
4905743e0a
2 changed files with 43 additions and 0 deletions
|
|
@ -29,11 +29,36 @@
|
|||
#include <llvm/Analysis/Verifier.h>
|
||||
#include <llvm/PassRegistry.h>
|
||||
#include <llvm/Support/Host.h>
|
||||
#include <llvm/Support/MemoryObject.h>
|
||||
|
||||
#include <llvm/ExecutionEngine/MCJIT.h> // to make MCJIT working
|
||||
|
||||
#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;
|
||||
|
||||
|
|
@ -984,3 +1009,4 @@ PyObject* llvm_sys_isBigEndianHost()
|
|||
Py_RETURN_FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
17
llvmpy/src/BytesMemoryObject.py
Normal file
17
llvmpy/src/BytesMemoryObject.py
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
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))
|
||||
Loading…
Add table
Add a link
Reference in a new issue