diff options
author | Michael Gottesman <mgottesman@apple.com> | 2013-09-11 00:23:10 +0000 |
---|---|---|
committer | Michael Gottesman <mgottesman@apple.com> | 2013-09-11 00:23:10 +0000 |
commit | b507e3ed8b368b7431dd20f08999d62db8c49fa9 (patch) | |
tree | a716189c9a3f1c1e1f8cbf39e2900c3306ee537c /llvm/bindings/python | |
parent | 41eee30cd79606683835982606dc9e4365bed2da (diff) | |
download | bcm5719-llvm-b507e3ed8b368b7431dd20f08999d62db8c49fa9.tar.gz bcm5719-llvm-b507e3ed8b368b7431dd20f08999d62db8c49fa9.zip |
[python-bindings] Added bindings for LLVMContextRef and a test for creating a new context or getting the global context.
llvm-svn: 190457
Diffstat (limited to 'llvm/bindings/python')
-rw-r--r-- | llvm/bindings/python/llvm/core.py | 25 | ||||
-rw-r--r-- | llvm/bindings/python/llvm/tests/test_core.py | 4 |
2 files changed, 29 insertions, 0 deletions
diff --git a/llvm/bindings/python/llvm/core.py b/llvm/bindings/python/llvm/core.py index 74be0ab5525..76d1b14e631 100644 --- a/llvm/bindings/python/llvm/core.py +++ b/llvm/bindings/python/llvm/core.py @@ -20,6 +20,7 @@ from ctypes import c_char_p __all__ = [ "lib", "MemoryBuffer", + "Context", "PassRegistry" ] @@ -87,6 +88,19 @@ class MemoryBuffer(LLVMObject): def __len__(self): return lib.LLVMGetBufferSize(self) +class Context(LLVMObject): + + def __init__(self, context=None): + if context is None: + context = lib.LLVMContextCreate() + LLVMObject.__init__(self, context, disposer=lib.LLVMContextDispose) + else: + LLVMObject.__init__(self, context) + + @classmethod + def GetGlobalContext(cls): + return Context(lib.LLVMGetGlobalContext()) + class PassRegistry(LLVMObject): """Represents an opaque pass registry object.""" @@ -139,6 +153,16 @@ def register_library(library): library.LLVMGetGlobalPassRegistry.argtypes = [] library.LLVMGetGlobalPassRegistry.restype = c_object_p + # Context declarations. + library.LLVMContextCreate.argtypes = [] + library.LLVMContextCreate.restype = c_object_p + + library.LLVMContextDispose.argtypes = [Context] + library.LLVMContextDispose.restype = None + + library.LLVMGetGlobalContext.argtypes = [] + library.LLVMGetGlobalContext.restype = c_object_p + # Memory buffer declarations library.LLVMCreateMemoryBufferWithContentsOfFile.argtypes = [c_char_p, POINTER(c_object_p), POINTER(c_char_p)] @@ -153,6 +177,7 @@ def register_enumerations(): OpCode.register(name, value) def initialize_llvm(): + c = Context.GetGlobalContext() p = PassRegistry() lib.LLVMInitializeCore(p) lib.LLVMInitializeTransformUtils(p) diff --git a/llvm/bindings/python/llvm/tests/test_core.py b/llvm/bindings/python/llvm/tests/test_core.py index 3fdaf455fd4..3364a66cb55 100644 --- a/llvm/bindings/python/llvm/tests/test_core.py +++ b/llvm/bindings/python/llvm/tests/test_core.py @@ -2,6 +2,7 @@ from .base import TestBase from ..core import OpCode from ..core import MemoryBuffer from ..core import PassRegistry +from ..core import Context class TestCore(TestBase): def test_opcode(self): @@ -29,3 +30,6 @@ class TestCore(TestBase): def test_create_passregistry(self): PassRegistry() + + def test_create_context(self): + Context.GetGlobalContext() |