__all__ = [
"lib",
"MemoryBuffer",
+ "Context",
"PassRegistry"
]
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."""
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)]
OpCode.register(name, value)
def initialize_llvm():
+ c = Context.GetGlobalContext()
p = PassRegistry()
lib.LLVMInitializeCore(p)
lib.LLVMInitializeTransformUtils(p)
from ..core import OpCode
from ..core import MemoryBuffer
from ..core import PassRegistry
+from ..core import Context
class TestCore(TestBase):
def test_opcode(self):
def test_create_passregistry(self):
PassRegistry()
+
+ def test_create_context(self):
+ Context.GetGlobalContext()