ruby-llvm 20.1.7 → 22.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/ext/ruby-llvm-support/Rakefile +5 -4
- data/ext/ruby-llvm-support/support.cpp +75 -4
- data/lib/llvm/analysis.rb +9 -0
- data/lib/llvm/analysis_ffi.rb +1 -2
- data/lib/llvm/core/attribute.rb +41 -2
- data/lib/llvm/core/bitcode.rb +24 -6
- data/lib/llvm/core/bitcode_ffi.rb +1 -2
- data/lib/llvm/core/builder.rb +140 -21
- data/lib/llvm/core/context.rb +7 -2
- data/lib/llvm/core/module.rb +79 -23
- data/lib/llvm/core/pass_manager.rb +1 -0
- data/lib/llvm/core/type.rb +139 -63
- data/lib/llvm/core/value.rb +156 -42
- data/lib/llvm/core.rb +7 -4
- data/lib/llvm/core_ffi.rb +11 -34
- data/lib/llvm/core_ffi_v2.rb +5 -0
- data/lib/llvm/execution_engine.rb +59 -39
- data/lib/llvm/execution_engine_ffi.rb +5 -6
- data/lib/llvm/linker.rb +13 -5
- data/lib/llvm/linker_ffi.rb +1 -2
- data/lib/llvm/lljit.rb +9 -9
- data/lib/llvm/owned_string.rb +48 -0
- data/lib/llvm/pass_builder.rb +21 -18
- data/lib/llvm/support.rb +11 -7
- data/lib/llvm/target.rb +40 -23
- data/lib/llvm/target_ffi.rb +5 -6
- data/lib/llvm/transforms/ipo.rb +1 -0
- data/lib/llvm/transforms/pass_manager_builder.rb +1 -0
- data/lib/llvm/transforms/scalar.rb +1 -0
- data/lib/llvm/transforms/utils.rb +1 -0
- data/lib/llvm/transforms/vectorize.rb +1 -0
- data/lib/llvm/version.rb +24 -3
- data/lib/llvm.rb +10 -3
- metadata +11 -55
- data/lib/llvm/config.rb +0 -14
data/lib/llvm/core.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# typed: strict
|
|
2
3
|
|
|
3
4
|
require 'llvm'
|
|
4
5
|
require 'llvm/core_ffi'
|
|
@@ -12,8 +13,9 @@ module LLVM
|
|
|
12
13
|
#
|
|
13
14
|
# @yield [FFI::MemoryPointer]
|
|
14
15
|
# @return [String, nil]
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
#: { (FFI::MemoryPointer) -> Integer } -> String?
|
|
17
|
+
def self.with_message_output(&)
|
|
18
|
+
message = nil #: String?
|
|
17
19
|
|
|
18
20
|
FFI::MemoryPointer.new(FFI.type_size(:pointer)) do |str|
|
|
19
21
|
result = yield str
|
|
@@ -36,8 +38,9 @@ module LLVM
|
|
|
36
38
|
#
|
|
37
39
|
# @yield [FFI::MemoryPointer]
|
|
38
40
|
# @return [nil]
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
#: { (FFI::MemoryPointer) -> Integer } -> String?
|
|
42
|
+
def self.with_error_output(&)
|
|
43
|
+
error = with_message_output(&)
|
|
41
44
|
|
|
42
45
|
raise error unless error.nil?
|
|
43
46
|
end
|
data/lib/llvm/core_ffi.rb
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
# Generated by ffi_gen. Please do not change this file by hand.
|
|
2
2
|
|
|
3
3
|
require 'ffi'
|
|
4
|
+
require 'llvm/version'
|
|
5
|
+
require 'llvm/owned_string'
|
|
4
6
|
|
|
5
7
|
module LLVM::C
|
|
6
8
|
extend FFI::Library
|
|
7
|
-
|
|
9
|
+
|
|
10
|
+
# bind here for FFI in module LLVM::C
|
|
11
|
+
ffi_lib LLVM::LIB_NAMES
|
|
8
12
|
|
|
9
13
|
# (Not documented)
|
|
10
14
|
#
|
|
@@ -778,7 +782,7 @@ module LLVM::C
|
|
|
778
782
|
# @param [String] message
|
|
779
783
|
# @return [String]
|
|
780
784
|
# @scope class
|
|
781
|
-
attach_function :create_message, :LLVMCreateMessage, [:string],
|
|
785
|
+
attach_function :create_message, :LLVMCreateMessage, [:string], LLVM::OwnedString
|
|
782
786
|
|
|
783
787
|
# (Not documented)
|
|
784
788
|
#
|
|
@@ -786,7 +790,7 @@ module LLVM::C
|
|
|
786
790
|
# @param [String] message
|
|
787
791
|
# @return [nil]
|
|
788
792
|
# @scope class
|
|
789
|
-
attach_function :dispose_message, :LLVMDisposeMessage, [:
|
|
793
|
+
attach_function :dispose_message, :LLVMDisposeMessage, [:pointer], :void
|
|
790
794
|
|
|
791
795
|
# @defgroup LLVMCCoreContext Contexts
|
|
792
796
|
#
|
|
@@ -877,7 +881,7 @@ module LLVM::C
|
|
|
877
881
|
# @param [FFI::Pointer(DiagnosticInfoRef)] di
|
|
878
882
|
# @return [String]
|
|
879
883
|
# @scope class
|
|
880
|
-
attach_function :get_diag_info_description, :LLVMGetDiagInfoDescription, [:pointer],
|
|
884
|
+
attach_function :get_diag_info_description, :LLVMGetDiagInfoDescription, [:pointer], LLVM::OwnedString
|
|
881
885
|
|
|
882
886
|
# Return an enum LLVMDiagnosticSeverity.
|
|
883
887
|
#
|
|
@@ -1027,7 +1031,7 @@ module LLVM::C
|
|
|
1027
1031
|
# @param [FFI::Pointer(ModuleRef)] m
|
|
1028
1032
|
# @return [String]
|
|
1029
1033
|
# @scope class
|
|
1030
|
-
attach_function :print_module_to_string, :LLVMPrintModuleToString, [:pointer],
|
|
1034
|
+
attach_function :print_module_to_string, :LLVMPrintModuleToString, [:pointer], LLVM::OwnedString
|
|
1031
1035
|
|
|
1032
1036
|
# Set inline assembly for a module.
|
|
1033
1037
|
#
|
|
@@ -1219,7 +1223,7 @@ module LLVM::C
|
|
|
1219
1223
|
# @param [FFI::Pointer(TypeRef)] val
|
|
1220
1224
|
# @return [String]
|
|
1221
1225
|
# @scope class
|
|
1222
|
-
attach_function :print_type_to_string, :LLVMPrintTypeToString, [:pointer],
|
|
1226
|
+
attach_function :print_type_to_string, :LLVMPrintTypeToString, [:pointer], LLVM::OwnedString
|
|
1223
1227
|
|
|
1224
1228
|
# Obtain an integer type from a context with specified bit width.
|
|
1225
1229
|
#
|
|
@@ -1756,7 +1760,7 @@ module LLVM::C
|
|
|
1756
1760
|
# @param [FFI::Pointer(ValueRef)] val
|
|
1757
1761
|
# @return [String]
|
|
1758
1762
|
# @scope class
|
|
1759
|
-
attach_function :print_value_to_string, :LLVMPrintValueToString, [:pointer],
|
|
1763
|
+
attach_function :print_value_to_string, :LLVMPrintValueToString, [:pointer], LLVM::OwnedString
|
|
1760
1764
|
|
|
1761
1765
|
# Replace all uses of a value with another one.
|
|
1762
1766
|
#
|
|
@@ -2893,33 +2897,6 @@ module LLVM::C
|
|
|
2893
2897
|
# @scope class
|
|
2894
2898
|
attach_function :const_nuw_sub, :LLVMConstNUWSub, [:pointer, :pointer], :pointer
|
|
2895
2899
|
|
|
2896
|
-
# (Not documented)
|
|
2897
|
-
#
|
|
2898
|
-
# @method const_mul(lhs_constant, rhs_constant)
|
|
2899
|
-
# @param [FFI::Pointer(ValueRef)] lhs_constant
|
|
2900
|
-
# @param [FFI::Pointer(ValueRef)] rhs_constant
|
|
2901
|
-
# @return [FFI::Pointer(ValueRef)]
|
|
2902
|
-
# @scope class
|
|
2903
|
-
attach_function :const_mul, :LLVMConstMul, [:pointer, :pointer], :pointer
|
|
2904
|
-
|
|
2905
|
-
# (Not documented)
|
|
2906
|
-
#
|
|
2907
|
-
# @method const_nsw_mul(lhs_constant, rhs_constant)
|
|
2908
|
-
# @param [FFI::Pointer(ValueRef)] lhs_constant
|
|
2909
|
-
# @param [FFI::Pointer(ValueRef)] rhs_constant
|
|
2910
|
-
# @return [FFI::Pointer(ValueRef)]
|
|
2911
|
-
# @scope class
|
|
2912
|
-
attach_function :const_nsw_mul, :LLVMConstNSWMul, [:pointer, :pointer], :pointer
|
|
2913
|
-
|
|
2914
|
-
# (Not documented)
|
|
2915
|
-
#
|
|
2916
|
-
# @method const_nuw_mul(lhs_constant, rhs_constant)
|
|
2917
|
-
# @param [FFI::Pointer(ValueRef)] lhs_constant
|
|
2918
|
-
# @param [FFI::Pointer(ValueRef)] rhs_constant
|
|
2919
|
-
# @return [FFI::Pointer(ValueRef)]
|
|
2920
|
-
# @scope class
|
|
2921
|
-
attach_function :const_nuw_mul, :LLVMConstNUWMul, [:pointer, :pointer], :pointer
|
|
2922
|
-
|
|
2923
2900
|
# (Not documented)
|
|
2924
2901
|
#
|
|
2925
2902
|
# @method const_xor(lhs_constant, rhs_constant)
|
data/lib/llvm/core_ffi_v2.rb
CHANGED
|
@@ -5,6 +5,11 @@ module LLVM
|
|
|
5
5
|
module C
|
|
6
6
|
attach_function :dispose_message, :LLVMDisposeMessage, [:pointer], :void
|
|
7
7
|
|
|
8
|
+
# Both disposers must take :pointer, not :string. With :string, FFI marshals
|
|
9
|
+
# the Ruby String into a temporary buffer and LLVM frees that instead of its
|
|
10
|
+
# own allocation, aborting with "munmap_chunk(): invalid pointer".
|
|
11
|
+
attach_function :dispose_error_message, :LLVMDisposeErrorMessage, [:pointer], :void
|
|
12
|
+
|
|
8
13
|
# typedef unsigned LLVMAttributeIndex;
|
|
9
14
|
typedef(:uint, :llvmattributeindex)
|
|
10
15
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# typed: true
|
|
2
3
|
|
|
3
4
|
require 'llvm'
|
|
4
5
|
require 'llvm/core'
|
|
@@ -18,18 +19,13 @@ module LLVM
|
|
|
18
19
|
# @return [ExecutionEngine] JIT execution engine
|
|
19
20
|
def initialize(mod, options)
|
|
20
21
|
FFI::MemoryPointer.new(FFI.type_size(:pointer)) do |ptr|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
errorp = error.read_pointer
|
|
24
|
-
message = errorp.read_string unless errorp.null?
|
|
25
|
-
|
|
26
|
-
if status.zero?
|
|
27
|
-
@ptr = ptr.read_pointer
|
|
28
|
-
else
|
|
29
|
-
C.dispose_message(error)
|
|
30
|
-
error.autorelease = false
|
|
31
|
-
raise "Error creating JIT compiler: #{message}"
|
|
22
|
+
message = LLVM.with_message_output do |err|
|
|
23
|
+
create_execution_engine_for_module(ptr, mod, err, options)
|
|
32
24
|
end
|
|
25
|
+
|
|
26
|
+
raise "Error creating JIT compiler: #{message}" if message
|
|
27
|
+
|
|
28
|
+
@ptr = ptr.read_pointer
|
|
33
29
|
end
|
|
34
30
|
end
|
|
35
31
|
|
|
@@ -62,11 +58,13 @@ module LLVM
|
|
|
62
58
|
# GenericValues).
|
|
63
59
|
# Important: Call #dispose on the returned GenericValue to
|
|
64
60
|
# free backend memory after use.
|
|
61
|
+
#: (LLVM::Function, *untyped) -> GenericValue?
|
|
65
62
|
def run_function(fun, *args)
|
|
63
|
+
result = nil #: GenericValue?
|
|
66
64
|
FFI::MemoryPointer.new(FFI.type_size(:pointer) * args.size) do |args_ptr|
|
|
67
65
|
new_values = []
|
|
68
66
|
args_ptr.write_array_of_pointer(fun.params.zip(args).map do |p, a|
|
|
69
|
-
if a.
|
|
67
|
+
if a.is_a?(GenericValue)
|
|
70
68
|
a
|
|
71
69
|
else
|
|
72
70
|
value = LLVM.make_generic_value(p.type, a)
|
|
@@ -74,11 +72,14 @@ module LLVM
|
|
|
74
72
|
value
|
|
75
73
|
end
|
|
76
74
|
end)
|
|
77
|
-
result =
|
|
78
|
-
C.run_function
|
|
75
|
+
result = begin
|
|
76
|
+
LLVM::GenericValue.from_ptr(C.send(:run_function, self, fun, args.size, args_ptr))
|
|
77
|
+
rescue ArgumentError
|
|
78
|
+
nil
|
|
79
|
+
end
|
|
79
80
|
new_values.each(&:dispose)
|
|
80
|
-
return result
|
|
81
81
|
end
|
|
82
|
+
result
|
|
82
83
|
end
|
|
83
84
|
|
|
84
85
|
# Obtain an FFI::Pointer to a global within the current module.
|
|
@@ -117,22 +118,15 @@ module LLVM
|
|
|
117
118
|
# @param [LLVM::Module] mod
|
|
118
119
|
# @return [LLVM::Module] deleted module
|
|
119
120
|
def delete(mod)
|
|
120
|
-
error = FFI::MemoryPointer.new(:pointer)
|
|
121
121
|
out_mod = FFI::MemoryPointer.new(:pointer)
|
|
122
122
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
LLVM::Module.from_ptr(out_mod.read_pointer)
|
|
127
|
-
else
|
|
128
|
-
errorp = error.read_pointer
|
|
129
|
-
message = errorp.read_string unless errorp.null?
|
|
123
|
+
message = LLVM.with_message_output do |err|
|
|
124
|
+
C.remove_module(@engine, mod, out_mod, err)
|
|
125
|
+
end
|
|
130
126
|
|
|
131
|
-
|
|
132
|
-
error.autorelease = false
|
|
127
|
+
raise "Error removing module: #{message}" if message
|
|
133
128
|
|
|
134
|
-
|
|
135
|
-
end
|
|
129
|
+
LLVM::Module.from_ptr(out_mod.read_pointer)
|
|
136
130
|
end
|
|
137
131
|
|
|
138
132
|
alias_method :<<, :add
|
|
@@ -146,6 +140,7 @@ module LLVM
|
|
|
146
140
|
|
|
147
141
|
# @param [String, Symbol] name function name
|
|
148
142
|
# @return [Function]
|
|
143
|
+
#: (String | Symbol) -> Function?
|
|
149
144
|
def named(name)
|
|
150
145
|
out_fun = FFI::MemoryPointer.new(:pointer)
|
|
151
146
|
|
|
@@ -211,15 +206,20 @@ module LLVM
|
|
|
211
206
|
end
|
|
212
207
|
end
|
|
213
208
|
|
|
209
|
+
#: (Function, *untyped) -> GenericValue?
|
|
214
210
|
def run_function(fun, *args)
|
|
215
|
-
args2 = fun.params.map {|e| convert_type(e.type)}
|
|
211
|
+
args2 = fun.params.map { |e| convert_type(e.type) }
|
|
216
212
|
ptr = FFI::Pointer.new(function_address(fun.name))
|
|
217
213
|
raise "Couldn't find function" if ptr.null?
|
|
218
214
|
|
|
219
215
|
return_type = convert_type(fun.function_type.return_type)
|
|
220
|
-
f = FFI::Function.new(return_type, args2, ptr)
|
|
216
|
+
f = FFI::Function.new(return_type, args2, ptr) #: as untyped
|
|
221
217
|
ret1 = f.call(*args)
|
|
222
|
-
|
|
218
|
+
begin
|
|
219
|
+
LLVM.make_generic_value(fun.function_type.return_type, ret1)
|
|
220
|
+
rescue ArgumentError
|
|
221
|
+
nil
|
|
222
|
+
end
|
|
223
223
|
end
|
|
224
224
|
|
|
225
225
|
protected
|
|
@@ -247,13 +247,19 @@ module LLVM
|
|
|
247
247
|
end
|
|
248
248
|
|
|
249
249
|
# Casts an FFI::Pointer pointing to a GenericValue to an instance.
|
|
250
|
+
#: (FFI::Pointer) -> GenericValue
|
|
250
251
|
def self.from_ptr(ptr)
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
252
|
+
new(ptr)
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
# @private
|
|
256
|
+
#: (FFI::Pointer) -> void
|
|
257
|
+
def initialize(ptr)
|
|
258
|
+
raise ArgumentError if ptr.null?
|
|
259
|
+
@ptr = ptr #: FFI::Pointer?
|
|
255
260
|
end
|
|
256
261
|
|
|
262
|
+
#: -> void
|
|
257
263
|
def dispose
|
|
258
264
|
return if @ptr.nil?
|
|
259
265
|
C.dispose_generic_value(@ptr)
|
|
@@ -262,22 +268,26 @@ module LLVM
|
|
|
262
268
|
|
|
263
269
|
# Creates a Generic Value from an integer. Type is the size of integer to
|
|
264
270
|
# create (ex. Int32, Int8, etc.)
|
|
271
|
+
#: (Numeric, ?Hash[untyped, untyped]) -> GenericValue
|
|
265
272
|
def self.from_i(i, options = {})
|
|
266
273
|
type = options.fetch(:type, LLVM::Int)
|
|
267
274
|
signed = options.fetch(:signed, true)
|
|
268
|
-
from_ptr(C.create_generic_value_of_int(type, i, signed ? 1 : 0))
|
|
275
|
+
from_ptr(C.create_generic_value_of_int(type, i.to_i, signed ? 1 : 0)) #: as !nil
|
|
269
276
|
end
|
|
270
277
|
|
|
271
278
|
# Creates a Generic Value from a Float.
|
|
279
|
+
#: (Numeric) -> GenericValue
|
|
272
280
|
def self.from_f(f)
|
|
273
|
-
from_ptr(C.create_generic_value_of_float(LLVM::Float, f))
|
|
281
|
+
from_ptr(C.create_generic_value_of_float(LLVM::Float, f.to_f)) #: as !nil
|
|
274
282
|
end
|
|
275
283
|
|
|
284
|
+
#: (Numeric) -> GenericValue
|
|
276
285
|
def self.from_d(val)
|
|
277
|
-
from_ptr(C.create_generic_value_of_float(LLVM::Double, val))
|
|
286
|
+
from_ptr(C.create_generic_value_of_float(LLVM::Double, val.to_f)) #: as !nil
|
|
278
287
|
end
|
|
279
288
|
|
|
280
289
|
# Creates a GenericValue from a Ruby boolean.
|
|
290
|
+
#: (bool) -> GenericValue
|
|
281
291
|
def self.from_b(b)
|
|
282
292
|
from_i(b ? 1 : 0, type: LLVM::Int1, signed: false)
|
|
283
293
|
end
|
|
@@ -288,18 +298,27 @@ module LLVM
|
|
|
288
298
|
end
|
|
289
299
|
|
|
290
300
|
# Converts a GenericValue to a Ruby Integer.
|
|
301
|
+
#: (?bool) -> Integer
|
|
291
302
|
def to_i(signed = true)
|
|
292
303
|
v = C.generic_value_to_int(self, signed ? 1 : 0)
|
|
293
|
-
v -= 2**64 if signed
|
|
304
|
+
v -= 2**64 if signed && (v >= 2**63)
|
|
294
305
|
v
|
|
295
306
|
end
|
|
296
307
|
|
|
297
308
|
# Converts a GenericValue to a Ruby Float.
|
|
309
|
+
#: (?LLVM::Type) -> ::Float
|
|
298
310
|
def to_f(type = LLVM::Float.type)
|
|
299
311
|
C.generic_value_to_float(type, self)
|
|
300
312
|
end
|
|
301
313
|
|
|
314
|
+
# Converts a GenericValue to a Ruby Float.
|
|
315
|
+
#: -> ::Float
|
|
316
|
+
def to_d
|
|
317
|
+
C.generic_value_to_float(LLVM.double, self)
|
|
318
|
+
end
|
|
319
|
+
|
|
302
320
|
# Converts a GenericValue to a Ruby boolean.
|
|
321
|
+
#: -> bool
|
|
303
322
|
def to_b
|
|
304
323
|
to_i(false) != 0
|
|
305
324
|
end
|
|
@@ -310,6 +329,7 @@ module LLVM
|
|
|
310
329
|
end
|
|
311
330
|
|
|
312
331
|
# @private
|
|
332
|
+
#: (LLVM::Type, untyped) -> GenericValue
|
|
313
333
|
def make_generic_value(ty, val)
|
|
314
334
|
case ty.kind
|
|
315
335
|
when :double then GenericValue.from_d(val)
|
|
@@ -317,7 +337,7 @@ module LLVM
|
|
|
317
337
|
when :pointer then GenericValue.from_value_ptr(val)
|
|
318
338
|
when :integer then GenericValue.from_i(val, :type => ty)
|
|
319
339
|
else
|
|
320
|
-
raise "Unsupported type #{ty.kind}."
|
|
340
|
+
raise ArgumentError, "Unsupported type #{ty.kind}."
|
|
321
341
|
end
|
|
322
342
|
end
|
|
323
343
|
module_function :make_generic_value
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
# Generated by ffi_gen. Please do not change this file by hand.
|
|
2
2
|
|
|
3
3
|
require 'ffi'
|
|
4
|
+
require 'llvm/core_ffi'
|
|
4
5
|
|
|
5
6
|
module LLVM::C
|
|
6
|
-
extend FFI::Library
|
|
7
|
-
ffi_lib ["LLVM-20", "libLLVM-20.so.1", "libLLVM.so.20", "libLLVM.so.20.1"]
|
|
8
7
|
# @defgroup LLVMCExecutionEngine Execution Engine
|
|
9
8
|
# @ingroup LLVMC
|
|
10
9
|
#
|
|
@@ -52,10 +51,10 @@ module LLVM::C
|
|
|
52
51
|
# (OpaqueMCJITMemoryManager)
|
|
53
52
|
class MCJITCompilerOptions < FFI::Struct
|
|
54
53
|
layout :opt_level, :uint,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
:code_model, :char,
|
|
55
|
+
:no_frame_pointer_elim, :int,
|
|
56
|
+
:enable_fast_i_sel, :int,
|
|
57
|
+
:mcjmm, OpaqueMCJITMemoryManager
|
|
59
58
|
end
|
|
60
59
|
|
|
61
60
|
# ===-- Operations on generic values --------------------------------------===
|
data/lib/llvm/linker.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# typed: strict
|
|
2
3
|
|
|
3
4
|
require 'llvm'
|
|
4
5
|
require 'llvm/core'
|
|
@@ -6,13 +7,20 @@ require 'llvm/linker_ffi'
|
|
|
6
7
|
|
|
7
8
|
module LLVM
|
|
8
9
|
class Module
|
|
9
|
-
# Link the current module into +other+.
|
|
10
|
+
# Link the current module into +other+. LLVM destroys the current module,
|
|
11
|
+
# so afterward it is cleared as if disposed, and must not be used.
|
|
10
12
|
#
|
|
11
|
-
# @return [
|
|
13
|
+
# @return [Boolean] true if linking succeeded; the inverse of
|
|
14
|
+
# LLVMLinkModules2, which returns true if an error occurred. A failed
|
|
15
|
+
# link ends the process, because LLVM's default diagnostic handler
|
|
16
|
+
# prints the error and exits; false is returned only if a diagnostic
|
|
17
|
+
# handler is installed on the context. See
|
|
18
|
+
# https://github.com/ruby-llvm/ruby-llvm/issues/346
|
|
19
|
+
#: (LLVM::Module) -> bool
|
|
12
20
|
def link_into(other)
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
21
|
+
succeeded = C.link_modules2(other, self).zero?
|
|
22
|
+
@ptr = nil #: FFI::Pointer?
|
|
23
|
+
succeeded
|
|
16
24
|
end
|
|
17
25
|
end
|
|
18
26
|
end
|
data/lib/llvm/linker_ffi.rb
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
# Generated by ffi_gen. Please do not change this file by hand.
|
|
2
2
|
|
|
3
3
|
require 'ffi'
|
|
4
|
+
require 'llvm/core_ffi'
|
|
4
5
|
|
|
5
6
|
module LLVM::C
|
|
6
|
-
extend FFI::Library
|
|
7
|
-
ffi_lib ["LLVM-20", "libLLVM-20.so.1", "libLLVM.so.20", "libLLVM.so.20.1"]
|
|
8
7
|
# This enum is provided for backwards-compatibility only. It has no effect.
|
|
9
8
|
#
|
|
10
9
|
# <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:linker_mode).</em>
|
data/lib/llvm/lljit.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# typed: true
|
|
2
3
|
|
|
3
4
|
require 'llvm/core'
|
|
4
5
|
|
|
@@ -45,8 +46,9 @@ module LLVM
|
|
|
45
46
|
|
|
46
47
|
module C
|
|
47
48
|
extend FFI::Library
|
|
49
|
+
|
|
48
50
|
ffi_lib_flags(:lazy, :global)
|
|
49
|
-
ffi_lib
|
|
51
|
+
ffi_lib LLVM::LIB_NAMES
|
|
50
52
|
attach_function :create_lljit_builder, :LLVMOrcCreateLLJITBuilder, [], :pointer
|
|
51
53
|
attach_function :dispose_lljit_builder, :LLVMOrcDisposeLLJITBuilder, [:pointer], :void
|
|
52
54
|
|
|
@@ -71,34 +73,32 @@ module LLVM
|
|
|
71
73
|
# LLVMOrcResourceTrackerRef
|
|
72
74
|
# LLVMOrcJITDylibCreateResourceTracker(LLVMOrcJITDylibRef JD);
|
|
73
75
|
attach_function :dylib_create_resource_tracker, :LLVMOrcJITDylibCreateResourceTracker,
|
|
74
|
-
|
|
76
|
+
[:pointer], :pointer
|
|
75
77
|
|
|
76
78
|
# LLVMOrcThreadSafeContextRef LLVMOrcCreateNewThreadSafeContext(void);
|
|
77
79
|
attach_function :create_new_thread_safe_context, :LLVMOrcCreateNewThreadSafeContext,
|
|
78
|
-
|
|
80
|
+
[], :pointer
|
|
79
81
|
|
|
80
82
|
# LLVMOrcThreadSafeModuleRef
|
|
81
83
|
# LLVMOrcCreateNewThreadSafeModule(LLVMModuleRef M,
|
|
82
84
|
# LLVMOrcThreadSafeContextRef TSCtx);
|
|
83
85
|
attach_function :create_new_thread_safe_module, :LLVMOrcCreateNewThreadSafeContext,
|
|
84
|
-
|
|
86
|
+
[:pointer, :pointer], :pointer
|
|
85
87
|
|
|
86
88
|
# LLVMErrorRef LLVMOrcLLJITAddLLVMIRModule(LLVMOrcLLJITRef J,
|
|
87
89
|
# LLVMOrcJITDylibRef JD,
|
|
88
90
|
# LLVMOrcThreadSafeModuleRef TSM);
|
|
89
91
|
attach_function :add_llvm_ir_module, :LLVMOrcLLJITAddLLVMIRModule,
|
|
90
|
-
|
|
92
|
+
[:pointer, :pointer, :pointer], :pointer
|
|
91
93
|
|
|
92
94
|
# LLVMErrorRef LLVMOrcLLJITAddLLVMIRModuleWithRT(LLVMOrcLLJITRef J,
|
|
93
95
|
# LLVMOrcResourceTrackerRef JD,
|
|
94
96
|
# LLVMOrcThreadSafeModuleRef TSM);
|
|
95
97
|
attach_function :add_llvm_ir_module_with_rt, :LLVMOrcLLJITAddLLVMIRModuleWithRT,
|
|
96
|
-
|
|
98
|
+
[:pointer, :pointer, :pointer], :pointer
|
|
97
99
|
|
|
98
100
|
# TODO: extract and combine with PassBuilder
|
|
99
|
-
attach_function(:get_error_message, :LLVMGetErrorMessage, [:pointer],
|
|
100
|
-
|
|
101
|
-
attach_function(:dispose_error_message, :LLVMDisposeErrorMessage, [:string], :void)
|
|
101
|
+
attach_function(:get_error_message, :LLVMGetErrorMessage, [:pointer], LLVM::OwnedErrorString)
|
|
102
102
|
end
|
|
103
103
|
end
|
|
104
104
|
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# typed: true
|
|
3
|
+
|
|
4
|
+
require 'ffi'
|
|
5
|
+
|
|
6
|
+
module LLVM
|
|
7
|
+
# Intended for LLVM functions that return a caller owned string which requires
|
|
8
|
+
# freeing with `dispose_message` i.e. those declared `char *` rather than `const
|
|
9
|
+
# char *`. Reads the buffer into a Ruby String and releases it with LLVMDisposeMessage.
|
|
10
|
+
#
|
|
11
|
+
# This prevents memory leaks at the expense of a string copy and free following return
|
|
12
|
+
module OwnedString
|
|
13
|
+
extend FFI::DataConverter
|
|
14
|
+
|
|
15
|
+
native_type FFI::Type::POINTER
|
|
16
|
+
|
|
17
|
+
#: (FFI::Pointer, untyped) -> String?
|
|
18
|
+
def self.from_native(ptr, _ctx)
|
|
19
|
+
return if ptr.null?
|
|
20
|
+
|
|
21
|
+
begin
|
|
22
|
+
ptr.read_string
|
|
23
|
+
ensure
|
|
24
|
+
LLVM::C.dispose_message(ptr)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# As OwnedString, but for LLVMGetErrorMessage, which the LLVM headers require
|
|
30
|
+
# be freed with LLVMDisposeErrorMessage rather than LLVMDisposeMessage. The
|
|
31
|
+
# two are not interchangeable, so this cannot share OwnedString.
|
|
32
|
+
module OwnedErrorString
|
|
33
|
+
extend FFI::DataConverter
|
|
34
|
+
|
|
35
|
+
native_type FFI::Type::POINTER
|
|
36
|
+
|
|
37
|
+
#: (FFI::Pointer, untyped) -> String?
|
|
38
|
+
def self.from_native(ptr, _ctx)
|
|
39
|
+
return if ptr.null?
|
|
40
|
+
|
|
41
|
+
begin
|
|
42
|
+
ptr.read_string
|
|
43
|
+
ensure
|
|
44
|
+
LLVM::C.dispose_error_message(ptr)
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|