diff --git a/llvm/test_llvmpy.py b/llvm/test_llvmpy.py index da2433c..0673efb 100644 --- a/llvm/test_llvmpy.py +++ b/llvm/test_llvmpy.py @@ -25,6 +25,52 @@ import llvm.ee as le tests = [] +# --------------------------------------------------------------------------- + +class TestAsm(unittest.TestCase): + def test_asm(self): + # create a module + m = Module.new('module1') + m.add_global_variable(Type.int(), 'i') + + # write it's assembly representation to a file + asm = str(m) + + with open("/tmp/testasm.ll", "w") as fout: + fout.write(asm) + + # read it back into a module + with open("/tmp/testasm.ll") as fin: + m2 = Module.from_assembly(fin) + # The default `m.id` is ''. + m2.id = m.id # Copy the name from `m` + + self.assertEqual(str(m2).strip(), asm.strip()) + + + def test_bitcode(self): + # create a module + m = Module.new('module1') + m.add_global_variable(Type.int(), 'i') + + # write it's assembly representation to a file + asm = str(m) + + with open("/tmp/testasm.bc", "wb") as fout: + m.to_bitcode(fout) + + # read it back into a module + with open("/tmp/testasm.bc", "rb") as fin: + m2 = Module.from_bitcode(fin) + # The default `m.id` is ''. + m2.id = m.id # Copy the name from `m` + + self.assertEqual(str(m2).strip(), asm.strip()) + +tests.append(TestAsm) + +# --------------------------------------------------------------------------- + class TestOperands(unittest.TestCase): # implement a test function test_module = """ diff --git a/test/asm.py b/test/asm.py deleted file mode 100644 index ed003c1..0000000 --- a/test/asm.py +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env python - -from llvm import * -from llvm.core import * - -import unittest - -class TestAsm(unittest.TestCase): - def test_asm(self): - # create a module - m = Module.new('module1') - m.add_global_variable(Type.int(), 'i') - - # write it's assembly representation to a file - asm = str(m) - - with open("/tmp/testasm.ll", "w") as fout: - fout.write(asm) - - # read it back into a module - with open("/tmp/testasm.ll") as fin: - m2 = Module.from_assembly(fin) - # The default `m.id` is ''. - m2.id = m.id # Copy the name from `m` - - self.assertEqual(str(m2).strip(), asm.strip()) - - - def test_bitcode(self): - # create a module - m = Module.new('module1') - m.add_global_variable(Type.int(), 'i') - - # write it's assembly representation to a file - asm = str(m) - - with open("/tmp/testasm.bc", "wb") as fout: - m.to_bitcode(fout) - - # read it back into a module - with open("/tmp/testasm.bc", "rb") as fin: - m2 = Module.from_bitcode(fin) - # The default `m.id` is ''. - m2.id = m.id # Copy the name from `m` - - self.assertEqual(str(m2).strip(), asm.strip()) - -if __name__ == '__main__': - unittest.main() diff --git a/test/issue10.py b/test/issue10.py deleted file mode 100644 index 9c654f4..0000000 --- a/test/issue10.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python - -from llvm.core import * - -import unittest - -class TestIssue10(unittest.TestCase): - def test_issue10(self): - m = Module.new('a') - ti = Type.int() - tf = Type.function(ti, [ti, ti]) - - f = m.add_function(tf, "func1") - - bb = f.append_basic_block('entry') - - b = Builder.new(bb) - - # There are no instructions in bb. Positioning of the - # builder at beginning (or end) should succeed (trivially). - - b.position_at_end(bb) - b.position_at_beginning(bb) - -if __name__ == '__main__': - unittest.main() -