mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-15 21:24:00 +00:00
[python-bindings] Added code for loading a module from bitcode, getset its datalayout, getset its target, dump it, print it to a file.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190458 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
31
bindings/python/llvm/bit_reader.py
Normal file
31
bindings/python/llvm/bit_reader.py
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
from .common import LLVMObject
|
||||
from .common import c_object_p
|
||||
from .common import get_library
|
||||
from . import enumerations
|
||||
from .core import MemoryBuffer
|
||||
from .core import Module
|
||||
from .core import OpCode
|
||||
from ctypes import POINTER
|
||||
from ctypes import byref
|
||||
from ctypes import c_char_p
|
||||
from ctypes import cast
|
||||
__all__ = ['parse_bitcode']
|
||||
lib = get_library()
|
||||
|
||||
def parse_bitcode(mem_buffer):
|
||||
"""Input is .core.MemoryBuffer"""
|
||||
module = c_object_p()
|
||||
out = c_char_p(None)
|
||||
result = lib.LLVMParseBitcode(mem_buffer, byref(module), byref(out))
|
||||
if result:
|
||||
raise RuntimeError('LLVM Error: %s' % out.value)
|
||||
m = Module(module)
|
||||
m.take_ownership(mem_buffer)
|
||||
return m
|
||||
|
||||
def register_library(library):
|
||||
library.LLVMParseBitcode.argtypes = [MemoryBuffer, POINTER(c_object_p), POINTER(c_char_p)]
|
||||
library.LLVMParseBitcode.restype = bool
|
||||
|
||||
register_library(lib)
|
Reference in New Issue
Block a user