Skip to content

Commit

Permalink
[python-bindings] Implemented the PassRegistry class and the calls to…
Browse files Browse the repository at this point in the history
… initialize/shutdown llvm. Also included an initialize_llvm declaration.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190456 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
gottesmm committed Sep 11, 2013
1 parent 699f8c3 commit 8184ca6
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
68 changes: 68 additions & 0 deletions bindings/python/llvm/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
__all__ = [
"lib",
"MemoryBuffer",
"PassRegistry"
]

lib = get_library()
Expand Down Expand Up @@ -86,7 +87,58 @@ def __init__(self, filename=None):
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)]
Expand All @@ -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()
4 changes: 4 additions & 0 deletions bindings/python/llvm/tests/test_core.py
Original file line number Diff line number Diff line change
@@ -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):
Expand All @@ -25,3 +26,6 @@ def test_memory_buffer_len(self):
source = self.get_test_file()
m = MemoryBuffer(filename=source)
self.assertEqual(len(m), 50)

def test_create_passregistry(self):
PassRegistry()

0 comments on commit 8184ca6

Please sign in to comment.