ruby-llvm-next 10.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +30 -0
  3. data/README.md +67 -0
  4. data/ext/ruby-llvm-support/Rakefile +110 -0
  5. data/ext/ruby-llvm-support/support.cpp +32 -0
  6. data/lib/llvm.rb +29 -0
  7. data/lib/llvm/analysis.rb +49 -0
  8. data/lib/llvm/analysis_ffi.rb +77 -0
  9. data/lib/llvm/config.rb +10 -0
  10. data/lib/llvm/core.rb +97 -0
  11. data/lib/llvm/core/bitcode.rb +84 -0
  12. data/lib/llvm/core/bitcode_ffi.rb +132 -0
  13. data/lib/llvm/core/builder.rb +944 -0
  14. data/lib/llvm/core/context.rb +24 -0
  15. data/lib/llvm/core/module.rb +240 -0
  16. data/lib/llvm/core/pass_manager.rb +80 -0
  17. data/lib/llvm/core/type.rb +210 -0
  18. data/lib/llvm/core/value.rb +1005 -0
  19. data/lib/llvm/core_ffi.rb +6021 -0
  20. data/lib/llvm/execution_engine.rb +323 -0
  21. data/lib/llvm/execution_engine_ffi.rb +421 -0
  22. data/lib/llvm/linker.rb +16 -0
  23. data/lib/llvm/linker_ffi.rb +44 -0
  24. data/lib/llvm/support.rb +38 -0
  25. data/lib/llvm/target.rb +318 -0
  26. data/lib/llvm/target_ffi.rb +628 -0
  27. data/lib/llvm/transforms/builder.rb +107 -0
  28. data/lib/llvm/transforms/builder_ffi.rb +117 -0
  29. data/lib/llvm/transforms/ipo.rb +78 -0
  30. data/lib/llvm/transforms/ipo_ffi.rb +127 -0
  31. data/lib/llvm/transforms/scalar.rb +152 -0
  32. data/lib/llvm/transforms/scalar_ffi.rb +344 -0
  33. data/lib/llvm/transforms/vectorize.rb +22 -0
  34. data/lib/llvm/transforms/vectorize_ffi.rb +38 -0
  35. data/lib/llvm/version.rb +5 -0
  36. data/test/array_test.rb +38 -0
  37. data/test/basic_block_test.rb +87 -0
  38. data/test/binary_operations_test.rb +58 -0
  39. data/test/bitcode_test.rb +24 -0
  40. data/test/branch_test.rb +57 -0
  41. data/test/call_test.rb +82 -0
  42. data/test/comparisons_test.rb +66 -0
  43. data/test/conversions_test.rb +92 -0
  44. data/test/double_test.rb +34 -0
  45. data/test/equality_test.rb +89 -0
  46. data/test/function_test.rb +100 -0
  47. data/test/generic_value_test.rb +22 -0
  48. data/test/instruction_test.rb +30 -0
  49. data/test/ipo_test.rb +53 -0
  50. data/test/linker_test.rb +37 -0
  51. data/test/mcjit_test.rb +94 -0
  52. data/test/memory_access_test.rb +38 -0
  53. data/test/module_test.rb +93 -0
  54. data/test/parameter_collection_test.rb +28 -0
  55. data/test/pass_manager_builder_test.rb +53 -0
  56. data/test/phi_test.rb +33 -0
  57. data/test/select_test.rb +22 -0
  58. data/test/struct_test.rb +98 -0
  59. data/test/target_test.rb +113 -0
  60. data/test/test_helper.rb +62 -0
  61. data/test/type_test.rb +15 -0
  62. data/test/vector_test.rb +64 -0
  63. metadata +240 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d62975c1e0b9ec9fba55e600e40e84f08263cc70e1e0dc8f395f9b03935d06e3
4
+ data.tar.gz: af890548a7e0ea7dffc559cb46efef77de62adb69fe1a1e7eb42ceb3015f6c0f
5
+ SHA512:
6
+ metadata.gz: a8a7acaa310753969acfd44ef0b7db5b5b9900d95eb83f1845fe655cb274bcc222cf872a747c431d3a90508804a2733e637044cad35c76efc370f9fb1224953c
7
+ data.tar.gz: 99a09ea3aa71123379bd26a29f58696479ab5c892b35bffab133e84b2c56d70f937da248e752fdeddd9f98d12502a0981c3dbd3bef04f7e5c38cac19c29c87b1
data/LICENSE ADDED
@@ -0,0 +1,30 @@
1
+ Copyright (c) 2010-2011 Jeremy Voorhis
2
+
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions
7
+ are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright
10
+ notice, this list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright
13
+ notice, this list of conditions and the following disclaimer in the
14
+ documentation and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the author nor the names of his contributors
17
+ may be used to endorse or promote products derived from this software
18
+ without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
21
+ IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
24
+ ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29
+ ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
+ POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,67 @@
1
+ [![Known Vulnerabilities](https://snyk.io/test/github/ruby-llvm/ruby-llvm/badge.svg)](https://snyk.io/test/github/ruby-llvm/ruby-llvm)
2
+
3
+ Ruby-LLVM
4
+ =========
5
+
6
+ Ruby-LLVM is a Ruby language binding to the LLVM compiler infrastructure
7
+ library. LLVM allows users to create just-in-time (JIT) compilers, ahead-of-time
8
+ (AOT) compilers for multiple architectures, code analyzers and more. LLVM
9
+ bindings can also be used to speed up Ruby code by compiling and loading
10
+ computationally intensive algorithms on the fly.
11
+
12
+ Current version
13
+ ---------------
14
+
15
+ This library currently binds to LLVM-10 (specifically llvm-c 10).
16
+
17
+ About version numbers
18
+ ---------------------
19
+
20
+ The first two digits of ruby-llvm's version number refer to the required
21
+ major and minor version of LLVM. The third digit refers to the ruby-llvm
22
+ release itself. Because LLVM's api changes often, this coupling between
23
+ LLVM and ruby-llvm versions is useful.
24
+
25
+ Debian/Ubuntu
26
+ -------------
27
+
28
+ [LLVM Debian/Ubuntu Packages](https://apt.llvm.org/)
29
+
30
+ Homebrew
31
+ --------
32
+
33
+ LLVM can be installed with Homebrew by executing `brew install llvm --shared`
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
+
41
+ See Also
42
+ --------
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)
45
+ * [ffi-gen](https://github.com/neelance/ffi-gen) – Generate
46
+ [FFI](https://github.com/ffi/ffi) bindings with LLVM and Clang
47
+
48
+ License
49
+ -------
50
+ Ruby-LLVM is available under the BSD 3-clause (see LICENSE), Copyright (c) 2010-2013 Jeremy Voorhis
51
+
52
+ Ruby-LLVM is possible because of its contributors:
53
+
54
+ * Evan Phoenix
55
+ * David Holroyd
56
+ * Takanori Ishikawa
57
+ * Ronaldo M. Ferraz
58
+ * Mac Malone
59
+ * Chris Wailes
60
+ * Ary Borenszweig
61
+ * Richard Musiol
62
+ * Juan Wajnerman
63
+ * Steven Farlie
64
+ * Peter Zotov
65
+ * Austin Seipp
66
+ * Torsten Rüger
67
+ * Nathaniel Barnes
@@ -0,0 +1,110 @@
1
+ require 'rubygems'
2
+ require 'rake/clean'
3
+ require 'ffi'
4
+
5
+ require File.expand_path('../../lib/llvm/version', File.dirname(__FILE__))
6
+ include LLVM
7
+
8
+ def check_for(what, variants, env_var)
9
+ variants = [ ENV[env_var], *variants ] if ENV.include?(env_var)
10
+
11
+ $stdout.print("checking for #{what}... ")
12
+ $stdout.flush
13
+
14
+ result = variants.find do |variant|
15
+ if yield(variant)
16
+ $stdout.puts(variant)
17
+ true
18
+ end
19
+ end
20
+
21
+ if result
22
+ result
23
+ else
24
+ raise "Cannot find #{what}: tried #{variants}"
25
+ end
26
+ end
27
+
28
+ def find_llvm_config
29
+ check_for('llvm-config',
30
+ %W(llvm-config-#{LLVM_VERSION} llvm-config),
31
+ 'LLVM_CONFIG') do |llvm_config|
32
+
33
+ begin
34
+ actual_version = `#{llvm_config} --version`.strip
35
+ actual_maj, actual_min, _ = actual_version.split('.')
36
+
37
+ required_maj, required_min = LLVM_REQUIRED_VERSION.split('.')
38
+
39
+ actual_maj == required_maj && actual_min == required_min
40
+ rescue Errno::ENOENT
41
+ false
42
+ end
43
+ end
44
+ end
45
+
46
+ def find_cxx
47
+ check_for('C++ compiler', %W(g++ clang++), 'CXX') do |cxx|
48
+ system(cxx, "--version", out: File::NULL, err: File::NULL)
49
+ $?.success?
50
+ end
51
+ end
52
+
53
+ LLVM_CONFIG = find_llvm_config
54
+ CXX = find_cxx
55
+
56
+ def invoke_llvm_config(options)
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
67
+ end
68
+
69
+ SUPPORT_LIB = FFI.map_library_name("RubyLLVMSupport-#{LLVM_VERSION}")
70
+ CONFIG_MOD = File.expand_path('../../lib/llvm/config.rb', File.dirname(__FILE__))
71
+
72
+ CLEAN.include(SUPPORT_LIB, CONFIG_MOD)
73
+
74
+ desc "Build the shared library and config module"
75
+ task :default => [SUPPORT_LIB, CONFIG_MOD]
76
+
77
+ file SUPPORT_LIB => %w(support.cpp) do |task|
78
+ sh "#{CXX} -shared #{task.prerequisites.join(' ')} -l#{llvm_lib_name} " \
79
+ "#{invoke_llvm_config('--cxxflags --ldflags')} -fPIC -o #{SUPPORT_LIB}"
80
+ end
81
+
82
+ LLVM_CONFIG_OPTS = [
83
+ ['COMPONENTS', :array, '--components'],
84
+ ['TARGETS_BUILT', :array, '--targets-built'],
85
+ ['HOST_TARGET', :string, '--host-target'],
86
+ ['BUILD_MODE', :string, '--build-mode'],
87
+ ['CFLAGS', :string, '--cflags'],
88
+ ].freeze
89
+
90
+ file CONFIG_MOD do
91
+ open(CONFIG_MOD, 'w') do |f|
92
+ f.puts '# Generated by ruby-llvm. Please do not change this file by hand.'
93
+ f.puts 'module LLVM'
94
+ f.puts ' module CONFIG'
95
+
96
+ LLVM_CONFIG_OPTS.each do |(const, fmt, flag)|
97
+ case fmt
98
+ when :string
99
+ value = invoke_llvm_config(flag)
100
+ when :array
101
+ value = invoke_llvm_config(flag).split
102
+ end
103
+
104
+ f.puts " #{const} = #{value.inspect}"
105
+ end
106
+
107
+ f.puts ' end'
108
+ f.puts 'end'
109
+ end
110
+ end
@@ -0,0 +1,32 @@
1
+ /*
2
+ * Extended bindings for LLVM.
3
+ */
4
+
5
+ #include <llvm/Support/TargetSelect.h>
6
+
7
+ extern "C" {
8
+ void LLVMInitializeAllTargetInfos() {
9
+ llvm::InitializeAllTargetInfos();
10
+ }
11
+
12
+ void LLVMInitializeAllTargets() {
13
+ llvm::InitializeAllTargets();
14
+ }
15
+
16
+ void LLVMInitializeAllTargetMCs() {
17
+ llvm::InitializeAllTargetMCs();
18
+ }
19
+
20
+ void LLVMInitializeAllAsmPrinters() {
21
+ llvm::InitializeAllAsmPrinters();
22
+ }
23
+
24
+ void LLVMInitializeNativeTarget() {
25
+ llvm::InitializeNativeTarget();
26
+ }
27
+
28
+ void LLVMInitializeNativeAsmPrinter() {
29
+ llvm::InitializeNativeTargetAsmPrinter();
30
+ }
31
+ }
32
+
@@ -0,0 +1,29 @@
1
+ require 'ffi'
2
+
3
+ module LLVM
4
+ require 'llvm/version'
5
+ require 'llvm/support'
6
+
7
+ module PointerIdentity
8
+ # @private
9
+ def to_ptr
10
+ @ptr
11
+ end
12
+
13
+ # Checks if the value is equal to other.
14
+ def ==(other)
15
+ other.respond_to?(:to_ptr) &&
16
+ @ptr == other.to_ptr
17
+ end
18
+
19
+ # Computes hash.
20
+ def hash
21
+ @ptr.address.hash
22
+ end
23
+
24
+ # Checks if the value is equivalent to other.
25
+ def eql?(other)
26
+ self == other
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,49 @@
1
+ require 'llvm'
2
+ require 'llvm/core'
3
+ require 'llvm/target'
4
+ require 'llvm/analysis_ffi'
5
+
6
+ module LLVM
7
+ class Module
8
+ # Verify that the module is valid.
9
+ # @return [nil, String] human-readable description of any invalid
10
+ # constructs if invalid.
11
+ def verify
12
+ do_verification(:return_status)
13
+ end
14
+
15
+ # Verify that a module is valid, and abort the process if not.
16
+ # @return [nil]
17
+ def verify!
18
+ do_verification(:abort_process)
19
+ end
20
+
21
+ private
22
+
23
+ def do_verification(action)
24
+ LLVM.with_message_output do |str|
25
+ C.verify_module(self, action, str)
26
+ end
27
+ end
28
+ end
29
+
30
+ class Function
31
+ # Verify that a function is valid.
32
+ # @return [true, false]
33
+ def verify
34
+ do_verification(:return_status)
35
+ end
36
+
37
+ # Verify that a function is valid, and abort the process if not.
38
+ # @return [true, false]
39
+ def verify!
40
+ do_verification(:abort_process)
41
+ end
42
+
43
+ private
44
+
45
+ def do_verification(action)
46
+ C.verify_function(self, action) != 0
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,77 @@
1
+ # Generated by ffi_gen. Please do not change this file by hand.
2
+
3
+ require 'ffi'
4
+
5
+ module LLVM::C
6
+ extend FFI::Library
7
+ ffi_lib ["libLLVM-10.so.1", "LLVM-10"]
8
+
9
+ def self.attach_function(name, *_)
10
+ begin; super; rescue FFI::NotFoundError => e
11
+ (class << self; self; end).class_eval { define_method(name) { |*_| raise e } }
12
+ end
13
+ end
14
+
15
+ # @defgroup LLVMCAnalysis Analysis
16
+ # @ingroup LLVMC
17
+ #
18
+ # @{
19
+ #
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
+ #
22
+ # === Options:
23
+ # :abort_process ::
24
+ #
25
+ # :print_message ::
26
+ # verifier will print to stderr and abort()
27
+ # :return_status ::
28
+ # verifier will print to stderr and return 1
29
+ #
30
+ # @method _enum_verifier_failure_action_
31
+ # @return [Symbol]
32
+ # @scope class
33
+ enum :verifier_failure_action, [
34
+ :abort_process, 0,
35
+ :print_message, 1,
36
+ :return_status, 2
37
+ ]
38
+
39
+ # Verifies that a module is valid, taking the specified action if not.
40
+ # Optionally returns a human-readable description of any invalid constructs.
41
+ # OutMessage must be disposed with LLVMDisposeMessage.
42
+ #
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]
48
+ # @scope class
49
+ attach_function :verify_module, :LLVMVerifyModule, [:pointer, :verifier_failure_action, :pointer], :int
50
+
51
+ # Verifies that a single function is valid, taking the specified action. Useful
52
+ # for debugging.
53
+ #
54
+ # @method verify_function(fn, action)
55
+ # @param [FFI::Pointer(ValueRef)] fn
56
+ # @param [Symbol from _enum_verifier_failure_action_] action
57
+ # @return [Integer]
58
+ # @scope class
59
+ attach_function :verify_function, :LLVMVerifyFunction, [:pointer, :verifier_failure_action], :int
60
+
61
+ # Open up a ghostview window that displays the CFG of the current function.
62
+ # Useful for debugging.
63
+ #
64
+ # @method view_function_cfg(fn)
65
+ # @param [FFI::Pointer(ValueRef)] fn
66
+ # @return [nil]
67
+ # @scope class
68
+ attach_function :view_function_cfg, :LLVMViewFunctionCFG, [:pointer], :void
69
+
70
+ # (Not documented)
71
+ #
72
+ # @method view_function_cfg_only(fn)
73
+ # @param [FFI::Pointer(ValueRef)] fn
74
+ # @return [nil]
75
+ # @scope class
76
+ attach_function :view_function_cfg_only, :LLVMViewFunctionCFGOnly, [:pointer], :void
77
+ end
@@ -0,0 +1,10 @@
1
+ # Generated by ruby-llvm. Please do not change this file by hand.
2
+ module LLVM
3
+ module CONFIG
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
+ HOST_TARGET = "x86_64-pc-linux-gnu "
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
+ end
10
+ end
@@ -0,0 +1,97 @@
1
+ require 'llvm'
2
+ require 'llvm/core_ffi'
3
+ require 'llvm/support'
4
+
5
+ module LLVM
6
+ # @private
7
+ module C
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
52
+ end
53
+
54
+ # Yields a pointer suitable for storing an LLVM output message.
55
+ # If the message pointer is non-NULL (an error has happened), converts
56
+ # the result to a string and returns it. Otherwise, returns +nil+.
57
+ #
58
+ # @yield [FFI::MemoryPointer]
59
+ # @return [String, nil]
60
+ def self.with_message_output
61
+ message = nil
62
+
63
+ FFI::MemoryPointer.new(FFI.type_size(:pointer)) do |str|
64
+ result = yield str
65
+
66
+ msg_ptr = str.read_pointer
67
+
68
+ if result != 0
69
+ raise "Error is signalled, but msg_ptr is null" if msg_ptr.null?
70
+
71
+ message = msg_ptr.read_string
72
+ C.dispose_message msg_ptr
73
+ end
74
+ end
75
+
76
+ message
77
+ end
78
+
79
+ # Same as #with_message_output, but raises a RuntimeError with the
80
+ # resulting message.
81
+ #
82
+ # @yield [FFI::MemoryPointer]
83
+ # @return [nil]
84
+ def self.with_error_output(&block)
85
+ error = with_message_output(&block)
86
+
87
+ raise error unless error.nil?
88
+ end
89
+
90
+ require 'llvm/core/context'
91
+ require 'llvm/core/module'
92
+ require 'llvm/core/type'
93
+ require 'llvm/core/value'
94
+ require 'llvm/core/builder'
95
+ require 'llvm/core/pass_manager'
96
+ require 'llvm/core/bitcode'
97
+ end