[llvm.py] Make ObjectFile destructor work
[oota-llvm.git] / bindings / python / llvm / common.py
1 #===- common.py - Python LLVM Bindings -----------------------*- python -*--===#
2 #
3 #                     The LLVM Compiler Infrastructure
4 #
5 # This file is distributed under the University of Illinois Open Source
6 # License. See LICENSE.TXT for details.
7 #
8 #===------------------------------------------------------------------------===#
9
10 from ctypes import POINTER
11 from ctypes import c_void_p
12 from ctypes import cdll
13
14 import ctypes.util
15
16 __all__ = [
17     'LLVMObject',
18     'find_library',
19     'get_library',
20 ]
21
22 LLVMObject = POINTER(c_void_p)
23
24 def find_library():
25     # FIXME should probably have build system define absolute path of shared
26     # library at install time.
27     for lib in ['LLVM-3.1svn', 'LLVM']:
28         result = ctypes.util.find_library(lib)
29         if result:
30             return result
31
32     # FIXME This is a local hack to ease development.
33     return "/usr/local/llvm/lib/libLLVM-3.1svn.so"
34
35 def get_library():
36     """Obtain a reference to the llvm library."""
37     lib = find_library()
38     if not lib:
39         raise Exception('LLVM shared library not found!')
40
41     return cdll.LoadLibrary(lib)