[ARM] More MVE compare vector splat combines for ANDs
[llvm-complete.git] / bindings / python / llvm / tests / test_core.py
blob68572b50b3d66afff8a0861799f67fa54ca7f924
1 from __future__ import print_function
3 from .base import TestBase
4 from ..core import MemoryBuffer
5 from ..core import PassRegistry
6 from ..core import Context
7 from ..core import Module
8 from ..core import Enums
9 from ..core import OpCode
10 from ..bit_reader import parse_bitcode
12 class TestCore(TestBase):
13 def test_enumerations(self):
14 for enum_cls, enum_spec in Enums:
15 for enum_name, enum_value in enum_spec:
16 # First make sure that enum_cls has the name of the enum as an
17 # attribute. People will access these values as
18 # EnumCls.EnumName.
19 self.assertTrue(hasattr(enum_cls, enum_name))
20 v_attr = getattr(enum_cls, enum_name)
21 self.assertTrue(isinstance(v_attr, enum_cls))
23 # Then make sure that the value returned for this attribute is
24 # correct in both ways.
25 self.assertEqual(v_attr.value, enum_value)
27 e = enum_cls.from_value(enum_value)
28 self.assertTrue(isinstance(e, enum_cls))
29 self.assertEqual(e, v_attr)
31 def test_memory_buffer_create_from_file(self):
32 source = self.get_test_file()
34 MemoryBuffer(filename=source)
36 def test_memory_buffer_failing(self):
37 with self.assertRaises(Exception):
38 MemoryBuffer(filename="/hopefully/this/path/doesnt/exist")
40 def test_memory_buffer_len(self):
41 source = self.get_test_file()
42 m = MemoryBuffer(filename=source)
43 self.assertEqual(len(m), 50)
45 def test_create_passregistry(self):
46 PassRegistry()
48 def test_create_context(self):
49 Context.GetGlobalContext()
51 def test_create_module_with_name(self):
52 # Make sure we can not create a module without a LLVMModuleRef.
53 with self.assertRaises(TypeError):
54 m = Module()
55 m = Module.CreateWithName("test-module")
57 def test_module_getset_datalayout(self):
58 m = Module.CreateWithName("test-module")
59 dl = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:32:64-v128:32:128-a0:0:32-n32-S32"
60 m.datalayout = dl
61 self.assertEqual(m.datalayout, dl)
63 def test_module_getset_target(self):
64 m = Module.CreateWithName("test-module")
65 target = "thumbv7-apple-ios5.0.0"
66 m.target = target
67 self.assertEqual(m.target, target)
69 def test_module_print_module_to_file(self):
70 m = Module.CreateWithName("test")
71 dl = "e-p:32:32:32-i1:8:32-i8:8:32-i16:16:32-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:32:64-v128:32:128-a0:0:32-n32-S32"
72 m.datalayout = dl
73 target = "thumbv7-apple-ios5.0.0"
74 m.target = target
75 m.print_module_to_file("test2.ll")
77 def test_module_function_iteration(self):
78 m = parse_bitcode(MemoryBuffer(filename=self.get_test_bc()))
79 i = 0
80 functions = ["f", "f2", "f3", "f4", "f5", "f6", "g1", "g2", "h1", "h2",
81 "h3"]
82 # Forward
83 for f in m:
84 self.assertEqual(f.name, functions[i])
85 f.dump()
86 i += 1
87 # Backwards
88 for f in reversed(m):
89 i -= 1
90 self.assertEqual(f.name, functions[i])
91 f.dump()
93 def test_function_basicblock_iteration(self):
94 m = parse_bitcode(MemoryBuffer(filename=self.get_test_bc()))
95 i = 0
97 bb_list = ['b1', 'b2', 'end']
99 f = m.first
100 while f.name != "f6":
101 f = f.next
103 # Forward
104 for bb in f:
105 self.assertEqual(bb.name, bb_list[i])
106 bb.dump()
107 i += 1
109 # Backwards
110 for bb in reversed(f):
111 i -= 1
112 self.assertEqual(bb.name, bb_list[i])
113 bb.dump()
115 def test_basicblock_instruction_iteration(self):
116 m = parse_bitcode(MemoryBuffer(filename=self.get_test_bc()))
117 i = 0
119 inst_list = [('arg1', OpCode.ExtractValue),
120 ('arg2', OpCode.ExtractValue),
121 ('', OpCode.Call),
122 ('', OpCode.Ret)]
124 bb = m.first.first
126 # Forward
127 for inst in bb:
128 self.assertEqual(inst.name, inst_list[i][0])
129 self.assertEqual(inst.opcode, inst_list[i][1])
130 for op in range(len(inst)):
131 o = inst.get_operand(op)
132 print(o.name)
133 o.dump()
134 inst.dump()
135 i += 1
137 # Backwards
138 for inst in reversed(bb):
139 i -= 1
140 self.assertEqual(inst.name, inst_list[i][0])
141 self.assertEqual(inst.opcode, inst_list[i][1])
142 inst.dump()