ruby-llvm 20.1.2 → 21.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.
data/lib/llvm/core_ffi.rb CHANGED
@@ -4,7 +4,8 @@ require 'ffi'
4
4
 
5
5
  module LLVM::C
6
6
  extend FFI::Library
7
- ffi_lib ["LLVM-20", "libLLVM-20.so.1", "libLLVM.so.20", "libLLVM.so.20.1"]
7
+
8
+ ffi_lib ["LLVM-21", "libLLVM-21.so.1", "libLLVM.so.21", "libLLVM.so.21.1"]
8
9
 
9
10
  # (Not documented)
10
11
  #
@@ -2893,33 +2894,6 @@ module LLVM::C
2893
2894
  # @scope class
2894
2895
  attach_function :const_nuw_sub, :LLVMConstNUWSub, [:pointer, :pointer], :pointer
2895
2896
 
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
2897
  # (Not documented)
2924
2898
  #
2925
2899
  # @method const_xor(lhs_constant, rhs_constant)
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # typed: true
2
3
 
3
4
  require 'llvm'
4
5
  require 'llvm/core'
@@ -62,7 +63,9 @@ module LLVM
62
63
  # GenericValues).
63
64
  # Important: Call #dispose on the returned GenericValue to
64
65
  # free backend memory after use.
66
+ #: (LLVM::Function, *untyped) -> GenericValue?
65
67
  def run_function(fun, *args)
68
+ result = nil #: GenericValue?
66
69
  FFI::MemoryPointer.new(FFI.type_size(:pointer) * args.size) do |args_ptr|
67
70
  new_values = []
68
71
  args_ptr.write_array_of_pointer(fun.params.zip(args).map do |p, a|
@@ -74,11 +77,14 @@ module LLVM
74
77
  value
75
78
  end
76
79
  end)
77
- result = LLVM::GenericValue.from_ptr(
78
- C.run_function(self, fun, args.size, args_ptr))
80
+ result = begin
81
+ LLVM::GenericValue.from_ptr(C.send(:run_function, self, fun, args.size, args_ptr))
82
+ rescue ArgumentError
83
+ nil
84
+ end
79
85
  new_values.each(&:dispose)
80
- return result
81
86
  end
87
+ result
82
88
  end
83
89
 
84
90
  # Obtain an FFI::Pointer to a global within the current module.
@@ -211,16 +217,20 @@ module LLVM
211
217
  end
212
218
  end
213
219
 
220
+ #: (Function, *untyped) -> GenericValue?
214
221
  def run_function(fun, *args)
215
222
  args2 = fun.params.map {|e| convert_type(e.type)}
216
223
  ptr = FFI::Pointer.new(function_address(fun.name))
217
224
  raise "Couldn't find function" if ptr.null?
218
225
 
219
226
  return_type = convert_type(fun.function_type.return_type)
220
- f = FFI::Function.new(return_type, args2, ptr)
227
+ f = FFI::Function.new(return_type, args2, ptr) #: as untyped
221
228
  ret1 = f.call(*args)
222
- ret2 = LLVM.make_generic_value(fun.function_type.return_type, ret1)
223
- ret2
229
+ begin
230
+ LLVM.make_generic_value(fun.function_type.return_type, ret1)
231
+ rescue ArgumentError
232
+ nil
233
+ end
224
234
  end
225
235
 
226
236
  protected
@@ -248,13 +258,15 @@ module LLVM
248
258
  end
249
259
 
250
260
  # Casts an FFI::Pointer pointing to a GenericValue to an instance.
261
+ #: (FFI::Pointer?) -> GenericValue?
251
262
  def self.from_ptr(ptr)
252
- return if ptr.null?
263
+ return if ptr.nil? || ptr.null?
253
264
  val = allocate
254
265
  val.instance_variable_set(:@ptr, ptr)
255
266
  val
256
267
  end
257
268
 
269
+ #: -> void
258
270
  def dispose
259
271
  return if @ptr.nil?
260
272
  C.dispose_generic_value(@ptr)
@@ -263,22 +275,26 @@ module LLVM
263
275
 
264
276
  # Creates a Generic Value from an integer. Type is the size of integer to
265
277
  # create (ex. Int32, Int8, etc.)
278
+ #: (Numeric, ?Hash[untyped, untyped]) -> GenericValue
266
279
  def self.from_i(i, options = {})
267
280
  type = options.fetch(:type, LLVM::Int)
268
281
  signed = options.fetch(:signed, true)
269
- from_ptr(C.create_generic_value_of_int(type, i, signed ? 1 : 0))
282
+ from_ptr(C.create_generic_value_of_int(type, i.to_i, signed ? 1 : 0)) #: as !nil
270
283
  end
271
284
 
272
285
  # Creates a Generic Value from a Float.
286
+ #: (Numeric) -> GenericValue
273
287
  def self.from_f(f)
274
- from_ptr(C.create_generic_value_of_float(LLVM::Float, f))
288
+ from_ptr(C.create_generic_value_of_float(LLVM::Float, f.to_f)) #: as !nil
275
289
  end
276
290
 
291
+ #: (Numeric) -> GenericValue
277
292
  def self.from_d(val)
278
- from_ptr(C.create_generic_value_of_float(LLVM::Double, val))
293
+ from_ptr(C.create_generic_value_of_float(LLVM::Double, val.to_f)) #: as !nil
279
294
  end
280
295
 
281
296
  # Creates a GenericValue from a Ruby boolean.
297
+ #: (bool) -> GenericValue
282
298
  def self.from_b(b)
283
299
  from_i(b ? 1 : 0, type: LLVM::Int1, signed: false)
284
300
  end
@@ -289,6 +305,7 @@ module LLVM
289
305
  end
290
306
 
291
307
  # Converts a GenericValue to a Ruby Integer.
308
+ #: (?bool) -> Integer
292
309
  def to_i(signed = true)
293
310
  v = C.generic_value_to_int(self, signed ? 1 : 0)
294
311
  v -= 2**64 if signed and v >= 2**63
@@ -296,11 +313,19 @@ module LLVM
296
313
  end
297
314
 
298
315
  # Converts a GenericValue to a Ruby Float.
316
+ #: (?LLVM::Type) -> ::Float
299
317
  def to_f(type = LLVM::Float.type)
300
318
  C.generic_value_to_float(type, self)
301
319
  end
302
320
 
321
+ # Converts a GenericValue to a Ruby Float.
322
+ #: -> ::Float
323
+ def to_d
324
+ C.generic_value_to_float(LLVM.double, self)
325
+ end
326
+
303
327
  # Converts a GenericValue to a Ruby boolean.
328
+ #: -> bool
304
329
  def to_b
305
330
  to_i(false) != 0
306
331
  end
@@ -311,6 +336,7 @@ module LLVM
311
336
  end
312
337
 
313
338
  # @private
339
+ #: (LLVM::Type, untyped) -> GenericValue
314
340
  def make_generic_value(ty, val)
315
341
  case ty.kind
316
342
  when :double then GenericValue.from_d(val)
@@ -318,7 +344,7 @@ module LLVM
318
344
  when :pointer then GenericValue.from_value_ptr(val)
319
345
  when :integer then GenericValue.from_i(val, :type => ty)
320
346
  else
321
- raise "Unsupported type #{ty.kind}."
347
+ raise ArgumentError, "Unsupported type #{ty.kind}."
322
348
  end
323
349
  end
324
350
  module_function :make_generic_value
@@ -4,7 +4,8 @@ require 'ffi'
4
4
 
5
5
  module LLVM::C
6
6
  extend FFI::Library
7
- ffi_lib ["LLVM-20", "libLLVM-20.so.1", "libLLVM.so.20", "libLLVM.so.20.1"]
7
+
8
+ ffi_lib ["LLVM-21", "libLLVM-21.so.1", "libLLVM.so.21", "libLLVM.so.21.1"]
8
9
  # @defgroup LLVMCExecutionEngine Execution Engine
9
10
  # @ingroup LLVMC
10
11
  #
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'
@@ -9,6 +10,7 @@ module LLVM
9
10
  # Link the current module into +other+.
10
11
  #
11
12
  # @return [nil, String] human-readable error if linking has failed
13
+ #: (LLVM::Module) -> String?
12
14
  def link_into(other)
13
15
  LLVM.with_message_output do |msg|
14
16
  C.link_modules2(other, self)
@@ -4,7 +4,8 @@ require 'ffi'
4
4
 
5
5
  module LLVM::C
6
6
  extend FFI::Library
7
- ffi_lib ["LLVM-20", "libLLVM-20.so.1", "libLLVM.so.20", "libLLVM.so.20.1"]
7
+
8
+ ffi_lib ["LLVM-21", "libLLVM-21.so.1", "libLLVM.so.21", "libLLVM.so.21.1"]
8
9
  # This enum is provided for backwards-compatibility only. It has no effect.
9
10
  #
10
11
  # <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 ["LLVM-20", "libLLVM-20.so.1", "libLLVM.so.20", "libLLVM.so.20.1"]
51
+ ffi_lib ["LLVM-21", "libLLVM-21.so.1", "libLLVM.so.21", "libLLVM.so.21.1"]
50
52
  attach_function :create_lljit_builder, :LLVMOrcCreateLLJITBuilder, [], :pointer
51
53
  attach_function :dispose_lljit_builder, :LLVMOrcDisposeLLJITBuilder, [:pointer], :void
52
54
 
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
+ # typed: true
2
3
 
3
4
  module LLVM
4
5
  class PassBuilder # rubocop:disable Metrics/ClassLength
5
6
  extend FFI::Library
6
- ffi_lib ["LLVM-20", "libLLVM-20.so.1", "libLLVM.so.20", "libLLVM.so.20.1"]
7
+
8
+ ffi_lib ["LLVM-21", "libLLVM-21.so.1", "libLLVM.so.21", "libLLVM.so.21.1"]
7
9
  attr_reader :passes
8
10
  attr_accessor :inliner_threshold, :merge_functions
9
11
 
@@ -60,6 +62,7 @@ module LLVM
60
62
  end
61
63
 
62
64
  # @return self
65
+ #: (String) -> self
63
66
  def add_pass(pass)
64
67
  passes << pass
65
68
  self
@@ -754,6 +757,14 @@ module LLVM
754
757
  add_pass('tysan')
755
758
  end
756
759
 
760
+ # This optimization is only applied to integer constants in instructions and
761
+ # simple (this means not nested) constant cast expressions
762
+ # https://llvm.org/doxygen/ConstantHoisting_8cpp_source.html
763
+ #: -> self
764
+ def consthoist!
765
+ add_pass('consthoist')
766
+ end
767
+
757
768
  private
758
769
 
759
770
  attr_writer :passes
data/lib/llvm/support.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # typed: true
2
3
 
3
4
  require 'llvm/core_ffi'
4
5
 
data/lib/llvm/target.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # typed: true
2
3
 
3
4
  require 'llvm'
4
5
  require 'llvm/core'
@@ -7,7 +8,9 @@ require 'llvm/target_ffi'
7
8
  module LLVM
8
9
  # A shorthand for {LLVM::Target.init_native}
9
10
  def self.init_jit(*args)
10
- LLVM::Target.init_native(*args)
11
+ LLVM::Target.init_native(
12
+ *args #: as untyped
13
+ )
11
14
  end
12
15
 
13
16
  # @deprecated Use LLVM.init_jit or LLVM::Target.init('X86').
@@ -25,11 +28,15 @@ module LLVM
25
28
 
26
29
  module TargetModule
27
30
  extend FFI::Library
28
- ffi_lib ["LLVM-20", "libLLVM-20.so.1", "libLLVM.so.20", "libLLVM.so.20.1"]
31
+
32
+ ffi_lib ["LLVM-21", "libLLVM-21.so.1", "libLLVM.so.21", "libLLVM.so.21.1"]
33
+ #: (*untyped) -> void
29
34
  def self.safe_attach_function(*args)
30
- attach_function(*args)
35
+ attach_function(
36
+ *args #: as untyped
37
+ )
31
38
  rescue FFI::NotFoundError => e
32
- warn(e)
39
+ warn(e.message)
33
40
  end
34
41
  end
35
42
 
@@ -113,6 +120,7 @@ module LLVM
113
120
  include PointerIdentity
114
121
 
115
122
  # @private
123
+ #: (FFI::Pointer) -> Target
116
124
  def self.from_ptr(ptr)
117
125
  target = allocate
118
126
  target.instance_variable_set :@ptr, ptr
@@ -275,8 +283,9 @@ module LLVM
275
283
  # Returns the integer type that is the same size as a pointer on a target.
276
284
  #
277
285
  # @param [Integer] addr_space address space number
278
- def int_ptr_type(addr_space = 0)
279
- Type.from_ptr(C.int_ptr_type_for_as(self, addr_space), :integer)
286
+ # (?address_space: Integer) -> Type
287
+ def int_ptr_type(address_space: 0)
288
+ Type.from_ptr(C.int_ptr_type_for_as(self, address_space), kind: :integer)
280
289
  end
281
290
 
282
291
  # Computes the size of a type in bits for a target.
@@ -4,7 +4,8 @@ require 'ffi'
4
4
 
5
5
  module LLVM::C
6
6
  extend FFI::Library
7
- ffi_lib ["LLVM-20", "libLLVM-20.so.1", "libLLVM.so.20", "libLLVM.so.20.1"]
7
+
8
+ ffi_lib ["LLVM-21", "libLLVM-21.so.1", "libLLVM.so.21", "libLLVM.so.21.1"]
8
9
  # (Not documented)
9
10
  #
10
11
  # <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:byte_ordering).</em>
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # typed: true
2
3
 
3
4
  # Interprocedural optimization (IPO)
4
5
  require 'llvm'
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # typed: true
2
3
 
3
4
  require 'llvm'
4
5
  require 'llvm/core'
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # typed: true
2
3
 
3
4
  require 'llvm'
4
5
  require 'llvm/core'
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # typed: true
2
3
 
3
4
  require 'llvm'
4
5
  require 'llvm/core'
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # typed: true
2
3
 
3
4
  require 'llvm'
4
5
  require 'llvm/core'
data/lib/llvm/version.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
+ # typed: strict
2
3
 
3
4
  module LLVM
4
- LLVM_VERSION = "20"
5
- LLVM_REQUIRED_VERSION = "20.1.2"
6
- RUBY_LLVM_VERSION = "20.1.2"
5
+ LLVM_VERSION = "21"
6
+ LLVM_REQUIRED_VERSION = "21.1.0"
7
+ RUBY_LLVM_VERSION = "21.1.0"
7
8
  end
data/lib/llvm.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # typed: strict
2
3
 
3
4
  require 'ffi'
4
5
 
@@ -9,23 +10,29 @@ module LLVM
9
10
  class DeprecationError < StandardError; end
10
11
 
11
12
  module PointerIdentity
13
+ attr_reader :ptr #: as FFI::Pointer
14
+
12
15
  # @private
16
+ #: -> FFI::Pointer
13
17
  def to_ptr
14
- @ptr
18
+ ptr #: FFI::Pointer
15
19
  end
16
20
 
17
21
  # Checks if the value is equal to other.
22
+ #: (untyped) -> bool
18
23
  def ==(other)
19
24
  other.respond_to?(:to_ptr) &&
20
- @ptr == other.to_ptr
25
+ ptr == other.to_ptr
21
26
  end
22
27
 
23
28
  # Computes hash.
29
+ #: -> Integer
24
30
  def hash
25
- @ptr.address.hash
31
+ ptr.address.hash
26
32
  end
27
33
 
28
34
  # Checks if the value is equivalent to other.
35
+ #: (untyped) -> bool
29
36
  def eql?(other)
30
37
  self == other
31
38
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-llvm
3
3
  version: !ruby/object:Gem::Version
4
- version: 20.1.2
4
+ version: 21.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Johnson
8
8
  - Jeremy Voorhis
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2025-04-10 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: ffi
@@ -59,20 +58,6 @@ dependencies:
59
58
  - - ">="
60
59
  - !ruby/object:Gem::Version
61
60
  version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: ffi_gen
64
- requirement: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '1.2'
69
- type: :development
70
- prerelease: false
71
- version_requirements: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.2'
76
61
  - !ruby/object:Gem::Dependency
77
62
  name: minitest
78
63
  requirement: !ruby/object:Gem::Requirement
@@ -171,6 +156,34 @@ dependencies:
171
156
  - - ">="
172
157
  - !ruby/object:Gem::Version
173
158
  version: '0'
159
+ - !ruby/object:Gem::Dependency
160
+ name: sorbet-static
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - ">="
171
+ - !ruby/object:Gem::Version
172
+ version: '0'
173
+ - !ruby/object:Gem::Dependency
174
+ name: tapioca
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: 0.16.11
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - "~>"
185
+ - !ruby/object:Gem::Version
186
+ version: 0.16.11
174
187
  - !ruby/object:Gem::Dependency
175
188
  name: yard
176
189
  requirement: !ruby/object:Gem::Requirement
@@ -194,8 +207,8 @@ executables: []
194
207
  extensions:
195
208
  - ext/ruby-llvm-support/Rakefile
196
209
  extra_rdoc_files:
197
- - README.md
198
210
  - LICENSE
211
+ - README.md
199
212
  files:
200
213
  - LICENSE
201
214
  - README.md
@@ -236,7 +249,6 @@ homepage: http://github.com/ruby-llvm/ruby-llvm
236
249
  licenses: []
237
250
  metadata:
238
251
  rubygems_mfa_required: 'true'
239
- post_install_message:
240
252
  rdoc_options: []
241
253
  require_paths:
242
254
  - lib
@@ -244,15 +256,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
244
256
  requirements:
245
257
  - - ">="
246
258
  - !ruby/object:Gem::Version
247
- version: '2.7'
259
+ version: '3.1'
248
260
  required_rubygems_version: !ruby/object:Gem::Requirement
249
261
  requirements:
250
262
  - - ">="
251
263
  - !ruby/object:Gem::Version
252
264
  version: '0'
253
265
  requirements: []
254
- rubygems_version: 3.5.9
255
- signing_key:
266
+ rubygems_version: 3.6.7
256
267
  specification_version: 4
257
268
  summary: LLVM bindings for Ruby
258
269
  test_files: []