Added GenericValue. EE.run() uses GVs now. Converted line endings in wrap.{c,h}.
git-svn-id: http://llvm-py.googlecode.com/svn/trunk@19 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
parent
0a8dc6a115
commit
01eb4a7133
5 changed files with 1051 additions and 942 deletions
65
llvm/ee.py
65
llvm/ee.py
|
|
@ -25,6 +25,53 @@ class TargetData(llvm.Ownable):
|
|||
return _core.LLVMTargetDataAsString(self.ptr)
|
||||
|
||||
|
||||
#===----------------------------------------------------------------------===
|
||||
# Generic value
|
||||
#===----------------------------------------------------------------------===
|
||||
|
||||
class GenericValue(object):
|
||||
|
||||
@staticmethod
|
||||
def int(ty, intval):
|
||||
check_is_type(ty)
|
||||
ptr = _core.LLVMCreateGenericValueOfInt(ty.ptr, intval, 0)
|
||||
return GenericValue(ptr)
|
||||
|
||||
@staticmethod
|
||||
def int_signed(ty, intval):
|
||||
check_is_type(ty)
|
||||
ptr = _core.LLVMCreateGenericValueOfInt(ty.ptr, intval, 1)
|
||||
return GenericValue(ptr)
|
||||
|
||||
@staticmethod
|
||||
def real(ty, floatval):
|
||||
check_is_type(ty) # only float or double
|
||||
ptr = _core.LLVMCreateGenericValueOfFloat(ty.ptr, floatval)
|
||||
return GenericValue(ptr)
|
||||
|
||||
def __init__(self, ptr):
|
||||
self.ptr = ptr
|
||||
|
||||
def __del__(self):
|
||||
_core.LLVMDisposeGenericValue(self.ptr)
|
||||
|
||||
def as_int(self):
|
||||
return _core.LLVMGenericValueToInt(self.ptr, 0)
|
||||
|
||||
def as_int_signed(self):
|
||||
return _core.LLVMGenericValueToInt(self.ptr, 1)
|
||||
|
||||
def as_real(self, ty):
|
||||
check_is_type(ty) # only float or double
|
||||
return _core.LLVMGenericValueToFloat(ty.ptr, self.ptr)
|
||||
|
||||
|
||||
# helper functions for generic value objects
|
||||
def _check_is_generic_value(obj): check_gen(obj, GenericValue)
|
||||
def _unpack_generic_values(objlist):
|
||||
return unpack_gen(objlist, _check_is_generic_value)
|
||||
|
||||
|
||||
#===----------------------------------------------------------------------===
|
||||
# Execution engine
|
||||
#===----------------------------------------------------------------------===
|
||||
|
|
@ -49,7 +96,23 @@ class ExecutionEngine(object):
|
|||
|
||||
def run_function(self, fn, args):
|
||||
check_is_function(fn)
|
||||
return _core.LLVMRunFunction(self.ptr, fn.ptr, args)
|
||||
ptrs = _unpack_generic_values(args)
|
||||
gvptr = _core.LLVMRunFunction2(self.ptr, fn.ptr, ptrs)
|
||||
return GenericValue(gvptr)
|
||||
|
||||
def run_static_ctors(self):
|
||||
_core.LLVMRunStaticConstructors(self.ptr)
|
||||
|
||||
def run_static_dtors(self):
|
||||
_core.LLVMRunStaticDestructors(self.ptr)
|
||||
|
||||
def free_machine_code_for(self, fn):
|
||||
check_is_function(fn)
|
||||
_core.LLVMFreeMachineCodeForFunction(self.ptr, fn.ptr)
|
||||
|
||||
def add_module_provider(self, mp):
|
||||
check_is_module_provider(mp)
|
||||
_core.LLVMAddModuleProvider(self.ptr, mp.ptr)
|
||||
|
||||
@property
|
||||
def target_data(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue