mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-12 17:32:19 +00:00
[python-bindings] Added bindings for LLVMContextRef and a test for creating a new context or getting the global context.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190457 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
8184ca673b
commit
6a63cd1281
@ -20,6 +20,7 @@ from ctypes import c_char_p
|
|||||||
__all__ = [
|
__all__ = [
|
||||||
"lib",
|
"lib",
|
||||||
"MemoryBuffer",
|
"MemoryBuffer",
|
||||||
|
"Context",
|
||||||
"PassRegistry"
|
"PassRegistry"
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -87,6 +88,19 @@ class MemoryBuffer(LLVMObject):
|
|||||||
def __len__(self):
|
def __len__(self):
|
||||||
return lib.LLVMGetBufferSize(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):
|
class PassRegistry(LLVMObject):
|
||||||
"""Represents an opaque pass registry object."""
|
"""Represents an opaque pass registry object."""
|
||||||
|
|
||||||
@ -139,6 +153,16 @@ def register_library(library):
|
|||||||
library.LLVMGetGlobalPassRegistry.argtypes = []
|
library.LLVMGetGlobalPassRegistry.argtypes = []
|
||||||
library.LLVMGetGlobalPassRegistry.restype = c_object_p
|
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
|
# 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)]
|
||||||
@ -153,6 +177,7 @@ def register_enumerations():
|
|||||||
OpCode.register(name, value)
|
OpCode.register(name, value)
|
||||||
|
|
||||||
def initialize_llvm():
|
def initialize_llvm():
|
||||||
|
c = Context.GetGlobalContext()
|
||||||
p = PassRegistry()
|
p = PassRegistry()
|
||||||
lib.LLVMInitializeCore(p)
|
lib.LLVMInitializeCore(p)
|
||||||
lib.LLVMInitializeTransformUtils(p)
|
lib.LLVMInitializeTransformUtils(p)
|
||||||
|
@ -2,6 +2,7 @@ from .base import TestBase
|
|||||||
from ..core import OpCode
|
from ..core import OpCode
|
||||||
from ..core import MemoryBuffer
|
from ..core import MemoryBuffer
|
||||||
from ..core import PassRegistry
|
from ..core import PassRegistry
|
||||||
|
from ..core import Context
|
||||||
|
|
||||||
class TestCore(TestBase):
|
class TestCore(TestBase):
|
||||||
def test_opcode(self):
|
def test_opcode(self):
|
||||||
@ -29,3 +30,6 @@ class TestCore(TestBase):
|
|||||||
|
|
||||||
def test_create_passregistry(self):
|
def test_create_passregistry(self):
|
||||||
PassRegistry()
|
PassRegistry()
|
||||||
|
|
||||||
|
def test_create_context(self):
|
||||||
|
Context.GetGlobalContext()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user