From 81cbb207c8ead25b9001379a091b47c8849ed87a Mon Sep 17 00:00:00 2001 From: Michael Gottesman Date: Wed, 11 Sep 2013 00:23:08 +0000 Subject: [PATCH] [python-bindings] Implemented the PassRegistry class and the calls to initialize/shutdown llvm. Also included an initialize_llvm declaration. llvm-svn: 190456 --- bindings/python/llvm/core.py | 68 +++++++++++++++++++++++++ bindings/python/llvm/tests/test_core.py | 4 ++ 2 files changed, 72 insertions(+) diff --git a/bindings/python/llvm/core.py b/bindings/python/llvm/core.py index bd61a6ac993..74be0ab5525 100644 --- a/bindings/python/llvm/core.py +++ b/bindings/python/llvm/core.py @@ -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() diff --git a/bindings/python/llvm/tests/test_core.py b/bindings/python/llvm/tests/test_core.py index bd792a10330..3fdaf455fd4 100644 --- a/bindings/python/llvm/tests/test_core.py +++ b/bindings/python/llvm/tests/test_core.py @@ -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()