ruby-llvm-next 10.0.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.
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,16 @@
1
+ require 'llvm'
2
+ require 'llvm/core'
3
+ require 'llvm/linker_ffi'
4
+
5
+ module LLVM
6
+ class Module
7
+ # Link the current module into +other+.
8
+ #
9
+ # @return [nil, String] human-readable error if linking has failed
10
+ def link_into(other)
11
+ LLVM.with_message_output do |msg|
12
+ C.link_modules2(other, self)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,44 @@
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
+ # This enum is provided for backwards-compatibility only. It has no effect.
16
+ #
17
+ # <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:linker_mode).</em>
18
+ #
19
+ # === Options:
20
+ # :destroy_source ::
21
+ #
22
+ # :preserve_source_removed ::
23
+ # This is the default behavior.
24
+ #
25
+ # @method _enum_linker_mode_
26
+ # @return [Symbol]
27
+ # @scope class
28
+ enum :linker_mode, [
29
+ :destroy_source, 0,
30
+ :preserve_source_removed, 1
31
+ ]
32
+
33
+ # Links the source module into the destination module. The source module is
34
+ # destroyed.
35
+ # The return value is true if an error occurred, false otherwise.
36
+ # Use the diagnostic handler to get any diagnostic message.
37
+ #
38
+ # @method link_modules2(dest, src)
39
+ # @param [FFI::Pointer(ModuleRef)] dest
40
+ # @param [FFI::Pointer(ModuleRef)] src
41
+ # @return [Integer]
42
+ # @scope class
43
+ attach_function :link_modules2, :LLVMLinkModules2, [:pointer, :pointer], :int
44
+ end
@@ -0,0 +1,38 @@
1
+ require 'llvm/core_ffi'
2
+
3
+ module LLVM
4
+
5
+ module Support
6
+ # @private
7
+
8
+ module C
9
+ extend FFI::Library
10
+
11
+ lib_name = FFI.map_library_name("RubyLLVMSupport-#{LLVM_VERSION}")
12
+ lib_path = File.expand_path("../../ext/ruby-llvm-support/#{lib_name}", File.dirname(__FILE__))
13
+ ffi_lib [lib_path]
14
+
15
+ attach_function :initialize_all_target_infos,
16
+ :LLVMInitializeAllTargetInfos, [], :void
17
+ attach_function :initialize_all_targets,
18
+ :LLVMInitializeAllTargets, [], :void
19
+ attach_function :initialize_all_target_mcs,
20
+ :LLVMInitializeAllTargetMCs, [], :void
21
+ attach_function :initialize_all_asm_printers,
22
+ :LLVMInitializeAllAsmPrinters, [], :void
23
+
24
+ attach_function :initialize_native_target,
25
+ :LLVMInitializeNativeTarget, [], :void
26
+ attach_function :initialize_native_asm_printer,
27
+ :LLVMInitializeNativeAsmPrinter, [], :void
28
+ end
29
+ end
30
+
31
+ def self.load_library(libname)
32
+ if C.load_library_permanently(libname) != 0
33
+ raise "LLVM::Support.load_library failed"
34
+ end
35
+
36
+ nil
37
+ end
38
+ end
@@ -0,0 +1,318 @@
1
+ require 'llvm'
2
+ require 'llvm/core'
3
+ require 'llvm/target_ffi'
4
+
5
+ module LLVM
6
+ # A shorthand for {LLVM::Target.init_native}
7
+ def self.init_jit(*args)
8
+ LLVM::Target.init_native(*args)
9
+ end
10
+
11
+ # @deprecated Use LLVM.init_jit or LLVM::Target.init('X86').
12
+ def self.init_x86
13
+ warn "LLVM.init_x86 is deprecated. Use LLVM.init_jit or LLVM::Target.init('X86')."
14
+ LLVM::Target.init('X86')
15
+ end
16
+
17
+ # You need to call {Target.init} for a target to be usable.
18
+ class Target
19
+ # Initializes target +target+; in particular, TargetInfo, Target and TargetMC.
20
+ #
21
+ # @param [String] target Target name in LLVM format, e.g. "X86", "ARM" or "PowerPC".
22
+ # @param [true, false] asm_printer Initialize corresponding AsmPrinter.
23
+ def self.init(target, asm_printer = false)
24
+ C.module_eval do
25
+ attach_function :"initialize_target_info_#{target}",
26
+ :"LLVMInitialize#{target}TargetInfo", [], :void
27
+ attach_function :"initialize_target_#{target}",
28
+ :"LLVMInitialize#{target}Target", [], :void
29
+ attach_function :"initialize_target_#{target}_mc",
30
+ :"LLVMInitialize#{target}TargetMC", [], :void
31
+
32
+ attach_function :"initialize_#{target}_asm_printer",
33
+ :"LLVMInitialize#{target}AsmPrinter", [], :void
34
+ attach_function :"initialize_#{target}_asm_parser",
35
+ :"LLVMInitialize#{target}AsmParser", [], :void
36
+ attach_function :"initialize_#{target}_disassembler",
37
+ :"LLVMInitialize#{target}Disassembler", [], :void
38
+ end
39
+
40
+ begin
41
+ %W(initialize_target_info_#{target}
42
+ initialize_target_#{target}
43
+ initialize_target_#{target}_mc).each do |init|
44
+ C.send init
45
+ end
46
+ rescue FFI::NotFoundError
47
+ raise ArgumentError, "LLVM target #{target} is not linked in. Try `llvm-config-#{LLVM_VERSION} --targets-built'."
48
+ end
49
+
50
+ begin
51
+ C.send :"initialize_#{target}_asm_printer" if asm_printer
52
+ rescue FFI::NotFoundError => e
53
+ raise ArgumentError, "LLVM target #{target} does not implement an ASM routime: #{e.message}"
54
+ end
55
+ end
56
+
57
+ # Initializes all available targets.
58
+ #
59
+ # @param [true, false] asm_printer Initialize corresponding AsmPrinters.
60
+ def self.init_all(asm_printer = false)
61
+ Support::C.initialize_all_target_infos
62
+ Support::C.initialize_all_targets
63
+ Support::C.initialize_all_target_mcs
64
+
65
+ Support::C.initialize_all_asm_printers if asm_printer
66
+ end
67
+
68
+ # Initializes native target. Useful for JIT applications.
69
+ #
70
+ # @param [true, false] asm_printer Initialize corresponding AsmPrinter.
71
+ # True by default, as this is required for MCJIT to function.
72
+ def self.init_native(asm_printer = true)
73
+ Support::C.initialize_native_target
74
+
75
+ Support::C.initialize_native_asm_printer if asm_printer
76
+ end
77
+
78
+ # Enumerate all initialized targets.
79
+ #
80
+ # @yield [Target]
81
+ def self.each(&block)
82
+ return to_enum(:each) if block.nil?
83
+
84
+ target = C.get_first_target
85
+ until target.null?
86
+ yield from_ptr(target)
87
+
88
+ target = C.get_next_target(target)
89
+ end
90
+ end
91
+
92
+ # Fetch a target by its name.
93
+ #
94
+ # @return [Target]
95
+ def self.by_name(name)
96
+ each do |target|
97
+ return target if target.name == name
98
+ end
99
+ end
100
+
101
+ include PointerIdentity
102
+
103
+ # @private
104
+ def self.from_ptr(ptr)
105
+ target = allocate
106
+ target.instance_variable_set :@ptr, ptr
107
+ target
108
+ end
109
+
110
+ # Returns the name of the target.
111
+ #
112
+ # @return [String]
113
+ def name
114
+ C.get_target_name(self)
115
+ end
116
+
117
+ # Returns the description of the target.
118
+ #
119
+ # @return [String]
120
+ def description
121
+ C.get_target_description(self)
122
+ end
123
+
124
+ # Returns if the target has a JIT.
125
+ def jit?
126
+ !C.target_has_jit(self).zero?
127
+ end
128
+
129
+ # Returns if the target has a TargetMachine associated.
130
+ def target_machine?
131
+ !C.target_has_target_machine(self).zero?
132
+ end
133
+
134
+ # Returns if the target has an ASM backend (required for emitting output).
135
+ def asm_backend?
136
+ !C.target_has_asm_backend(self).zero?
137
+ end
138
+
139
+ # Constructs a TargetMachine.
140
+ #
141
+ # @param [String] triple Target triple
142
+ # @param [String] cpu Target CPU
143
+ # @param [String] features Target feature string
144
+ # @param [Symbol] opt_level :none, :less, :default, :aggressive
145
+ # @param [Symbol] reloc :default, :static, :pic, :dynamic_no_pic
146
+ # @param [Symbol] code_model :default, :jit_default, :small, :kernel, :medium, :large
147
+ # @return [TargetMachine]
148
+ def create_machine(triple, cpu = "", features = "",
149
+ opt_level = :default, reloc = :default, code_model = :default)
150
+ TargetMachine.from_ptr(C.create_target_machine(self,
151
+ triple, cpu, features, opt_level, reloc, code_model))
152
+ end
153
+ end
154
+
155
+ class TargetMachine
156
+ include PointerIdentity
157
+
158
+ # @private
159
+ def self.from_ptr(ptr)
160
+ target = allocate
161
+ target.instance_variable_set :@ptr, ptr
162
+ target
163
+ end
164
+
165
+ # Destroys this instance of TargetMachine.
166
+ def dispose
167
+ return if @ptr.nil?
168
+
169
+ C.dispose_target_machine(self)
170
+ @ptr = nil
171
+ end
172
+
173
+ # Returns the corresponding Target.
174
+ #
175
+ # @return [Target]
176
+ def target
177
+ Target.from_ptr(C.get_target_machine_target(self))
178
+ end
179
+
180
+ # Returns the triple used for creating this target machine.
181
+ def triple
182
+ C.get_target_machine_triple(self)
183
+ end
184
+
185
+ # Returns the CPU used for creating this target machine.
186
+ def cpu
187
+ C.get_target_machine_cpu(self)
188
+ end
189
+
190
+ # Returns the feature string used for creating this target machine.
191
+ def features
192
+ C.get_target_machine_feature_string(self)
193
+ end
194
+
195
+ # Emits an asm or object file for the given module.
196
+ #
197
+ # @param [Symbol] codegen :assembly, :object
198
+ def emit(mod, filename, codegen = :assembly)
199
+ LLVM.with_error_output do |err|
200
+ C.target_machine_emit_to_file(self, mod, filename.to_s, codegen, err)
201
+ end
202
+ end
203
+ end
204
+
205
+ # @private
206
+ module C
207
+ # ffi_gen autodetects :string, which is too weak to be usable
208
+ # with LLVMDisposeMessage
209
+ attach_function :copy_string_rep_of_target_data, :LLVMCopyStringRepOfTargetData, [OpaqueTargetData], :pointer
210
+ end
211
+
212
+ class TargetDataLayout
213
+ # Creates a target data layout from a string representation.
214
+ #
215
+ # @param [String] representation
216
+ def initialize(representation)
217
+ @ptr = C.create_target_data(representation.to_s)
218
+ end
219
+
220
+ # @private
221
+ def self.from_ptr(ptr)
222
+ target = allocate
223
+ target.instance_variable_set :@ptr, ptr
224
+ target
225
+ end
226
+
227
+ # @private
228
+ def to_ptr
229
+ @ptr
230
+ end
231
+
232
+ # Destroys this instance of TargetDataLayout.
233
+ def dispose
234
+ return if ptr.nil?
235
+
236
+ C.dispose_target_data(self)
237
+ @ptr = nil
238
+ end
239
+
240
+ # Returns string representation of target data layout.
241
+ #
242
+ # @return [String]
243
+ def to_s
244
+ string_ptr = C.copy_string_rep_of_target_data(self)
245
+ string = string_ptr.read_string
246
+ C.dispose_message(string_ptr)
247
+
248
+ string
249
+ end
250
+
251
+ # Returns the byte order of a target, either :big_endian or :little_endian.
252
+ def byte_order
253
+ C.byte_order(self)
254
+ end
255
+
256
+ # Returns the pointer size in bytes for a target.
257
+ #
258
+ # @param [Integer] addr_space address space number
259
+ def pointer_size(addr_space = 0)
260
+ C.pointer_size_for_as(self, addr_space)
261
+ end
262
+
263
+ # Returns the integer type that is the same size as a pointer on a target.
264
+ #
265
+ # @param [Integer] addr_space address space number
266
+ def int_ptr_type(addr_space = 0)
267
+ Type.from_ptr(C.int_ptr_type_for_as(self, addr_space), :integer)
268
+ end
269
+
270
+ # Computes the size of a type in bits for a target.
271
+ def bit_size_of(type)
272
+ C.size_of_type_in_bits(self, type)
273
+ end
274
+
275
+ # Computes the storage size of a type in bytes for a target.
276
+ def storage_size_of(type)
277
+ C.store_size_of_type(self, type)
278
+ end
279
+
280
+ # Computes the ABI size of a type in bytes for a target.
281
+ def abi_size_of(type)
282
+ C.abi_size_of_type(self, type)
283
+ end
284
+
285
+ # Computes the ABI alignment of a type in bytes for a target.
286
+ def abi_alignment_of(type)
287
+ C.abi_alignment_of_type(self, type)
288
+ end
289
+
290
+ # Computes the call frame alignment of a type in bytes for a target.
291
+ def call_frame_alignment_of(type)
292
+ C.call_frame_alignment_of_type(self, type)
293
+ end
294
+
295
+ # Computes the preferred alignment of a type or a global variable in bytes
296
+ # for a target.
297
+ #
298
+ # @param [LLVM::Type, LLVM::GlobalValue] entity
299
+ def preferred_alignment_of(entity)
300
+ case entity
301
+ when LLVM::Type
302
+ C.preferred_alignment_of_type(self, entity)
303
+ when LLVM::GlobalValue
304
+ C.preferred_alignment_of_global(self, entity)
305
+ end
306
+ end
307
+
308
+ # Computes the structure element that contains the byte offset for a target.
309
+ def element_at_offset(type, offset)
310
+ C.element_at_offset(self, type, offset)
311
+ end
312
+
313
+ # Computes the byte offset of the indexed struct element for a target.
314
+ def offset_of_element(type, element)
315
+ C.offset_of_element(self, type, element)
316
+ end
317
+ end
318
+ end
@@ -0,0 +1,628 @@
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
+ # (Not documented)
16
+ #
17
+ # <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:byte_ordering).</em>
18
+ #
19
+ # === Options:
20
+ # :big_endian ::
21
+ #
22
+ # :little_endian ::
23
+ #
24
+ #
25
+ # @method _enum_byte_ordering_
26
+ # @return [Symbol]
27
+ # @scope class
28
+ enum :byte_ordering, [
29
+ :big_endian, 0,
30
+ :little_endian, 1
31
+ ]
32
+
33
+ # (Not documented)
34
+ class OpaqueTargetData < FFI::Struct
35
+ layout :dummy, :char
36
+ end
37
+
38
+ # (Not documented)
39
+ class OpaqueTargetLibraryInfotData < FFI::Struct
40
+ layout :dummy, :char
41
+ end
42
+
43
+ # (Not documented)
44
+ #
45
+ # @method initialize_all_target_infos()
46
+ # @return [nil]
47
+ # @scope class
48
+ attach_function :initialize_all_target_infos, :LLVMInitializeAllTargetInfos, [], :void
49
+
50
+ # (Not documented)
51
+ #
52
+ # @method initialize_all_targets()
53
+ # @return [nil]
54
+ # @scope class
55
+ attach_function :initialize_all_targets, :LLVMInitializeAllTargets, [], :void
56
+
57
+ # (Not documented)
58
+ #
59
+ # @method initialize_all_target_m_cs()
60
+ # @return [nil]
61
+ # @scope class
62
+ attach_function :initialize_all_target_m_cs, :LLVMInitializeAllTargetMCs, [], :void
63
+
64
+ # (Not documented)
65
+ #
66
+ # @method initialize_all_asm_printers()
67
+ # @return [nil]
68
+ # @scope class
69
+ attach_function :initialize_all_asm_printers, :LLVMInitializeAllAsmPrinters, [], :void
70
+
71
+ # (Not documented)
72
+ #
73
+ # @method initialize_all_asm_parsers()
74
+ # @return [nil]
75
+ # @scope class
76
+ attach_function :initialize_all_asm_parsers, :LLVMInitializeAllAsmParsers, [], :void
77
+
78
+ # (Not documented)
79
+ #
80
+ # @method initialize_all_disassemblers()
81
+ # @return [nil]
82
+ # @scope class
83
+ attach_function :initialize_all_disassemblers, :LLVMInitializeAllDisassemblers, [], :void
84
+
85
+ # (Not documented)
86
+ #
87
+ # @method initialize_native_target()
88
+ # @return [Integer]
89
+ # @scope class
90
+ attach_function :initialize_native_target, :LLVMInitializeNativeTarget, [], :int
91
+
92
+ # (Not documented)
93
+ #
94
+ # @method initialize_native_asm_parser()
95
+ # @return [Integer]
96
+ # @scope class
97
+ attach_function :initialize_native_asm_parser, :LLVMInitializeNativeAsmParser, [], :int
98
+
99
+ # (Not documented)
100
+ #
101
+ # @method initialize_native_asm_printer()
102
+ # @return [Integer]
103
+ # @scope class
104
+ attach_function :initialize_native_asm_printer, :LLVMInitializeNativeAsmPrinter, [], :int
105
+
106
+ # (Not documented)
107
+ #
108
+ # @method initialize_native_disassembler()
109
+ # @return [Integer]
110
+ # @scope class
111
+ attach_function :initialize_native_disassembler, :LLVMInitializeNativeDisassembler, [], :int
112
+
113
+ # (Not documented)
114
+ #
115
+ # @method get_module_data_layout(m)
116
+ # @param [FFI::Pointer(ModuleRef)] m
117
+ # @return [OpaqueTargetData]
118
+ # @scope class
119
+ attach_function :get_module_data_layout, :LLVMGetModuleDataLayout, [:pointer], OpaqueTargetData
120
+
121
+ # (Not documented)
122
+ #
123
+ # @method set_module_data_layout(m, dl)
124
+ # @param [FFI::Pointer(ModuleRef)] m
125
+ # @param [OpaqueTargetData] dl
126
+ # @return [nil]
127
+ # @scope class
128
+ attach_function :set_module_data_layout, :LLVMSetModuleDataLayout, [:pointer, OpaqueTargetData], :void
129
+
130
+ # (Not documented)
131
+ #
132
+ # @method create_target_data(string_rep)
133
+ # @param [String] string_rep
134
+ # @return [OpaqueTargetData]
135
+ # @scope class
136
+ attach_function :create_target_data, :LLVMCreateTargetData, [:string], OpaqueTargetData
137
+
138
+ # (Not documented)
139
+ #
140
+ # @method dispose_target_data(td)
141
+ # @param [OpaqueTargetData] td
142
+ # @return [nil]
143
+ # @scope class
144
+ attach_function :dispose_target_data, :LLVMDisposeTargetData, [OpaqueTargetData], :void
145
+
146
+ # (Not documented)
147
+ #
148
+ # @method add_target_library_info(tli, pm)
149
+ # @param [OpaqueTargetLibraryInfotData] tli
150
+ # @param [FFI::Pointer(PassManagerRef)] pm
151
+ # @return [nil]
152
+ # @scope class
153
+ attach_function :add_target_library_info, :LLVMAddTargetLibraryInfo, [OpaqueTargetLibraryInfotData, :pointer], :void
154
+
155
+ # (Not documented)
156
+ #
157
+ # @method copy_string_rep_of_target_data(td)
158
+ # @param [OpaqueTargetData] td
159
+ # @return [String]
160
+ # @scope class
161
+ attach_function :copy_string_rep_of_target_data, :LLVMCopyStringRepOfTargetData, [OpaqueTargetData], :string
162
+
163
+ # (Not documented)
164
+ #
165
+ # @method byte_order(td)
166
+ # @param [OpaqueTargetData] td
167
+ # @return [Symbol from _enum_byte_ordering_]
168
+ # @scope class
169
+ attach_function :byte_order, :LLVMByteOrder, [OpaqueTargetData], :byte_ordering
170
+
171
+ # (Not documented)
172
+ #
173
+ # @method pointer_size(td)
174
+ # @param [OpaqueTargetData] td
175
+ # @return [Integer]
176
+ # @scope class
177
+ attach_function :pointer_size, :LLVMPointerSize, [OpaqueTargetData], :uint
178
+
179
+ # (Not documented)
180
+ #
181
+ # @method pointer_size_for_as(td, as)
182
+ # @param [OpaqueTargetData] td
183
+ # @param [Integer] as
184
+ # @return [Integer]
185
+ # @scope class
186
+ attach_function :pointer_size_for_as, :LLVMPointerSizeForAS, [OpaqueTargetData, :uint], :uint
187
+
188
+ # (Not documented)
189
+ #
190
+ # @method int_ptr_type(td)
191
+ # @param [OpaqueTargetData] td
192
+ # @return [FFI::Pointer(TypeRef)]
193
+ # @scope class
194
+ attach_function :int_ptr_type, :LLVMIntPtrType, [OpaqueTargetData], :pointer
195
+
196
+ # (Not documented)
197
+ #
198
+ # @method int_ptr_type_for_as(td, as)
199
+ # @param [OpaqueTargetData] td
200
+ # @param [Integer] as
201
+ # @return [FFI::Pointer(TypeRef)]
202
+ # @scope class
203
+ attach_function :int_ptr_type_for_as, :LLVMIntPtrTypeForAS, [OpaqueTargetData, :uint], :pointer
204
+
205
+ # (Not documented)
206
+ #
207
+ # @method int_ptr_type_in_context(c, td)
208
+ # @param [FFI::Pointer(ContextRef)] c
209
+ # @param [OpaqueTargetData] td
210
+ # @return [FFI::Pointer(TypeRef)]
211
+ # @scope class
212
+ attach_function :int_ptr_type_in_context, :LLVMIntPtrTypeInContext, [:pointer, OpaqueTargetData], :pointer
213
+
214
+ # (Not documented)
215
+ #
216
+ # @method int_ptr_type_for_as_in_context(c, td, as)
217
+ # @param [FFI::Pointer(ContextRef)] c
218
+ # @param [OpaqueTargetData] td
219
+ # @param [Integer] as
220
+ # @return [FFI::Pointer(TypeRef)]
221
+ # @scope class
222
+ attach_function :int_ptr_type_for_as_in_context, :LLVMIntPtrTypeForASInContext, [:pointer, OpaqueTargetData, :uint], :pointer
223
+
224
+ # (Not documented)
225
+ #
226
+ # @method size_of_type_in_bits(td, ty)
227
+ # @param [OpaqueTargetData] td
228
+ # @param [FFI::Pointer(TypeRef)] ty
229
+ # @return [Integer]
230
+ # @scope class
231
+ attach_function :size_of_type_in_bits, :LLVMSizeOfTypeInBits, [OpaqueTargetData, :pointer], :ulong_long
232
+
233
+ # (Not documented)
234
+ #
235
+ # @method store_size_of_type(td, ty)
236
+ # @param [OpaqueTargetData] td
237
+ # @param [FFI::Pointer(TypeRef)] ty
238
+ # @return [Integer]
239
+ # @scope class
240
+ attach_function :store_size_of_type, :LLVMStoreSizeOfType, [OpaqueTargetData, :pointer], :ulong_long
241
+
242
+ # (Not documented)
243
+ #
244
+ # @method abi_size_of_type(td, ty)
245
+ # @param [OpaqueTargetData] td
246
+ # @param [FFI::Pointer(TypeRef)] ty
247
+ # @return [Integer]
248
+ # @scope class
249
+ attach_function :abi_size_of_type, :LLVMABISizeOfType, [OpaqueTargetData, :pointer], :ulong_long
250
+
251
+ # (Not documented)
252
+ #
253
+ # @method abi_alignment_of_type(td, ty)
254
+ # @param [OpaqueTargetData] td
255
+ # @param [FFI::Pointer(TypeRef)] ty
256
+ # @return [Integer]
257
+ # @scope class
258
+ attach_function :abi_alignment_of_type, :LLVMABIAlignmentOfType, [OpaqueTargetData, :pointer], :uint
259
+
260
+ # (Not documented)
261
+ #
262
+ # @method call_frame_alignment_of_type(td, ty)
263
+ # @param [OpaqueTargetData] td
264
+ # @param [FFI::Pointer(TypeRef)] ty
265
+ # @return [Integer]
266
+ # @scope class
267
+ attach_function :call_frame_alignment_of_type, :LLVMCallFrameAlignmentOfType, [OpaqueTargetData, :pointer], :uint
268
+
269
+ # (Not documented)
270
+ #
271
+ # @method preferred_alignment_of_type(td, ty)
272
+ # @param [OpaqueTargetData] td
273
+ # @param [FFI::Pointer(TypeRef)] ty
274
+ # @return [Integer]
275
+ # @scope class
276
+ attach_function :preferred_alignment_of_type, :LLVMPreferredAlignmentOfType, [OpaqueTargetData, :pointer], :uint
277
+
278
+ # (Not documented)
279
+ #
280
+ # @method preferred_alignment_of_global(td, global_var)
281
+ # @param [OpaqueTargetData] td
282
+ # @param [FFI::Pointer(ValueRef)] global_var
283
+ # @return [Integer]
284
+ # @scope class
285
+ attach_function :preferred_alignment_of_global, :LLVMPreferredAlignmentOfGlobal, [OpaqueTargetData, :pointer], :uint
286
+
287
+ # (Not documented)
288
+ #
289
+ # @method element_at_offset(td, struct_ty, offset)
290
+ # @param [OpaqueTargetData] td
291
+ # @param [FFI::Pointer(TypeRef)] struct_ty
292
+ # @param [Integer] offset
293
+ # @return [Integer]
294
+ # @scope class
295
+ attach_function :element_at_offset, :LLVMElementAtOffset, [OpaqueTargetData, :pointer, :ulong_long], :uint
296
+
297
+ # (Not documented)
298
+ #
299
+ # @method offset_of_element(td, struct_ty, element)
300
+ # @param [OpaqueTargetData] td
301
+ # @param [FFI::Pointer(TypeRef)] struct_ty
302
+ # @param [Integer] element
303
+ # @return [Integer]
304
+ # @scope class
305
+ attach_function :offset_of_element, :LLVMOffsetOfElement, [OpaqueTargetData, :pointer, :uint], :ulong_long
306
+
307
+ # (Not documented)
308
+ class OpaqueTargetMachine < FFI::Struct
309
+ layout :dummy, :char
310
+ end
311
+
312
+ # (Not documented)
313
+ module TargetWrappers
314
+ # @return [Integer]
315
+ def has_jit()
316
+ LLVM::C.target_has_jit(self)
317
+ end
318
+
319
+ # @return [Integer]
320
+ def has_target_machine()
321
+ LLVM::C.target_has_target_machine(self)
322
+ end
323
+
324
+ # @return [Integer]
325
+ def has_asm_backend()
326
+ LLVM::C.target_has_asm_backend(self)
327
+ end
328
+ end
329
+
330
+ class Target < FFI::Struct
331
+ include TargetWrappers
332
+ layout :dummy, :char
333
+ end
334
+
335
+ # (Not documented)
336
+ #
337
+ # <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:code_gen_opt_level).</em>
338
+ #
339
+ # === Options:
340
+ # :none ::
341
+ #
342
+ # :less ::
343
+ #
344
+ # :default ::
345
+ #
346
+ # :aggressive ::
347
+ #
348
+ #
349
+ # @method _enum_code_gen_opt_level_
350
+ # @return [Symbol]
351
+ # @scope class
352
+ enum :code_gen_opt_level, [
353
+ :none, 0,
354
+ :less, 1,
355
+ :default, 2,
356
+ :aggressive, 3
357
+ ]
358
+
359
+ # (Not documented)
360
+ #
361
+ # <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:reloc_mode).</em>
362
+ #
363
+ # === Options:
364
+ # :default ::
365
+ #
366
+ # :static ::
367
+ #
368
+ # :pic ::
369
+ #
370
+ # :dynamic_no_pic ::
371
+ #
372
+ #
373
+ # @method _enum_reloc_mode_
374
+ # @return [Symbol]
375
+ # @scope class
376
+ enum :reloc_mode, [
377
+ :default, 0,
378
+ :static, 1,
379
+ :pic, 2,
380
+ :dynamic_no_pic, 3
381
+ ]
382
+
383
+ # (Not documented)
384
+ #
385
+ # <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:code_model).</em>
386
+ #
387
+ # === Options:
388
+ # :default ::
389
+ #
390
+ # :jit_default ::
391
+ #
392
+ # :small ::
393
+ #
394
+ # :kernel ::
395
+ #
396
+ # :medium ::
397
+ #
398
+ # :large ::
399
+ #
400
+ #
401
+ # @method _enum_code_model_
402
+ # @return [Symbol]
403
+ # @scope class
404
+ enum :code_model, [
405
+ :default, 0,
406
+ :jit_default, 1,
407
+ :small, 2,
408
+ :kernel, 3,
409
+ :medium, 4,
410
+ :large, 5
411
+ ]
412
+
413
+ # (Not documented)
414
+ #
415
+ # <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:code_gen_file_type).</em>
416
+ #
417
+ # === Options:
418
+ # :assembly ::
419
+ #
420
+ # :object ::
421
+ #
422
+ #
423
+ # @method _enum_code_gen_file_type_
424
+ # @return [Symbol]
425
+ # @scope class
426
+ enum :code_gen_file_type, [
427
+ :assembly, 0,
428
+ :object, 1
429
+ ]
430
+
431
+ # Returns the first llvm::Target in the registered targets list.
432
+ #
433
+ # @method get_first_target()
434
+ # @return [Target]
435
+ # @scope class
436
+ attach_function :get_first_target, :LLVMGetFirstTarget, [], Target
437
+
438
+ # Returns the next llvm::Target given a previous one (or null if there's none)
439
+ #
440
+ # @method get_next_target(t)
441
+ # @param [Target] t
442
+ # @return [Target]
443
+ # @scope class
444
+ attach_function :get_next_target, :LLVMGetNextTarget, [Target], Target
445
+
446
+ # Finds the target corresponding to the given name and stores it in \p T.
447
+ # Returns 0 on success.
448
+ #
449
+ # @method get_target_from_name(name)
450
+ # @param [String] name
451
+ # @return [Target]
452
+ # @scope class
453
+ attach_function :get_target_from_name, :LLVMGetTargetFromName, [:string], Target
454
+
455
+ # Finds the target corresponding to the given triple and stores it in \p T.
456
+ # Returns 0 on success. Optionally returns any error in ErrorMessage.
457
+ # Use LLVMDisposeMessage to dispose the message.
458
+ #
459
+ # @method get_target_from_triple(triple, t, error_message)
460
+ # @param [String] triple
461
+ # @param [FFI::Pointer(*TargetRef)] t
462
+ # @param [FFI::Pointer(**CharS)] error_message
463
+ # @return [Integer]
464
+ # @scope class
465
+ attach_function :get_target_from_triple, :LLVMGetTargetFromTriple, [:string, :pointer, :pointer], :int
466
+
467
+ # Returns the name of a target. See llvm::Target::getName
468
+ #
469
+ # @method get_target_name(t)
470
+ # @param [Target] t
471
+ # @return [String]
472
+ # @scope class
473
+ attach_function :get_target_name, :LLVMGetTargetName, [Target], :string
474
+
475
+ # Returns the description of a target. See llvm::Target::getDescription
476
+ #
477
+ # @method get_target_description(t)
478
+ # @param [Target] t
479
+ # @return [String]
480
+ # @scope class
481
+ attach_function :get_target_description, :LLVMGetTargetDescription, [Target], :string
482
+
483
+ # Returns if the target has a JIT
484
+ #
485
+ # @method target_has_jit(t)
486
+ # @param [Target] t
487
+ # @return [Integer]
488
+ # @scope class
489
+ attach_function :target_has_jit, :LLVMTargetHasJIT, [Target], :int
490
+
491
+ # Returns if the target has a TargetMachine associated
492
+ #
493
+ # @method target_has_target_machine(t)
494
+ # @param [Target] t
495
+ # @return [Integer]
496
+ # @scope class
497
+ attach_function :target_has_target_machine, :LLVMTargetHasTargetMachine, [Target], :int
498
+
499
+ # Returns if the target as an ASM backend (required for emitting output)
500
+ #
501
+ # @method target_has_asm_backend(t)
502
+ # @param [Target] t
503
+ # @return [Integer]
504
+ # @scope class
505
+ attach_function :target_has_asm_backend, :LLVMTargetHasAsmBackend, [Target], :int
506
+
507
+ # Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine
508
+ #
509
+ # @method create_target_machine(t, triple, cpu, features, level, reloc, code_model)
510
+ # @param [Target] t
511
+ # @param [String] triple
512
+ # @param [String] cpu
513
+ # @param [String] features
514
+ # @param [Symbol from _enum_code_gen_opt_level_] level
515
+ # @param [Symbol from _enum_reloc_mode_] reloc
516
+ # @param [Symbol from _enum_code_model_] code_model
517
+ # @return [OpaqueTargetMachine]
518
+ # @scope class
519
+ attach_function :create_target_machine, :LLVMCreateTargetMachine, [Target, :string, :string, :string, :code_gen_opt_level, :reloc_mode, :code_model], OpaqueTargetMachine
520
+
521
+ # Dispose the LLVMTargetMachineRef instance generated by
522
+ # LLVMCreateTargetMachine.
523
+ #
524
+ # @method dispose_target_machine(t)
525
+ # @param [OpaqueTargetMachine] t
526
+ # @return [nil]
527
+ # @scope class
528
+ attach_function :dispose_target_machine, :LLVMDisposeTargetMachine, [OpaqueTargetMachine], :void
529
+
530
+ # Returns the Target used in a TargetMachine
531
+ #
532
+ # @method get_target_machine_target(t)
533
+ # @param [OpaqueTargetMachine] t
534
+ # @return [Target]
535
+ # @scope class
536
+ attach_function :get_target_machine_target, :LLVMGetTargetMachineTarget, [OpaqueTargetMachine], Target
537
+
538
+ # Returns the triple used creating this target machine. See
539
+ # llvm::TargetMachine::getTriple. The result needs to be disposed with
540
+ # LLVMDisposeMessage.
541
+ #
542
+ # @method get_target_machine_triple(t)
543
+ # @param [OpaqueTargetMachine] t
544
+ # @return [String]
545
+ # @scope class
546
+ attach_function :get_target_machine_triple, :LLVMGetTargetMachineTriple, [OpaqueTargetMachine], :string
547
+
548
+ # Returns the cpu used creating this target machine. See
549
+ # llvm::TargetMachine::getCPU. The result needs to be disposed with
550
+ # LLVMDisposeMessage.
551
+ #
552
+ # @method get_target_machine_cpu(t)
553
+ # @param [OpaqueTargetMachine] t
554
+ # @return [String]
555
+ # @scope class
556
+ attach_function :get_target_machine_cpu, :LLVMGetTargetMachineCPU, [OpaqueTargetMachine], :string
557
+
558
+ # Returns the feature string used creating this target machine. See
559
+ # llvm::TargetMachine::getFeatureString. The result needs to be disposed with
560
+ # LLVMDisposeMessage.
561
+ #
562
+ # @method get_target_machine_feature_string(t)
563
+ # @param [OpaqueTargetMachine] t
564
+ # @return [String]
565
+ # @scope class
566
+ attach_function :get_target_machine_feature_string, :LLVMGetTargetMachineFeatureString, [OpaqueTargetMachine], :string
567
+
568
+ # Create a DataLayout based on the targetMachine.
569
+ #
570
+ # @method create_target_data_layout(t)
571
+ # @param [OpaqueTargetMachine] t
572
+ # @return [OpaqueTargetData]
573
+ # @scope class
574
+ attach_function :create_target_data_layout, :LLVMCreateTargetDataLayout, [OpaqueTargetMachine], OpaqueTargetData
575
+
576
+ # Set the target machine's ASM verbosity.
577
+ #
578
+ # @method set_target_machine_asm_verbosity(t, verbose_asm)
579
+ # @param [OpaqueTargetMachine] t
580
+ # @param [Integer] verbose_asm
581
+ # @return [nil]
582
+ # @scope class
583
+ attach_function :set_target_machine_asm_verbosity, :LLVMSetTargetMachineAsmVerbosity, [OpaqueTargetMachine, :int], :void
584
+
585
+ # Emits an asm or object file for the given module to the filename. This
586
+ # wraps several c++ only classes (among them a file stream). Returns any
587
+ # error in ErrorMessage. Use LLVMDisposeMessage to dispose the message.
588
+ #
589
+ # @method target_machine_emit_to_file(t, m, filename, codegen, error_message)
590
+ # @param [OpaqueTargetMachine] t
591
+ # @param [FFI::Pointer(ModuleRef)] m
592
+ # @param [String] filename
593
+ # @param [Symbol from _enum_code_gen_file_type_] codegen
594
+ # @param [FFI::Pointer(**CharS)] error_message
595
+ # @return [Integer]
596
+ # @scope class
597
+ attach_function :target_machine_emit_to_file, :LLVMTargetMachineEmitToFile, [OpaqueTargetMachine, :pointer, :string, :code_gen_file_type, :pointer], :int
598
+
599
+ # Compile the LLVM IR stored in \p M and store the result in \p OutMemBuf.
600
+ #
601
+ # @method target_machine_emit_to_memory_buffer(t, m, codegen, error_message, out_mem_buf)
602
+ # @param [OpaqueTargetMachine] t
603
+ # @param [FFI::Pointer(ModuleRef)] m
604
+ # @param [Symbol from _enum_code_gen_file_type_] codegen
605
+ # @param [FFI::Pointer(**CharS)] error_message
606
+ # @param [FFI::Pointer(*MemoryBufferRef)] out_mem_buf
607
+ # @return [Integer]
608
+ # @scope class
609
+ attach_function :target_machine_emit_to_memory_buffer, :LLVMTargetMachineEmitToMemoryBuffer, [OpaqueTargetMachine, :pointer, :code_gen_file_type, :pointer, :pointer], :int
610
+
611
+ # Get a triple for the host machine as a string. The result needs to be
612
+ # disposed with LLVMDisposeMessage.
613
+ #
614
+ # @method get_default_target_triple()
615
+ # @return [String]
616
+ # @scope class
617
+ attach_function :get_default_target_triple, :LLVMGetDefaultTargetTriple, [], :string
618
+
619
+ # Adds the target-specific analysis passes to the pass manager.
620
+ #
621
+ # @method add_analysis_passes(t, pm)
622
+ # @param [OpaqueTargetMachine] t
623
+ # @param [FFI::Pointer(PassManagerRef)] pm
624
+ # @return [nil]
625
+ # @scope class
626
+ attach_function :add_analysis_passes, :LLVMAddAnalysisPasses, [OpaqueTargetMachine, :pointer], :void
627
+
628
+ end