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 get_library
13 from ctypes import POINTER
14 from ctypes import byref
15 from ctypes import c_char_p
16 from ctypes import c_void_p
25 class MemoryBuffer(object):
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)
47 self._as_parameter_ = self._memory
52 lib.LLVMDisposeMemoryBuffer(self._memory)
55 return self._as_parameter_
57 def release_ownership(self):
61 def register_library(library):
62 library.LLVMCreateMemoryBufferWithContentsOfFile.argtypes = [c_char_p,
63 POINTER(LLVMObject), POINTER(c_char_p)]
64 library.LLVMCreateMemoryBufferWithContentsOfFile.restype = bool
66 library.LLVMDisposeMemoryBuffer.argtypes = [c_void_p]