ruby-llvm 3.4.2 → 13.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b4c3ca01e2020b5ce26bdf7db68f78f33d4fefbe
4
- data.tar.gz: 4580027aed01abdc1c9055dfd4d3736f1fae4606
2
+ SHA256:
3
+ metadata.gz: 93a0f0ec49145c009677352d8765f8c1f79d4aa0b88aa7c17bb005d4b18f44c1
4
+ data.tar.gz: '03604842f13d9f1108e36ff5f2089884fe3673f43a08866d8c73bb5135f05cb8'
5
5
  SHA512:
6
- metadata.gz: b111187af62e59fd09acd472f241f0e64913832f956f99cf2fb3faf16806f7b61957840f4fe0246181a41521c9180d0b18420356915077635fa5a9690853b81e
7
- data.tar.gz: 108a673c529d5b7621c7206f169b8704473cc518fafed2e10880f2f96fbe58537e8b2f47cab56b5ac0dabf3c2ef7affa9a0166c0e2cf1511a1ba98b5f6ed824e
6
+ metadata.gz: 0ef8e20027e12ea46c5f4764fe50f4e7e07aab58579e84c2692ad323c5fb2c6b77c329bc97ae742d226eba0c345c5b9e774ef8381f8336db8927d4d678159691
7
+ data.tar.gz: 29c3b9e27042468d2db9d6bf0745675390d665824fd0149e9c55617c6d4da1627635576ced6722e8638fd3061b46127b49aaf449ad5e957105a903409d23dd06
data/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ [![Known Vulnerabilities](https://snyk.io/test/github/ruby-llvm/ruby-llvm/badge.svg)](https://snyk.io/test/github/ruby-llvm/ruby-llvm)
2
+ [![Code Climate Maintainability](https://codeclimate.com/github/ruby-llvm/ruby-llvm/badges/gpa.svg)](https://codeclimate.com/github/ruby-llvm/ruby-llvm)
3
+ [![Code Climate Issue Count](https://codeclimate.com/github/ruby-llvm/ruby-llvm/badges/issue_count.svg)](https://codeclimate.com/github/ruby-llvm/ruby-llvm/issues)
4
+
1
5
  Ruby-LLVM
2
6
  =========
3
7
 
@@ -7,10 +11,10 @@ library. LLVM allows users to create just-in-time (JIT) compilers, ahead-of-time
7
11
  bindings can also be used to speed up Ruby code by compiling and loading
8
12
  computationally intensive algorithms on the fly.
9
13
 
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.
14
+ Current version
15
+ ---------------
16
+
17
+ This library currently binds to LLVM-13 (specifically llvm-c 13).
14
18
 
15
19
  About version numbers
16
20
  ---------------------
@@ -20,13 +24,26 @@ major and minor version of LLVM. The third digit refers to the ruby-llvm
20
24
  release itself. Because LLVM's api changes often, this coupling between
21
25
  LLVM and ruby-llvm versions is useful.
22
26
 
27
+ Debian/Ubuntu
28
+ -------------
29
+
30
+ [LLVM Debian/Ubuntu Packages](https://apt.llvm.org/)
31
+
23
32
  Homebrew
24
33
  --------
34
+
25
35
  LLVM can be installed with Homebrew by executing `brew install llvm --shared`
26
36
 
37
+ Source and other binaries
38
+ -------------------------
39
+
40
+ * [LLVM Download Page](https://releases.llvm.org/download.html)
41
+ * If compiling from source the --enable-shared and --enable-jit flags may be needed.
42
+
27
43
  See Also
28
44
  --------
29
45
  * [The LLVM project](http://llvm.org)
46
+ * [Mirror of llvm-c on github](https://github.com/llvm-mirror/llvm/tree/master/include/llvm-c)
30
47
  * [ffi-gen](https://github.com/neelance/ffi-gen) – Generate
31
48
  [FFI](https://github.com/ffi/ffi) bindings with LLVM and Clang
32
49
 
@@ -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|
@@ -2,21 +2,9 @@
2
2
  * Extended bindings for LLVM.
3
3
  */
4
4
 
5
- #include <llvm-c/Core.h>
6
- #include <llvm/IR/GlobalValue.h>
7
5
  #include <llvm/Support/TargetSelect.h>
8
6
 
9
7
  extern "C" {
10
- using namespace llvm;
11
-
12
- LLVMBool LLVMHasUnnamedAddr(LLVMValueRef global) {
13
- return unwrap<GlobalValue>(global)->hasUnnamedAddr();
14
- }
15
-
16
- void LLVMSetUnnamedAddr(LLVMValueRef global, LLVMBool val) {
17
- unwrap<GlobalValue>(global)->setUnnamedAddr(val != 0);
18
- }
19
-
20
8
  void LLVMInitializeAllTargetInfos() {
21
9
  llvm::InitializeAllTargetInfos();
22
10
  }
@@ -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-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
+ # @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
data/lib/llvm/config.rb CHANGED
@@ -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
@@ -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-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
-
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
@@ -118,8 +118,8 @@ module LLVM
118
118
  # @return [LLVM::Instruction]
119
119
  def switch(val, default, cases)
120
120
  inst = SwitchInst.from_ptr(C.build_switch(self, val, default, cases.size))
121
- cases.each do |(val, block)|
122
- inst.add_case(val, block)
121
+ cases.each do |(c, block)|
122
+ inst.add_case(c, block)
123
123
  end
124
124
  inst
125
125
  end
@@ -820,7 +820,6 @@ module LLVM
820
820
  # @return [LLVM::Instruction] The phi node
821
821
  # @LLVMinst phi
822
822
  def phi(ty, incoming, name = "")
823
-
824
823
  phi = Phi.from_ptr(C.build_phi(self, LLVM::Type(ty), name))
825
824
  phi.add_incoming(incoming)
826
825
  phi
@@ -1,4 +1,4 @@
1
- module LLVM
1
+ module LLVM
2
2
  class Context
3
3
  def initialize(ptr = nil)
4
4
  @ptr = ptr || C.context_create()
@@ -5,9 +5,11 @@ module LLVM
5
5
  # Creates a new pass manager.
6
6
  #
7
7
  # @param [LLVM::ExecutionEngine, LLVM::TargetMachine] machine
8
- def initialize(machine)
8
+ def initialize(machine = nil)
9
+ if machine
10
+ warn("[DEPRECATION] PassManager.new should be called without parameters")
11
+ end
9
12
  @ptr = C.create_pass_manager()
10
- C.add_target_data(machine.data_layout, @ptr)
11
13
  end
12
14
 
13
15
  # @private
@@ -33,7 +33,7 @@ module LLVM
33
33
 
34
34
  # Returns the type of this types elements (works only for Pointer, Vector, and Array types.)
35
35
  def element_type
36
- case self.kind
36
+ case kind
37
37
  when :pointer, :vector, :array
38
38
  Type.from_ptr(C.get_element_type(self), nil)
39
39
  end
@@ -128,7 +128,7 @@ module LLVM
128
128
  C.get_param_types(self, types_ptr)
129
129
  result = types_ptr.read_array_of_pointer(size)
130
130
  end
131
- result.map{ |p| Type.from_ptr(p, nil) }
131
+ result.map { |p| Type.from_ptr(p, nil) }
132
132
  end
133
133
 
134
134
  def vararg?