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 get_library
12 from ctypes import POINTER
13 from ctypes import byref
14 from ctypes import c_char_p
15 from ctypes import c_void_p
24 class MemoryBuffer(object):
25 """Represents an opaque memory buffer."""
27 def __init__(self, filename=None):
28 """Create a new memory buffer.
30 Currently, we support creating from the contents of a file at the
34 raise Exception("filename argument must be defined")
36 memory = c_void_p(None)
39 result = lib.LLVMCreateMemoryBufferWithContentsOfFile(filename,
40 byref(memory), byref(out))
43 raise Exception("Could not create memory buffer: %s" % out.value)
48 lib.LLVMDisposeMemoryBuffer(self._memory)
54 def register_library(library):
55 library.LLVMCreateMemoryBufferWithContentsOfFile.argtypes = [c_char_p,
56 POINTER(c_void_p), POINTER(c_char_p)]
57 library.LLVMCreateMemoryBufferWithContentsOfFile.restype = bool
59 library.LLVMDisposeMemoryBuffer.argtypes = [c_void_p]