summaryrefslogtreecommitdiff
path: root/bindings/python/llvm/tests/test_core.py
diff options
context:
space:
mode:
authorMichael Gottesman <mgottesman@apple.com>2013-09-11 00:52:47 +0000
committerMichael Gottesman <mgottesman@apple.com>2013-09-11 00:52:47 +0000
commit7dfa4bc4716aaa34cc7c6226fd00675899263e9d (patch)
tree749dbbbfde6a37cdf9754f5234dd8482be42199e /bindings/python/llvm/tests/test_core.py
parent7eb8b0fd84474f6a77ffa6211c0c753ed3142277 (diff)
downloadllvm-7dfa4bc4716aaa34cc7c6226fd00675899263e9d.tar.gz
llvm-7dfa4bc4716aaa34cc7c6226fd00675899263e9d.tar.bz2
llvm-7dfa4bc4716aaa34cc7c6226fd00675899263e9d.tar.xz
[python-bindings] Added support for getting a module's functions, iterating f/b over said functions, dumping/print name of functions.
Tests are included as well. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@190471 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'bindings/python/llvm/tests/test_core.py')
-rw-r--r--bindings/python/llvm/tests/test_core.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/bindings/python/llvm/tests/test_core.py b/bindings/python/llvm/tests/test_core.py
index 07a574e585..a1f79a490d 100644
--- a/bindings/python/llvm/tests/test_core.py
+++ b/bindings/python/llvm/tests/test_core.py
@@ -4,6 +4,7 @@ from ..core import MemoryBuffer
from ..core import PassRegistry
from ..core import Context
from ..core import Module
+from ..bit_reader import parse_bitcode
class TestCore(TestBase):
def test_opcode(self):
@@ -61,3 +62,19 @@ class TestCore(TestBase):
m.target = target
m.print_module_to_file("test2.ll")
+ def test_module_function_iteration(self):
+ m = parse_bitcode(MemoryBuffer(filename=self.get_test_bc()))
+ i = 0
+ functions = ["f", "f2", "f3", "f4", "f5", "f6", "g1", "g2", "h1", "h2",
+ "h3"]
+ # Forward
+ for f in m:
+ self.assertEqual(f.name, functions[i])
+ f.dump()
+ i += 1
+ # Backwards
+ for f in reversed(m):
+ i -= 1
+ self.assertEqual(f.name, functions[i])
+ f.dump()
+