mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-26 20:26:07 +00:00
[python-bindings] Implemented the PassRegistry class and the calls to 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
This commit is contained in:
@@ -20,6 +20,7 @@ from ctypes import c_char_p
|
|||||||
__all__ = [
|
__all__ = [
|
||||||
"lib",
|
"lib",
|
||||||
"MemoryBuffer",
|
"MemoryBuffer",
|
||||||
|
"PassRegistry"
|
||||||
]
|
]
|
||||||
|
|
||||||
lib = get_library()
|
lib = get_library()
|
||||||
@@ -86,7 +87,58 @@ class MemoryBuffer(LLVMObject):
|
|||||||
def __len__(self):
|
def __len__(self):
|
||||||
return lib.LLVMGetBufferSize(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):
|
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
|
# Memory buffer declarations
|
||||||
library.LLVMCreateMemoryBufferWithContentsOfFile.argtypes = [c_char_p,
|
library.LLVMCreateMemoryBufferWithContentsOfFile.argtypes = [c_char_p,
|
||||||
POINTER(c_object_p), POINTER(c_char_p)]
|
POINTER(c_object_p), POINTER(c_char_p)]
|
||||||
@@ -100,5 +152,21 @@ def register_enumerations():
|
|||||||
for name, value in enumerations.OpCodes:
|
for name, value in enumerations.OpCodes:
|
||||||
OpCode.register(name, value)
|
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_library(lib)
|
||||||
register_enumerations()
|
register_enumerations()
|
||||||
|
initialize_llvm()
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
from .base import TestBase
|
from .base import TestBase
|
||||||
from ..core import OpCode
|
from ..core import OpCode
|
||||||
from ..core import MemoryBuffer
|
from ..core import MemoryBuffer
|
||||||
|
from ..core import PassRegistry
|
||||||
|
|
||||||
class TestCore(TestBase):
|
class TestCore(TestBase):
|
||||||
def test_opcode(self):
|
def test_opcode(self):
|
||||||
@@ -25,3 +26,6 @@ class TestCore(TestBase):
|
|||||||
source = self.get_test_file()
|
source = self.get_test_file()
|
||||||
m = MemoryBuffer(filename=source)
|
m = MemoryBuffer(filename=source)
|
||||||
self.assertEqual(len(m), 50)
|
self.assertEqual(len(m), 50)
|
||||||
|
|
||||||
|
def test_create_passregistry(self):
|
||||||
|
PassRegistry()
|
||||||
|
Reference in New Issue
Block a user