ruby-llvm 3.1.0.beta.1 → 3.2.0.beta.1

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 (53) hide show
  1. data/LICENSE +30 -0
  2. data/README.md +49 -0
  3. data/ext/ruby-llvm-support/Rakefile +30 -7
  4. data/ext/ruby-llvm-support/support.cpp +48 -1
  5. data/lib/llvm.rb +26 -3
  6. data/lib/llvm/analysis.rb +8 -11
  7. data/lib/llvm/analysis_ffi.rb +1 -1
  8. data/lib/llvm/core.rb +36 -1
  9. data/lib/llvm/core/bitcode_ffi.rb +1 -1
  10. data/lib/llvm/core/builder.rb +20 -14
  11. data/lib/llvm/core/module.rb +87 -63
  12. data/lib/llvm/core/pass_manager.rb +30 -30
  13. data/lib/llvm/core/type.rb +34 -51
  14. data/lib/llvm/core/value.rb +13 -25
  15. data/lib/llvm/core_ffi.rb +62 -21
  16. data/lib/llvm/execution_engine.rb +13 -19
  17. data/lib/llvm/execution_engine_ffi.rb +1 -1
  18. data/lib/llvm/linker.rb +35 -0
  19. data/lib/llvm/linker_ffi.rb +45 -0
  20. data/lib/llvm/support.rb +32 -6
  21. data/lib/llvm/target.rb +318 -1
  22. data/lib/llvm/target_ffi.rb +302 -14
  23. data/lib/llvm/transforms/ipo_ffi.rb +1 -1
  24. data/lib/llvm/transforms/scalar_ffi.rb +1 -1
  25. data/lib/llvm/transforms/vectorize.rb +17 -0
  26. data/lib/llvm/transforms/vectorize_ffi.rb +31 -0
  27. data/lib/llvm/version.rb +21 -2
  28. data/test/array_test.rb +1 -1
  29. data/test/basic_block_test.rb +1 -1
  30. data/test/basic_test.rb +1 -1
  31. data/test/binary_operations_test.rb +1 -1
  32. data/test/bitcode_test.rb +2 -2
  33. data/test/branch_test.rb +1 -1
  34. data/test/call_test.rb +1 -1
  35. data/test/comparisons_test.rb +1 -1
  36. data/test/conversions_test.rb +1 -1
  37. data/test/double_test.rb +2 -2
  38. data/test/equality_test.rb +5 -5
  39. data/test/generic_value_test.rb +1 -1
  40. data/test/instruction_test.rb +1 -1
  41. data/test/ipo_test.rb +1 -1
  42. data/test/linker_test.rb +46 -0
  43. data/test/memory_access_test.rb +1 -1
  44. data/test/module_test.rb +50 -1
  45. data/test/phi_test.rb +1 -1
  46. data/test/select_test.rb +1 -1
  47. data/test/struct_test.rb +3 -3
  48. data/test/target_test.rb +124 -0
  49. data/test/test_helper.rb +10 -1
  50. data/test/type_test.rb +1 -1
  51. data/test/vector_test.rb +1 -1
  52. metadata +33 -22
  53. data/README.rdoc +0 -34
@@ -4,7 +4,7 @@ require 'ffi'
4
4
 
5
5
  module LLVM::C
6
6
  extend FFI::Library
7
- ffi_lib 'LLVM-3.1'
7
+ ffi_lib 'LLVM-3.2'
8
8
 
9
9
  def self.attach_function(name, *_)
10
10
  begin; super; rescue FFI::NotFoundError => e
@@ -107,7 +107,7 @@ module LLVM::C
107
107
  attach_function :initialize_native_target, :LLVMInitializeNativeTarget, [], :int
108
108
 
109
109
  # Creates target data from a target layout string.
110
- # See the constructor llvm::TargetData::TargetData.
110
+ # See the constructor llvm::DataLayout::DataLayout.
111
111
  #
112
112
  # @method create_target_data(string_rep)
113
113
  # @param [String] string_rep
@@ -139,7 +139,7 @@ module LLVM::C
139
139
 
140
140
  # Converts target data to a target layout string. The string must be disposed
141
141
  # with LLVMDisposeMessage.
142
- # See the constructor llvm::TargetData::TargetData.
142
+ # See the constructor llvm::DataLayout::DataLayout.
143
143
  #
144
144
  # @method copy_string_rep_of_target_data(opaque_target_data)
145
145
  # @param [OpaqueTargetData] opaque_target_data
@@ -149,7 +149,7 @@ module LLVM::C
149
149
 
150
150
  # Returns the byte order of a target, either LLVMBigEndian or
151
151
  # LLVMLittleEndian.
152
- # See the method llvm::TargetData::isLittleEndian.
152
+ # See the method llvm::DataLayout::isLittleEndian.
153
153
  #
154
154
  # @method byte_order(opaque_target_data)
155
155
  # @param [OpaqueTargetData] opaque_target_data
@@ -158,7 +158,7 @@ module LLVM::C
158
158
  attach_function :byte_order, :LLVMByteOrder, [OpaqueTargetData], :byte_ordering
159
159
 
160
160
  # Returns the pointer size in bytes for a target.
161
- # See the method llvm::TargetData::getPointerSize.
161
+ # See the method llvm::DataLayout::getPointerSize.
162
162
  #
163
163
  # @method pointer_size(opaque_target_data)
164
164
  # @param [OpaqueTargetData] opaque_target_data
@@ -166,8 +166,19 @@ module LLVM::C
166
166
  # @scope class
167
167
  attach_function :pointer_size, :LLVMPointerSize, [OpaqueTargetData], :uint
168
168
 
169
+ # Returns the pointer size in bytes for a target for a specified
170
+ # address space.
171
+ # See the method llvm::DataLayout::getPointerSize.
172
+ #
173
+ # @method pointer_size_for_as(opaque_target_data, as)
174
+ # @param [OpaqueTargetData] opaque_target_data
175
+ # @param [Integer] as
176
+ # @return [Integer]
177
+ # @scope class
178
+ attach_function :pointer_size_for_as, :LLVMPointerSizeForAS, [OpaqueTargetData, :uint], :uint
179
+
169
180
  # Returns the integer type that is the same size as a pointer on a target.
170
- # See the method llvm::TargetData::getIntPtrType.
181
+ # See the method llvm::DataLayout::getIntPtrType.
171
182
  #
172
183
  # @method int_ptr_type(opaque_target_data)
173
184
  # @param [OpaqueTargetData] opaque_target_data
@@ -175,8 +186,19 @@ module LLVM::C
175
186
  # @scope class
176
187
  attach_function :int_ptr_type, :LLVMIntPtrType, [OpaqueTargetData], :pointer
177
188
 
189
+ # Returns the integer type that is the same size as a pointer on a target.
190
+ # This version allows the address space to be specified.
191
+ # See the method llvm::DataLayout::getIntPtrType.
192
+ #
193
+ # @method int_ptr_type_for_as(opaque_target_data, as)
194
+ # @param [OpaqueTargetData] opaque_target_data
195
+ # @param [Integer] as
196
+ # @return [FFI::Pointer(TypeRef)]
197
+ # @scope class
198
+ attach_function :int_ptr_type_for_as, :LLVMIntPtrTypeForAS, [OpaqueTargetData, :uint], :pointer
199
+
178
200
  # Computes the size of a type in bytes for a target.
179
- # See the method llvm::TargetData::getTypeSizeInBits.
201
+ # See the method llvm::DataLayout::getTypeSizeInBits.
180
202
  #
181
203
  # @method size_of_type_in_bits(opaque_target_data, type_ref)
182
204
  # @param [OpaqueTargetData] opaque_target_data
@@ -186,7 +208,7 @@ module LLVM::C
186
208
  attach_function :size_of_type_in_bits, :LLVMSizeOfTypeInBits, [OpaqueTargetData, :pointer], :ulong_long
187
209
 
188
210
  # Computes the storage size of a type in bytes for a target.
189
- # See the method llvm::TargetData::getTypeStoreSize.
211
+ # See the method llvm::DataLayout::getTypeStoreSize.
190
212
  #
191
213
  # @method store_size_of_type(opaque_target_data, type_ref)
192
214
  # @param [OpaqueTargetData] opaque_target_data
@@ -196,7 +218,7 @@ module LLVM::C
196
218
  attach_function :store_size_of_type, :LLVMStoreSizeOfType, [OpaqueTargetData, :pointer], :ulong_long
197
219
 
198
220
  # Computes the ABI size of a type in bytes for a target.
199
- # See the method llvm::TargetData::getTypeAllocSize.
221
+ # See the method llvm::DataLayout::getTypeAllocSize.
200
222
  #
201
223
  # @method abi_size_of_type(opaque_target_data, type_ref)
202
224
  # @param [OpaqueTargetData] opaque_target_data
@@ -206,7 +228,7 @@ module LLVM::C
206
228
  attach_function :abi_size_of_type, :LLVMABISizeOfType, [OpaqueTargetData, :pointer], :ulong_long
207
229
 
208
230
  # Computes the ABI alignment of a type in bytes for a target.
209
- # See the method llvm::TargetData::getTypeABISize.
231
+ # See the method llvm::DataLayout::getTypeABISize.
210
232
  #
211
233
  # @method abi_alignment_of_type(opaque_target_data, type_ref)
212
234
  # @param [OpaqueTargetData] opaque_target_data
@@ -216,7 +238,7 @@ module LLVM::C
216
238
  attach_function :abi_alignment_of_type, :LLVMABIAlignmentOfType, [OpaqueTargetData, :pointer], :uint
217
239
 
218
240
  # Computes the call frame alignment of a type in bytes for a target.
219
- # See the method llvm::TargetData::getTypeABISize.
241
+ # See the method llvm::DataLayout::getTypeABISize.
220
242
  #
221
243
  # @method call_frame_alignment_of_type(opaque_target_data, type_ref)
222
244
  # @param [OpaqueTargetData] opaque_target_data
@@ -226,7 +248,7 @@ module LLVM::C
226
248
  attach_function :call_frame_alignment_of_type, :LLVMCallFrameAlignmentOfType, [OpaqueTargetData, :pointer], :uint
227
249
 
228
250
  # Computes the preferred alignment of a type in bytes for a target.
229
- # See the method llvm::TargetData::getTypeABISize.
251
+ # See the method llvm::DataLayout::getTypeABISize.
230
252
  #
231
253
  # @method preferred_alignment_of_type(opaque_target_data, type_ref)
232
254
  # @param [OpaqueTargetData] opaque_target_data
@@ -236,7 +258,7 @@ module LLVM::C
236
258
  attach_function :preferred_alignment_of_type, :LLVMPreferredAlignmentOfType, [OpaqueTargetData, :pointer], :uint
237
259
 
238
260
  # Computes the preferred alignment of a global variable in bytes for a target.
239
- # See the method llvm::TargetData::getPreferredAlignment.
261
+ # See the method llvm::DataLayout::getPreferredAlignment.
240
262
  #
241
263
  # @method preferred_alignment_of_global(opaque_target_data, global_var)
242
264
  # @param [OpaqueTargetData] opaque_target_data
@@ -268,7 +290,7 @@ module LLVM::C
268
290
  attach_function :offset_of_element, :LLVMOffsetOfElement, [OpaqueTargetData, :pointer, :uint], :ulong_long
269
291
 
270
292
  # Deallocates a TargetData.
271
- # See the destructor llvm::TargetData::~TargetData.
293
+ # See the destructor llvm::DataLayout::~DataLayout.
272
294
  #
273
295
  # @method dispose_target_data(opaque_target_data)
274
296
  # @param [OpaqueTargetData] opaque_target_data
@@ -276,4 +298,270 @@ module LLVM::C
276
298
  # @scope class
277
299
  attach_function :dispose_target_data, :LLVMDisposeTargetData, [OpaqueTargetData], :void
278
300
 
301
+ # (Not documented)
302
+ module TargetMachineWrappers
303
+ def emit_to_file(m, filename, codegen, error_message)
304
+ LLVM::C.target_machine_emit_to_file(self, m, filename, codegen, error_message)
305
+ end
306
+ end
307
+
308
+ class TargetMachine < FFI::Struct
309
+ include TargetMachineWrappers
310
+ layout :dummy, :char
311
+ end
312
+
313
+ # (Not documented)
314
+ module TargetWrappers
315
+ def has_jit()
316
+ LLVM::C.target_has_jit(self)
317
+ end
318
+
319
+ def has_target_machine()
320
+ LLVM::C.target_has_target_machine(self)
321
+ end
322
+
323
+ def has_asm_backend()
324
+ LLVM::C.target_has_asm_backend(self)
325
+ end
326
+ end
327
+
328
+ class Target < FFI::Struct
329
+ include TargetWrappers
330
+ layout :dummy, :char
331
+ end
332
+
333
+ # (Not documented)
334
+ #
335
+ # <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>
336
+ #
337
+ # === Options:
338
+ # :none ::
339
+ #
340
+ # :less ::
341
+ #
342
+ # :default ::
343
+ #
344
+ # :aggressive ::
345
+ #
346
+ #
347
+ # @method _enum_code_gen_opt_level_
348
+ # @return [Symbol]
349
+ # @scope class
350
+ enum :code_gen_opt_level, [
351
+ :none, 0,
352
+ :less, 1,
353
+ :default, 2,
354
+ :aggressive, 3
355
+ ]
356
+
357
+ # (Not documented)
358
+ #
359
+ # <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:reloc_mode).</em>
360
+ #
361
+ # === Options:
362
+ # :default ::
363
+ #
364
+ # :static ::
365
+ #
366
+ # :pic ::
367
+ #
368
+ # :dynamic_no_pic ::
369
+ #
370
+ #
371
+ # @method _enum_reloc_mode_
372
+ # @return [Symbol]
373
+ # @scope class
374
+ enum :reloc_mode, [
375
+ :default, 0,
376
+ :static, 1,
377
+ :pic, 2,
378
+ :dynamic_no_pic, 3
379
+ ]
380
+
381
+ # (Not documented)
382
+ #
383
+ # <em>This entry is only for documentation and no real method. The FFI::Enum can be accessed via #enum_type(:code_model).</em>
384
+ #
385
+ # === Options:
386
+ # :default ::
387
+ #
388
+ # :jit_default ::
389
+ #
390
+ # :small ::
391
+ #
392
+ # :kernel ::
393
+ #
394
+ # :medium ::
395
+ #
396
+ # :large ::
397
+ #
398
+ #
399
+ # @method _enum_code_model_
400
+ # @return [Symbol]
401
+ # @scope class
402
+ enum :code_model, [
403
+ :default, 0,
404
+ :jit_default, 1,
405
+ :small, 2,
406
+ :kernel, 3,
407
+ :medium, 4,
408
+ :large, 5
409
+ ]
410
+
411
+ # (Not documented)
412
+ #
413
+ # <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>
414
+ #
415
+ # === Options:
416
+ # :assembly ::
417
+ #
418
+ # :object ::
419
+ #
420
+ #
421
+ # @method _enum_code_gen_file_type_
422
+ # @return [Symbol]
423
+ # @scope class
424
+ enum :code_gen_file_type, [
425
+ :assembly, 0,
426
+ :object, 1
427
+ ]
428
+
429
+ # Returns the first llvm::Target in the registered targets list.
430
+ #
431
+ # @method get_first_target()
432
+ # @return [Target]
433
+ # @scope class
434
+ attach_function :get_first_target, :LLVMGetFirstTarget, [], Target
435
+
436
+ # Returns the next llvm::Target given a previous one (or null if there's none)
437
+ #
438
+ # @method get_next_target(t)
439
+ # @param [Target] t
440
+ # @return [Target]
441
+ # @scope class
442
+ attach_function :get_next_target, :LLVMGetNextTarget, [Target], Target
443
+
444
+ # Returns the name of a target. See llvm::Target::getName
445
+ #
446
+ # @method get_target_name(t)
447
+ # @param [Target] t
448
+ # @return [String]
449
+ # @scope class
450
+ attach_function :get_target_name, :LLVMGetTargetName, [Target], :string
451
+
452
+ # Returns the description of a target. See llvm::Target::getDescription
453
+ #
454
+ # @method get_target_description(t)
455
+ # @param [Target] t
456
+ # @return [String]
457
+ # @scope class
458
+ attach_function :get_target_description, :LLVMGetTargetDescription, [Target], :string
459
+
460
+ # Returns if the target has a JIT
461
+ #
462
+ # @method target_has_jit(t)
463
+ # @param [Target] t
464
+ # @return [Integer]
465
+ # @scope class
466
+ attach_function :target_has_jit, :LLVMTargetHasJIT, [Target], :int
467
+
468
+ # Returns if the target has a TargetMachine associated
469
+ #
470
+ # @method target_has_target_machine(t)
471
+ # @param [Target] t
472
+ # @return [Integer]
473
+ # @scope class
474
+ attach_function :target_has_target_machine, :LLVMTargetHasTargetMachine, [Target], :int
475
+
476
+ # Returns if the target as an ASM backend (required for emitting output)
477
+ #
478
+ # @method target_has_asm_backend(t)
479
+ # @param [Target] t
480
+ # @return [Integer]
481
+ # @scope class
482
+ attach_function :target_has_asm_backend, :LLVMTargetHasAsmBackend, [Target], :int
483
+
484
+ # Creates a new llvm::TargetMachine. See llvm::Target::createTargetMachine
485
+ #
486
+ # @method create_target_machine(t, triple, cpu, features, level, reloc, code_model)
487
+ # @param [Target] t
488
+ # @param [String] triple
489
+ # @param [String] cpu
490
+ # @param [String] features
491
+ # @param [Symbol from _enum_code_gen_opt_level_] level
492
+ # @param [Symbol from _enum_reloc_mode_] reloc
493
+ # @param [Symbol from _enum_code_model_] code_model
494
+ # @return [TargetMachine]
495
+ # @scope class
496
+ attach_function :create_target_machine, :LLVMCreateTargetMachine, [Target, :string, :string, :string, :code_gen_opt_level, :reloc_mode, :code_model], TargetMachine
497
+
498
+ # Dispose the LLVMTargetMachineRef instance generated by
499
+ # LLVMCreateTargetMachine.
500
+ #
501
+ # @method dispose_target_machine(t)
502
+ # @param [TargetMachine] t
503
+ # @return [nil]
504
+ # @scope class
505
+ attach_function :dispose_target_machine, :LLVMDisposeTargetMachine, [TargetMachine], :void
506
+
507
+ # Returns the Target used in a TargetMachine
508
+ #
509
+ # @method get_target_machine_target(t)
510
+ # @param [TargetMachine] t
511
+ # @return [Target]
512
+ # @scope class
513
+ attach_function :get_target_machine_target, :LLVMGetTargetMachineTarget, [TargetMachine], Target
514
+
515
+ # Returns the triple used creating this target machine. See
516
+ # llvm::TargetMachine::getTriple. The result needs to be disposed with
517
+ # LLVMDisposeMessage.
518
+ #
519
+ # @method get_target_machine_triple(t)
520
+ # @param [TargetMachine] t
521
+ # @return [String]
522
+ # @scope class
523
+ attach_function :get_target_machine_triple, :LLVMGetTargetMachineTriple, [TargetMachine], :string
524
+
525
+ # Returns the cpu used creating this target machine. See
526
+ # llvm::TargetMachine::getCPU. The result needs to be disposed with
527
+ # LLVMDisposeMessage.
528
+ #
529
+ # @method get_target_machine_cpu(t)
530
+ # @param [TargetMachine] t
531
+ # @return [String]
532
+ # @scope class
533
+ attach_function :get_target_machine_cpu, :LLVMGetTargetMachineCPU, [TargetMachine], :string
534
+
535
+ # Returns the feature string used creating this target machine. See
536
+ # llvm::TargetMachine::getFeatureString. The result needs to be disposed with
537
+ # LLVMDisposeMessage.
538
+ #
539
+ # @method get_target_machine_feature_string(t)
540
+ # @param [TargetMachine] t
541
+ # @return [String]
542
+ # @scope class
543
+ attach_function :get_target_machine_feature_string, :LLVMGetTargetMachineFeatureString, [TargetMachine], :string
544
+
545
+ # Returns the llvm::DataLayout used for this llvm:TargetMachine.
546
+ #
547
+ # @method get_target_machine_data(t)
548
+ # @param [TargetMachine] t
549
+ # @return [OpaqueTargetData]
550
+ # @scope class
551
+ attach_function :get_target_machine_data, :LLVMGetTargetMachineData, [TargetMachine], OpaqueTargetData
552
+
553
+ # Emits an asm or object file for the given module to the filename. This
554
+ # wraps several c++ only classes (among them a file stream). Returns any
555
+ # error in ErrorMessage. Use LLVMDisposeMessage to dispose the message.
556
+ #
557
+ # @method target_machine_emit_to_file(t, m, filename, codegen, error_message)
558
+ # @param [TargetMachine] t
559
+ # @param [FFI::Pointer(ModuleRef)] m
560
+ # @param [String] filename
561
+ # @param [Symbol from _enum_code_gen_file_type_] codegen
562
+ # @param [FFI::Pointer(**CharS)] error_message
563
+ # @return [Integer]
564
+ # @scope class
565
+ attach_function :target_machine_emit_to_file, :LLVMTargetMachineEmitToFile, [TargetMachine, :pointer, :string, :code_gen_file_type, :pointer], :int
566
+
279
567
  end
@@ -4,7 +4,7 @@ require 'ffi'
4
4
 
5
5
  module LLVM::C
6
6
  extend FFI::Library
7
- ffi_lib 'LLVM-3.1'
7
+ ffi_lib 'LLVM-3.2'
8
8
 
9
9
  def self.attach_function(name, *_)
10
10
  begin; super; rescue FFI::NotFoundError => e
@@ -4,7 +4,7 @@ require 'ffi'
4
4
 
5
5
  module LLVM::C
6
6
  extend FFI::Library
7
- ffi_lib 'LLVM-3.1'
7
+ ffi_lib 'LLVM-3.2'
8
8
 
9
9
  def self.attach_function(name, *_)
10
10
  begin; super; rescue FFI::NotFoundError => e
@@ -0,0 +1,17 @@
1
+ require 'llvm'
2
+ require 'llvm/core'
3
+ require 'llvm/transforms/vectorize_ffi'
4
+
5
+ module LLVM
6
+ class PassManager
7
+ # @LLVMpass bb_vectorize
8
+ def bb_vectorize!
9
+ C.add_bb_vectorize_pass(self)
10
+ end
11
+
12
+ # @LLVMpass loop_vectorize
13
+ def loop_vectorize!
14
+ C.add_loop_vectorize_pass(self)
15
+ end
16
+ end
17
+ end