ruby-llvm 3.4.0 → 11.0.1

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 (46) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +19 -4
  3. data/ext/ruby-llvm-support/Rakefile +20 -8
  4. data/ext/ruby-llvm-support/support.cpp +0 -20
  5. data/lib/llvm.rb +0 -6
  6. data/lib/llvm/analysis_ffi.rb +30 -28
  7. data/lib/llvm/config.rb +4 -4
  8. data/lib/llvm/core.rb +45 -2
  9. data/lib/llvm/core/bitcode.rb +10 -10
  10. data/lib/llvm/core/bitcode_ffi.rb +92 -70
  11. data/lib/llvm/core/builder.rb +2 -3
  12. data/lib/llvm/core/context.rb +1 -1
  13. data/lib/llvm/core/pass_manager.rb +4 -2
  14. data/lib/llvm/core/type.rb +2 -2
  15. data/lib/llvm/core/value.rb +155 -28
  16. data/lib/llvm/core_ffi.rb +4038 -3716
  17. data/lib/llvm/execution_engine.rb +176 -8
  18. data/lib/llvm/execution_engine_ffi.rb +245 -272
  19. data/lib/llvm/linker.rb +2 -19
  20. data/lib/llvm/linker_ffi.rb +24 -25
  21. data/lib/llvm/support.rb +4 -12
  22. data/lib/llvm/target.rb +11 -17
  23. data/lib/llvm/target_ffi.rb +336 -362
  24. data/lib/llvm/transforms/builder.rb +8 -3
  25. data/lib/llvm/transforms/builder_ffi.rb +57 -58
  26. data/lib/llvm/transforms/ipo.rb +1 -1
  27. data/lib/llvm/transforms/ipo_ffi.rb +60 -61
  28. data/lib/llvm/transforms/scalar_ffi.rb +208 -136
  29. data/lib/llvm/transforms/vectorize_ffi.rb +15 -16
  30. data/lib/llvm/version.rb +3 -2
  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 +100 -0
  42. data/test/module_test.rb +31 -1
  43. data/test/pass_manager_builder_test.rb +23 -3
  44. data/test/target_test.rb +7 -24
  45. data/test/test_helper.rb +4 -1
  46. metadata +117 -94
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 878b8916b8491bdbe2853e9595d7e462f3409b7e
4
- data.tar.gz: eb5a2758a1f1711f7f7832974459a00571ffe9bf
2
+ SHA256:
3
+ metadata.gz: a863554200f16a07a9cd989d7a3dcd397c0e52e212308316cc39af2bb9a3394f
4
+ data.tar.gz: 79c3543ca89b7136dd3ff241b472738968fd74ffa7ec82713c6230590e0d8149
5
5
  SHA512:
6
- metadata.gz: 76d69849283e05f5ef6352c4f2e0acd60184ff16c1835485163327bff58c0401b99ea4d2562aa996d1a721b1c04a95befca5eb3a5feec128d712f82a121f4944
7
- data.tar.gz: 21a27d8d676573270a0e412e76d2e29ad1649b8850297fe51a7f370dbeca127fb4fd7f8ac235e0c286c1d0c3206f90f58966681e5149789945d32a962a3a739e
6
+ metadata.gz: caac65e20ca51936477266a9b5e41f18786f55ee347efbc86773be12f98074764baea28f27e9e0c0a39e658fc8b82da97d91fc7940654f3f8d4467c257eec91c
7
+ data.tar.gz: '020822c2c9e802ad4483ae25863a4e0aa43a24e9e397b74caa902ad5f84f7c1803a662ca099b65d212b6a8ab70e35d049ab0a28789ec33719611e5a43af34ef0'
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-11 (specifically llvm-c 11).
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
 
@@ -32,8 +32,11 @@ def find_llvm_config
32
32
 
33
33
  begin
34
34
  actual_version = `#{llvm_config} --version`.strip
35
+ actual_maj, actual_min, _ = actual_version.split('.')
35
36
 
36
- actual_version == LLVM_VERSION
37
+ required_maj, required_min = LLVM_REQUIRED_VERSION.split('.')
38
+
39
+ actual_maj == required_maj && actual_min == required_min
37
40
  rescue Errno::ENOENT
38
41
  false
39
42
  end
@@ -41,8 +44,8 @@ def find_llvm_config
41
44
  end
42
45
 
43
46
  def find_cxx
44
- check_for('C++ compiler', %W(clang++ g++), 'CXX') do |cxx|
45
- system(cxx, "--version", out: :close, err: :close)
47
+ check_for('C++ compiler', %W(g++ clang++), 'CXX') do |cxx|
48
+ system(cxx, "--version", out: File::NULL, err: File::NULL)
46
49
  $?.success?
47
50
  end
48
51
  end
@@ -51,7 +54,16 @@ LLVM_CONFIG = find_llvm_config
51
54
  CXX = find_cxx
52
55
 
53
56
  def invoke_llvm_config(options)
54
- `#{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
55
67
  end
56
68
 
57
69
  SUPPORT_LIB = FFI.map_library_name("RubyLLVMSupport-#{LLVM_VERSION}")
@@ -63,8 +75,8 @@ desc "Build the shared library and config module"
63
75
  task :default => [SUPPORT_LIB, CONFIG_MOD]
64
76
 
65
77
  file SUPPORT_LIB => %w(support.cpp) do |task|
66
- sh "#{CXX} -shared -lLLVM-#{LLVM_VERSION} #{task.prerequisites.join(' ')} " \
67
- "#{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}"
68
80
  end
69
81
 
70
82
  LLVM_CONFIG_OPTS = [
@@ -73,7 +85,7 @@ LLVM_CONFIG_OPTS = [
73
85
  ['HOST_TARGET', :string, '--host-target'],
74
86
  ['BUILD_MODE', :string, '--build-mode'],
75
87
  ['CFLAGS', :string, '--cflags'],
76
- ]
88
+ ].freeze
77
89
 
78
90
  file CONFIG_MOD do
79
91
  open(CONFIG_MOD, 'w') do |f|
@@ -2,29 +2,9 @@
2
2
  * Extended bindings for LLVM.
3
3
  */
4
4
 
5
- #include <llvm-c/Core.h>
6
- #include <llvm/IR/Type.h>
7
- #include <llvm/IR/Module.h>
8
- #include <llvm/IR/GlobalValue.h>
9
- #include <llvm/Support/DynamicLibrary.h>
10
5
  #include <llvm/Support/TargetSelect.h>
11
- #include <llvm/Support/raw_ostream.h>
12
6
 
13
7
  extern "C" {
14
- using namespace llvm;
15
-
16
- int LLVMLoadLibraryPermanently(const char* filename) {
17
- return llvm::sys::DynamicLibrary::LoadLibraryPermanently(filename);
18
- }
19
-
20
- LLVMBool LLVMHasUnnamedAddr(LLVMValueRef global) {
21
- return unwrap<GlobalValue>(global)->hasUnnamedAddr();
22
- }
23
-
24
- void LLVMSetUnnamedAddr(LLVMValueRef global, LLVMBool val) {
25
- unwrap<GlobalValue>(global)->setUnnamedAddr(val != 0);
26
- }
27
-
28
8
  void LLVMInitializeAllTargetInfos() {
29
9
  llvm::InitializeAllTargetInfos();
30
10
  }
@@ -4,12 +4,6 @@ module LLVM
4
4
  require 'llvm/version'
5
5
  require 'llvm/support'
6
6
 
7
- # @private
8
- module C
9
- extend ::FFI::Library
10
- ffi_lib ["LLVM-#{LLVM_VERSION}"]
11
- end
12
-
13
7
  module PointerIdentity
14
8
  # @private
15
9
  def to_ptr
@@ -4,26 +4,29 @@ 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-11.so.1", "libLLVM.so.11", "LLVM-11"]
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
+ # @defgroup LLVMCAnalysis Analysis
16
+ # @ingroup LLVMC
17
+ #
18
+ # @{
19
+ #
17
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>
18
- #
21
+ #
19
22
  # === Options:
20
23
  # :abort_process ::
21
- #
24
+ #
22
25
  # :print_message ::
23
26
  # verifier will print to stderr and abort()
24
27
  # :return_status ::
25
28
  # verifier will print to stderr and return 1
26
- #
29
+ #
27
30
  # @method _enum_verifier_failure_action_
28
31
  # @return [Symbol]
29
32
  # @scope class
@@ -32,44 +35,43 @@ module LLVM::C
32
35
  :print_message, 1,
33
36
  :return_status, 2
34
37
  ]
35
-
38
+
36
39
  # Verifies that a module is valid, taking the specified action if not.
37
40
  # Optionally returns a human-readable description of any invalid constructs.
38
41
  # OutMessage must be disposed with LLVMDisposeMessage.
39
- #
42
+ #
40
43
  # @method verify_module(m, action, out_message)
41
- # @param [FFI::Pointer(ModuleRef)] m
42
- # @param [Symbol from _enum_verifier_failure_action_] action
43
- # @param [FFI::Pointer(**CharS)] out_message
44
- # @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]
45
48
  # @scope class
46
49
  attach_function :verify_module, :LLVMVerifyModule, [:pointer, :verifier_failure_action, :pointer], :int
47
-
50
+
48
51
  # Verifies that a single function is valid, taking the specified action. Useful
49
52
  # for debugging.
50
- #
53
+ #
51
54
  # @method verify_function(fn, action)
52
- # @param [FFI::Pointer(ValueRef)] fn
53
- # @param [Symbol from _enum_verifier_failure_action_] action
54
- # @return [Integer]
55
+ # @param [FFI::Pointer(ValueRef)] fn
56
+ # @param [Symbol from _enum_verifier_failure_action_] action
57
+ # @return [Integer]
55
58
  # @scope class
56
59
  attach_function :verify_function, :LLVMVerifyFunction, [:pointer, :verifier_failure_action], :int
57
-
60
+
58
61
  # Open up a ghostview window that displays the CFG of the current function.
59
62
  # Useful for debugging.
60
- #
63
+ #
61
64
  # @method view_function_cfg(fn)
62
- # @param [FFI::Pointer(ValueRef)] fn
63
- # @return [nil]
65
+ # @param [FFI::Pointer(ValueRef)] fn
66
+ # @return [nil]
64
67
  # @scope class
65
68
  attach_function :view_function_cfg, :LLVMViewFunctionCFG, [:pointer], :void
66
-
69
+
67
70
  # (Not documented)
68
- #
71
+ #
69
72
  # @method view_function_cfg_only(fn)
70
- # @param [FFI::Pointer(ValueRef)] fn
71
- # @return [nil]
73
+ # @param [FFI::Pointer(ValueRef)] fn
74
+ # @return [nil]
72
75
  # @scope class
73
76
  attach_function :view_function_cfg_only, :LLVMViewFunctionCFGOnly, [:pointer], :void
74
-
75
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", "linker", "lto", "mc", "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", "powerpcinfo", "r600", "r600asmprinter", "r600codegen", "r600desc", "r600info", "runtimedyld", "scalaropts", "selectiondag", "sparc", "sparccodegen", "sparcdesc", "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", "AArch64", "ARM", "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.4/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-11/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,107 +4,129 @@ 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-11.so.1", "libLLVM.so.11", "LLVM-11"]
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
-
36
- # Reads a module from the specified path, returning via the OutMP parameter
37
- # a module provider which performs lazy deserialization. Returns 0 on success.
38
- # Optionally returns a human-readable error message via OutMessage.
39
- #
44
+
45
+ # (Not documented)
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
+ #
40
57
  # @method get_bitcode_module_in_context(context_ref, mem_buf, out_m, out_message)
41
- # @param [FFI::Pointer(ContextRef)] context_ref
42
- # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
43
- # @param [FFI::Pointer(*ModuleRef)] out_m
44
- # @param [FFI::Pointer(**CharS)] out_message
45
- # @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]
46
63
  # @scope class
47
64
  attach_function :get_bitcode_module_in_context, :LLVMGetBitcodeModuleInContext, [:pointer, :pointer, :pointer, :pointer], :int
48
-
65
+
49
66
  # (Not documented)
50
- #
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]
73
+ # @scope class
74
+ attach_function :get_bitcode_module_in_context2, :LLVMGetBitcodeModuleInContext2, [:pointer, :pointer, :pointer], :int
75
+
76
+ # (Not documented)
77
+ #
51
78
  # @method get_bitcode_module(mem_buf, out_m, out_message)
52
- # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
53
- # @param [FFI::Pointer(*ModuleRef)] out_m
54
- # @param [FFI::Pointer(**CharS)] out_message
55
- # @return [Integer]
79
+ # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
80
+ # @param [FFI::Pointer(*ModuleRef)] out_m
81
+ # @param [FFI::Pointer(**CharS)] out_message
82
+ # @return [Integer]
56
83
  # @scope class
57
84
  attach_function :get_bitcode_module, :LLVMGetBitcodeModule, [:pointer, :pointer, :pointer], :int
58
-
59
- # Deprecated: Use LLVMGetBitcodeModuleInContext instead.
60
- #
61
- # @method get_bitcode_module_provider_in_context(context_ref, mem_buf, out_mp, out_message)
62
- # @param [FFI::Pointer(ContextRef)] context_ref
63
- # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
64
- # @param [FFI::Pointer(*ModuleProviderRef)] out_mp
65
- # @param [FFI::Pointer(**CharS)] out_message
66
- # @return [Integer]
67
- # @scope class
68
- attach_function :get_bitcode_module_provider_in_context, :LLVMGetBitcodeModuleProviderInContext, [:pointer, :pointer, :pointer, :pointer], :int
69
-
70
- # Deprecated: Use LLVMGetBitcodeModule instead.
71
- #
72
- # @method get_bitcode_module_provider(mem_buf, out_mp, out_message)
73
- # @param [FFI::Pointer(MemoryBufferRef)] mem_buf
74
- # @param [FFI::Pointer(*ModuleProviderRef)] out_mp
75
- # @param [FFI::Pointer(**CharS)] out_message
76
- # @return [Integer]
77
- # @scope class
78
- attach_function :get_bitcode_module_provider, :LLVMGetBitcodeModuleProvider, [:pointer, :pointer, :pointer], :int
79
-
85
+
80
86
  # (Not documented)
81
- #
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]
92
+ # @scope class
93
+ attach_function :get_bitcode_module2, :LLVMGetBitcodeModule2, [:pointer, :pointer], :int
94
+
95
+ # Writes a module to the specified path. Returns 0 on success.
96
+ #
82
97
  # @method write_bitcode_to_file(m, path)
83
- # @param [FFI::Pointer(ModuleRef)] m
84
- # @param [String] path
85
- # @return [Integer]
98
+ # @param [FFI::Pointer(ModuleRef)] m
99
+ # @param [String] path
100
+ # @return [Integer]
86
101
  # @scope class
87
102
  attach_function :write_bitcode_to_file, :LLVMWriteBitcodeToFile, [:pointer, :string], :int
88
-
103
+
89
104
  # Writes a module to an open file descriptor. Returns 0 on success.
90
- #
105
+ #
91
106
  # @method write_bitcode_to_fd(m, fd, should_close, unbuffered)
92
- # @param [FFI::Pointer(ModuleRef)] m
93
- # @param [Integer] fd
94
- # @param [Integer] should_close
95
- # @param [Integer] unbuffered
96
- # @return [Integer]
107
+ # @param [FFI::Pointer(ModuleRef)] m
108
+ # @param [Integer] fd
109
+ # @param [Integer] should_close
110
+ # @param [Integer] unbuffered
111
+ # @return [Integer]
97
112
  # @scope class
98
113
  attach_function :write_bitcode_to_fd, :LLVMWriteBitcodeToFD, [:pointer, :int, :int, :int], :int
99
-
114
+
100
115
  # Deprecated for LLVMWriteBitcodeToFD. Writes a module to an open file
101
116
  # descriptor. Returns 0 on success. Closes the Handle.
102
- #
117
+ #
103
118
  # @method write_bitcode_to_file_handle(m, handle)
104
- # @param [FFI::Pointer(ModuleRef)] m
105
- # @param [Integer] handle
106
- # @return [Integer]
119
+ # @param [FFI::Pointer(ModuleRef)] m
120
+ # @param [Integer] handle
121
+ # @return [Integer]
107
122
  # @scope class
108
123
  attach_function :write_bitcode_to_file_handle, :LLVMWriteBitcodeToFileHandle, [:pointer, :int], :int
109
-
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
110
132
  end