ruby-llvm 13.0.1 → 13.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/test/type_test.rb DELETED
@@ -1,62 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class TypeTestCase < Minitest::Test
6
-
7
- extend MiniTest::Spec::DSL
8
-
9
- def test_element_type
10
- pointer = LLVM.Pointer(LLVM::Int32.type)
11
- pointee = pointer.element_type
12
-
13
- assert_equal :pointer, pointer.kind
14
- assert_equal :integer, pointee.kind
15
-
16
- assert_nil pointee.element_type
17
- end
18
-
19
- TO_S_TESTS = [
20
- [LLVM.Struct(LLVM::Int32, LLVM::Int32), '{ i32, i32 }'],
21
- [LLVM.Struct(LLVM::Int32, LLVM::Int32, "s1"), '%s1 = type { i32, i32 }'],
22
- [LLVM::Type.struct([LLVM::Int32, LLVM::Int32], true), '<{ i32, i32 }>'],
23
- [LLVM::Type.struct([LLVM::Int32, LLVM::Int32], true, "s2"), '%s2 = type <{ i32, i32 }>'],
24
-
25
- [LLVM.Array(LLVM::Int8), '[0 x i8]'],
26
- [LLVM.Array(LLVM::Int8, 42), '[42 x i8]'],
27
- [LLVM::Type.array(LLVM::Int1), '[0 x i1]'],
28
- [LLVM::Type.array(LLVM::Int1, 42), '[42 x i1]'],
29
-
30
- [LLVM.Vector(LLVM::Int8, 42), '<42 x i8>'],
31
- [LLVM::Type.vector(LLVM::Int1, 42), '<42 x i1>'],
32
-
33
- [LLVM.Void, 'void'],
34
- [LLVM::Type.void, 'void'],
35
-
36
- [LLVM.Pointer(LLVM::Int8), 'i8*'],
37
- [LLVM::Type.pointer(LLVM::Int1), 'i1*'],
38
-
39
- [LLVM.Function([LLVM::Int8], LLVM.Void), 'void (i8)'],
40
- [LLVM.Function([LLVM::Int8], LLVM::Int8), 'i8 (i8)'],
41
- [LLVM.Function([], LLVM::Int8), 'i8 ()'],
42
- [LLVM.Function([], LLVM.Void), 'void ()'],
43
- [LLVM::Type.function([LLVM::Int1], LLVM.Void), 'void (i1)'],
44
- [LLVM::Type.function([LLVM::Int1], LLVM::Int1), 'i1 (i1)'],
45
- [LLVM::Type.function([], LLVM::Int1), 'i1 ()'],
46
- [LLVM::Type.function([], LLVM.Void), 'void ()'],
47
- ].freeze
48
-
49
- describe "LLVM::Type#to_s" do
50
- TO_S_TESTS.each do |(type, string)|
51
- it "should return '#{string}'" do
52
- assert type.is_a?(LLVM::Type)
53
- assert_equal string, type.to_s
54
- end
55
- end
56
-
57
- it 'should have 22 dynamic tests' do
58
- assert_equal 22, TO_S_TESTS.size
59
- end
60
- end
61
-
62
- end
data/test/vector_test.rb DELETED
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class VectorTestCase < Minitest::Test
6
-
7
- def setup
8
- LLVM.init_jit
9
- end
10
-
11
- def test_all_ones_vector
12
- assert_raises(NotImplementedError) do
13
- LLVM::ConstantVector.all_ones
14
- end
15
- end
16
-
17
- def test_constant_vector_from_size
18
- vector = LLVM::ConstantVector.const(2) { |i| LLVM::Int(i) }
19
- assert_instance_of LLVM::ConstantVector, vector
20
- assert_equal 2, vector.size
21
- end
22
-
23
- def test_constant_vector_from_array
24
- vector = LLVM::ConstantVector.const([LLVM::Int(0), LLVM::Int(1)])
25
- assert_instance_of LLVM::ConstantVector, vector
26
- assert_equal 2, vector.size
27
- end
28
-
29
- def test_vector_elements
30
- assert_equal 2 + 3, run_vector_elements(2, 3).to_i
31
- end
32
-
33
- def test_vector_shuffle
34
- assert_equal 1 + 4, run_vector_shuffle(1, 2, 3, 4).to_i
35
- end
36
-
37
- def run_vector_elements(value1, value2)
38
- run_function([LLVM::Int, LLVM::Int], [value1, value2], LLVM::Int) do |builder, function, *arguments|
39
- entry = function.basic_blocks.append
40
- builder.position_at_end(entry)
41
- pointer = builder.alloca(LLVM::Vector(LLVM::Int, 2))
42
- vector = builder.load(pointer)
43
- vector = builder.insert_element(vector, arguments.first, LLVM::Int32.from_i(0))
44
- vector = builder.insert_element(vector, arguments.last, LLVM::Int32.from_i(1))
45
- builder.ret(builder.add(builder.extract_element(vector, LLVM::Int32.from_i(0)),
46
- builder.extract_element(vector, LLVM::Int32.from_i(1))))
47
- end
48
- end
49
-
50
- def run_vector_shuffle(*values)
51
- run_function([LLVM::Int, LLVM::Int, LLVM::Int, LLVM::Int], values, LLVM::Int) do |builder, function, *arguments|
52
- entry = function.basic_blocks.append
53
- builder.position_at_end(entry)
54
- vector1 = builder.load(builder.alloca(LLVM::Vector(LLVM::Int, 2)))
55
- vector1 = builder.insert_element(vector1, arguments[0], LLVM::Int32.from_i(0))
56
- vector1 = builder.insert_element(vector1, arguments[1], LLVM::Int32.from_i(1))
57
- vector2 = builder.load(builder.alloca(LLVM::Vector(LLVM::Int, 2)))
58
- vector2 = builder.insert_element(vector2, arguments[2], LLVM::Int32.from_i(0))
59
- vector2 = builder.insert_element(vector2, arguments[3], LLVM::Int32.from_i(1))
60
- vector3 = builder.shuffle_vector(vector1, vector2, LLVM::ConstantVector.const([LLVM::Int(0), LLVM::Int(3)]))
61
- builder.ret(builder.add(builder.extract_element(vector3, LLVM::Int32.from_i(0)),
62
- builder.extract_element(vector3, LLVM::Int32.from_i(1))))
63
- end
64
- end
65
-
66
- end