Added User class, moved operands to User, cleanup
git-svn-id: http://llvm-py.googlecode.com/svn/trunk@69 8d1e9007-1d4e-0410-b67e-1979fd6579aa
This commit is contained in:
parent
10843ec2ec
commit
8b6109d8eb
7 changed files with 144 additions and 154 deletions
|
|
@ -77,11 +77,15 @@ b3 = f1.get_entry_basic_block()
|
|||
check(b1, b3)
|
||||
|
||||
print "Testing basic block aliasing 3 .. ",
|
||||
b31 = f1.entry_basic_block
|
||||
check(b1, b31)
|
||||
|
||||
print "Testing basic block aliasing 4 .. ",
|
||||
bldr = Builder.new(b1)
|
||||
b4 = bldr.basic_block
|
||||
check(b1, b4)
|
||||
|
||||
print "Testing basic block aliasing 4 .. ",
|
||||
print "Testing basic block aliasing 5 .. ",
|
||||
i1 = bldr.ret_void()
|
||||
b5 = i1.basic_block
|
||||
check(b1, b5)
|
||||
|
|
|
|||
|
|
@ -4,40 +4,69 @@
|
|||
|
||||
from llvm.core import *
|
||||
|
||||
m = None
|
||||
|
||||
#===----------------------------------------------------------------------===
|
||||
|
||||
# implement a test function
|
||||
def make_function():
|
||||
test_module = """
|
||||
define i32 @prod(i32, i32) {
|
||||
entry:
|
||||
%2 = mul i32 %0, %1
|
||||
ret i32 %2
|
||||
}
|
||||
test_module = """
|
||||
define i32 @prod(i32, i32) {
|
||||
entry:
|
||||
%2 = mul i32 %0, %1
|
||||
ret i32 %2
|
||||
}
|
||||
|
||||
define i32 @test_func(i32, i32, i32) {
|
||||
entry:
|
||||
%tmp1 = call i32 @prod(i32 %0, i32 %1)
|
||||
%tmp2 = add i32 %tmp1, %2
|
||||
%tmp3 = add i32 %tmp2, 1
|
||||
ret i32 %tmp3
|
||||
}
|
||||
"""
|
||||
class strstream(object):
|
||||
def __init__(self): pass
|
||||
def read(self): return test_module
|
||||
m = Module.from_assembly(strstream())
|
||||
print "-"*60
|
||||
print m
|
||||
print "-"*60
|
||||
print "Examining function `test_func':"
|
||||
return m.get_function_named("test_func")
|
||||
define i32 @test_func(i32, i32, i32) {
|
||||
entry:
|
||||
%tmp1 = call i32 @prod(i32 %0, i32 %1)
|
||||
%tmp2 = add i32 %tmp1, %2
|
||||
%tmp3 = add i32 %tmp2, 1
|
||||
ret i32 %tmp3
|
||||
}
|
||||
"""
|
||||
class strstream(object):
|
||||
def __init__(self): pass
|
||||
def read(self): return test_module
|
||||
m = Module.from_assembly(strstream())
|
||||
print "-"*60
|
||||
print m
|
||||
print "-"*60
|
||||
|
||||
test_func = m.get_function_named("test_func")
|
||||
prod = m.get_function_named("prod")
|
||||
|
||||
#===----------------------------------------------------------------------===
|
||||
# test operands
|
||||
|
||||
func = make_function()
|
||||
print
|
||||
i1 = test_func.basic_blocks[0].instructions[0]
|
||||
i2 = test_func.basic_blocks[0].instructions[1]
|
||||
print "Testing User.operand_count ..",
|
||||
if i1.operand_count == 3 and i2.operand_count == 2:
|
||||
print "OK"
|
||||
else:
|
||||
print "FAIL"
|
||||
|
||||
print "Testing User.operands ..",
|
||||
c1 = i1.operands[0] is prod
|
||||
c2 = i1.operands[1] is test_func.args[0]
|
||||
c3 = i1.operands[2] is test_func.args[1]
|
||||
c4 = i2.operands[0] is i1
|
||||
c5 = i2.operands[1] is test_func.args[2]
|
||||
c6 = len(i1.operands) == 3
|
||||
c7 = len(i2.operands) == 2
|
||||
if c1 and c2 and c3 and c5 and c6 and c7:
|
||||
print "OK"
|
||||
else:
|
||||
print "FAIL"
|
||||
print
|
||||
|
||||
#===----------------------------------------------------------------------===
|
||||
# show test_function
|
||||
|
||||
print "Examining test_function `test_test_func':"
|
||||
idx = 1
|
||||
for inst in func.basic_blocks[0].instructions:
|
||||
for inst in test_func.basic_blocks[0].instructions:
|
||||
print "Instruction #%d:" % (idx,)
|
||||
print " operand_count =", inst.operand_count
|
||||
print " operands:"
|
||||
|
|
|
|||
|
|
@ -168,6 +168,21 @@ def do_value():
|
|||
i = k.value_id
|
||||
|
||||
|
||||
def do_user():
|
||||
m = Module.new('a')
|
||||
ft = Type.function(ti, [ti]*2)
|
||||
f = Function.new(m, ft, 'func')
|
||||
b = f.append_basic_block('a')
|
||||
bb = Builder.new(b)
|
||||
i1 = bb.add(f.args[0], f.args[1])
|
||||
i2 = bb.ret(i1)
|
||||
i1.operand_count == 2
|
||||
i2.operand_count == 1
|
||||
i1.operands[0] is f.args[0]
|
||||
i1.operands[1] is f.args[1]
|
||||
i2.operands[0] is i1
|
||||
|
||||
|
||||
def do_constant():
|
||||
print " Testing class Constant"
|
||||
Constant.null(ti)
|
||||
|
|
@ -475,6 +490,7 @@ def do_llvm_core():
|
|||
do_type()
|
||||
do_typehandle()
|
||||
do_value()
|
||||
do_user()
|
||||
do_constant()
|
||||
do_global_value()
|
||||
do_global_variable()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue