ruby-llvm 20.1.2 → 21.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 342e7abcf15812442f171497b427194bab39f151d11aa20e9d064611b6e9f16f
4
- data.tar.gz: 5f6f7158dd6e5fbaabfa7ab09bd8a804892595a5792b6052080a5a771f4e6167
3
+ metadata.gz: cbf4a61de5472ea85477b7b0c26d36a9d29512e43a8d1fc5c67babd7ec7ee9d5
4
+ data.tar.gz: 031f350a31ae2c6202cb765fe1ac01345796ef5c8dfea1972c0048c857d19db3
5
5
  SHA512:
6
- metadata.gz: e55f839543e593a87f4c44436197815ddfb56b8953a21776840f027e42d6bf7ec16c70eba9ac895f6139585eab967c8aff4ad84cdd75a84a6aa1f9a465cce79d
7
- data.tar.gz: a2f6d34587fa4d4e3be24fd99a3a147851198881a937195aa4f0891c11e2e0c684091677d80da038dab68f93676e2ea1ef208b9817ce147562db841c441a5e4f
6
+ metadata.gz: a01da90f6dbe9f65826526a0cc8ca2e428b9e47bc3a4393824d13ae7683fa8b21971ace1aedfedc9f0db92d658e346ff75ca252821c29614355ee0d8aea67ae0
7
+ data.tar.gz: f228a01b0495163e264410b1f379d60f4dfdd0d4e4716597a50228581371105b5222bbfffa12fdc643bf78d060870fd0f9a3256138f1057fe7b000f534fe5d09
data/lib/llvm/analysis.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # typed: strict
2
3
 
3
4
  require 'llvm'
4
5
  require 'llvm/core'
@@ -10,24 +11,28 @@ module LLVM
10
11
  # Verify that the module is valid.
11
12
  # @return [nil, String] human-readable description of any invalid
12
13
  # constructs if invalid.
14
+ #: -> String?
13
15
  def verify
14
16
  do_verification(:return_status)
15
17
  end
16
18
 
17
19
  # Verify that a module is valid, and abort the process if not.
18
20
  # @return [nil]
21
+ #: -> String?
19
22
  def verify!
20
23
  # :nocov:
21
24
  do_verification(:abort_process)
22
25
  # :nocov:
23
26
  end
24
27
 
28
+ #: -> bool
25
29
  def valid?
26
30
  verify.nil?
27
31
  end
28
32
 
29
33
  private
30
34
 
35
+ #: (Symbol) -> String?
31
36
  def do_verification(action)
32
37
  LLVM.with_message_output do |str|
33
38
  C.verify_module(self, action, str)
@@ -38,24 +43,28 @@ module LLVM
38
43
  class Function
39
44
  # Verify that a function is valid.
40
45
  # @return [true, false]
46
+ #: -> bool
41
47
  def verify
42
48
  do_verification(:return_status)
43
49
  end
44
50
 
45
51
  # Verify that a function is valid, and abort the process if not.
46
52
  # @return [true, false]
53
+ #: -> bool
47
54
  def verify!
48
55
  # :nocov:
49
56
  do_verification(:abort_process)
50
57
  # :nocov:
51
58
  end
52
59
 
60
+ #: -> bool
53
61
  def valid?
54
62
  verify
55
63
  end
56
64
 
57
65
  private
58
66
 
67
+ #: (Symbol) -> bool
59
68
  def do_verification(action)
60
69
  C.verify_function(self, action).zero?
61
70
  end
@@ -4,7 +4,8 @@ require 'ffi'
4
4
 
5
5
  module LLVM::C
6
6
  extend FFI::Library
7
- ffi_lib ["LLVM-20", "libLLVM-20.so.1", "libLLVM.so.20", "libLLVM.so.20.1"]
7
+
8
+ ffi_lib ["LLVM-21", "libLLVM-21.so.1", "libLLVM.so.21", "libLLVM.so.21.1"]
8
9
  # @defgroup LLVMCAnalysis Analysis
9
10
  # @ingroup LLVMC
10
11
  #
data/lib/llvm/config.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # Generated by ruby-llvm. Please do not change this file by hand.
2
2
  module LLVM
3
3
  module CONFIG
4
- VERSION = "20.1.2"
4
+ VERSION = "20.1.7"
5
5
  COMPONENTS = ["aarch64", "aarch64asmparser", "aarch64codegen", "aarch64desc", "aarch64disassembler", "aarch64info", "aarch64utils", "aggressiveinstcombine", "all", "all-targets", "amdgpu", "amdgpuasmparser", "amdgpucodegen", "amdgpudesc", "amdgpudisassembler", "amdgpuinfo", "amdgputargetmca", "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", "cgdata", "codegen", "codegentypes", "core", "coroutines", "coverage", "debuginfobtf", "debuginfocodeview", "debuginfodwarf", "debuginfogsym", "debuginfologicalview", "debuginfomsf", "debuginfopdb", "demangle", "dlltooldriver", "dwarflinker", "dwarflinkerclassic", "dwarflinkerparallel", "dwp", "engine", "executionengine", "extensions", "filecheck", "frontendatomic", "frontenddriver", "frontendhlsl", "frontendoffloading", "frontendopenacc", "frontendopenmp", "fuzzercli", "fuzzmutate", "globalisel", "hexagon", "hexagonasmparser", "hexagoncodegen", "hexagondesc", "hexagondisassembler", "hexagoninfo", "hipstdpar", "instcombine", "instrumentation", "interfacestub", "interpreter", "ipo", "irprinter", "irreader", "jitlink", "lanai", "lanaiasmparser", "lanaicodegen", "lanaidesc", "lanaidisassembler", "lanaiinfo", "libdriver", "lineeditor", "linker", "loongarch", "loongarchasmparser", "loongarchcodegen", "loongarchdesc", "loongarchdisassembler", "loongarchinfo", "lto", "m68k", "m68kasmparser", "m68kcodegen", "m68kdesc", "m68kdisassembler", "m68kinfo", "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", "objcopy", "object", "objectyaml", "option", "orcdebugging", "orcjit", "orcshared", "orctargetprocess", "passes", "perfjitevents", "powerpc", "powerpcasmparser", "powerpccodegen", "powerpcdesc", "powerpcdisassembler", "powerpcinfo", "profiledata", "remarks", "riscv", "riscvasmparser", "riscvcodegen", "riscvdesc", "riscvdisassembler", "riscvinfo", "riscvtargetmca", "runtimedyld", "sandboxir", "scalaropts", "selectiondag", "sparc", "sparcasmparser", "sparccodegen", "sparcdesc", "sparcdisassembler", "sparcinfo", "spirv", "spirvanalysis", "spirvcodegen", "spirvdesc", "spirvinfo", "support", "symbolize", "systemz", "systemzasmparser", "systemzcodegen", "systemzdesc", "systemzdisassembler", "systemzinfo", "tablegen", "target", "targetparser", "telemetry", "textapi", "textapibinaryreader", "transformutils", "ve", "veasmparser", "vecodegen", "vectorize", "vedesc", "vedisassembler", "veinfo", "webassembly", "webassemblyasmparser", "webassemblycodegen", "webassemblydesc", "webassemblydisassembler", "webassemblyinfo", "webassemblyutils", "windowsdriver", "windowsmanifest", "x86", "x86asmparser", "x86codegen", "x86desc", "x86disassembler", "x86info", "x86targetmca", "xcore", "xcorecodegen", "xcoredesc", "xcoredisassembler", "xcoreinfo", "xray", "xtensa", "xtensaasmparser", "xtensacodegen", "xtensadesc", "xtensadisassembler", "xtensainfo"]
6
6
  TARGETS_BUILT = ["AArch64", "AMDGPU", "ARM", "AVR", "BPF", "Hexagon", "Lanai", "LoongArch", "Mips", "MSP430", "NVPTX", "PowerPC", "RISCV", "Sparc", "SPIRV", "SystemZ", "VE", "WebAssembly", "X86", "XCore", "M68k", "Xtensa"]
7
7
  HOST_TARGET = "x86_64-pc-linux-gnu"
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # typed: strict
2
3
 
3
4
  module LLVM
4
5
  # wrapper for LLVMAttributeRef
@@ -6,6 +7,7 @@ module LLVM
6
7
  include PointerIdentity
7
8
 
8
9
  class << self
10
+ #: (String | Symbol) -> Attribute?
9
11
  def new(from)
10
12
  case from
11
13
  when String, Symbol
@@ -19,13 +21,20 @@ module LLVM
19
21
  # argmem, inaccessiblemem, memory
20
22
  # and the valid values are:
21
23
  # read, write, readwrite
24
+ #: (?Hash[untyped, untyped]) -> Attribute?
22
25
  def memory(opts = {})
23
26
  opts = opts.transform_keys(&:to_sym)
24
27
  val = bit_value(opts[:argmem]) | (bit_value(opts[:inaccessiblemem]) << 2) | (bit_value(opts[:memory]) << 4)
25
28
  enum(:memory, val)
26
29
  end
27
30
 
31
+ #: -> Attribute?
32
+ def captures_none
33
+ enum(:captures)
34
+ end
35
+
28
36
  # create enum attribute with optional value and context
37
+ #: (untyped, ?Integer, ?Context) -> Attribute?
29
38
  def enum(kind, value = 0, context = Context.global)
30
39
  attr_id = attribute_id(kind)
31
40
  ptr = C.create_enum_attribute(context, attr_id, value)
@@ -33,6 +42,7 @@ module LLVM
33
42
  end
34
43
 
35
44
  # create string attribute with key and value
45
+ #: (untyped, untyped, ?Context) -> Attribute?
36
46
  def string(key, value, context = Context.global)
37
47
  key = key.to_s
38
48
  value = value.to_s
@@ -40,12 +50,14 @@ module LLVM
40
50
  from_ptr(ptr)
41
51
  end
42
52
 
53
+ #: -> Integer
43
54
  def last_enum
44
55
  C.get_last_enum_attribute_kind
45
56
  end
46
57
 
47
58
  private
48
59
 
60
+ #: (FFI::Pointer) -> Attribute?
49
61
  def from_ptr(ptr)
50
62
  return if ptr.null?
51
63
  val = allocate
@@ -53,6 +65,7 @@ module LLVM
53
65
  val
54
66
  end
55
67
 
68
+ #: (String | Symbol) -> String
56
69
  def attribute_name(attr_name)
57
70
  attr_name = attr_name.to_s
58
71
  if /_attribute$/.match?(attr_name)
@@ -62,6 +75,7 @@ module LLVM
62
75
  end
63
76
  end
64
77
 
78
+ #: (String | Symbol) -> Integer
65
79
  def attribute_id(attr_name)
66
80
  attr_mem = FFI::MemoryPointer.from_string(attribute_name(attr_name))
67
81
  attr_kind_id = C.get_enum_attribute_kind_for_name(attr_mem, attr_mem.size - 1)
@@ -75,6 +89,7 @@ module LLVM
75
89
  # 1 = read
76
90
  # 2 = write
77
91
  # 3 = readwrite
92
+ #: (String | Symbol)-> Integer
78
93
  def bit_value(maybe_value)
79
94
  case maybe_value.to_s
80
95
  when 'read'
@@ -89,42 +104,51 @@ module LLVM
89
104
  end
90
105
  end
91
106
 
107
+ #: -> (Integer | String)
92
108
  def kind
93
109
  return enum_kind if enum?
94
110
  return string_kind if string?
95
111
  raise
96
112
  end
97
113
 
114
+ #: -> (Integer | String)
98
115
  def value
99
116
  return enum_value if enum?
100
117
  return string_value if string?
101
118
  raise
102
119
  end
103
120
 
121
+ #: -> bool
104
122
  def enum?
105
123
  C.is_enum_attribute(self)
106
124
  end
107
125
 
126
+ #: -> bool
108
127
  def string?
109
128
  C.is_string_attribute(self)
110
129
  end
111
130
 
131
+ #: -> bool
112
132
  def type?
113
133
  C.is_type_attribute(self)
114
134
  end
115
135
 
136
+ #: -> String
116
137
  def inspect
117
138
  to_s
118
139
  end
119
140
 
141
+ #: -> String
120
142
  def to_s
121
143
  Support::C.get_attribute_as_string(self)
122
144
  end
123
145
 
146
+ #: -> Integer
124
147
  def kind_id
125
148
  enum_kind_id
126
149
  end
127
150
 
151
+ #: (untyped) -> bool
128
152
  def ==(other)
129
153
  super if self.class == other.class
130
154
 
@@ -134,56 +158,71 @@ module LLVM
134
158
  false
135
159
  end
136
160
 
161
+ #: -> bool
137
162
  def readnone?
138
163
  enum_kind == 'readnone' || (enum_kind == 'memory' && enum_value_mem_none?)
139
164
  end
140
165
 
166
+ #: -> bool
141
167
  def readonly?
142
168
  enum_kind == 'readonly' || (enum_kind == 'memory' && enum_value_mem_read?)
143
169
  end
144
170
 
171
+ #: -> bool
145
172
  def writeonly?
146
173
  enum_kind == 'writeonly' || (enum_kind == 'memory' && enum_value_mem_write?)
147
174
  end
148
175
 
149
176
  private
150
177
 
178
+ #: -> bool
151
179
  def enum_value_mem_none?
152
180
  enum_value.nobits?(63)
153
181
  end
154
182
 
183
+ #: -> bool
155
184
  def enum_value_mem_read?
156
185
  enum_value.anybits?(21)
157
186
  end
158
187
 
188
+ #: -> bool
159
189
  def enum_value_mem_write?
160
190
  enum_value.anybits?(42)
161
191
  end
162
192
 
193
+ #: -> Integer
163
194
  def enum_kind_id
164
195
  C.get_enum_attribute_kind(self)
165
196
  end
166
197
 
198
+ #: -> String
167
199
  def enum_kind
168
200
  Support::C.get_enum_attribute_name_for_kind(enum_kind_id)
169
201
  end
170
202
 
203
+ #: -> Integer
171
204
  def enum_value
172
205
  C.get_enum_attribute_value(self)
173
206
  end
174
207
 
175
208
  # wraps get_string_attribute_kind
209
+ #: -> String
176
210
  def string_kind
211
+ ret = ''
177
212
  FFI::MemoryPointer.new(:uint64) do |size_ptr|
178
- return C.get_string_attribute_kind(self, size_ptr)
213
+ ret = C.get_string_attribute_kind(self, size_ptr) #: as String
179
214
  end
215
+ ret
180
216
  end
181
217
 
182
218
  # wraps get_string_attribute_value
219
+ #: -> String
183
220
  def string_value
221
+ ret = ''
184
222
  FFI::MemoryPointer.new(:uint) do |size_ptr|
185
- return C.get_string_attribute_value(self, size_ptr)
223
+ ret = C.get_string_attribute_value(self, size_ptr) #: as String
186
224
  end
225
+ ret
187
226
  end
188
227
  end
189
228
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+ # typed: strict
2
3
 
3
4
  require 'llvm/core/bitcode_ffi'
4
5
 
@@ -7,23 +8,27 @@ module LLVM
7
8
  # Parse a module from a memory buffer
8
9
  # @param [String, LLVM::MemoryBuffer] path_or_memory_buffer
9
10
  # @return [LLVM::Module]
11
+ #: (untyped) -> LLVM::Module
10
12
  def self.parse_bitcode(path_or_memory_buffer)
11
13
  memory_buffer = case path_or_memory_buffer
12
14
  when MemoryBuffer then path_or_memory_buffer
13
15
  else MemoryBuffer.from_file(path_or_memory_buffer)
14
16
  end
17
+ llvm_module = nil #: LLVM::Module?
15
18
  FFI::MemoryPointer.new(:pointer) do |mod_ref|
16
19
  FFI::MemoryPointer.new(:pointer) do |msg_ref|
17
20
  status = C.parse_bitcode(memory_buffer, mod_ref, msg_ref)
18
21
  raise msg_ref.get_pointer(0).get_string(0) if status != 0
19
- return from_ptr(mod_ref.get_pointer(0))
22
+ llvm_module = from_ptr(mod_ref.get_pointer(0))
20
23
  end
21
24
  end
25
+ llvm_module #: as !nil
22
26
  end
23
27
 
24
28
  # Write bitcode to the given path, IO object or file descriptor
25
29
  # @param [String, IO, Integer] path_or_io Pathname, IO object or file descriptor
26
30
  # @return [true, false] Success
31
+ #: (untyped) -> bool
27
32
  def write_bitcode(path_or_io)
28
33
  status = if path_or_io.respond_to?(:path)
29
34
  C.write_bitcode_to_file(self, path_or_io.path)
@@ -34,23 +39,27 @@ module LLVM
34
39
  else
35
40
  C.write_bitcode_to_file(self, path_or_io.to_str)
36
41
  end
37
- status == 0
42
+ status.zero?
38
43
  end
39
44
 
45
+ #: (untyped, ?LLVM::Context) -> LLVM::Module
40
46
  def self.parse_ir(path_or_memory_buffer, context = Context.global)
41
47
  memory_buffer = case path_or_memory_buffer
42
48
  when MemoryBuffer then path_or_memory_buffer
43
49
  else MemoryBuffer.from_file(path_or_memory_buffer)
44
50
  end
51
+ llvm_module = nil #: LLVM::Module?
45
52
  FFI::MemoryPointer.new(:pointer) do |mod_ref|
46
53
  FFI::MemoryPointer.new(:pointer) do |msg_ref|
47
54
  status = C.parse_ir_in_context(context, memory_buffer, mod_ref, msg_ref)
48
55
  raise msg_ref.get_pointer(0).get_string(0) if status
49
- return from_ptr(mod_ref.get_pointer(0))
56
+ llvm_module = from_ptr(mod_ref.get_pointer(0))
50
57
  end
51
58
  end
59
+ llvm_module #: as !nil
52
60
  end
53
61
 
62
+ #: (String) -> self
54
63
  def write_ir!(filename)
55
64
  FFI::MemoryPointer.new(:pointer) do |msg_ref|
56
65
  status = C.print_module_to_file(self, filename, msg_ref)
@@ -65,11 +74,13 @@ module LLVM
65
74
  private_class_method :new
66
75
 
67
76
  # @private
77
+ #: (FFI::Pointer) -> void
68
78
  def initialize(ptr)
69
- @ptr = ptr
79
+ @ptr = ptr #: FFI::Pointer?
70
80
  end
71
81
 
72
82
  # @private
83
+ #: -> FFI::Pointer?
73
84
  def to_ptr
74
85
  @ptr
75
86
  end
@@ -77,28 +88,35 @@ module LLVM
77
88
  # Read the contents of a file into a memory buffer
78
89
  # @param [String] path
79
90
  # @return [LLVM::MemoryBuffer]
91
+ #: (String) -> LLVM::MemoryBuffer
80
92
  def self.from_file(path)
93
+ buffer = nil #: LLVM::MemoryBuffer?
81
94
  FFI::MemoryPointer.new(:pointer) do |buf_ref|
82
95
  FFI::MemoryPointer.new(:pointer) do |msg_ref|
83
96
  status = C.create_memory_buffer_with_contents_of_file(path.to_str, buf_ref, msg_ref)
84
97
  raise msg_ref.get_pointer(0).get_string(0) if status != 0
85
- return new(buf_ref.get_pointer(0))
98
+ buffer = new(buf_ref.get_pointer(0))
86
99
  end
87
100
  end
101
+ buffer #: as !nil
88
102
  end
89
103
 
90
104
  # Read STDIN into a memory buffer
91
105
  # @return [LLVM::MemoryBuffer]
106
+ #: -> LLVM::MemoryBuffer
92
107
  def self.from_stdin
108
+ buffer = nil #: LLVM::MemoryBuffer?
93
109
  FFI::Buffer.new(:pointer) do |buf_ref|
94
110
  FFI::Buffer.new(:pointer) do |msg_ref|
95
111
  status = C.create_memory_buffer_with_stdin(buf_ref, msg_ref)
96
112
  raise msg_ref.get_pointer(0).get_string(0) if status != 0
97
- return new(buf_ref.get_pointer(0))
113
+ buffer = new(buf_ref.get_pointer(0))
98
114
  end
99
115
  end
116
+ buffer #: as !nil
100
117
  end
101
118
 
119
+ #: -> void
102
120
  def dispose
103
121
  return if @ptr.nil?
104
122
  C.dispose_memory_buffer(@ptr)
@@ -4,7 +4,8 @@ require 'ffi'
4
4
 
5
5
  module LLVM::C
6
6
  extend FFI::Library
7
- ffi_lib ["LLVM-20", "libLLVM-20.so.1", "libLLVM.so.20", "libLLVM.so.20.1"]
7
+
8
+ ffi_lib ["LLVM-21", "libLLVM-21.so.1", "libLLVM.so.21", "libLLVM.so.21.1"]
8
9
  # (Not documented)
9
10
  #
10
11
  # @method parse_bitcode(mem_buf, out_module, out_message)