1 #===- core.py - Python LLVM Bindings -------------------------*- python -*--===#
3 # The LLVM Compiler Infrastructure
5 # This file is distributed under the University of Illinois Open Source
6 # License. See LICENSE.TXT for details.
8 #===------------------------------------------------------------------------===#
10 from .common import LLVMObject
11 from .common import c_object_p
12 from .common import get_library
14 from ctypes import POINTER
15 from ctypes import byref
16 from ctypes import c_char_p
25 class MemoryBuffer(LLVMObject):
26 """Represents an opaque memory buffer."""
28 def __init__(self, filename=None):
29 """Create a new memory buffer.
31 Currently, we support creating from the contents of a file at the
35 raise Exception("filename argument must be defined")
40 result = lib.LLVMCreateMemoryBufferWithContentsOfFile(filename,
41 byref(memory), byref(out))
44 raise Exception("Could not create memory buffer: %s" % out.value)
46 LLVMObject.__init__(self, memory, disposer=lib.LLVMDisposeMemoryBuffer)
48 def register_library(library):
49 library.LLVMCreateMemoryBufferWithContentsOfFile.argtypes = [c_char_p,
50 POINTER(c_object_p), POINTER(c_char_p)]
51 library.LLVMCreateMemoryBufferWithContentsOfFile.restype = bool
53 library.LLVMDisposeMemoryBuffer.argtypes = [MemoryBuffer]