From 6d60c4a46961a1ca9b8c64647cf4a8cbbdf83a52 Mon Sep 17 00:00:00 2001 From: Ilan Schnell Date: Wed, 12 Sep 2012 15:18:12 -0500 Subject: [PATCH] add inline test to common test suite --- llvm/test_llvmpy.py | 31 ++++++++++++++++++++++++++++++- test/inlining.py | 32 -------------------------------- 2 files changed, 30 insertions(+), 33 deletions(-) delete mode 100644 test/inlining.py diff --git a/llvm/test_llvmpy.py b/llvm/test_llvmpy.py index 8a9f155..987e98b 100644 --- a/llvm/test_llvmpy.py +++ b/llvm/test_llvmpy.py @@ -16,7 +16,7 @@ else: from llvm import __version__ from llvm.core import (Module, Type, GlobalVariable, Function, Builder, - Constant, MetaData, MetaDataString) + Constant, MetaData, MetaDataString, inline_function) import llvm.passes as lp import llvm.ee as le @@ -407,6 +407,35 @@ tests.append(TestMetaData) # --------------------------------------------------------------------------- +class TestInlining(unittest.TestCase): + def test_inline_call(self): + mod = Module.new(__name__) + callee = mod.add_function(Type.function(Type.int(), [Type.int()]), + name='bar') + + builder = Builder.new(callee.append_basic_block('entry')) + builder.ret(builder.add(callee.args[0], callee.args[0])) + + caller = mod.add_function(Type.function(Type.int(), []), + name='foo') + + builder = Builder.new(caller.append_basic_block('entry')) + callinst = builder.call(callee, [Constant.int(Type.int(), 1234)]) + builder.ret(callinst) + + pre_inlining = str(caller) + self.assertIn('call', pre_inlining) + + self.assertTrue(inline_function(callinst)) + + post_inlining = str(caller) + self.assertNotIn('call', post_inlining) + self.assertIn('2468', post_inlining) + +tests.append(TestInlining) + +# --------------------------------------------------------------------------- + def run(verbosity=1): print('llvmpy is installed in: ' + os.path.dirname(__file__)) print('llvmpy version: ' + __version__) diff --git a/test/inlining.py b/test/inlining.py deleted file mode 100644 index 82d6932..0000000 --- a/test/inlining.py +++ /dev/null @@ -1,32 +0,0 @@ -from llvm.core import * -import unittest - -class TestInlining(unittest.TestCase): - def test_inline_call(self): - mod = Module.new(__name__) - callee = mod.add_function(Type.function(Type.int(), [Type.int()]), - name='bar') - - builder = Builder.new(callee.append_basic_block('entry')) - builder.ret(builder.add(callee.args[0], callee.args[0])) - - caller = mod.add_function(Type.function(Type.int(), []), - name='foo') - - builder = Builder.new(caller.append_basic_block('entry')) - callinst = builder.call(callee, [Constant.int(Type.int(), 1234)]) - builder.ret(callinst) - - pre_inlining = str(caller) - self.assertIn('call', pre_inlining) - - self.assertTrue(inline_function(callinst)) - - post_inlining = str(caller) - self.assertNotIn('call', post_inlining) - self.assertIn('2468', post_inlining) - - -if __name__ == '__main__': - unittest.main() -