Execution engine and passes work. Documentation and tests updated.

git-svn-id: http://llvm-py.googlecode.com/svn/trunk@4 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
mdevan.foobar 2008-06-07 13:44:25 +00:00
commit 2255a7e5dd
15 changed files with 559 additions and 396 deletions

View file

@ -1,12 +1,19 @@
"""Utility functions and classes.
Not for public use!"""
Used only in other modules, not for public use."""
import core
import llvm
#===----------------------------------------------------------------------===
# A set of helpers to check various things. Raises exceptions on
# failures.
#===----------------------------------------------------------------------===
def _check_gen(obj, type):
if not isinstance(obj, type):
msg = "argument must be an instance of llvm.core.%s (or of a class derived from it)" % type_str
msg = "argument not an instance of llvm.core.%s" % type_str
raise TypeError, msg
def check_is_type(obj): _check_gen(obj, core.Type)
@ -15,25 +22,54 @@ def check_is_pointer(obj): _check_gen(obj, core.Pointer)
def check_is_constant(obj): _check_gen(obj, core.Constant)
def check_is_function(obj): _check_gen(obj, core.Function)
def check_is_basic_block(obj): _check_gen(obj, core.BasicBlock)
def check_is_module(obj): _check_gen(obj, core.Module)
def check_is_module_provider(obj): _check_gen(obj, core.ModuleProvider)
def unpack_gen(objlist, check_fn):
def check_is_unowned(ownable):
if ownable.owner:
raise llvm.LLVMException, "object is already owned"
#===----------------------------------------------------------------------===
# A set of helpers to unpack a list of Python wrapper objects
# into a list of PyCObject wrapped objects, checking types along
# the way.
#===----------------------------------------------------------------------===
def _unpack_gen(objlist, check_fn):
for obj in objlist: check_fn(obj)
return [ obj.ptr for obj in objlist ]
def unpack_types(objlist): return unpack_gen(objlist, check_is_type)
def unpack_values(objlist): return unpack_gen(objlist, check_is_value)
def unpack_constants(objlist): return unpack_gen(objlist, check_is_constant)
def unpack_types(objlist): return _unpack_gen(objlist, check_is_type)
def unpack_values(objlist): return _unpack_gen(objlist, check_is_value)
def unpack_constants(objlist): return _unpack_gen(objlist, check_is_constant)
#===----------------------------------------------------------------------===
# Helper to wrap over iterables (LLVMFirstXXX, LLVMNextXXX). This used
# to be a generator, but that loses subscriptability of the result, so
# we now return a list.
#===----------------------------------------------------------------------===
def wrapiter(first, next, container, wrapper):
# ptr = first(container)
# while ptr:
# yield wrapper(ptr)
# ptr = next(ptr)
ret = []
ptr = first(container)
while ptr:
yield wrapper(ptr)
ret.append(wrapper(ptr))
ptr = next(ptr)
return ret
#===----------------------------------------------------------------------===
# Dummy owner, will not delete ownee. Be careful.
#===----------------------------------------------------------------------===
class dummy_owner(object):
def __init__(self, ownee):
ownee._own(self)