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
|
|
@ -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:"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue