[python-bindings] Implemented the PassRegistry class and the calls to initialize...
authorMichael Gottesman <mgottesman@apple.com>
Wed, 11 Sep 2013 00:23:08 +0000 (00:23 +0000)
committerMichael Gottesman <mgottesman@apple.com>
Wed, 11 Sep 2013 00:23:08 +0000 (00:23 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190456 91177308-0d34-0410-b5e6-96231b3b80d8

bindings/python/llvm/core.py
bindings/python/llvm/tests/test_core.py

index bd61a6a..74be0ab 100644 (file)
@@ -20,6 +20,7 @@ from ctypes import c_char_p
 __all__ = [
     "lib",
     "MemoryBuffer",
+    "PassRegistry"
 ]
 
 lib = get_library()
@@ -86,7 +87,58 @@ class MemoryBuffer(LLVMObject):
     def __len__(self):
         return lib.LLVMGetBufferSize(self)
 
+class PassRegistry(LLVMObject):
+    """Represents an opaque pass registry object."""
+
+    def __init__(self):
+        LLVMObject.__init__(self,
+                            lib.LLVMGetGlobalPassRegistry())
+
 def register_library(library):
+    # Initialization/Shutdown declarations.
+    library.LLVMInitializeCore.argtypes = [PassRegistry]
+    library.LLVMInitializeCore.restype = None
+
+    library.LLVMInitializeTransformUtils.argtypes = [PassRegistry]
+    library.LLVMInitializeTransformUtils.restype = None
+
+    library.LLVMInitializeScalarOpts.argtypes = [PassRegistry]
+    library.LLVMInitializeScalarOpts.restype = None
+
+    library.LLVMInitializeObjCARCOpts.argtypes = [PassRegistry]
+    library.LLVMInitializeObjCARCOpts.restype = None
+
+    library.LLVMInitializeVectorization.argtypes = [PassRegistry]
+    library.LLVMInitializeVectorization.restype = None
+
+    library.LLVMInitializeInstCombine.argtypes = [PassRegistry]
+    library.LLVMInitializeInstCombine.restype = None
+
+    library.LLVMInitializeIPO.argtypes = [PassRegistry]
+    library.LLVMInitializeIPO.restype = None
+
+    library.LLVMInitializeInstrumentation.argtypes = [PassRegistry]
+    library.LLVMInitializeInstrumentation.restype = None
+
+    library.LLVMInitializeAnalysis.argtypes = [PassRegistry]
+    library.LLVMInitializeAnalysis.restype = None
+
+    library.LLVMInitializeIPA.argtypes = [PassRegistry]
+    library.LLVMInitializeIPA.restype = None
+
+    library.LLVMInitializeCodeGen.argtypes = [PassRegistry]
+    library.LLVMInitializeCodeGen.restype = None
+
+    library.LLVMInitializeTarget.argtypes = [PassRegistry]
+    library.LLVMInitializeTarget.restype = None
+
+    library.LLVMShutdown.argtypes = []
+    library.LLVMShutdown.restype = None
+
+    # Pass Registry declarations.
+    library.LLVMGetGlobalPassRegistry.argtypes = []
+    library.LLVMGetGlobalPassRegistry.restype = c_object_p
+
     # Memory buffer declarations
     library.LLVMCreateMemoryBufferWithContentsOfFile.argtypes = [c_char_p,
             POINTER(c_object_p), POINTER(c_char_p)]
@@ -100,5 +152,21 @@ def register_enumerations():
     for name, value in enumerations.OpCodes:
         OpCode.register(name, value)
 
+def initialize_llvm():
+    p = PassRegistry()
+    lib.LLVMInitializeCore(p)
+    lib.LLVMInitializeTransformUtils(p)
+    lib.LLVMInitializeScalarOpts(p)
+    lib.LLVMInitializeObjCARCOpts(p)
+    lib.LLVMInitializeVectorization(p)
+    lib.LLVMInitializeInstCombine(p)
+    lib.LLVMInitializeIPO(p)
+    lib.LLVMInitializeInstrumentation(p)
+    lib.LLVMInitializeAnalysis(p)
+    lib.LLVMInitializeIPA(p)
+    lib.LLVMInitializeCodeGen(p)
+    lib.LLVMInitializeTarget(p)
+
 register_library(lib)
 register_enumerations()
+initialize_llvm()
index bd792a1..3fdaf45 100644 (file)
@@ -1,6 +1,7 @@
 from .base import TestBase
 from ..core import OpCode
 from ..core import MemoryBuffer
+from ..core import PassRegistry
 
 class TestCore(TestBase):
     def test_opcode(self):
@@ -25,3 +26,6 @@ class TestCore(TestBase):
         source = self.get_test_file()
         m = MemoryBuffer(filename=source)
         self.assertEqual(len(m), 50)
+
+    def test_create_passregistry(self):
+        PassRegistry()