ruby-llvm 3.4.2 → 13.0.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.
Files changed (47) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +21 -4
  3. data/ext/ruby-llvm-support/Rakefile +15 -6
  4. data/ext/ruby-llvm-support/support.cpp +0 -12
  5. data/lib/llvm/analysis_ffi.rb +30 -28
  6. data/lib/llvm/config.rb +4 -4
  7. data/lib/llvm/core/bitcode.rb +10 -10
  8. data/lib/llvm/core/bitcode_ffi.rb +92 -70
  9. data/lib/llvm/core/builder.rb +2 -3
  10. data/lib/llvm/core/context.rb +1 -1
  11. data/lib/llvm/core/pass_manager.rb +4 -2
  12. data/lib/llvm/core/type.rb +2 -2
  13. data/lib/llvm/core/value.rb +148 -26
  14. data/lib/llvm/core.rb +45 -2
  15. data/lib/llvm/core_ffi.rb +4038 -3716
  16. data/lib/llvm/execution_engine.rb +45 -36
  17. data/lib/llvm/execution_engine_ffi.rb +245 -272
  18. data/lib/llvm/linker.rb +2 -19
  19. data/lib/llvm/linker_ffi.rb +24 -25
  20. data/lib/llvm/support.rb +0 -8
  21. data/lib/llvm/target.rb +9 -15
  22. data/lib/llvm/target_ffi.rb +336 -362
  23. data/lib/llvm/transforms/builder.rb +1 -1
  24. data/lib/llvm/transforms/builder_ffi.rb +57 -58
  25. data/lib/llvm/transforms/ipo.rb +1 -1
  26. data/lib/llvm/transforms/ipo_ffi.rb +60 -61
  27. data/lib/llvm/transforms/scalar_ffi.rb +208 -136
  28. data/lib/llvm/transforms/vectorize_ffi.rb +15 -16
  29. data/lib/llvm/version.rb +3 -2
  30. data/lib/llvm.rb +0 -6
  31. data/test/basic_block_test.rb +0 -1
  32. data/test/bitcode_test.rb +1 -2
  33. data/test/call_test.rb +1 -1
  34. data/test/double_test.rb +8 -7
  35. data/test/equality_test.rb +2 -4
  36. data/test/function_test.rb +27 -0
  37. data/test/generic_value_test.rb +1 -1
  38. data/test/instruction_test.rb +0 -2
  39. data/test/ipo_test.rb +1 -1
  40. data/test/linker_test.rb +0 -9
  41. data/test/mcjit_test.rb +14 -1
  42. data/test/module_test.rb +20 -1
  43. data/test/pass_manager_builder_test.rb +1 -2
  44. data/test/target_test.rb +8 -24
  45. data/test/test_helper.rb +4 -1
  46. metadata +103 -41
  47. data/lib/llvm/support_ffi.rb +0 -23
data/lib/llvm/linker.rb CHANGED
@@ -9,25 +9,8 @@ module LLVM
9
9
  # @return [nil, String] human-readable error if linking has failed
10
10
  def link_into(other)
11
11
  LLVM.with_message_output do |msg|
12
- # HACK ALERT: ffi-gen missed LLVMLinkerPreserveSource enumeration for
13
- # some reason. It is inlined as a constant here.
14
-
15
- # C.link_modules(mod, self, :linker_preserve_source, msg)
16
- C.link_modules(other, self, 1, msg)
17
- end
18
- end
19
-
20
- # Link the current module into +other+, and dispose the current module.
21
- #
22
- # @return [nil, String] human-readable error if linking has failed
23
- def link_into_and_destroy(other)
24
- result = LLVM.with_message_output do |msg|
25
- C.link_modules(other, self, :linker_destroy_source, msg)
12
+ C.link_modules2(other, self)
26
13
  end
27
-
28
- @ptr = nil
29
-
30
- result
31
14
  end
32
15
  end
33
- end
16
+ end
@@ -4,42 +4,41 @@ require 'ffi'
4
4
 
5
5
  module LLVM::C
6
6
  extend FFI::Library
7
- ffi_lib 'LLVM-3.4'
8
-
7
+ ffi_lib ["libLLVM-13.so.1", "libLLVM.so.13", "LLVM-13"]
8
+
9
9
  def self.attach_function(name, *_)
10
10
  begin; super; rescue FFI::NotFoundError => e
11
11
  (class << self; self; end).class_eval { define_method(name) { |*_| raise e } }
12
12
  end
13
13
  end
14
-
15
- # (Not documented)
16
- #
14
+
15
+ # This enum is provided for backwards-compatibility only. It has no effect.
16
+ #
17
17
  # <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:linker_mode).</em>
18
- #
18
+ #
19
19
  # === Options:
20
- # :linker_destroy_source ::
21
- #
22
- #
20
+ # :destroy_source ::
21
+ #
22
+ # :preserve_source_removed ::
23
+ # This is the default behavior.
24
+ #
23
25
  # @method _enum_linker_mode_
24
26
  # @return [Symbol]
25
27
  # @scope class
26
28
  enum :linker_mode, [
27
- :linker_destroy_source, 0
29
+ :destroy_source, 0,
30
+ :preserve_source_removed, 1
28
31
  ]
29
-
30
- # Links the source module into the destination module, taking ownership
31
- # of the source module away from the caller. Optionally returns a
32
- # human-readable description of any errors that occurred in linking.
33
- # OutMessage must be disposed with LLVMDisposeMessage. The return value
34
- # is true if an error occurred, false otherwise.
35
- #
36
- # @method link_modules(dest, src, mode, out_message)
37
- # @param [FFI::Pointer(ModuleRef)] dest
38
- # @param [FFI::Pointer(ModuleRef)] src
39
- # @param [Symbol from _enum_linker_mode_] mode
40
- # @param [FFI::Pointer(**CharS)] out_message
41
- # @return [Integer]
32
+
33
+ # Links the source module into the destination module. The source module is
34
+ # destroyed.
35
+ # The return value is true if an error occurred, false otherwise.
36
+ # Use the diagnostic handler to get any diagnostic message.
37
+ #
38
+ # @method link_modules2(dest, src)
39
+ # @param [FFI::Pointer(ModuleRef)] dest
40
+ # @param [FFI::Pointer(ModuleRef)] src
41
+ # @return [Integer]
42
42
  # @scope class
43
- attach_function :link_modules, :LLVMLinkModules, [:pointer, :pointer, :linker_mode, :pointer], :int
44
-
43
+ attach_function :link_modules2, :LLVMLinkModules2, [:pointer, :pointer], :int
45
44
  end
data/lib/llvm/support.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  require 'llvm/core_ffi'
2
- require 'llvm/support_ffi'
3
2
 
4
3
  module LLVM
5
4
 
@@ -9,17 +8,10 @@ module LLVM
9
8
  module C
10
9
  extend FFI::Library
11
10
 
12
- OpaqueValue = LLVM::C::OpaqueValue
13
- OpaqueType = LLVM::C::OpaqueType
14
- OpaqueModule = LLVM::C::OpaqueModule
15
-
16
11
  lib_name = FFI.map_library_name("RubyLLVMSupport-#{LLVM_VERSION}")
17
12
  lib_path = File.expand_path("../../ext/ruby-llvm-support/#{lib_name}", File.dirname(__FILE__))
18
13
  ffi_lib [lib_path]
19
14
 
20
- attach_function :has_unnamed_addr, :LLVMHasUnnamedAddr, [OpaqueValue], :int
21
- attach_function :set_unnamed_addr, :LLVMSetUnnamedAddr, [OpaqueValue, :int], :void
22
-
23
15
  attach_function :initialize_all_target_infos,
24
16
  :LLVMInitializeAllTargetInfos, [], :void
25
17
  attach_function :initialize_all_targets,
data/lib/llvm/target.rb CHANGED
@@ -20,7 +20,7 @@ module LLVM
20
20
  #
21
21
  # @param [String] target Target name in LLVM format, e.g. "X86", "ARM" or "PowerPC".
22
22
  # @param [true, false] asm_printer Initialize corresponding AsmPrinter.
23
- def self.init(target, asm_printer=false)
23
+ def self.init(target, asm_printer = false)
24
24
  C.module_eval do
25
25
  attach_function :"initialize_target_info_#{target}",
26
26
  :"LLVMInitialize#{target}TargetInfo", [], :void
@@ -57,7 +57,7 @@ module LLVM
57
57
  # Initializes all available targets.
58
58
  #
59
59
  # @param [true, false] asm_printer Initialize corresponding AsmPrinters.
60
- def self.init_all(asm_printer=false)
60
+ def self.init_all(asm_printer = false)
61
61
  Support::C.initialize_all_target_infos
62
62
  Support::C.initialize_all_targets
63
63
  Support::C.initialize_all_target_mcs
@@ -68,7 +68,8 @@ module LLVM
68
68
  # Initializes native target. Useful for JIT applications.
69
69
  #
70
70
  # @param [true, false] asm_printer Initialize corresponding AsmPrinter.
71
- def self.init_native(asm_printer=false)
71
+ # True by default, as this is required for MCJIT to function.
72
+ def self.init_native(asm_printer = true)
72
73
  Support::C.initialize_native_target
73
74
 
74
75
  Support::C.initialize_native_asm_printer if asm_printer
@@ -144,8 +145,8 @@ module LLVM
144
145
  # @param [Symbol] reloc :default, :static, :pic, :dynamic_no_pic
145
146
  # @param [Symbol] code_model :default, :jit_default, :small, :kernel, :medium, :large
146
147
  # @return [TargetMachine]
147
- def create_machine(triple, cpu="", features="",
148
- opt_level=:default, reloc=:default, code_model=:default)
148
+ def create_machine(triple, cpu = "", features = "",
149
+ opt_level = :default, reloc = :default, code_model = :default)
149
150
  TargetMachine.from_ptr(C.create_target_machine(self,
150
151
  triple, cpu, features, opt_level, reloc, code_model))
151
152
  end
@@ -191,17 +192,10 @@ module LLVM
191
192
  C.get_target_machine_feature_string(self)
192
193
  end
193
194
 
194
- # Returns the data layout used for this target machine.
195
- #
196
- # @return [TargetDataLayout]
197
- def data_layout
198
- TargetDataLayout.from_ptr(C.get_target_machine_data(self))
199
- end
200
-
201
195
  # Emits an asm or object file for the given module.
202
196
  #
203
197
  # @param [Symbol] codegen :assembly, :object
204
- def emit(mod, filename, codegen=:assembly)
198
+ def emit(mod, filename, codegen = :assembly)
205
199
  LLVM.with_error_output do |err|
206
200
  C.target_machine_emit_to_file(self, mod, filename.to_s, codegen, err)
207
201
  end
@@ -262,14 +256,14 @@ module LLVM
262
256
  # Returns the pointer size in bytes for a target.
263
257
  #
264
258
  # @param [Integer] addr_space address space number
265
- def pointer_size(addr_space=0)
259
+ def pointer_size(addr_space = 0)
266
260
  C.pointer_size_for_as(self, addr_space)
267
261
  end
268
262
 
269
263
  # Returns the integer type that is the same size as a pointer on a target.
270
264
  #
271
265
  # @param [Integer] addr_space address space number
272
- def int_ptr_type(addr_space=0)
266
+ def int_ptr_type(addr_space = 0)
273
267
  Type.from_ptr(C.int_ptr_type_for_as(self, addr_space), :integer)
274
268
  end
275
269