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/call_test.rb DELETED
@@ -1,84 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class CallTestCase < Minitest::Test
6
-
7
- def setup
8
- LLVM.init_jit
9
- end
10
-
11
- def test_simple_call
12
- test_module = define_module("test_module") do |host_module|
13
- define_function(host_module, "test_function", [], LLVM::Int) do |builder, function, *arguments|
14
- entry = function.basic_blocks.append
15
- builder.position_at_end(entry)
16
- builder.ret(LLVM::Int(1))
17
- end
18
- end
19
- assert_equal 1, run_function_on_module(test_module, "test_function").to_i
20
- end
21
-
22
- def test_nested_call
23
- test_module = define_module("test_module") do |host_module|
24
- function_1 = define_function(host_module, "test_function_1", [], LLVM::Int) do |builder, function, *arguments|
25
- entry = function.basic_blocks.append
26
- builder.position_at_end(entry)
27
- builder.ret(LLVM::Int(1))
28
- end
29
- function_2 = define_function(host_module, "test_function_2", [], LLVM::Int) do |builder, function, *arguments|
30
- entry = function.basic_blocks.append
31
- builder.position_at_end(entry)
32
- builder.ret(builder.call(function_1))
33
- end
34
- end
35
- assert_equal 1, run_function_on_module(test_module, "test_function_2").to_i
36
- end
37
-
38
- def test_recursive_call
39
- test_module = define_module("test_module") do |host_module|
40
- define_function(host_module, "test_function", [LLVM::Int], LLVM::Int) do |builder, function, *arguments|
41
- entry = function.basic_blocks.append
42
- recurse = function.basic_blocks.append
43
- exit = function.basic_blocks.append
44
- builder.position_at_end(entry)
45
- builder.cond(builder.icmp(:uge, arguments.first, LLVM::Int(5)), exit, recurse)
46
- builder.position_at_end(recurse)
47
- result = builder.call(function, builder.add(arguments.first, LLVM::Int(1)))
48
- builder.br(exit)
49
- builder.position_at_end(exit)
50
- builder.ret(builder.phi(LLVM::Int, entry => arguments.first, recurse => result))
51
- end
52
- end
53
- assert_equal 5, run_function_on_module(test_module, "test_function", 1).to_i
54
- end
55
-
56
- def test_external
57
- test_module = define_module("test_module") do |host_module|
58
- external = host_module.functions.add("abs", [LLVM::Int], LLVM::Int)
59
- define_function(host_module, "test_function", [LLVM::Int], LLVM::Int) do |builder, function, *arguments|
60
- entry = function.basic_blocks.append
61
- builder.position_at_end(entry)
62
- builder.ret(builder.call(external, arguments.first))
63
- end
64
- end
65
- assert_equal(-10.abs, run_function_on_module(test_module, "test_function", -10).to_i)
66
- end
67
-
68
- def test_external_string
69
- test_module = define_module("test_module") do |host_module|
70
- global = host_module.globals.add(LLVM::Array(LLVM::Int8, 5), "path")
71
- global.linkage = :internal
72
- global.initializer = LLVM::ConstantArray.string("PATH")
73
- external = host_module.functions.add("getenv", [LLVM::Pointer(LLVM::Int8)], LLVM::Pointer(LLVM::Int8))
74
- define_function(host_module, "test_function", [], LLVM::Pointer(LLVM::Int8)) do |builder, function, *arguments|
75
- entry = function.basic_blocks.append
76
- builder.position_at_end(entry)
77
- parameter = builder.gep(global, [LLVM::Int(0), LLVM::Int(0)])
78
- builder.ret(builder.call(external, parameter))
79
- end
80
- end
81
- assert_equal ENV["PATH"], run_function_on_module(test_module, "test_function").to_ptr.read_pointer.read_string
82
- end
83
-
84
- end
@@ -1,68 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class ComparisonsTestCase < Minitest::Test
6
-
7
- def setup
8
- LLVM.init_jit
9
- end
10
-
11
- def test_integer_comparison
12
- integer_comparison_assertion(:eq, 1, 1, LLVM_SIGNED, LLVM_TRUE)
13
- integer_comparison_assertion(:ne, 1, 1, LLVM_SIGNED, LLVM_FALSE)
14
- integer_comparison_assertion(:ugt, 2, 2, LLVM_UNSIGNED, LLVM_FALSE)
15
- integer_comparison_assertion(:uge, 2, 1, LLVM_UNSIGNED, LLVM_TRUE)
16
- integer_comparison_assertion(:ult, 1, 1, LLVM_UNSIGNED, LLVM_FALSE)
17
- integer_comparison_assertion(:ule, 1, 2, LLVM_UNSIGNED, LLVM_TRUE)
18
- integer_comparison_assertion(:sgt, -2, 2, LLVM_SIGNED, LLVM_FALSE)
19
- integer_comparison_assertion(:sge, -2, 1, LLVM_SIGNED, LLVM_FALSE)
20
- integer_comparison_assertion(:slt, -1, 2, LLVM_SIGNED, LLVM_TRUE)
21
- integer_comparison_assertion(:sle, -1, 2, LLVM_SIGNED, LLVM_TRUE)
22
- end
23
-
24
- def test_float_comparison
25
- float_comparison_assertion(:oeq, 1.0, 1.0, LLVM_TRUE)
26
- float_comparison_assertion(:one, 1.0, 1.0, LLVM_FALSE)
27
- float_comparison_assertion(:ogt, 2.0, 2.0, LLVM_FALSE)
28
- float_comparison_assertion(:oge, 2.0, 1.0, LLVM_TRUE)
29
- float_comparison_assertion(:olt, 1.0, 1.0, LLVM_FALSE)
30
- float_comparison_assertion(:ole, 1.0, 2.0, LLVM_TRUE)
31
- float_comparison_assertion(:ord, 1.0, 2.0, LLVM_TRUE)
32
- float_comparison_assertion(:ueq, 1.0, 1.0, LLVM_TRUE)
33
- float_comparison_assertion(:une, 1.0, 1.0, LLVM_FALSE)
34
- float_comparison_assertion(:ugt, 2.0, 2.0, LLVM_FALSE)
35
- float_comparison_assertion(:uge, 2.0, 1.0, LLVM_TRUE)
36
- float_comparison_assertion(:ult, 1.0, 1.0, LLVM_FALSE)
37
- float_comparison_assertion(:ule, 1.0, 2.0, LLVM_TRUE)
38
- float_comparison_assertion(:uno, 1.0, 2.0, LLVM_FALSE)
39
- end
40
-
41
- def integer_comparison_assertion(operation, operand1, operand2, signed, expected_result)
42
- result = run_comparison_operation(:icmp,
43
- operation,
44
- LLVM::Int.from_i(operand1, signed),
45
- LLVM::Int.from_i(operand2, signed),
46
- LLVM::Int1).to_i(false)
47
- assert_equal expected_result, result
48
- end
49
-
50
- def float_comparison_assertion(operation, operand1, operand2, expected_result)
51
- result = run_comparison_operation(:fcmp,
52
- operation,
53
- LLVM::Float(operand1),
54
- LLVM::Float(operand2),
55
- LLVM::Int1).to_i(false)
56
- assert_equal expected_result, result
57
- end
58
-
59
- def run_comparison_operation(comparison_operation, comparison_operator,
60
- operand1, operand2, return_type)
61
- run_function([], [], return_type) do |builder, function, *arguments|
62
- entry = function.basic_blocks.append
63
- builder.position_at_end(entry)
64
- builder.ret(builder.send(comparison_operation, comparison_operator, operand1, operand2))
65
- end
66
- end
67
-
68
- end
@@ -1,94 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class ConversionsTestCase < Minitest::Test
6
-
7
- def setup
8
- LLVM.init_jit
9
- end
10
-
11
- def test_trunc_to
12
- integer_conversion_assertion(:trunc, LLVM::Int32.from_i(257), LLVM::Int8, LLVM_UNSIGNED, 1)
13
- integer_conversion_assertion(:trunc, LLVM::Int32.from_i(123), LLVM::Int1, LLVM_UNSIGNED, 1)
14
- integer_conversion_assertion(:trunc, LLVM::Int32.from_i(122), LLVM::Int1, LLVM_UNSIGNED, 0)
15
- end
16
-
17
- def test_zext_to
18
- integer_conversion_assertion(:zext, LLVM::Int16.from_i(257), LLVM::Int32, LLVM_UNSIGNED, 257)
19
- end
20
-
21
- def test_sext_to
22
- integer_conversion_assertion(:sext, LLVM::Int1.from_i(1), LLVM::Int32, LLVM_SIGNED, -1)
23
- integer_conversion_assertion(:sext, LLVM::Int8.from_i(-1), LLVM::Int16, LLVM_UNSIGNED, 65535)
24
- end
25
-
26
- def test_fptrunc_to
27
- float_conversion_assertion(:fp_trunc, LLVM::Double(123.0), LLVM::Float, 123.0)
28
- end
29
-
30
- def test_fpext_to
31
- float_conversion_assertion(:fp_ext, LLVM::Float(123.0), LLVM::Double, 123.0)
32
- float_conversion_assertion(:fp_ext, LLVM::Float(123.0), LLVM::Float, 123.0)
33
- end
34
-
35
- def test_fptoui_to
36
- different_type_assertion(:fp2ui, LLVM::Double(123.3), LLVM::Int32, :integer, 123)
37
- different_type_assertion(:fp2ui, LLVM::Double(0.7), LLVM::Int32, :integer, 0)
38
- different_type_assertion(:fp2ui, LLVM::Double(1.7), LLVM::Int32, :integer, 1)
39
- end
40
-
41
- def test_fptosi_to
42
- different_type_assertion(:fp2si, LLVM::Double(-123.3), LLVM::Int32, :integer, -123)
43
- different_type_assertion(:fp2si, LLVM::Double(0.7), LLVM::Int32, :integer, 0)
44
- different_type_assertion(:fp2si, LLVM::Double(1.7), LLVM::Int32, :integer, 1)
45
- end
46
-
47
- def test_uitofp_to
48
- different_type_assertion(:ui2fp, LLVM::Int32.from_i(257), LLVM::Float, :float, 257.0)
49
- different_type_assertion(:ui2fp, LLVM::Int8.from_i(-1), LLVM::Double, :float, 255.0)
50
- end
51
-
52
- def test_sitofp_to
53
- different_type_assertion(:si2fp, LLVM::Int32.from_i(257), LLVM::Float, :float, 257.0)
54
- different_type_assertion(:si2fp, LLVM::Int8.from_i(-1), LLVM::Double, :float, -1.0)
55
- end
56
-
57
- def test_bitcast_to
58
- different_type_assertion(:bit_cast, LLVM::Int8.from_i(255), LLVM::Int8, :integer, -1)
59
- end
60
-
61
- def test_int64
62
- integer_conversion_assertion(:zext, LLVM::Int64.from_i(2**62 + 123), LLVM::Int64, LLVM_SIGNED, 2**62 + 123)
63
- integer_conversion_assertion(:zext, LLVM::Int64.from_i(-2**62 - 123), LLVM::Int64, LLVM_SIGNED, -2**62 - 123)
64
- integer_conversion_assertion(:zext, LLVM::Int64.from_i(2**63 + 123), LLVM::Int64, LLVM_UNSIGNED, 2**63 + 123)
65
- end
66
-
67
- def integer_conversion_assertion(operation, operand, return_type, signed, expected_result)
68
- result = run_conversion_operation(operation, operand, return_type)
69
- assert_equal expected_result, result.to_i(signed)
70
- end
71
-
72
- def float_conversion_assertion(operation, operand, return_type, expected_result)
73
- result = run_conversion_operation(operation, operand, return_type)
74
- assert_in_delta expected_result, result.to_f(return_type), 0.001
75
- end
76
-
77
- def different_type_assertion(operation, operand, return_type, assertion_type, expected_result)
78
- result = run_conversion_operation(operation, operand, return_type)
79
- if assertion_type == :integer
80
- assert_equal expected_result, result.to_i
81
- else
82
- assert_in_delta expected_result, result.to_f(return_type), 0.001
83
- end
84
- end
85
-
86
- def run_conversion_operation(operation, operand, return_type)
87
- run_function([], [], return_type) do |builder, function, *arguments|
88
- entry = function.basic_blocks.append
89
- builder.position_at_end(entry)
90
- builder.ret(builder.send(operation, operand, return_type))
91
- end
92
- end
93
-
94
- end
data/test/double_test.rb DELETED
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class DoubleTestCase < Minitest::Test
6
- def setup
7
- LLVM.init_jit
8
- end
9
-
10
- def test_double
11
- mod = LLVM::Module.new("Double Test")
12
- mod.functions.add(:sin, [LLVM::Double], LLVM::Double)
13
-
14
- builder = LLVM::Builder.new
15
-
16
- mod.functions.add('test', [LLVM::Double], LLVM::Double) do |fun, p0|
17
- p0.name = 'x'
18
-
19
- bb = fun.basic_blocks.append
20
- builder.position_at_end(bb)
21
-
22
- builder.ret(builder.fadd(p0, LLVM::Double(1.0)))
23
- end
24
-
25
- engine = LLVM::MCJITCompiler.new(mod)
26
-
27
- arg = 5.0
28
- result = engine.run_function(mod.functions["test"], arg)
29
- assert_equal arg + 1, result.to_f(LLVM::Double)
30
-
31
- # TODO: fix this
32
- # assert_in_delta(Math.sin(1.0),
33
- # engine.run_function(mod.functions["sin"], 1.0).to_f(LLVM::Double),
34
- # 1e-10)
35
- end
36
- end
@@ -1,91 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
- require "llvm/core"
5
-
6
- class EqualityTestCase < Minitest::Test
7
- def setup
8
- LLVM.init_jit
9
- end
10
-
11
- class MyModule < LLVM::Module; end
12
- class MyInt < LLVM::Int32; end
13
- class MyType < LLVM::Type; end
14
- class MyFunction < LLVM::Function; end
15
-
16
- def assert_equalities(options)
17
- map = {
18
- :equal => method(:assert_equal),
19
- :not_equal => lambda {|n, m, name| assert n != m, name },
20
- :same => method(:assert_same),
21
- :not_same => lambda {|n, m, name| assert !n.equal?(m), name },
22
- :eql => lambda {|n, m, name| assert n.eql?(m), name },
23
- :not_eql => lambda {|n, m, name| assert !n.eql?(m), name },
24
- }
25
-
26
- map.each do |name, callable|
27
- options[name].combination(2).each do |n, m|
28
- callable.call(n, m, name.to_s)
29
- end
30
- end
31
- end
32
-
33
- def test_int_value
34
- int1 = LLVM::Int32.from_i(1)
35
- int2 = LLVM::Int32.from_ptr(int1.to_ptr)
36
- int3 = LLVM::Int32.from_i(2)
37
- int4 = MyInt.from_ptr(int1.to_ptr)
38
-
39
- assert_equalities :equal => [int1, int2, int4],
40
- :not_equal => [int1, int3],
41
- :same => [int1, int1],
42
- :not_same => [int1, int2, int3, int4],
43
- :eql => [int1, int2],
44
- :not_eql => [int1, int3]
45
- end
46
-
47
- def test_module
48
- mod1 = LLVM::Module.new('test')
49
- mod2 = LLVM::Module.from_ptr(mod1.to_ptr)
50
- mod3 = LLVM::Module.new('dummy')
51
- mod4 = MyModule.from_ptr(mod1.to_ptr)
52
-
53
- assert_equalities :equal => [mod1, mod2, mod4],
54
- :not_equal => [mod1, mod3],
55
- :same => [mod1, mod1],
56
- :not_same => [mod1, mod2, mod3, mod4],
57
- :eql => [mod1, mod2],
58
- :not_eql => [mod1, mod3]
59
- end
60
-
61
- def test_type
62
- type1 = LLVM::Float.type
63
- type2 = LLVM::Type.from_ptr(type1.to_ptr, nil)
64
- type3 = LLVM::Double.type
65
- type4 = MyType.from_ptr(type1.to_ptr, :mytype)
66
-
67
- assert_equalities :equal => [type1, type2, type4],
68
- :not_equal => [type1, type3],
69
- :same => [type1, type1],
70
- :not_same => [type1, type2, type3, type4],
71
- :eql => [type1, type2],
72
- :not_eql => [type1, type3]
73
- end
74
-
75
- def test_function
76
- mod = LLVM::Module.new('test')
77
-
78
- fn1 = mod.functions.add('test1', [], LLVM.Void)
79
- fn2 = LLVM::Function.from_ptr(fn1.to_ptr)
80
- fn3 = mod.functions.add('test2', [], LLVM.Void)
81
- fn4 = MyFunction.from_ptr(fn1.to_ptr)
82
-
83
- assert_equalities :equal => [fn1, fn2, fn4],
84
- :not_equal => [fn1, fn3],
85
- :same => [fn1, fn1],
86
- :not_same => [fn1, fn2, fn3, fn4],
87
- :eql => [fn1, fn2],
88
- :not_eql => [fn1, fn3]
89
- end
90
-
91
- end
@@ -1,102 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
- require "llvm/core"
5
-
6
-
7
- def with_function(arguments, retty, &block)
8
- mod = LLVM::Module.new('test')
9
- fun = mod.functions.add('fun', arguments, retty)
10
- block.yield(fun)
11
- mod.dispose
12
- end
13
-
14
- class FunctionTest < Minitest::Test
15
-
16
- def test_type
17
- with_function [], LLVM.Void do |fun|
18
- type = fun.type
19
-
20
- assert_instance_of LLVM::Type, type
21
- assert_equal :pointer, type.kind
22
- assert_equal :function, type.element_type.kind
23
- end
24
- end
25
-
26
- def test_function_type
27
- with_function [], LLVM.Void do |fun|
28
- type = fun.function_type
29
-
30
- assert_instance_of LLVM::FunctionType, type
31
- assert_equal :function, type.kind
32
- end
33
- end
34
-
35
- def helper_test_attribute(name)
36
- with_function [], LLVM.Void do |fun|
37
- assert_equal 0, fun.attribute_count
38
- assert_equal [], fun.attributes
39
-
40
- fun.add_attribute(name)
41
- assert_equal 1, fun.attribute_count
42
- assert_equal [34], fun.attributes
43
-
44
- assert_equal false, fun.verify
45
-
46
- fun.remove_attribute(name)
47
- assert_equal 0, fun.attribute_count
48
- assert_equal [], fun.attributes
49
-
50
- assert_equal false, fun.verify
51
- end
52
- end
53
-
54
- def test_add_attribute_old_name
55
- helper_test_attribute(:no_unwind_attribute)
56
- end
57
-
58
- def test_add_attribute_new_name
59
- helper_test_attribute(:nounwind)
60
- end
61
-
62
- end
63
-
64
- class FunctionTypeTest < Minitest::Test
65
-
66
- def test_return_type
67
- with_function [], LLVM.Void do |fun|
68
- type = fun.function_type
69
- assert_equal LLVM.Void, type.return_type
70
- end
71
-
72
- with_function [], LLVM::Int32 do |fun|
73
- retty = fun.function_type.return_type
74
-
75
- assert_kind_of LLVM::IntType, retty
76
- assert_equal 32, retty.width
77
- end
78
- end
79
-
80
- def test_argument_types
81
- with_function [], LLVM.Void do |fun|
82
- types = fun.function_type.argument_types
83
- assert_equal [], types
84
- end
85
-
86
- with_function [LLVM::Int32], LLVM.Void do |fun|
87
- types = fun.function_type.argument_types
88
- assert_equal 1, types.size
89
- a1 = types[0]
90
- assert_kind_of LLVM::IntType, a1
91
- assert_equal 32, a1.width
92
- end
93
- end
94
-
95
- def test_vararg
96
- with_function [], LLVM.Void do |fun|
97
- type = fun.function_type
98
- assert !type.vararg?, 'should be false'
99
- end
100
- end
101
-
102
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class GenericValueTestCase < Minitest::Test
6
-
7
- def setup
8
- LLVM.init_jit
9
- end
10
-
11
- def test_from_i
12
- assert_equal 2, LLVM::GenericValue.from_i(2).to_i
13
- assert_equal 2, LLVM::GenericValue.from_i(2.2).to_i
14
- end
15
-
16
- def test_from_float
17
- assert_in_delta 2.2, LLVM::GenericValue.from_f(2.2).to_f, 1e-6
18
- end
19
-
20
- def test_from_double
21
- assert_in_delta 2.2, LLVM::GenericValue.from_d(2.2).to_f(LLVM::Double), 1e-6
22
- end
23
-
24
- end
@@ -1,32 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class InstructionTestCase < Minitest::Test
6
- def setup
7
- LLVM.init_jit
8
- @module = LLVM::Module.new("InstructionTestCase")
9
- end
10
-
11
- def test_instruction
12
- fn = @module.functions.add("test_instruction", [LLVM::Double], LLVM::Double) do |fn, arg|
13
- fn.basic_blocks.append.build do |builder|
14
- builder.ret(
15
- builder.fadd(arg, LLVM.Double(3.0)))
16
- end
17
- end
18
-
19
- entry = fn.basic_blocks.entry
20
-
21
- inst1 = entry.instructions.first
22
- inst2 = entry.instructions.last
23
-
24
- assert_kind_of LLVM::Instruction, inst1
25
- assert_kind_of LLVM::Instruction, inst2
26
-
27
- assert_equal inst2, inst1.next
28
- assert_equal inst1, inst2.previous
29
- assert_equal entry, inst1.parent
30
- assert_equal entry, inst2.parent
31
- end
32
- end
data/test/integer_test.rb DELETED
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
-
5
- class IntegerTestCase < Minitest::Test
6
-
7
- def test_const_zext
8
- assert i = LLVM::Int8.from_i(-1)
9
- assert_equal 'i8 -1', i.to_s
10
- assert_equal :integer, i.type.kind
11
- assert_equal 8, i.type.width
12
- assert zext = i.zext(LLVM::Int64)
13
- assert_equal 'i64 255', zext.to_s
14
- assert_equal :integer, zext.type.kind
15
- assert_equal 64, zext.type.width
16
- end
17
-
18
- def test_const_sext
19
- assert i = LLVM::Int8.from_i(-1)
20
- assert_equal 'i8 -1', i.to_s
21
- assert_equal :integer, i.type.kind
22
- assert_equal 8, i.type.width
23
- assert sext = i.sext(LLVM::Int64)
24
- assert_equal 'i64 -1', sext.to_s
25
- assert_equal :integer, sext.type.kind
26
- assert_equal 64, sext.type.width
27
- end
28
- end
data/test/ipo_test.rb DELETED
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "test_helper"
4
- require "llvm/core"
5
- require 'llvm/transforms/ipo'
6
- require 'llvm/core/pass_manager'
7
-
8
- class IPOTestCase < Minitest::Test
9
-
10
- def setup
11
- LLVM.init_jit
12
- end
13
-
14
- def test_gdce
15
- mod = LLVM::Module.new('test')
16
-
17
- fn1 = mod.functions.add("fn1", [], LLVM.Void) do |fn|
18
- fn.linkage = :internal
19
- fn.basic_blocks.append.build do |builder|
20
- builder.ret_void
21
- end
22
- end
23
-
24
- fn2 = mod.functions.add("fn2", [], LLVM.Void) do |fn|
25
- fn.linkage = :internal
26
- fn.basic_blocks.append.build do |builder|
27
- builder.ret_void
28
- end
29
- end
30
-
31
- main = mod.functions.add("main", [], LLVM.Void) do |fn|
32
- fn.basic_blocks.append.build do |builder|
33
- builder.call(fn1)
34
- builder.ret_void
35
- end
36
- end
37
-
38
- fns = mod.functions.to_a
39
- assert fns.include?(fn1)
40
- assert fns.include?(fn2)
41
- assert fns.include?(main)
42
-
43
- # optimize
44
- engine = LLVM::MCJITCompiler.new(mod)
45
- passm = LLVM::PassManager.new(engine)
46
-
47
- passm.gdce!
48
- passm.run(mod)
49
-
50
- fns = mod.functions.to_a
51
- assert fns.include?(fn1)
52
- assert !fns.include?(fn2), 'fn2 should be eliminated'
53
- assert fns.include?(main)
54
- end
55
- end
data/test/linker_test.rb DELETED
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- require 'llvm/core'
5
- require 'llvm/linker'
6
-
7
- class LinkerTestCase < Minitest::Test
8
- def setup
9
- LLVM.init_jit
10
- end
11
-
12
- def create_modules
13
- @mod1 = define_module('mod1') do |mod|
14
- mod1calc = mod.functions.add("calc", [], LLVM::Int32)
15
-
16
- mod.functions.add("main", [], LLVM::Int32) do |fn|
17
- fn.basic_blocks.append.build do |builder|
18
- val = builder.call(mod1calc)
19
- builder.ret val
20
- end
21
- end
22
- end
23
-
24
- @mod2 = define_module('mod2') do |mod|
25
- mod.functions.add("calc", [], LLVM::Int32) do |fn|
26
- fn.basic_blocks.append.build do |builder|
27
- builder.ret LLVM::Int32.from_i(42)
28
- end
29
- end
30
- end
31
- end
32
-
33
- def test_link_into
34
- create_modules
35
- @mod2.link_into(@mod1)
36
-
37
- assert_equal 42, run_function_on_module(@mod1, 'main').to_i
38
- end
39
- end