ruby-llvm 3.5.0 → 10.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 (43) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +19 -4
  3. data/ext/ruby-llvm-support/Rakefile +15 -6
  4. data/lib/llvm/analysis_ffi.rb +27 -28
  5. data/lib/llvm/config.rb +4 -4
  6. data/lib/llvm/core.rb +45 -2
  7. data/lib/llvm/core/bitcode.rb +10 -10
  8. data/lib/llvm/core/bitcode_ffi.rb +89 -65
  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 +138 -24
  14. data/lib/llvm/core_ffi.rb +3863 -3730
  15. data/lib/llvm/execution_engine.rb +37 -35
  16. data/lib/llvm/execution_engine_ffi.rb +238 -276
  17. data/lib/llvm/linker.rb +1 -14
  18. data/lib/llvm/linker_ffi.rb +22 -26
  19. data/lib/llvm/target.rb +9 -15
  20. data/lib/llvm/target_ffi.rb +301 -293
  21. data/lib/llvm/transforms/builder.rb +1 -1
  22. data/lib/llvm/transforms/builder_ffi.rb +57 -58
  23. data/lib/llvm/transforms/ipo.rb +1 -1
  24. data/lib/llvm/transforms/ipo_ffi.rb +59 -60
  25. data/lib/llvm/transforms/scalar_ffi.rb +199 -143
  26. data/lib/llvm/transforms/vectorize_ffi.rb +15 -16
  27. data/lib/llvm/version.rb +3 -2
  28. data/test/basic_block_test.rb +0 -1
  29. data/test/bitcode_test.rb +1 -2
  30. data/test/call_test.rb +1 -1
  31. data/test/double_test.rb +8 -7
  32. data/test/equality_test.rb +2 -4
  33. data/test/function_test.rb +27 -0
  34. data/test/generic_value_test.rb +1 -1
  35. data/test/instruction_test.rb +0 -2
  36. data/test/ipo_test.rb +1 -1
  37. data/test/linker_test.rb +0 -9
  38. data/test/mcjit_test.rb +3 -3
  39. data/test/module_test.rb +16 -1
  40. data/test/pass_manager_builder_test.rb +1 -2
  41. data/test/target_test.rb +3 -20
  42. data/test/test_helper.rb +4 -1
  43. metadata +55 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: e559929d919c913ffacaef820430b37093a23adc
4
- data.tar.gz: d98b42343be29f103dbbb9f518cc304542d0fdff
2
+ SHA256:
3
+ metadata.gz: c7077c05ecee582525cd5526bfc87670921c5e54acff2fe5ebc011004fabd2b3
4
+ data.tar.gz: b4626a00ec972c15f9f069ff3f3d9d2022bcf2ad2d6c78c20faaaa8d7c91df71
5
5
  SHA512:
6
- metadata.gz: 3ad54d41292618fb2c48a56b89812e97ce66fd4a8708858d5137ac7064721fbe339eefe3c938f57af1c596acc8f019ff278f9e62d3a6e259e638cbd7dfcdd029
7
- data.tar.gz: 2743c5a6ef7e374eb158f436d01ca39f1f0dd5f218957060f57fb54d5d205f14322ffc2957b39f4cf2f60e78feefd5cb314723fb11012d76885b0c001beecf6e
6
+ metadata.gz: 07ed15a10baad306e15107741224880c8bcffb4739b345cd3542d53cd4501d8b05222b10c1f0faf705dcfef889cf60e038521b1d08acdda2b86b347788a2a4a1
7
+ data.tar.gz: 134a6f2d90c03f5ad318985eb017e2076095a6be2a91abcdf0b467a3aea18b5901f6e723ff4339e7db5afd721e2b340f2f2749858db1e43433852a5bfd97f152
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Known Vulnerabilities](https://snyk.io/test/github/ruby-llvm/ruby-llvm/badge.svg)](https://snyk.io/test/github/ruby-llvm/ruby-llvm)
2
+
1
3
  Ruby-LLVM
2
4
  =========
3
5
 
@@ -7,10 +9,10 @@ library. LLVM allows users to create just-in-time (JIT) compilers, ahead-of-time
7
9
  bindings can also be used to speed up Ruby code by compiling and loading
8
10
  computationally intensive algorithms on the fly.
9
11
 
10
- Requirements
11
- ------------
12
- * LLVM 3.4, including libLLVM-3.4 (compile LLVM with --enable-shared).
13
- * In order to ensure the usability of JIT features (i.e. create_jit_compiler), compile LLVM with --enable-jit as well.
12
+ Current version
13
+ ---------------
14
+
15
+ This library currently binds to LLVM-10 (specifically llvm-c 10).
14
16
 
15
17
  About version numbers
16
18
  ---------------------
@@ -20,13 +22,26 @@ major and minor version of LLVM. The third digit refers to the ruby-llvm
20
22
  release itself. Because LLVM's api changes often, this coupling between
21
23
  LLVM and ruby-llvm versions is useful.
22
24
 
25
+ Debian/Ubuntu
26
+ -------------
27
+
28
+ [LLVM Debian/Ubuntu Packages](https://apt.llvm.org/)
29
+
23
30
  Homebrew
24
31
  --------
32
+
25
33
  LLVM can be installed with Homebrew by executing `brew install llvm --shared`
26
34
 
35
+ Source and other binaries
36
+ -------------------------
37
+
38
+ * [LLVM Download Page](https://releases.llvm.org/download.html)
39
+ * If compiling from source the --enable-shared and --enable-jit flags may be needed.
40
+
27
41
  See Also
28
42
  --------
29
43
  * [The LLVM project](http://llvm.org)
44
+ * [Mirror of llvm-c on github](https://github.com/llvm-mirror/llvm/tree/master/include/llvm-c)
30
45
  * [ffi-gen](https://github.com/neelance/ffi-gen) – Generate
31
46
  [FFI](https://github.com/ffi/ffi) bindings with LLVM and Clang
32
47
 
@@ -21,7 +21,7 @@ def check_for(what, variants, env_var)
21
21
  if result
22
22
  result
23
23
  else
24
- raise RuntimeError, "Cannot find #{what}: tried #{variants}"
24
+ raise "Cannot find #{what}: tried #{variants}"
25
25
  end
26
26
  end
27
27
 
@@ -34,7 +34,7 @@ def find_llvm_config
34
34
  actual_version = `#{llvm_config} --version`.strip
35
35
  actual_maj, actual_min, _ = actual_version.split('.')
36
36
 
37
- required_maj, required_min = LLVM_VERSION.split('.')
37
+ required_maj, required_min = LLVM_REQUIRED_VERSION.split('.')
38
38
 
39
39
  actual_maj == required_maj && actual_min == required_min
40
40
  rescue Errno::ENOENT
@@ -54,7 +54,16 @@ LLVM_CONFIG = find_llvm_config
54
54
  CXX = find_cxx
55
55
 
56
56
  def invoke_llvm_config(options)
57
- `#{LLVM_CONFIG} #{options}`.gsub("\n", " ")
57
+ `#{LLVM_CONFIG} #{options}`.tr("\n", " ")
58
+ end
59
+
60
+ def llvm_lib_name
61
+ lib_dir = invoke_llvm_config('--libdir').strip
62
+ lib_name = 'LLVM'
63
+ versioned_lib_name = "#{lib_name}-#{LLVM_VERSION}"
64
+ versioned_lib_pattern = "lib#{versioned_lib_name}.*"
65
+ versioned_lib_found = Dir.glob(File.join(lib_dir, versioned_lib_pattern)) != []
66
+ versioned_lib_found ? versioned_lib_name : lib_name
58
67
  end
59
68
 
60
69
  SUPPORT_LIB = FFI.map_library_name("RubyLLVMSupport-#{LLVM_VERSION}")
@@ -66,8 +75,8 @@ desc "Build the shared library and config module"
66
75
  task :default => [SUPPORT_LIB, CONFIG_MOD]
67
76
 
68
77
  file SUPPORT_LIB => %w(support.cpp) do |task|
69
- sh "#{CXX} -shared #{task.prerequisites.join(' ')} -lLLVM-#{LLVM_VERSION} " \
70
- "#{invoke_llvm_config('--cxxflags --ldflags')} -o #{SUPPORT_LIB}"
78
+ sh "#{CXX} -shared #{task.prerequisites.join(' ')} -l#{llvm_lib_name} " \
79
+ "#{invoke_llvm_config('--cxxflags --ldflags')} -fPIC -o #{SUPPORT_LIB}"
71
80
  end
72
81
 
73
82
  LLVM_CONFIG_OPTS = [
@@ -76,7 +85,7 @@ LLVM_CONFIG_OPTS = [
76
85
  ['HOST_TARGET', :string, '--host-target'],
77
86
  ['BUILD_MODE', :string, '--build-mode'],
78
87
  ['CFLAGS', :string, '--cflags'],
79
- ]
88
+ ].freeze
80
89
 
81
90
  file CONFIG_MOD do
82
91
  open(CONFIG_MOD, 'w') do |f|
@@ -4,29 +4,29 @@ require 'ffi'
4
4
 
5
5
  module LLVM::C
6
6
  extend FFI::Library
7
- ffi_lib ["libLLVM-3.5.so.1", "LLVM-3.5"]
8
-
7
+ ffi_lib ["libLLVM-10.so.1", "LLVM-10"]
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
-
14
+
15
15
  # @defgroup LLVMCAnalysis Analysis
16
16
  # @ingroup LLVMC
17
- #
17
+ #
18
18
  # @{
19
- #
19
+ #
20
20
  # <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:verifier_failure_action).</em>
21
- #
21
+ #
22
22
  # === Options:
23
23
  # :abort_process ::
24
- #
24
+ #
25
25
  # :print_message ::
26
26
  # verifier will print to stderr and abort()
27
27
  # :return_status ::
28
28
  # verifier will print to stderr and return 1
29
- #
29
+ #
30
30
  # @method _enum_verifier_failure_action_
31
31
  # @return [Symbol]
32
32
  # @scope class
@@ -35,44 +35,43 @@ module LLVM::C
35
35
  :print_message, 1,
36
36
  :return_status, 2
37
37
  ]
38
-
38
+
39
39
  # Verifies that a module is valid, taking the specified action if not.
40
40
  # Optionally returns a human-readable description of any invalid constructs.
41
41
  # OutMessage must be disposed with LLVMDisposeMessage.
42
- #
42
+ #
43
43
  # @method verify_module(m, action, out_message)
44
- # @param [FFI::Pointer(ModuleRef)] m
45
- # @param [Symbol from _enum_verifier_failure_action_] action
46
- # @param [FFI::Pointer(**CharS)] out_message
47
- # @return [Integer]
44
+ # @param [FFI::Pointer(ModuleRef)] m
45
+ # @param [Symbol from _enum_verifier_failure_action_] action
46
+ # @param [FFI::Pointer(**CharS)] out_message
47
+ # @return [Integer]
48
48
  # @scope class
49
49
  attach_function :verify_module, :LLVMVerifyModule, [:pointer, :verifier_failure_action, :pointer], :int
50
-
50
+
51
51
  # Verifies that a single function is valid, taking the specified action. Useful
52
52
  # for debugging.
53
- #
53
+ #
54
54
  # @method verify_function(fn, action)
55
- # @param [FFI::Pointer(ValueRef)] fn
56
- # @param [Symbol from _enum_verifier_failure_action_] action
57
- # @return [Integer]
55
+ # @param [FFI::Pointer(ValueRef)] fn
56
+ # @param [Symbol from _enum_verifier_failure_action_] action
57
+ # @return [Integer]
58
58
  # @scope class
59
59
  attach_function :verify_function, :LLVMVerifyFunction, [:pointer, :verifier_failure_action], :int
60
-
60
+
61
61
  # Open up a ghostview window that displays the CFG of the current function.
62
62
  # Useful for debugging.
63
- #
63
+ #
64
64
  # @method view_function_cfg(fn)
65
- # @param [FFI::Pointer(ValueRef)] fn
66
- # @return [nil]
65
+ # @param [FFI::Pointer(ValueRef)] fn
66
+ # @return [nil]
67
67
  # @scope class
68
68
  attach_function :view_function_cfg, :LLVMViewFunctionCFG, [:pointer], :void
69
-
69
+
70
70
  # (Not documented)
71
- #
71
+ #
72
72
  # @method view_function_cfg_only(fn)
73
- # @param [FFI::Pointer(ValueRef)] fn
74
- # @return [nil]
73
+ # @param [FFI::Pointer(ValueRef)] fn
74
+ # @return [nil]
75
75
  # @scope class
76
76
  attach_function :view_function_cfg_only, :LLVMViewFunctionCFGOnly, [:pointer], :void
77
-
78
77
  end
@@ -1,10 +1,10 @@
1
1
  # Generated by ruby-llvm. Please do not change this file by hand.
2
2
  module LLVM
3
3
  module CONFIG
4
- COMPONENTS = ["aarch64", "aarch64asmparser", "aarch64asmprinter", "aarch64codegen", "aarch64desc", "aarch64disassembler", "aarch64info", "aarch64utils", "all", "all-targets", "analysis", "arm", "armasmparser", "armasmprinter", "armcodegen", "armdesc", "armdisassembler", "arminfo", "asmparser", "asmprinter", "bitreader", "bitwriter", "codegen", "core", "cppbackend", "cppbackendcodegen", "cppbackendinfo", "debuginfo", "engine", "executionengine", "hexagon", "hexagonasmprinter", "hexagoncodegen", "hexagondesc", "hexagoninfo", "instcombine", "instrumentation", "interpreter", "ipa", "ipo", "irreader", "jit", "lineeditor", "linker", "lto", "mc", "mcanalysis", "mcdisassembler", "mcjit", "mcparser", "mips", "mipsasmparser", "mipsasmprinter", "mipscodegen", "mipsdesc", "mipsdisassembler", "mipsinfo", "msp430", "msp430asmprinter", "msp430codegen", "msp430desc", "msp430info", "native", "nativecodegen", "nvptx", "nvptxasmprinter", "nvptxcodegen", "nvptxdesc", "nvptxinfo", "objcarcopts", "object", "option", "powerpc", "powerpcasmparser", "powerpcasmprinter", "powerpccodegen", "powerpcdesc", "powerpcdisassembler", "powerpcinfo", "profiledata", "r600", "r600asmprinter", "r600codegen", "r600desc", "r600info", "runtimedyld", "scalaropts", "selectiondag", "sparc", "sparcasmparser", "sparcasmprinter", "sparccodegen", "sparcdesc", "sparcdisassembler", "sparcinfo", "support", "systemz", "systemzasmparser", "systemzasmprinter", "systemzcodegen", "systemzdesc", "systemzdisassembler", "systemzinfo", "tablegen", "target", "transformutils", "vectorize", "x86", "x86asmparser", "x86asmprinter", "x86codegen", "x86desc", "x86disassembler", "x86info", "x86utils", "xcore", "xcoreasmprinter", "xcorecodegen", "xcoredesc", "xcoredisassembler", "xcoreinfo"]
5
- TARGETS_BUILT = ["X86", "Sparc", "PowerPC", "ARM", "AArch64", "Mips", "XCore", "MSP430", "CppBackend", "NVPTX", "Hexagon", "SystemZ", "R600"]
4
+ COMPONENTS = ["aarch64", "aarch64asmparser", "aarch64codegen", "aarch64desc", "aarch64disassembler", "aarch64info", "aarch64utils", "aggressiveinstcombine", "all", "all-targets", "amdgpu", "amdgpuasmparser", "amdgpucodegen", "amdgpudesc", "amdgpudisassembler", "amdgpuinfo", "amdgpuutils", "analysis", "arm", "armasmparser", "armcodegen", "armdesc", "armdisassembler", "arminfo", "armutils", "asmparser", "asmprinter", "avr", "avrasmparser", "avrcodegen", "avrdesc", "avrdisassembler", "avrinfo", "binaryformat", "bitreader", "bitstreamreader", "bitwriter", "bpf", "bpfasmparser", "bpfcodegen", "bpfdesc", "bpfdisassembler", "bpfinfo", "cfguard", "codegen", "core", "coroutines", "coverage", "debuginfocodeview", "debuginfodwarf", "debuginfogsym", "debuginfomsf", "debuginfopdb", "demangle", "dlltooldriver", "dwarflinker", "engine", "executionengine", "frontendopenmp", "fuzzmutate", "globalisel", "hexagon", "hexagonasmparser", "hexagoncodegen", "hexagondesc", "hexagondisassembler", "hexagoninfo", "instcombine", "instrumentation", "interpreter", "ipo", "irreader", "jitlink", "lanai", "lanaiasmparser", "lanaicodegen", "lanaidesc", "lanaidisassembler", "lanaiinfo", "libdriver", "lineeditor", "linker", "lto", "mc", "mca", "mcdisassembler", "mcjit", "mcparser", "mips", "mipsasmparser", "mipscodegen", "mipsdesc", "mipsdisassembler", "mipsinfo", "mirparser", "msp430", "msp430asmparser", "msp430codegen", "msp430desc", "msp430disassembler", "msp430info", "native", "nativecodegen", "nvptx", "nvptxcodegen", "nvptxdesc", "nvptxinfo", "objcarcopts", "object", "objectyaml", "option", "orcerror", "orcjit", "passes", "perfjitevents", "powerpc", "powerpcasmparser", "powerpccodegen", "powerpcdesc", "powerpcdisassembler", "powerpcinfo", "profiledata", "remarks", "riscv", "riscvasmparser", "riscvcodegen", "riscvdesc", "riscvdisassembler", "riscvinfo", "riscvutils", "runtimedyld", "scalaropts", "selectiondag", "sparc", "sparcasmparser", "sparccodegen", "sparcdesc", "sparcdisassembler", "sparcinfo", "support", "symbolize", "systemz", "systemzasmparser", "systemzcodegen", "systemzdesc", "systemzdisassembler", "systemzinfo", "tablegen", "target", "textapi", "transformutils", "vectorize", "webassembly", "webassemblyasmparser", "webassemblycodegen", "webassemblydesc", "webassemblydisassembler", "webassemblyinfo", "windowsmanifest", "x86", "x86asmparser", "x86codegen", "x86desc", "x86disassembler", "x86info", "x86utils", "xcore", "xcorecodegen", "xcoredesc", "xcoredisassembler", "xcoreinfo", "xray"]
5
+ TARGETS_BUILT = ["AArch64", "AMDGPU", "ARM", "BPF", "Hexagon", "Lanai", "Mips", "MSP430", "NVPTX", "PowerPC", "RISCV", "Sparc", "SystemZ", "WebAssembly", "X86", "XCore", "AVR"]
6
6
  HOST_TARGET = "x86_64-pc-linux-gnu "
7
- BUILD_MODE = "Release "
8
- CFLAGS = "-I/usr/lib/llvm-3.5/include -DNDEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -g -O2 -fomit-frame-pointer -fPIC "
7
+ BUILD_MODE = "RelWithDebInfo "
8
+ CFLAGS = "-I/usr/lib/llvm-10/include -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS "
9
9
  end
10
10
  end
@@ -6,6 +6,49 @@ module LLVM
6
6
  # @private
7
7
  module C
8
8
  attach_function :dispose_message, :LLVMDisposeMessage, [:pointer], :void
9
+
10
+ # typedef unsigned LLVMAttributeIndex;
11
+ typedef(:uint, :llvmattributeindex)
12
+
13
+ # void LLVMAddAttributeAtIndex
14
+ # (LLVMValueRef F, LLVMAttributeIndex Idx, LLVMAttributeRef A);
15
+ attach_function :add_attribute_at_index, :LLVMAddAttributeAtIndex, [:pointer, :llvmattributeindex, :pointer], :void
16
+
17
+ # void LLVMRemoveEnumAttributeAtIndex
18
+ # (LLVMValueRef F, LLVMAttributeIndex Idx, unsigned KindID);
19
+ attach_function :remove_enum_attribute_at_index, :LLVMRemoveEnumAttributeAtIndex, [:pointer, :llvmattributeindex, :uint], :void
20
+
21
+ # LLVMAttributeRef LLVMCreateEnumAttribute
22
+ # (LLVMContextRef C, unsigned KindID, uint64_t Val);
23
+ attach_function :create_enum_attribute, :LLVMCreateEnumAttribute, [:pointer, :uint, :uint64], :pointer
24
+
25
+ # unsigned LLVMGetEnumAttributeKindForName
26
+ # (const char *Name, size_t SLen);
27
+ attach_function :get_enum_attribute_kind_for_name, :LLVMGetEnumAttributeKindForName, [:pointer, :size_t], :uint
28
+
29
+ # unsigned LLVMGetAttributeCountAtIndex
30
+ # (LLVMValueRef F, LLVMAttributeIndex Idx);
31
+ attach_function :get_attribute_count_at_index, :LLVMGetAttributeCountAtIndex, [:pointer, :llvmattributeindex], :uint
32
+
33
+ # void LLVMGetAttributesAtIndex
34
+ # (LLVMValueRef F, LLVMAttributeIndex Idx, LLVMAttributeRef *Attrs);
35
+ attach_function :get_attributes_at_index, :LLVMGetAttributesAtIndex, [:pointer, :llvmattributeindex, :pointer], :void
36
+
37
+ # unsigned LLVMGetEnumAttributeKind
38
+ # (LLVMAttributeRef A);
39
+ attach_function :get_enum_attribute_kind, :LLVMGetEnumAttributeKind, [:pointer], :uint
40
+
41
+ # uint64_t LLVMGetEnumAttributeValue
42
+ # (LLVMAttributeRef A);
43
+ attach_function :get_enum_attribute_value, :LLVMGetEnumAttributeKind, [:pointer], :uint64
44
+
45
+ # const char *LLVMGetStringAttributeKind
46
+ # (LLVMAttributeRef A, unsigned *Length);
47
+ attach_function :get_string_attribute_kind, :LLVMGetStringAttributeKind, [:pointer, :pointer], :pointer
48
+
49
+ # const char *LLVMGetStringAttributeValue
50
+ # (LLVMAttributeRef A, unsigned *Length);
51
+ attach_function :get_string_attribute_value, :LLVMGetStringAttributeValue, [:pointer, :pointer], :pointer
9
52
  end
10
53
 
11
54
  # Yields a pointer suitable for storing an LLVM output message.
@@ -23,7 +66,7 @@ module LLVM
23
66
  msg_ptr = str.read_pointer
24
67
 
25
68
  if result != 0
26
- raise RuntimeError, "Error is signalled, but msg_ptr is null" if msg_ptr.null?
69
+ raise "Error is signalled, but msg_ptr is null" if msg_ptr.null?
27
70
 
28
71
  message = msg_ptr.read_string
29
72
  C.dispose_message msg_ptr
@@ -41,7 +84,7 @@ module LLVM
41
84
  def self.with_error_output(&block)
42
85
  error = with_message_output(&block)
43
86
 
44
- raise RuntimeError, error unless error.nil?
87
+ raise error unless error.nil?
45
88
  end
46
89
 
47
90
  require 'llvm/core/context'
@@ -9,7 +9,7 @@ module LLVM
9
9
  memory_buffer = case path_or_memory_buffer
10
10
  when MemoryBuffer then path_or_memory_buffer
11
11
  else MemoryBuffer.from_file(path_or_memory_buffer)
12
- end
12
+ end
13
13
  FFI::MemoryPointer.new(:pointer) do |mod_ref|
14
14
  FFI::MemoryPointer.new(:pointer) do |msg_ref|
15
15
  status = C.parse_bitcode(memory_buffer, mod_ref, msg_ref)
@@ -24,15 +24,15 @@ module LLVM
24
24
  # @return [true, false] Success
25
25
  def write_bitcode(path_or_io)
26
26
  status = if path_or_io.respond_to?(:path)
27
- C.write_bitcode_to_file(self, path_or_io.path)
28
- elsif path_or_io.respond_to?(:fileno)
29
- C.write_bitcode_to_fd(self, path_or_io.fileno, 0, 1)
30
- elsif path_or_io.kind_of?(Integer)
31
- C.write_bitcode_to_fd(self, path_or_io, 0, 1)
32
- else
33
- C.write_bitcode_to_file(self, path_or_io.to_str)
34
- end
35
- return status == 0
27
+ C.write_bitcode_to_file(self, path_or_io.path)
28
+ elsif path_or_io.respond_to?(:fileno)
29
+ C.write_bitcode_to_fd(self, path_or_io.fileno, 0, 1)
30
+ elsif path_or_io.kind_of?(Integer)
31
+ C.write_bitcode_to_fd(self, path_or_io, 0, 1)
32
+ else
33
+ C.write_bitcode_to_file(self, path_or_io.to_str)
34
+ end
35
+ status == 0
36
36
  end
37
37
  end
38
38
 
@@ -4,105 +4,129 @@ require 'ffi'
4
4
 
5
5
  module LLVM::C
6
6
  extend FFI::Library
7
- ffi_lib ["libLLVM-3.5.so.1", "LLVM-3.5"]
8
-
7
+ ffi_lib ["libLLVM-10.so.1", "LLVM-10"]
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
-
14
+
15
15
  # (Not documented)
16
- #
16
+ #
17
17
  # @method parse_bitcode(mem_buf, out_module, out_message)
18
- # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
19
- # @param [FFI::Pointer(*ModuleRef)] out_module
20
- # @param [FFI::Pointer(**CharS)] out_message
21
- # @return [Integer]
18
+ # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
19
+ # @param [FFI::Pointer(*ModuleRef)] out_module
20
+ # @param [FFI::Pointer(**CharS)] out_message
21
+ # @return [Integer]
22
22
  # @scope class
23
23
  attach_function :parse_bitcode, :LLVMParseBitcode, [:pointer, :pointer, :pointer], :int
24
-
24
+
25
+ # (Not documented)
26
+ #
27
+ # @method parse_bitcode2(mem_buf, out_module)
28
+ # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
29
+ # @param [FFI::Pointer(*ModuleRef)] out_module
30
+ # @return [Integer]
31
+ # @scope class
32
+ attach_function :parse_bitcode2, :LLVMParseBitcode2, [:pointer, :pointer], :int
33
+
25
34
  # (Not documented)
26
- #
35
+ #
27
36
  # @method parse_bitcode_in_context(context_ref, mem_buf, out_module, out_message)
28
- # @param [FFI::Pointer(ContextRef)] context_ref
29
- # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
30
- # @param [FFI::Pointer(*ModuleRef)] out_module
31
- # @param [FFI::Pointer(**CharS)] out_message
32
- # @return [Integer]
37
+ # @param [FFI::Pointer(ContextRef)] context_ref
38
+ # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
39
+ # @param [FFI::Pointer(*ModuleRef)] out_module
40
+ # @param [FFI::Pointer(**CharS)] out_message
41
+ # @return [Integer]
33
42
  # @scope class
34
43
  attach_function :parse_bitcode_in_context, :LLVMParseBitcodeInContext, [:pointer, :pointer, :pointer, :pointer], :int
35
-
44
+
36
45
  # (Not documented)
37
- #
46
+ #
47
+ # @method parse_bitcode_in_context2(context_ref, mem_buf, out_module)
48
+ # @param [FFI::Pointer(ContextRef)] context_ref
49
+ # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
50
+ # @param [FFI::Pointer(*ModuleRef)] out_module
51
+ # @return [Integer]
52
+ # @scope class
53
+ attach_function :parse_bitcode_in_context2, :LLVMParseBitcodeInContext2, [:pointer, :pointer, :pointer], :int
54
+
55
+ # (Not documented)
56
+ #
38
57
  # @method get_bitcode_module_in_context(context_ref, mem_buf, out_m, out_message)
39
- # @param [FFI::Pointer(ContextRef)] context_ref
40
- # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
41
- # @param [FFI::Pointer(*ModuleRef)] out_m
42
- # @param [FFI::Pointer(**CharS)] out_message
43
- # @return [Integer]
58
+ # @param [FFI::Pointer(ContextRef)] context_ref
59
+ # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
60
+ # @param [FFI::Pointer(*ModuleRef)] out_m
61
+ # @param [FFI::Pointer(**CharS)] out_message
62
+ # @return [Integer]
44
63
  # @scope class
45
64
  attach_function :get_bitcode_module_in_context, :LLVMGetBitcodeModuleInContext, [:pointer, :pointer, :pointer, :pointer], :int
46
-
65
+
47
66
  # (Not documented)
48
- #
49
- # @method get_bitcode_module(mem_buf, out_m, out_message)
50
- # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
51
- # @param [FFI::Pointer(*ModuleRef)] out_m
52
- # @param [FFI::Pointer(**CharS)] out_message
53
- # @return [Integer]
67
+ #
68
+ # @method get_bitcode_module_in_context2(context_ref, mem_buf, out_m)
69
+ # @param [FFI::Pointer(ContextRef)] context_ref
70
+ # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
71
+ # @param [FFI::Pointer(*ModuleRef)] out_m
72
+ # @return [Integer]
54
73
  # @scope class
55
- attach_function :get_bitcode_module, :LLVMGetBitcodeModule, [:pointer, :pointer, :pointer], :int
56
-
74
+ attach_function :get_bitcode_module_in_context2, :LLVMGetBitcodeModuleInContext2, [:pointer, :pointer, :pointer], :int
75
+
57
76
  # (Not documented)
58
- #
59
- # @method get_bitcode_module_provider_in_context(context_ref, mem_buf, out_mp, out_message)
60
- # @param [FFI::Pointer(ContextRef)] context_ref
61
- # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
62
- # @param [FFI::Pointer(*ModuleProviderRef)] out_mp
63
- # @param [FFI::Pointer(**CharS)] out_message
64
- # @return [Integer]
77
+ #
78
+ # @method get_bitcode_module(mem_buf, out_m, out_message)
79
+ # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
80
+ # @param [FFI::Pointer(*ModuleRef)] out_m
81
+ # @param [FFI::Pointer(**CharS)] out_message
82
+ # @return [Integer]
65
83
  # @scope class
66
- attach_function :get_bitcode_module_provider_in_context, :LLVMGetBitcodeModuleProviderInContext, [:pointer, :pointer, :pointer, :pointer], :int
67
-
84
+ attach_function :get_bitcode_module, :LLVMGetBitcodeModule, [:pointer, :pointer, :pointer], :int
85
+
68
86
  # (Not documented)
69
- #
70
- # @method get_bitcode_module_provider(mem_buf, out_mp, out_message)
71
- # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
72
- # @param [FFI::Pointer(*ModuleProviderRef)] out_mp
73
- # @param [FFI::Pointer(**CharS)] out_message
74
- # @return [Integer]
87
+ #
88
+ # @method get_bitcode_module2(mem_buf, out_m)
89
+ # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
90
+ # @param [FFI::Pointer(*ModuleRef)] out_m
91
+ # @return [Integer]
75
92
  # @scope class
76
- attach_function :get_bitcode_module_provider, :LLVMGetBitcodeModuleProvider, [:pointer, :pointer, :pointer], :int
77
-
93
+ attach_function :get_bitcode_module2, :LLVMGetBitcodeModule2, [:pointer, :pointer], :int
94
+
78
95
  # Writes a module to the specified path. Returns 0 on success.
79
- #
96
+ #
80
97
  # @method write_bitcode_to_file(m, path)
81
- # @param [FFI::Pointer(ModuleRef)] m
82
- # @param [String] path
83
- # @return [Integer]
98
+ # @param [FFI::Pointer(ModuleRef)] m
99
+ # @param [String] path
100
+ # @return [Integer]
84
101
  # @scope class
85
102
  attach_function :write_bitcode_to_file, :LLVMWriteBitcodeToFile, [:pointer, :string], :int
86
-
103
+
87
104
  # Writes a module to an open file descriptor. Returns 0 on success.
88
- #
105
+ #
89
106
  # @method write_bitcode_to_fd(m, fd, should_close, unbuffered)
90
- # @param [FFI::Pointer(ModuleRef)] m
91
- # @param [Integer] fd
92
- # @param [Integer] should_close
93
- # @param [Integer] unbuffered
94
- # @return [Integer]
107
+ # @param [FFI::Pointer(ModuleRef)] m
108
+ # @param [Integer] fd
109
+ # @param [Integer] should_close
110
+ # @param [Integer] unbuffered
111
+ # @return [Integer]
95
112
  # @scope class
96
113
  attach_function :write_bitcode_to_fd, :LLVMWriteBitcodeToFD, [:pointer, :int, :int, :int], :int
97
-
114
+
98
115
  # Deprecated for LLVMWriteBitcodeToFD. Writes a module to an open file
99
116
  # descriptor. Returns 0 on success. Closes the Handle.
100
- #
117
+ #
101
118
  # @method write_bitcode_to_file_handle(m, handle)
102
- # @param [FFI::Pointer(ModuleRef)] m
103
- # @param [Integer] handle
104
- # @return [Integer]
119
+ # @param [FFI::Pointer(ModuleRef)] m
120
+ # @param [Integer] handle
121
+ # @return [Integer]
105
122
  # @scope class
106
123
  attach_function :write_bitcode_to_file_handle, :LLVMWriteBitcodeToFileHandle, [:pointer, :int], :int
107
-
124
+
125
+ # Writes a module to a new memory buffer and returns it.
126
+ #
127
+ # @method write_bitcode_to_memory_buffer(m)
128
+ # @param [FFI::Pointer(ModuleRef)] m
129
+ # @return [FFI::Pointer(MemoryBufferRef)]
130
+ # @scope class
131
+ attach_function :write_bitcode_to_memory_buffer, :LLVMWriteBitcodeToMemoryBuffer, [:pointer], :pointer
108
132
  end