Add bindings for Pass, PassManagers, PassManagerBuilder and TargetLibraryInfo.
This commit is contained in:
parent
9485d03e18
commit
372d6804e4
7 changed files with 192 additions and 4 deletions
|
|
@ -195,6 +195,8 @@ class Enum(object):
|
|||
|
||||
def __init__(self, *value_names):
|
||||
self.parent = None
|
||||
if len(value_names) == 1:
|
||||
value_names = filter(bool, value_names[0].replace(',', ' ').split())
|
||||
self.value_names = value_names
|
||||
self.includes = set()
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,9 @@ from Module import Module
|
|||
from Type import Type, IntegerType, StructType
|
||||
from SmallVector import SmallVector_Value
|
||||
from GlobalVariable import GlobalVariable
|
||||
from Pass import ImmutablePass
|
||||
|
||||
DataLayout = llvm.Class()
|
||||
DataLayout = llvm.Class(ImmutablePass)
|
||||
StructLayout = llvm.Class()
|
||||
|
||||
@DataLayout
|
||||
|
|
@ -24,8 +25,6 @@ class DataLayout:
|
|||
else:
|
||||
return DataLayout._new_string(arg)
|
||||
|
||||
delete = Destructor()
|
||||
|
||||
isLittleEndian = Method(cast(Bool, bool))
|
||||
isBigEndian = Method(cast(Bool, bool))
|
||||
|
||||
|
|
|
|||
35
newbinding/src/Pass.py
Normal file
35
newbinding/src/Pass.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
from binding import *
|
||||
from namespace import llvm
|
||||
from StringRef import StringRef
|
||||
from Module import Module
|
||||
from Function import Function
|
||||
|
||||
Pass = llvm.Class()
|
||||
ModulePass = llvm.Class(Pass)
|
||||
FunctionPass = llvm.Class(Pass)
|
||||
ImmutablePass = llvm.Class(ModulePass)
|
||||
|
||||
|
||||
@Pass
|
||||
class Pass:
|
||||
_include_ = 'llvm/Pass.h'
|
||||
|
||||
delete = Destructor()
|
||||
getPassName = Method(cast(StringRef, str))
|
||||
|
||||
|
||||
@ModulePass
|
||||
class ModulePass:
|
||||
runOnModule = Method(cast(Bool, bool), ref(Module))
|
||||
|
||||
|
||||
@FunctionPass
|
||||
class FunctionPass:
|
||||
doInitialization = Method(cast(Bool, bool), ref(Module))
|
||||
doFinalization = Method(cast(Bool, bool), ref(Module))
|
||||
|
||||
|
||||
@ImmutablePass
|
||||
class ImmutablePass:
|
||||
pass
|
||||
|
||||
34
newbinding/src/PassManager.py
Normal file
34
newbinding/src/PassManager.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
from binding import *
|
||||
from namespace import llvm
|
||||
from Pass import Pass
|
||||
from Module import Module
|
||||
from Function import Function
|
||||
|
||||
PassManagerBase = llvm.Class()
|
||||
PassManager = llvm.Class(PassManagerBase)
|
||||
FunctionPassManager = llvm.Class(PassManagerBase)
|
||||
|
||||
@PassManagerBase
|
||||
class PassManagerBase:
|
||||
_include_ = 'llvm/PassManager.h'
|
||||
|
||||
delete = Destructor()
|
||||
|
||||
add = Method(Void, ownedptr(Pass))
|
||||
|
||||
@PassManager
|
||||
class PassManager:
|
||||
new = Constructor()
|
||||
|
||||
run = Method(cast(Bool, bool), ref(Module))
|
||||
|
||||
|
||||
@FunctionPassManager
|
||||
class FunctionPassManager:
|
||||
new = Constructor(ptr(Module))
|
||||
|
||||
run = Method(cast(Bool, bool), ref(Function))
|
||||
|
||||
doInitialization = Method(cast(Bool, bool))
|
||||
doFinalization = Method(cast(Bool, bool))
|
||||
|
||||
19
newbinding/src/PassManagerBuilder.py
Normal file
19
newbinding/src/PassManagerBuilder.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
from binding import *
|
||||
from namespace import llvm
|
||||
from PassManager import PassManagerBase, FunctionPassManager
|
||||
|
||||
@llvm.Class()
|
||||
class PassManagerBuilder:
|
||||
_include_ = 'llvm/Transforms/IPO/PassManagerBuilder.h'
|
||||
|
||||
new = Constructor()
|
||||
delete = Destructor()
|
||||
|
||||
populateFunctionPassManager = Method(Void, ref(FunctionPassManager))
|
||||
populateModulePassManager = Method(Void, ref(PassManagerBase))
|
||||
populateLTOPassManager = Method(Void,
|
||||
ref(PassManagerBase),
|
||||
cast(bool, Bool),
|
||||
cast(bool, Bool),
|
||||
cast(bool, Bool)).require_only(3)
|
||||
|
||||
76
newbinding/src/TargetLibraryInfo.py
Normal file
76
newbinding/src/TargetLibraryInfo.py
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
from binding import *
|
||||
from namespace import llvm
|
||||
from Triple import Triple
|
||||
from Pass import ImmutablePass
|
||||
from StringRef import StringRef
|
||||
|
||||
TargetLibraryInfo = llvm.Class(ImmutablePass)
|
||||
|
||||
@llvm.Class()
|
||||
class LibFunc:
|
||||
Func = Enum('''
|
||||
ZdaPv, ZdlPv, Znaj, ZnajRKSt9nothrow_t,
|
||||
Znam, ZnamRKSt9nothrow_t, Znwj, ZnwjRKSt9nothrow_t,
|
||||
Znwm, ZnwmRKSt9nothrow_t, cxa_atexit, cxa_guard_abort,
|
||||
cxa_guard_acquire, cxa_guard_release, memcpy_chk,
|
||||
acos, acosf, acosh, acoshf,
|
||||
acoshl, acosl, asin, asinf,
|
||||
asinh, asinhf, asinhl, asinl,
|
||||
atan, atan2, atan2f, atan2l,
|
||||
atanf, atanh, atanhf, atanhl,
|
||||
atanl, calloc, cbrt, cbrtf,
|
||||
cbrtl, ceil, ceilf, ceill,
|
||||
copysign, copysignf, copysignl, cos,
|
||||
cosf, cosh, coshf, coshl,
|
||||
cosl, exp, exp10, exp10f,
|
||||
exp10l, exp2, exp2f, exp2l,
|
||||
expf, expl, expm1, expm1f,
|
||||
expm1l, fabs, fabsf, fabsl,
|
||||
fiprintf,
|
||||
floor, floorf, floorl, fmod,
|
||||
fmodf, fmodl, fputc,
|
||||
fputs, free, fwrite, iprintf,
|
||||
log, log10, log10f, log10l,
|
||||
log1p, log1pf, log1pl, log2,
|
||||
log2f, log2l, logb, logbf,
|
||||
logbl, logf, logl, malloc,
|
||||
memchr, memcmp, memcpy, memmove,
|
||||
memset, memset_pattern16, nearbyint, nearbyintf,
|
||||
nearbyintl, posix_memalign, pow, powf,
|
||||
powl, putchar, puts,
|
||||
realloc, reallocf, rint, rintf,
|
||||
rintl, round, roundf, roundl,
|
||||
sin, sinf, sinh, sinhf,
|
||||
sinhl, sinl, siprintf,
|
||||
sqrt, sqrtf, sqrtl, stpcpy,
|
||||
strcat, strchr, strcmp, strcpy,
|
||||
strcspn, strdup, strlen, strncat,
|
||||
strncmp, strncpy, strndup, strnlen,
|
||||
strpbrk, strrchr, strspn, strstr,
|
||||
strtod, strtof, strtol, strtold,
|
||||
strtoll, strtoul, strtoull, tan,
|
||||
tanf, tanh, tanhf, tanhl,
|
||||
tanl, trunc, truncf,
|
||||
truncl, valloc, NumLibFuncs''')
|
||||
# not in llvm-3.2 abs, ffs, ffsl, ffsll, fprintf, isascii,
|
||||
# isdigit, labs, llabs, printf, sprintf, toascii
|
||||
|
||||
@TargetLibraryInfo
|
||||
class TargetLibraryInfo:
|
||||
_include_ = 'llvm/Target/TargetLibraryInfo.h'
|
||||
|
||||
new = Constructor()
|
||||
new |= Constructor(ref(Triple))
|
||||
|
||||
delete = Destructor()
|
||||
|
||||
has = Method(cast(bool, Bool), LibFunc.Func)
|
||||
hasOptimizedCodeGen = Method(cast(bool, Bool), LibFunc.Func)
|
||||
|
||||
getName = Method(cast(str, StringRef), LibFunc.Func)
|
||||
|
||||
setUnavailable = Method(Void, LibFunc.Func)
|
||||
setAvailable = Method(Void, LibFunc.Func)
|
||||
setAvailableWithName = Method(Void, LibFunc.Func, cast(str, StringRef))
|
||||
disableAllFunctions = Method()
|
||||
|
||||
|
|
@ -8,7 +8,6 @@ def test_basic_jit_use():
|
|||
api.InitializeNativeTarget()
|
||||
context = api.getGlobalContext()
|
||||
|
||||
|
||||
m = api.Module.new("modname", context)
|
||||
print m.getModuleIdentifier()
|
||||
m.setModuleIdentifier('modname2')
|
||||
|
|
@ -82,6 +81,26 @@ def test_basic_jit_use():
|
|||
errio = StringIO()
|
||||
print m
|
||||
|
||||
# build pass manager
|
||||
|
||||
pmb = api.PassManagerBuilder.new()
|
||||
|
||||
fpm = api.FunctionPassManager.new(m)
|
||||
pm = api.PassManager.new()
|
||||
|
||||
pmb.populateFunctionPassManager(fpm)
|
||||
pmb.populateModulePassManager(pm)
|
||||
|
||||
fpm.doInitialization()
|
||||
fpm.run(fn)
|
||||
fpm.doFinalization()
|
||||
|
||||
pm.run(m)
|
||||
|
||||
print m
|
||||
|
||||
# build engine
|
||||
|
||||
ee = api.ExecutionEngine.createJIT(m, errio)
|
||||
print ee, errio.getvalue()
|
||||
print ee.getDataLayout().getStringRepresentation()
|
||||
|
|
@ -149,6 +168,10 @@ def test_engine_builder():
|
|||
|
||||
print tm.getDataLayout()
|
||||
|
||||
pm = api.PassManager.new()
|
||||
pm.add(api.DataLayout.new(str(tm.getDataLayout())))
|
||||
pm.add(api.TargetLibraryInfo.new())
|
||||
|
||||
|
||||
def main():
|
||||
for name, value in globals().items():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue