ruby-llvm 3.5.0 → 13.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +21 -4
- data/ext/ruby-llvm-support/Rakefile +17 -6
- data/lib/llvm/analysis.rb +2 -0
- data/lib/llvm/analysis_ffi.rb +27 -28
- data/lib/llvm/config.rb +4 -4
- data/lib/llvm/core/bitcode.rb +12 -10
- data/lib/llvm/core/bitcode_ffi.rb +89 -65
- data/lib/llvm/core/builder.rb +4 -3
- data/lib/llvm/core/context.rb +3 -1
- data/lib/llvm/core/module.rb +2 -0
- data/lib/llvm/core/pass_manager.rb +6 -2
- data/lib/llvm/core/type.rb +9 -2
- data/lib/llvm/core/value.rb +154 -24
- data/lib/llvm/core.rb +47 -2
- data/lib/llvm/core_ffi.rb +3863 -3730
- data/lib/llvm/execution_engine.rb +39 -35
- data/lib/llvm/execution_engine_ffi.rb +238 -276
- data/lib/llvm/linker.rb +3 -14
- data/lib/llvm/linker_ffi.rb +22 -26
- data/lib/llvm/support.rb +2 -0
- data/lib/llvm/target.rb +11 -15
- data/lib/llvm/target_ffi.rb +301 -293
- data/lib/llvm/transforms/builder.rb +3 -1
- data/lib/llvm/transforms/builder_ffi.rb +57 -58
- data/lib/llvm/transforms/ipo.rb +3 -1
- data/lib/llvm/transforms/ipo_ffi.rb +59 -60
- data/lib/llvm/transforms/scalar.rb +12 -0
- data/lib/llvm/transforms/scalar_ffi.rb +199 -143
- data/lib/llvm/transforms/vectorize.rb +2 -0
- data/lib/llvm/transforms/vectorize_ffi.rb +15 -16
- data/lib/llvm/version.rb +5 -2
- data/lib/llvm.rb +2 -0
- data/test/array_test.rb +2 -0
- data/test/basic_block_test.rb +2 -1
- data/test/binary_operations_test.rb +2 -0
- data/test/bitcode_test.rb +3 -2
- data/test/branch_test.rb +2 -0
- data/test/call_test.rb +3 -1
- data/test/comparisons_test.rb +2 -0
- data/test/conversions_test.rb +2 -0
- data/test/double_test.rb +10 -7
- data/test/equality_test.rb +4 -4
- data/test/function_test.rb +29 -0
- data/test/generic_value_test.rb +3 -1
- data/test/instruction_test.rb +2 -2
- data/test/integer_test.rb +28 -0
- data/test/ipo_test.rb +3 -1
- data/test/linker_test.rb +2 -9
- data/test/mcjit_test.rb +11 -3
- data/test/memory_access_test.rb +2 -0
- data/test/module_test.rb +18 -1
- data/test/parameter_collection_test.rb +2 -0
- data/test/pass_manager_builder_test.rb +22 -2
- data/test/phi_test.rb +2 -0
- data/test/select_test.rb +2 -0
- data/test/struct_test.rb +2 -0
- data/test/target_test.rb +16 -20
- data/test/test_helper.rb +6 -1
- data/test/type_test.rb +47 -0
- data/test/vector_test.rb +2 -0
- metadata +105 -40
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e4728b4463e1ffaea0e8b00c976923fe77404b01c55ff3c25b015aa2fef5decf
|
4
|
+
data.tar.gz: 35e6017a7035f29b9a39cfd6cbf18116a181f9e2706b12c0318a251525250bc7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5353f3dfc22fcaa701ffa5bc70d5987e03a678881ad03a530ed99f4baada579396c9d8720a999cb9fff9fb93d4efad13fb2cd4ed6486b9a0658f54ad5676f663
|
7
|
+
data.tar.gz: 95cbae2bfda937b9d8eb1a821083bc04858a3e19942ffbf8c195671f51f817d17be2829c51015e3bcd9b699eb467e9dca127e0ff0bb743a2f76288180014846d
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rubygems'
|
2
4
|
require 'rake/clean'
|
3
5
|
require 'ffi'
|
@@ -21,7 +23,7 @@ def check_for(what, variants, env_var)
|
|
21
23
|
if result
|
22
24
|
result
|
23
25
|
else
|
24
|
-
raise
|
26
|
+
raise "Cannot find #{what}: tried #{variants}"
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
@@ -34,7 +36,7 @@ def find_llvm_config
|
|
34
36
|
actual_version = `#{llvm_config} --version`.strip
|
35
37
|
actual_maj, actual_min, _ = actual_version.split('.')
|
36
38
|
|
37
|
-
required_maj, required_min =
|
39
|
+
required_maj, required_min = LLVM_REQUIRED_VERSION.split('.')
|
38
40
|
|
39
41
|
actual_maj == required_maj && actual_min == required_min
|
40
42
|
rescue Errno::ENOENT
|
@@ -54,7 +56,16 @@ LLVM_CONFIG = find_llvm_config
|
|
54
56
|
CXX = find_cxx
|
55
57
|
|
56
58
|
def invoke_llvm_config(options)
|
57
|
-
`#{LLVM_CONFIG} #{options}`.
|
59
|
+
`#{LLVM_CONFIG} #{options}`.tr("\n", " ")
|
60
|
+
end
|
61
|
+
|
62
|
+
def llvm_lib_name
|
63
|
+
lib_dir = invoke_llvm_config('--libdir').strip
|
64
|
+
lib_name = 'LLVM'
|
65
|
+
versioned_lib_name = "#{lib_name}-#{LLVM_VERSION}"
|
66
|
+
versioned_lib_pattern = "lib#{versioned_lib_name}.*"
|
67
|
+
versioned_lib_found = Dir.glob(File.join(lib_dir, versioned_lib_pattern)) != []
|
68
|
+
versioned_lib_found ? versioned_lib_name : lib_name
|
58
69
|
end
|
59
70
|
|
60
71
|
SUPPORT_LIB = FFI.map_library_name("RubyLLVMSupport-#{LLVM_VERSION}")
|
@@ -66,8 +77,8 @@ desc "Build the shared library and config module"
|
|
66
77
|
task :default => [SUPPORT_LIB, CONFIG_MOD]
|
67
78
|
|
68
79
|
file SUPPORT_LIB => %w(support.cpp) do |task|
|
69
|
-
sh "#{CXX} -shared #{task.prerequisites.join(' ')} -
|
70
|
-
"#{invoke_llvm_config('--cxxflags --ldflags')} -o #{SUPPORT_LIB}"
|
80
|
+
sh "#{CXX} -shared #{task.prerequisites.join(' ')} -l#{llvm_lib_name} " \
|
81
|
+
"#{invoke_llvm_config('--cxxflags --ldflags')} -fPIC -o #{SUPPORT_LIB}"
|
71
82
|
end
|
72
83
|
|
73
84
|
LLVM_CONFIG_OPTS = [
|
@@ -76,7 +87,7 @@ LLVM_CONFIG_OPTS = [
|
|
76
87
|
['HOST_TARGET', :string, '--host-target'],
|
77
88
|
['BUILD_MODE', :string, '--build-mode'],
|
78
89
|
['CFLAGS', :string, '--cflags'],
|
79
|
-
]
|
90
|
+
].freeze
|
80
91
|
|
81
92
|
file CONFIG_MOD do
|
82
93
|
open(CONFIG_MOD, 'w') do |f|
|
data/lib/llvm/analysis.rb
CHANGED
data/lib/llvm/analysis_ffi.rb
CHANGED
@@ -4,29 +4,29 @@ require 'ffi'
|
|
4
4
|
|
5
5
|
module LLVM::C
|
6
6
|
extend FFI::Library
|
7
|
-
ffi_lib ["libLLVM-
|
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
|
# @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
|
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", "
|
5
|
-
TARGETS_BUILT = ["
|
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 = "
|
8
|
-
CFLAGS = "-I/usr/lib/llvm-
|
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
|
data/lib/llvm/core/bitcode.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'llvm/core/bitcode_ffi'
|
2
4
|
|
3
5
|
module LLVM
|
@@ -9,7 +11,7 @@ module LLVM
|
|
9
11
|
memory_buffer = case path_or_memory_buffer
|
10
12
|
when MemoryBuffer then path_or_memory_buffer
|
11
13
|
else MemoryBuffer.from_file(path_or_memory_buffer)
|
12
|
-
|
14
|
+
end
|
13
15
|
FFI::MemoryPointer.new(:pointer) do |mod_ref|
|
14
16
|
FFI::MemoryPointer.new(:pointer) do |msg_ref|
|
15
17
|
status = C.parse_bitcode(memory_buffer, mod_ref, msg_ref)
|
@@ -24,15 +26,15 @@ module LLVM
|
|
24
26
|
# @return [true, false] Success
|
25
27
|
def write_bitcode(path_or_io)
|
26
28
|
status = if path_or_io.respond_to?(:path)
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
29
|
+
C.write_bitcode_to_file(self, path_or_io.path)
|
30
|
+
elsif path_or_io.respond_to?(:fileno)
|
31
|
+
C.write_bitcode_to_fd(self, path_or_io.fileno, 0, 1)
|
32
|
+
elsif path_or_io.kind_of?(Integer)
|
33
|
+
C.write_bitcode_to_fd(self, path_or_io, 0, 1)
|
34
|
+
else
|
35
|
+
C.write_bitcode_to_file(self, path_or_io.to_str)
|
36
|
+
end
|
37
|
+
status == 0
|
36
38
|
end
|
37
39
|
end
|
38
40
|
|
@@ -4,105 +4,129 @@ require 'ffi'
|
|
4
4
|
|
5
5
|
module LLVM::C
|
6
6
|
extend FFI::Library
|
7
|
-
ffi_lib ["libLLVM-
|
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
|
-
|
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
|
50
|
-
# @param [FFI::Pointer(
|
51
|
-
# @param [FFI::Pointer(
|
52
|
-
# @param [FFI::Pointer(
|
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 :
|
56
|
-
|
74
|
+
attach_function :get_bitcode_module_in_context2, :LLVMGetBitcodeModuleInContext2, [:pointer, :pointer, :pointer], :int
|
75
|
+
|
57
76
|
# (Not documented)
|
58
|
-
#
|
59
|
-
# @method
|
60
|
-
# @param [FFI::Pointer(
|
61
|
-
# @param [FFI::Pointer(
|
62
|
-
# @param [FFI::Pointer(
|
63
|
-
# @
|
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 :
|
67
|
-
|
84
|
+
attach_function :get_bitcode_module, :LLVMGetBitcodeModule, [:pointer, :pointer, :pointer], :int
|
85
|
+
|
68
86
|
# (Not documented)
|
69
|
-
#
|
70
|
-
# @method
|
71
|
-
# @param [FFI::Pointer(MemoryBufferRef)] mem_buf
|
72
|
-
# @param [FFI::Pointer(*
|
73
|
-
# @
|
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 :
|
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
|
data/lib/llvm/core/builder.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module LLVM
|
2
4
|
class Builder
|
3
5
|
# Important: Call #dispose to free backend memory after use.
|
@@ -118,8 +120,8 @@ module LLVM
|
|
118
120
|
# @return [LLVM::Instruction]
|
119
121
|
def switch(val, default, cases)
|
120
122
|
inst = SwitchInst.from_ptr(C.build_switch(self, val, default, cases.size))
|
121
|
-
cases.each do |(
|
122
|
-
inst.add_case(
|
123
|
+
cases.each do |(c, block)|
|
124
|
+
inst.add_case(c, block)
|
123
125
|
end
|
124
126
|
inst
|
125
127
|
end
|
@@ -820,7 +822,6 @@ module LLVM
|
|
820
822
|
# @return [LLVM::Instruction] The phi node
|
821
823
|
# @LLVMinst phi
|
822
824
|
def phi(ty, incoming, name = "")
|
823
|
-
|
824
825
|
phi = Phi.from_ptr(C.build_phi(self, LLVM::Type(ty), name))
|
825
826
|
phi.add_incoming(incoming)
|
826
827
|
phi
|
data/lib/llvm/core/context.rb
CHANGED
data/lib/llvm/core/module.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module LLVM
|
2
4
|
# The PassManager runs a queue of passes on a module. See
|
3
5
|
# http://llvm.org/docs/Passes.html for the list of available passes.
|
@@ -5,9 +7,11 @@ module LLVM
|
|
5
7
|
# Creates a new pass manager.
|
6
8
|
#
|
7
9
|
# @param [LLVM::ExecutionEngine, LLVM::TargetMachine] machine
|
8
|
-
def initialize(machine)
|
10
|
+
def initialize(machine = nil)
|
11
|
+
if machine
|
12
|
+
warn("[DEPRECATION] PassManager.new should be called without parameters")
|
13
|
+
end
|
9
14
|
@ptr = C.create_pass_manager()
|
10
|
-
C.add_target_data(machine.data_layout, @ptr)
|
11
15
|
end
|
12
16
|
|
13
17
|
# @private
|
data/lib/llvm/core/type.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module LLVM
|
2
4
|
class Type
|
3
5
|
include PointerIdentity
|
@@ -33,7 +35,7 @@ module LLVM
|
|
33
35
|
|
34
36
|
# Returns the type of this types elements (works only for Pointer, Vector, and Array types.)
|
35
37
|
def element_type
|
36
|
-
case
|
38
|
+
case kind
|
37
39
|
when :pointer, :vector, :array
|
38
40
|
Type.from_ptr(C.get_element_type(self), nil)
|
39
41
|
end
|
@@ -59,6 +61,11 @@ module LLVM
|
|
59
61
|
C.dump_type(self)
|
60
62
|
end
|
61
63
|
|
64
|
+
# Build string of LLVM type representation.
|
65
|
+
def to_s
|
66
|
+
C.print_type_to_string(self)
|
67
|
+
end
|
68
|
+
|
62
69
|
# Creates an array type of Type with the given size.
|
63
70
|
def self.array(ty, sz = 0)
|
64
71
|
from_ptr(C.array_type(LLVM::Type(ty), sz), :array)
|
@@ -128,7 +135,7 @@ module LLVM
|
|
128
135
|
C.get_param_types(self, types_ptr)
|
129
136
|
result = types_ptr.read_array_of_pointer(size)
|
130
137
|
end
|
131
|
-
result.map{ |p| Type.from_ptr(p, nil) }
|
138
|
+
result.map { |p| Type.from_ptr(p, nil) }
|
132
139
|
end
|
133
140
|
|
134
141
|
def vararg?
|