Fix missing return in llvm/core.py and do some refactoring;

Update test/testall.py.

TODO: Need to update the passes.
This commit is contained in:
Siu Kwan Lam 2012-07-23 09:27:24 -07:00
commit 54a0a95faf
3 changed files with 53 additions and 32 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
*~
build
*.pyc

View file

@ -603,15 +603,7 @@ class Type(object):
If name is not '', creates a identified type;
otherwise, creates a literal type."""
elems = unpack_types(element_tys)
if name: # create Identified StructType
objptr = _core.LLVMStructTypeIdentified(name)
_core.LLVMSetStructBody(objptr, elems, 0)
else: # create Literal StructType
objptr = _core.LLVMStructType(elems, 0)
return _make_type(objptr, TYPE_STRUCT)
return Type.__struct(element_tys, packed=False, name=name)
@staticmethod
def packed_struct(element_tys, name=''):
@ -623,13 +615,25 @@ class Type(object):
If name is not '', creates a identified type;
otherwise, creates a literal type."""
return Type.__struct(element_tys, packed=True, name=name)
@staticmethod
def __struct(element_tys, packed, name):
elems = unpack_types(element_tys)
if packed:
packed=1
else:
packed=0
if name: # create Identified StructType
objptr = _core.LLVMStructTypeIdentified(name)
_core.LLVMSetStructBody(objptr, elems, 0)
_core.LLVMSetStructBody(objptr, elems, packed)
else: # create Literal StructType
objptr = _core.LLVMStructType(elems, 1)
objptr = _core.LLVMStructType(elems, packed)
return _make_type(objptr, TYPE_STRUCT)
@staticmethod
def array(element_ty, count):
@ -765,7 +769,7 @@ class StructType(Type):
# check
if not self.is_opaque:
raise llvm.LLVMException("Body is already defined.")
# prepare arguments
elems = unpack_types(elems)
if packed:

View file

@ -55,8 +55,11 @@ def do_module():
a = m.target
m.data_layout = 'a'
a = m.data_layout
m.add_type_name('a', ti)
m.delete_type_name('a')
# m.add_type_name('a', ti)
# m.delete_type_name('a')
Type.struct([ti], name='a')
m.get_type_named('a').name=''
s = str(m)
s = m == Module.new('a')
m.add_global_variable(ti, 'b')
@ -86,7 +89,9 @@ def do_module():
ss = strstream()
m2 = Module.new('test')
m2.add_type_name('myint', ti)
# m2.add_type_name('myint', ti)
Type.struct([ti], 'myint')
m2.to_bitcode(ss)
m3 = Module.from_bitcode(ss)
t = m2 == m3
@ -119,10 +124,11 @@ def do_type():
Type.vector(ti, 100)
Type.void()
Type.label()
Type.opaque()
Type.opaque('an_opaque_type')
s = str(ti)
s = ti == Type.float()
Type.opaque().refine(Type.int())
Type.opaque('whatever').set_body([Type.int()])
s = ti.width
ft = Type.function(ti, [ti]*10)
ft.return_type
@ -149,12 +155,12 @@ def do_type():
Type.int(32) != Type.int(64)
Type.int(32) != Type.float()
def do_typehandle():
print(" Testing class TypeHandle")
th = TypeHandle.new(Type.opaque())
ts = Type.struct([ Type.int(), Type.pointer(th.type) ])
th.type.refine(ts)
### Removed
#def do_typehandle():
# print(" Testing class TypeHandle")
# th = TypeHandle.new(Type.opaque())
# ts = Type.struct([ Type.int(), Type.pointer(th.type) ])
# th.type.refine(ts)
def do_value():
@ -210,6 +216,7 @@ def do_constant():
vi = Constant.vector([Constant.int(ti,42)]*10)
vf = Constant.vector([Constant.real(Type.float(), 3.14)]*10)
k.shl(k).lshr(k).ashr(k)
return
# TODO gep
k.trunc(Type.int(1))
k.sext(Type.int(64))
@ -414,7 +421,7 @@ def do_builder():
b.cbranch(Constant.int(Type.int(1), 1), blk, blk)
b.switch(f.args[0], blk)
b.invoke(f, [Constant.int(ti,10)], blk, blk)
b.unwind()
# b.unwind() # removed
b.unreachable()
v = f.args[0]
fv = Constant.real(Type.float(), "1.0")
@ -462,6 +469,7 @@ def do_builder():
b.icmp(IPRED_ULT, v, v)
b.fcmp(RPRED_ULT, fv, fv)
vi = Constant.vector([Constant.int(ti,42)]*10)
vi_mask = Constant.vector([Constant.int(ti, X) for X in range(20)])
vf = Constant.vector([Constant.real(Type.float(), 3.14)]*10)
# TODO b.extract_value(v, 0)
b.call(f, [v])
@ -469,7 +477,7 @@ def do_builder():
b.vaarg(v, Type.int())
b.extract_element(vi, v)
b.insert_element(vi, v, v)
b.shuffle_vector(vi, vi, vi)
b.shuffle_vector(vi, vi, vi_mask)
# NOTE: phi nodes without incoming values segfaults in LLVM during
# destruction.
i = b.phi(Type.int())
@ -491,7 +499,7 @@ def do_llvm_core():
print(" Testing module llvm.core")
do_module()
do_type()
do_typehandle()
# do_typehandle()
do_value()
do_user()
do_constant()
@ -577,11 +585,18 @@ def do_passmanager():
print(" Testing class PassManager")
pm = PassManager.new()
pm.add(TargetData.new(''))
for i in [getattr(llvm.passes, x) for x in \
dir(llvm.passes) if x.startswith('PASS_') and x not in \
('PASS_OPTIMAL_EDGE_PROFILER', 'PASS_EDGE_PROFILER', \
'PASS_PROFILE_LOADER', 'PASS_AAEVAL')]:
pm.add(i)
print('.........Begging for rewrite!!!')
### It is not practical to maintain all PASS_* constants.
#
# passes = ('PASS_OPTIMAL_EDGE_PROFILER', 'PASS_EDGE_PROFILER',
# 'PASS_PROFILE_LOADER', 'PASS_AAEVAL')
# all_these = [getattr(llvm.passes, x)
# for x in dir(llvm.passes)
# if x.startswith('PASS_') and x not in passes]
# for i in all_these:
# print i
# pm.add(i)
pm.run(Module.new('a'))
@ -615,7 +630,8 @@ def main():
do_llvm_passes()
main()
if __name__ == '__main__':
main()
# to add:
# IntegerType