summaryrefslogtreecommitdiff
path: root/bindings/python/llvm/core.py
diff options
context:
space:
mode:
authorGregory Szorc <gregory.szorc@gmail.com>2012-03-10 04:41:24 +0000
committerGregory Szorc <gregory.szorc@gmail.com>2012-03-10 04:41:24 +0000
commit61e22cd85cd4c84fff391da67018c92bf21a8e19 (patch)
tree9f3f6b06d25b5735247ea51b665ed16a858cab3b /bindings/python/llvm/core.py
parent51cf8661637c114e4b4f178bd2677a6bb246be0d (diff)
downloadllvm-61e22cd85cd4c84fff391da67018c92bf21a8e19.tar.gz
llvm-61e22cd85cd4c84fff391da67018c92bf21a8e19.tar.bz2
llvm-61e22cd85cd4c84fff391da67018c92bf21a8e19.tar.xz
[llvm.py] Implement interface to object files
It is now possible to load object files and scan over sections, symbols, and relocations! Includes test code with partial coverage. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152482 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings/python/llvm/core.py')
-rw-r--r--bindings/python/llvm/core.py27
1 files changed, 7 insertions, 20 deletions
diff --git a/bindings/python/llvm/core.py b/bindings/python/llvm/core.py
index bd9f8aaa2b..e0f35203ba 100644
--- a/bindings/python/llvm/core.py
+++ b/bindings/python/llvm/core.py
@@ -8,21 +8,21 @@
#===------------------------------------------------------------------------===#
from .common import LLVMObject
+from .common import c_object_p
from .common import get_library
from ctypes import POINTER
from ctypes import byref
from ctypes import c_char_p
-from ctypes import c_void_p
__all__ = [
"lib",
- "MemoryBufferRef",
+ "MemoryBuffer",
]
lib = get_library()
-class MemoryBuffer(object):
+class MemoryBuffer(LLVMObject):
"""Represents an opaque memory buffer."""
def __init__(self, filename=None):
@@ -34,7 +34,7 @@ class MemoryBuffer(object):
if filename is None:
raise Exception("filename argument must be defined")
- memory = LLVMObject()
+ memory = c_object_p()
out = c_char_p(None)
result = lib.LLVMCreateMemoryBufferWithContentsOfFile(filename,
@@ -43,26 +43,13 @@ class MemoryBuffer(object):
if result:
raise Exception("Could not create memory buffer: %s" % out.value)
- self._memory = memory
- self._as_parameter_ = self._memory
- self._owned = True
-
- def __del__(self):
- if self._owned:
- lib.LLVMDisposeMemoryBuffer(self._memory)
-
- def from_param(self):
- return self._as_parameter_
-
- def release_ownership(self):
- self._owned = False
-
+ LLVMObject.__init__(self, memory, disposer=lib.LLVMDisposeMemoryBuffer)
def register_library(library):
library.LLVMCreateMemoryBufferWithContentsOfFile.argtypes = [c_char_p,
- POINTER(LLVMObject), POINTER(c_char_p)]
+ POINTER(c_object_p), POINTER(c_char_p)]
library.LLVMCreateMemoryBufferWithContentsOfFile.restype = bool
- library.LLVMDisposeMemoryBuffer.argtypes = [c_void_p]
+ library.LLVMDisposeMemoryBuffer.argtypes = [MemoryBuffer]
register_library(lib)