ruby-llvm 13.0.2 → 15.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 84318238934c7be3357466dfcda5fdf52b587164a4756f1663a749edd3754964
4
- data.tar.gz: 2fee5d96b91ebe3edf7d835c4cbe5111e1d9ce8fa63042a32123b506cb65085d
3
+ metadata.gz: c32840c0ecd67347ba80b8521cb5bdac2820b38280c887ee8625b75a20b5345f
4
+ data.tar.gz: effe7776c25a308c5a6ff6fb5c87ddaefed4e6beb03ab946810b4b1f960bd464
5
5
  SHA512:
6
- metadata.gz: 5e03ffebe80a650098d8974ea5b218a727b3f165400cd797bc1d3e652d10cb06f4a621310917e6ee9011b31f4b3ab2dfe215165373c666e78b5d68c8e15703e6
7
- data.tar.gz: bd40aa282aeac16fe3e189c05ab26db1230af73f7b536803e218f1d78a86087fe6f4389e3dfe4ae66eab4fdc7a4417dd712bd2449c6c12b77efd1d99bfffc7a3
6
+ metadata.gz: fcec365b19b7620bf72395c92fb25f1dcf35830496fd1cf9d9778bebecaed85e842136721dd2c8b383191989afb5be0ed110d333e99c6e7a7a967aafe7516128
7
+ data.tar.gz: cc4646ff588df7005443524b14287f97deecc187046f77d87e84d784ee532f0b282d9a5d847d9e0c94e7b981b9484142cdc44e4cdd19bc7daca2a5e3d14bfef5
@@ -46,7 +46,7 @@ def find_llvm_config
46
46
  end
47
47
 
48
48
  def find_cxx
49
- check_for('C++ compiler', %W(g++ clang++), 'CXX') do |cxx|
49
+ check_for('C++ compiler', %W(clang++-#{LLVM_VERSION} clang++ g++), 'CXX') do |cxx|
50
50
  system(cxx, "--version", out: File::NULL, err: File::NULL)
51
51
  $?.success?
52
52
  end
@@ -4,7 +4,7 @@ require 'ffi'
4
4
 
5
5
  module LLVM::C
6
6
  extend FFI::Library
7
- ffi_lib ["libLLVM-13.so.1", "libLLVM.so.13", "LLVM-13"]
7
+ ffi_lib ["libLLVM-15.so.1", "libLLVM.so.15", "LLVM-15"]
8
8
 
9
9
  def self.attach_function(name, *_)
10
10
  begin; super; rescue FFI::NotFoundError => e
data/lib/llvm/config.rb CHANGED
@@ -5,6 +5,6 @@ module LLVM
5
5
  TARGETS_BUILT = ["AArch64", "AMDGPU", "ARM", "BPF", "Hexagon", "Lanai", "Mips", "MSP430", "NVPTX", "PowerPC", "RISCV", "Sparc", "SystemZ", "WebAssembly", "X86", "XCore", "AVR"]
6
6
  HOST_TARGET = "x86_64-pc-linux-gnu "
7
7
  BUILD_MODE = "RelWithDebInfo "
8
- CFLAGS = "-I/usr/lib/llvm-11/include -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS "
8
+ CFLAGS = "-I/usr/lib/llvm-15/include -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS "
9
9
  end
10
10
  end
@@ -9,8 +9,8 @@ module LLVM
9
9
  # @return [LLVM::Module]
10
10
  def self.parse_bitcode(path_or_memory_buffer)
11
11
  memory_buffer = case path_or_memory_buffer
12
- when MemoryBuffer then path_or_memory_buffer
13
- else MemoryBuffer.from_file(path_or_memory_buffer)
12
+ when MemoryBuffer then path_or_memory_buffer
13
+ else MemoryBuffer.from_file(path_or_memory_buffer)
14
14
  end
15
15
  FFI::MemoryPointer.new(:pointer) do |mod_ref|
16
16
  FFI::MemoryPointer.new(:pointer) do |msg_ref|
@@ -4,7 +4,7 @@ require 'ffi'
4
4
 
5
5
  module LLVM::C
6
6
  extend FFI::Library
7
- ffi_lib ["libLLVM-13.so.1", "libLLVM.so.13", "LLVM-13"]
7
+ ffi_lib ["libLLVM-15.so.1", "libLLVM.so.15", "LLVM-15"]
8
8
 
9
9
  def self.attach_function(name, *_)
10
10
  begin; super; rescue FFI::NotFoundError => e
@@ -169,12 +169,20 @@ module LLVM
169
169
  # unwind instruction occurs
170
170
  # @LLVMinst invoke
171
171
  def invoke(fun, args, normal, exception, name = "")
172
+ invoke2(nil, fun, args, normal, exception, name)
173
+ end
174
+
175
+ def invoke2(type, fun, args, normal, exception, name = "")
176
+ raise ArgumentError, "Trying to build LLVM call with non-function: #{fun.inspect}" if !fun.is_a?(LLVM::Function)
177
+
178
+ type ||= fun.return_type
179
+ must_be_type!(type)
180
+
172
181
  s = args.size
173
182
  FFI::MemoryPointer.new(FFI.type_size(:pointer) * s) do |args_ptr|
174
183
  args_ptr.write_array_of_pointer(args)
175
- return Instruction.from_ptr(
176
- C.build_invoke(self,
177
- fun, args_ptr, s, normal, exception, name))
184
+ ins = C.build_invoke2(self, type, fun, args_ptr, s, normal, exception, name)
185
+ return Instruction.from_ptr(ins)
178
186
  end
179
187
  end
180
188
 
@@ -524,7 +532,17 @@ module LLVM
524
532
  # a value of the pointer's type.
525
533
  # @LLVMinst load
526
534
  def load(ptr, name = "")
527
- Instruction.from_ptr(C.build_load(self, ptr, name))
535
+ load2(nil, ptr, name)
536
+ end
537
+
538
+ def load2(type, ptr, name = "")
539
+ must_be_value!(ptr)
540
+
541
+ type ||= infer_type(ptr)
542
+ must_be_type!(type)
543
+
544
+ load = C.build_load2(self, type, ptr, name)
545
+ Instruction.from_ptr(load)
528
546
  end
529
547
 
530
548
  # Store a value at a given pointer
@@ -546,11 +564,29 @@ module LLVM
546
564
  # @LLVMinst gep
547
565
  # @see http://llvm.org/docs/GetElementPtr.html
548
566
  def gep(ptr, indices, name = "")
567
+ gep2(nil, ptr, indices, name)
568
+ end
569
+
570
+ # Obtain a pointer to the element at the given indices
571
+ # @param [LLVM::Type] type An LLVM::Type
572
+ # @param [LLVM::Value] ptr A pointer to an aggregate value
573
+ # @param [Array<LLVM::Value>] indices Ruby array of LLVM::Value representing
574
+ # indices into the aggregate
575
+ # @param [String] name The name of the result in LLVM IR
576
+ # @return [LLVM::Instruction] The resulting pointer
577
+ # @LLVMinst gep2
578
+ # @see http://llvm.org/docs/GetElementPtr.html
579
+ def gep2(type, ptr, indices, name)
580
+ must_be_value!(ptr)
581
+
582
+ type ||= must_infer_type!(ptr)
583
+ must_be_type!(type)
584
+
549
585
  indices = Array(indices)
550
586
  FFI::MemoryPointer.new(FFI.type_size(:pointer) * indices.size) do |indices_ptr|
551
587
  indices_ptr.write_array_of_pointer(indices)
552
- return Instruction.from_ptr(
553
- C.build_gep(self, ptr, indices_ptr, indices.size, name))
588
+ ins = C.build_gep2(self, type, ptr, indices_ptr, indices.size, name)
589
+ return Instruction.from_ptr(ins)
554
590
  end
555
591
  end
556
592
 
@@ -564,25 +600,44 @@ module LLVM
564
600
  # @LLVMinst gep
565
601
  # @see http://llvm.org/docs/GetElementPtr.html
566
602
  def inbounds_gep(ptr, indices, name = "")
603
+ inbounds_gep2(nil, ptr, indices, name)
604
+ end
605
+
606
+ def inbounds_gep2(type, ptr, indices, name = "")
607
+ must_be_value!(ptr)
608
+
609
+ type = must_infer_type!(ptr)
610
+ must_be_type!(type)
611
+
567
612
  indices = Array(indices)
568
613
  FFI::MemoryPointer.new(FFI.type_size(:pointer) * indices.size) do |indices_ptr|
569
614
  indices_ptr.write_array_of_pointer(indices)
570
- return Instruction.from_ptr(
571
- C.build_in_bounds_gep(self, ptr, indices_ptr, indices.size, name))
615
+ ins = C.build_inbounds_gep2(self, type, ptr, indices_ptr, indices.size, name)
616
+ return Instruction.from_ptr(ins)
572
617
  end
573
618
  end
574
619
 
575
620
  # Builds a struct getelementptr Instruction.
576
621
  #
577
- # @param [LLVM::Value] pointer A pointer to a structure
622
+ # @param [LLVM::Value] ptr A pointer to a structure
578
623
  # @param [LLVM::Value] idx Unsigned integer representing the index of a
579
624
  # structure member
580
625
  # @param [String] name The name of the result in LLVM IR
581
626
  # @return [LLVM::Instruction] The resulting pointer
582
627
  # @LLVMinst gep
583
628
  # @see http://llvm.org/docs/GetElementPtr.html
584
- def struct_gep(pointer, idx, name = "")
585
- Instruction.from_ptr(C.build_struct_gep(self, pointer, idx, name))
629
+ def struct_gep(ptr, idx, name = "")
630
+ struct_gep2(nil, ptr, idx, name)
631
+ end
632
+
633
+ def struct_gep2(type, ptr, idx, name)
634
+ must_be_value!(ptr)
635
+
636
+ type ||= must_infer_type!(ptr)
637
+ must_be_type!(type)
638
+
639
+ ins = C.build_struct_gep2(self, type, ptr, idx, name)
640
+ Instruction.from_ptr(ins)
586
641
  end
587
642
 
588
643
  # Creates a global string initialized to a given value.
@@ -868,8 +923,15 @@ module LLVM
868
923
  # @param [LLVM::Instruction]
869
924
  # @LLVMinst call
870
925
  def call(fun, *args)
926
+ call2(nil, fun, *args)
927
+ end
928
+
929
+ def call2(type, fun, *args)
871
930
  raise ArgumentError, "Trying to build LLVM call with non-function: #{fun.inspect}" if !fun.is_a?(LLVM::Function)
872
931
 
932
+ type ||= fun.function_type
933
+ must_be_type!(type)
934
+
873
935
  if args.last.kind_of? String
874
936
  name = args.pop
875
937
  else
@@ -878,7 +940,8 @@ module LLVM
878
940
 
879
941
  args_ptr = FFI::MemoryPointer.new(FFI.type_size(:pointer) * args.size)
880
942
  args_ptr.write_array_of_pointer(args)
881
- CallInst.from_ptr(C.build_call(self, fun, args_ptr, args.size, name))
943
+ ins = C.build_call2(self, type, fun, args_ptr, args.size, name)
944
+ CallInst.from_ptr(ins)
882
945
  end
883
946
 
884
947
  # Return a value based on a condition. This differs from 'cond' in that
@@ -908,7 +971,8 @@ module LLVM
908
971
 
909
972
  raise ArgumentError, "Error building extract_element with #{error}" if error
910
973
 
911
- Instruction.from_ptr(C.build_extract_element(self, vector, idx, name))
974
+ ins = C.build_extract_element(self, vector, idx, name)
975
+ Instruction.from_ptr(ins)
912
976
  end
913
977
 
914
978
  # Insert an element into a vector
@@ -927,17 +991,8 @@ module LLVM
927
991
 
928
992
  raise ArgumentError, "Error building insert_element with #{error}" if error
929
993
 
930
- Instruction.from_ptr(C.build_insert_element(self, vector, elem, idx, name))
931
- end
932
-
933
- private def element_error(vector, idx) # rubocop:disable Style/AccessModifierDeclarations
934
- if !vector.is_a?(LLVM::Value)
935
- "non-value: #{vector.inspect}"
936
- elsif vector.type.kind != :vector
937
- "non-vector: #{vector.type.kind}"
938
- elsif !idx.is_a?(LLVM::Value)
939
- "index: #{idx}"
940
- end
994
+ ins = C.build_insert_element(self, vector, elem, idx, name)
995
+ Instruction.from_ptr(ins)
941
996
  end
942
997
 
943
998
  # Shuffle two vectors according to a given mask
@@ -963,7 +1018,8 @@ module LLVM
963
1018
 
964
1019
  raise ArgumentError, "Error building extract_value with #{error}" if error
965
1020
 
966
- Instruction.from_ptr(C.build_extract_value(self, aggregate, idx, name))
1021
+ ins = C.build_extract_value(self, aggregate, idx, name)
1022
+ Instruction.from_ptr(ins)
967
1023
  end
968
1024
 
969
1025
  # Insert a value into an aggregate value's member field
@@ -982,17 +1038,8 @@ module LLVM
982
1038
 
983
1039
  raise ArgumentError, "Error building insert_value with #{error}" if error
984
1040
 
985
- Instruction.from_ptr(C.build_insert_value(self, aggregate, elem, idx, name))
986
- end
987
-
988
- private def value_error(aggregate, idx) # rubocop:disable Style/AccessModifierDeclarations
989
- if !aggregate.is_a?(LLVM::Value)
990
- "non-value: #{aggregate.inspect}"
991
- elsif !aggregate.type.aggregate?
992
- "non-aggregate: #{aggregate.type.kind}"
993
- elsif !idx.is_a?(Integer) || idx.negative?
994
- "index: #{idx}"
995
- end
1041
+ ins = C.build_insert_value(self, aggregate, elem, idx, name)
1042
+ Instruction.from_ptr(ins)
996
1043
  end
997
1044
 
998
1045
  # Check if a value is null
@@ -1020,5 +1067,79 @@ module LLVM
1020
1067
  def ptr_diff(lhs, rhs, name = "")
1021
1068
  Instruction.from_ptr(C.build_ptr_diff(lhs, rhs, name))
1022
1069
  end
1070
+
1071
+ private
1072
+
1073
+ private def must_be_value!(value)
1074
+ raise "must be a Value, got #{value.class.name}" unless Value === value
1075
+ end
1076
+
1077
+ private def must_be_type!(type)
1078
+ type2 = LLVM.Type(type)
1079
+ raise "must be a Type (LLVMTypeRef), got #{type2.class.name}" unless Type === type2
1080
+ end
1081
+
1082
+ private def must_infer_type!(value)
1083
+ infer_type(value)
1084
+ end
1085
+
1086
+ private def infer_type(ptr)
1087
+ case ptr
1088
+ when GlobalVariable
1089
+ Type.from_ptr(C.global_get_value_type(ptr))
1090
+ when Instruction
1091
+ must_infer_instruction_type!(ptr)
1092
+ else
1093
+ raise "#{ptr.class.name} #{ptr}"
1094
+ end
1095
+ end
1096
+
1097
+ private def must_infer_instruction_type!(ptr)
1098
+ case ptr.opcode
1099
+ when :get_element_ptr
1100
+ must_infer_gep!(ptr)
1101
+ when :alloca
1102
+ Type.from_ptr(C.get_allocated_type(ptr))
1103
+ when :load
1104
+ ptr.type
1105
+ else
1106
+ raise "Inferring type for instruction not currently supported: #{ptr.opcode} #{ptr}"
1107
+ end
1108
+ end
1109
+
1110
+ private def must_infer_gep!(ptr)
1111
+ source_type = Type.from_ptr(C.get_gep_source_element_type(ptr))
1112
+ case source_type.kind
1113
+ when :integer
1114
+ source_type
1115
+ when :struct
1116
+ raise "Cannot currently infer type from gep of struct"
1117
+ when :array, :vector
1118
+ source_type.element_type
1119
+ else
1120
+ debugger
1121
+ end
1122
+ end
1123
+
1124
+ private def element_error(vector, idx) # rubocop:disable Style/AccessModifierDeclarations
1125
+ if !vector.is_a?(LLVM::Value)
1126
+ "non-value: #{vector.inspect}"
1127
+ elsif vector.type.kind != :vector
1128
+ "non-vector: #{vector.type.kind}"
1129
+ elsif !idx.is_a?(LLVM::Value)
1130
+ "index: #{idx}"
1131
+ end
1132
+ end
1133
+
1134
+ private def value_error(aggregate, idx) # rubocop:disable Style/AccessModifierDeclarations
1135
+ if !aggregate.is_a?(LLVM::Value)
1136
+ "non-value: #{aggregate.inspect}"
1137
+ # TODO: fix this
1138
+ elsif !aggregate.type.aggregate?
1139
+ "non-aggregate: #{aggregate.type.kind}"
1140
+ elsif !idx.is_a?(Integer) || idx.negative?
1141
+ "index: #{idx}"
1142
+ end
1143
+ end
1023
1144
  end
1024
1145
  end
@@ -0,0 +1,25 @@
1
+ # unmodule LLVM
2
+ # module OpaquePointerBuilder
3
+ # # Builds a struct getelementptr Instruction.
4
+ # #
5
+ # # @param [LLVM::Value] pointer A pointer to a structure
6
+ # # @param [LLVM::Value] idx Unsigned integer representing the index of a
7
+ # # structure member
8
+ # # @param [String] name The name of the result in LLVM IR
9
+ # # @return [LLVM::Instruction] The resulting pointer
10
+ # # @LLVMinst gep
11
+ # # @see http://llvm.org/docs/GetElementPtr.html
12
+ # def struct_gep1(pointer, idx, name = "")
13
+ # Instruction.from_ptr(C.build_struct_gep(self, pointer, idx, name))
14
+ # end
15
+ #
16
+ # private def struct_gep2(type, pointer, idx, name)
17
+ # Instruction.from_ptr(C.build_struct_gep2(self, type, pointer, idx, name))
18
+ # end
19
+ #
20
+ # def struct_gep(pointer, idx, name = "", type = nil)
21
+ # type2 = type || must_infer_type(pointer)
22
+ # struct_gep2(types2, pointer, idx, name)
23
+ # end
24
+ # end
25
+ # end
@@ -5,14 +5,18 @@ module LLVM
5
5
  include PointerIdentity
6
6
 
7
7
  # @private
8
- def self.from_ptr(ptr, kind)
8
+ def self.from_ptr(ptr, kind = nil)
9
9
  return if ptr.null?
10
10
  kind ||= C.get_type_kind(ptr)
11
11
  ty = case kind
12
- when :integer then IntType.allocate
13
- when :function then FunctionType.allocate
14
- when :struct then StructType.allocate
15
- else allocate
12
+ when :integer
13
+ IntType.allocate
14
+ when :function
15
+ FunctionType.allocate
16
+ when :struct
17
+ StructType.allocate
18
+ else
19
+ allocate
16
20
  end
17
21
  ty.instance_variable_set(:@ptr, ptr)
18
22
  ty.instance_variable_set(:@kind, kind)
@@ -36,8 +40,13 @@ module LLVM
36
40
  # Returns the type of this types elements (works only for Pointer, Vector, and Array types.)
37
41
  def element_type
38
42
  case kind
39
- when :pointer, :vector, :array
40
- Type.from_ptr(C.get_element_type(self), nil)
43
+ when :vector, :array
44
+ element_type = C.get_element_type(self)
45
+ Type.from_ptr(element_type)
46
+ when :pointer
47
+ LLVM.Void
48
+ else
49
+ raise "element_type not supported for kind: #{kind}"
41
50
  end
42
51
  end
43
52
 
@@ -113,6 +122,21 @@ module LLVM
113
122
  from_ptr(C.void_type, :void)
114
123
  end
115
124
 
125
+ def self.label
126
+ from_ptr(C.label_type, :label)
127
+ end
128
+
129
+ def self.x86_mmx
130
+ from_ptr(C.x86mmx_type, :x86mmx)
131
+ end
132
+
133
+ def self.x86_amx
134
+ from_ptr(C.x86amx_type, :x86amx)
135
+ end
136
+ # def self.opaque_pointer
137
+ # from_ptr(C.opaque_type, :pointer)
138
+ # end
139
+
116
140
  def self.rec
117
141
  h = opaque
118
142
  ty = yield h
@@ -129,7 +153,11 @@ module LLVM
129
153
 
130
154
  class FunctionType < Type
131
155
  def return_type
132
- Type.from_ptr(C.get_return_type(self), nil)
156
+ Type.from_ptr(C.get_return_type(self))
157
+ end
158
+
159
+ def element_type
160
+ self
133
161
  end
134
162
 
135
163
  def argument_types
@@ -26,6 +26,10 @@ module LLVM
26
26
  Type.from_ptr(C.type_of(self), nil)
27
27
  end
28
28
 
29
+ def allocated_type
30
+ Type.from_ptr(C.get_allocated_type(self), nil)
31
+ end
32
+
29
33
  # Returns the value's name.
30
34
  def name
31
35
  C.get_value_name(self)
@@ -315,6 +319,10 @@ module LLVM
315
319
  def size
316
320
  C.get_array_length(type)
317
321
  end
322
+
323
+ def [](idx)
324
+ self.class.from_ptr(C.get_aggregate_element(self, idx))
325
+ end
318
326
  end
319
327
 
320
328
  class ConstantExpr < Constant
@@ -631,6 +639,10 @@ module LLVM
631
639
  vals = LLVM::Support.allocate_pointers(size_or_values, &block)
632
640
  from_ptr C.const_named_struct(type, vals, vals.size / vals.type_size)
633
641
  end
642
+
643
+ def [](idx)
644
+ self.class.from_ptr(C.get_aggregate_element(self, idx))
645
+ end
634
646
  end
635
647
 
636
648
  class ConstantVector < Constant
@@ -646,6 +658,10 @@ module LLVM
646
658
  def size
647
659
  C.get_vector_size(type)
648
660
  end
661
+
662
+ def [](idx)
663
+ self.class.from_ptr(C.get_aggregate_element(self, idx))
664
+ end
649
665
  end
650
666
 
651
667
  class GlobalValue < Constant
@@ -735,12 +751,17 @@ module LLVM
735
751
  @basic_block_collection ||= BasicBlockCollection.new(self)
736
752
  end
737
753
 
754
+ def function_type
755
+ Type.from_ptr(C.get_element_type(self), :function)
756
+ end
757
+
758
+ # In LLVM 15, not overriding this yields a pointer type instead of a function type
738
759
  def type
739
- Type.from_ptr(C.type_of(self), :pointer)
760
+ function_type
740
761
  end
741
762
 
742
- def function_type
743
- type.element_type
763
+ def return_type
764
+ type.return_type
744
765
  end
745
766
 
746
767
  # Adds attr to this value's attributes.
@@ -962,6 +983,10 @@ module LLVM
962
983
  ptr = C.get_previous_instruction(self)
963
984
  LLVM::Instruction.from_ptr(ptr) unless ptr.null?
964
985
  end
986
+
987
+ def opcode
988
+ C.get_instruction_opcode(self)
989
+ end
965
990
  end
966
991
 
967
992
  class CallInst < Instruction
data/lib/llvm/core.rb CHANGED
@@ -51,6 +51,57 @@ module LLVM
51
51
  # const char *LLVMGetStringAttributeValue
52
52
  # (LLVMAttributeRef A, unsigned *Length);
53
53
  attach_function :get_string_attribute_value, :LLVMGetStringAttributeValue, [:pointer, :pointer], :pointer
54
+
55
+ # LLVMValueRef LLVMBuildLoad2(LLVMBuilderRef, LLVMTypeRef Ty, LLVMValueRef PointerVal, const char *Name);
56
+ attach_function :build_load2, :LLVMBuildLoad2, [:pointer, :pointer, :pointer, :string], :pointer
57
+
58
+ # LLVMValueRef LLVMBuildGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
59
+ # LLVMValueRef Pointer, LLVMValueRef *Indices,
60
+ # unsigned NumIndices, const char *Name);
61
+ attach_function :build_gep2, :LLVMBuildGEP2, [:pointer, :pointer, :pointer, :pointer, :uint, :string], :pointer
62
+
63
+ # LLVMValueRef LLVMBuildInBoundsGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
64
+ # LLVMValueRef Pointer, LLVMValueRef *Indices,
65
+ # unsigned NumIndices, const char *Name);
66
+ attach_function :build_inbounds_gep2, :LLVMBuildInBoundsGEP2, [:pointer, :pointer, :pointer, :pointer, :uint, :string], :pointer
67
+
68
+ # LLVMValueRef LLVMBuildStructGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
69
+ # LLVMValueRef Pointer, unsigned Idx,
70
+ # const char *Name);
71
+ attach_function :build_struct_gep2, :LLVMBuildStructGEP2, [:pointer, :pointer, :pointer, :uint, :string], :pointer
72
+
73
+ # LLVMValueRef LLVMBuildCall2(LLVMBuilderRef, LLVMTypeRef, LLVMValueRef Fn,
74
+ # LLVMValueRef *Args, unsigned NumArgs,
75
+ # const char *Name);
76
+ attach_function :build_call2, :LLVMBuildCall2, [:pointer, :pointer, :pointer, :pointer, :uint, :string], :pointer
77
+
78
+ # LLVMValueRef LLVMBuildInvoke2(LLVMBuilderRef, LLVMTypeRef Ty, LLVMValueRef Fn,
79
+ # LLVMValueRef *Args, unsigned NumArgs,
80
+ # LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
81
+ # const char *Name);
82
+ attach_function :build_invoke2, :LLVMBuildInvoke2, [:pointer, :pointer, :pointer, :pointer, :uint, :pointer, :pointer, :string], :pointer
83
+
84
+ # LLVMTypeRef LLVMGlobalGetValueType(LLVMValueRef Global);
85
+ attach_function :global_get_value_type, :LLVMGlobalGetValueType, [:pointer], :pointer
86
+
87
+ # LLVMTypeRef LLVMGetGEPSourceElementType(LLVMValueRef GEP);
88
+ attach_function :get_gep_source_element_type, :LLVMGetGEPSourceElementType, [:pointer], :pointer
89
+
90
+ # (Not documented)
91
+ #
92
+ # @method x86amx_type()
93
+ # @return [FFI::Pointer(TypeRef)]
94
+ # @scope class
95
+ attach_function :x86amx_type, :LLVMX86AMXType, [], :pointer
96
+
97
+ # LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca);
98
+ attach_function :get_allocated_type, :LLVMGetAllocatedType, [:pointer], :pointer
99
+
100
+ # LLVMTypeRef LLVMGlobalGetValueType(LLVMValueRef Global);
101
+ attach_function :get_value_type, :LLVMGlobalGetValueType, [:pointer], :pointer
102
+
103
+ # LLVMValueRef LLVMGetAggregateElement(LLVMValueRef C, unsigned Idx);
104
+ attach_function :get_aggregate_element, :LLVMGetAggregateElement, [:pointer, :int], :pointer
54
105
  end
55
106
 
56
107
  # Yields a pointer suitable for storing an LLVM output message.
data/lib/llvm/core_ffi.rb CHANGED
@@ -4,7 +4,7 @@ require 'ffi'
4
4
 
5
5
  module LLVM::C
6
6
  extend FFI::Library
7
- ffi_lib ["libLLVM-13.so.1", "libLLVM.so.13", "LLVM-13"]
7
+ ffi_lib ["libLLVM-15.so.1", "libLLVM.so.15", "LLVM-15"]
8
8
 
9
9
  def self.attach_function(name, *_)
10
10
  begin; super; rescue FFI::NotFoundError => e
@@ -410,7 +410,10 @@ module LLVM::C
410
410
  :vector, 13,
411
411
  :metadata, 14,
412
412
  :x86_mmx, 15,
413
- :token, 16
413
+ :token, 16,
414
+ :scalable_vector, 17,
415
+ :bfloat, 18,
416
+ :x86_amx, 19,
414
417
  ]
415
418
 
416
419
  # (Not documented)
@@ -3012,15 +3015,6 @@ module LLVM::C
3012
3015
  # @scope class
3013
3016
  attach_function :const_nuw_add, :LLVMConstNUWAdd, [:pointer, :pointer], :pointer
3014
3017
 
3015
- # (Not documented)
3016
- #
3017
- # @method const_f_add(lhs_constant, rhs_constant)
3018
- # @param [FFI::Pointer(ValueRef)] lhs_constant
3019
- # @param [FFI::Pointer(ValueRef)] rhs_constant
3020
- # @return [FFI::Pointer(ValueRef)]
3021
- # @scope class
3022
- attach_function :const_f_add, :LLVMConstFAdd, [:pointer, :pointer], :pointer
3023
-
3024
3018
  # (Not documented)
3025
3019
  #
3026
3020
  # @method const_sub(lhs_constant, rhs_constant)
@@ -3048,15 +3042,6 @@ module LLVM::C
3048
3042
  # @scope class
3049
3043
  attach_function :const_nuw_sub, :LLVMConstNUWSub, [:pointer, :pointer], :pointer
3050
3044
 
3051
- # (Not documented)
3052
- #
3053
- # @method const_f_sub(lhs_constant, rhs_constant)
3054
- # @param [FFI::Pointer(ValueRef)] lhs_constant
3055
- # @param [FFI::Pointer(ValueRef)] rhs_constant
3056
- # @return [FFI::Pointer(ValueRef)]
3057
- # @scope class
3058
- attach_function :const_f_sub, :LLVMConstFSub, [:pointer, :pointer], :pointer
3059
-
3060
3045
  # (Not documented)
3061
3046
  #
3062
3047
  # @method const_mul(lhs_constant, rhs_constant)
@@ -3084,78 +3069,6 @@ module LLVM::C
3084
3069
  # @scope class
3085
3070
  attach_function :const_nuw_mul, :LLVMConstNUWMul, [:pointer, :pointer], :pointer
3086
3071
 
3087
- # (Not documented)
3088
- #
3089
- # @method const_f_mul(lhs_constant, rhs_constant)
3090
- # @param [FFI::Pointer(ValueRef)] lhs_constant
3091
- # @param [FFI::Pointer(ValueRef)] rhs_constant
3092
- # @return [FFI::Pointer(ValueRef)]
3093
- # @scope class
3094
- attach_function :const_f_mul, :LLVMConstFMul, [:pointer, :pointer], :pointer
3095
-
3096
- # (Not documented)
3097
- #
3098
- # @method const_u_div(lhs_constant, rhs_constant)
3099
- # @param [FFI::Pointer(ValueRef)] lhs_constant
3100
- # @param [FFI::Pointer(ValueRef)] rhs_constant
3101
- # @return [FFI::Pointer(ValueRef)]
3102
- # @scope class
3103
- attach_function :const_u_div, :LLVMConstUDiv, [:pointer, :pointer], :pointer
3104
-
3105
- # (Not documented)
3106
- #
3107
- # @method const_s_div(lhs_constant, rhs_constant)
3108
- # @param [FFI::Pointer(ValueRef)] lhs_constant
3109
- # @param [FFI::Pointer(ValueRef)] rhs_constant
3110
- # @return [FFI::Pointer(ValueRef)]
3111
- # @scope class
3112
- attach_function :const_s_div, :LLVMConstSDiv, [:pointer, :pointer], :pointer
3113
-
3114
- # (Not documented)
3115
- #
3116
- # @method const_exact_s_div(lhs_constant, rhs_constant)
3117
- # @param [FFI::Pointer(ValueRef)] lhs_constant
3118
- # @param [FFI::Pointer(ValueRef)] rhs_constant
3119
- # @return [FFI::Pointer(ValueRef)]
3120
- # @scope class
3121
- attach_function :const_exact_s_div, :LLVMConstExactSDiv, [:pointer, :pointer], :pointer
3122
-
3123
- # (Not documented)
3124
- #
3125
- # @method const_f_div(lhs_constant, rhs_constant)
3126
- # @param [FFI::Pointer(ValueRef)] lhs_constant
3127
- # @param [FFI::Pointer(ValueRef)] rhs_constant
3128
- # @return [FFI::Pointer(ValueRef)]
3129
- # @scope class
3130
- attach_function :const_f_div, :LLVMConstFDiv, [:pointer, :pointer], :pointer
3131
-
3132
- # (Not documented)
3133
- #
3134
- # @method const_u_rem(lhs_constant, rhs_constant)
3135
- # @param [FFI::Pointer(ValueRef)] lhs_constant
3136
- # @param [FFI::Pointer(ValueRef)] rhs_constant
3137
- # @return [FFI::Pointer(ValueRef)]
3138
- # @scope class
3139
- attach_function :const_u_rem, :LLVMConstURem, [:pointer, :pointer], :pointer
3140
-
3141
- # (Not documented)
3142
- #
3143
- # @method const_s_rem(lhs_constant, rhs_constant)
3144
- # @param [FFI::Pointer(ValueRef)] lhs_constant
3145
- # @param [FFI::Pointer(ValueRef)] rhs_constant
3146
- # @return [FFI::Pointer(ValueRef)]
3147
- # @scope class
3148
- attach_function :const_s_rem, :LLVMConstSRem, [:pointer, :pointer], :pointer
3149
-
3150
- # (Not documented)
3151
- #
3152
- # @method const_f_rem(lhs_constant, rhs_constant)
3153
- # @param [FFI::Pointer(ValueRef)] lhs_constant
3154
- # @param [FFI::Pointer(ValueRef)] rhs_constant
3155
- # @return [FFI::Pointer(ValueRef)]
3156
- # @scope class
3157
- attach_function :const_f_rem, :LLVMConstFRem, [:pointer, :pointer], :pointer
3158
-
3159
3072
  # (Not documented)
3160
3073
  #
3161
3074
  # @method const_and(lhs_constant, rhs_constant)
@@ -3461,27 +3374,6 @@ module LLVM::C
3461
3374
  # @scope class
3462
3375
  attach_function :const_shuffle_vector, :LLVMConstShuffleVector, [:pointer, :pointer, :pointer], :pointer
3463
3376
 
3464
- # (Not documented)
3465
- #
3466
- # @method const_extract_value(agg_constant, idx_list, num_idx)
3467
- # @param [FFI::Pointer(ValueRef)] agg_constant
3468
- # @param [FFI::Pointer(*UInt)] idx_list
3469
- # @param [Integer] num_idx
3470
- # @return [FFI::Pointer(ValueRef)]
3471
- # @scope class
3472
- attach_function :const_extract_value, :LLVMConstExtractValue, [:pointer, :pointer, :uint], :pointer
3473
-
3474
- # (Not documented)
3475
- #
3476
- # @method const_insert_value(agg_constant, element_value_constant, idx_list, num_idx)
3477
- # @param [FFI::Pointer(ValueRef)] agg_constant
3478
- # @param [FFI::Pointer(ValueRef)] element_value_constant
3479
- # @param [FFI::Pointer(*UInt)] idx_list
3480
- # @param [Integer] num_idx
3481
- # @return [FFI::Pointer(ValueRef)]
3482
- # @scope class
3483
- attach_function :const_insert_value, :LLVMConstInsertValue, [:pointer, :pointer, :pointer, :uint], :pointer
3484
-
3485
3377
  # (Not documented)
3486
3378
  #
3487
3379
  # @method const_inline_asm(ty, asm_string, constraints, has_side_effects, is_align_stack)
@@ -4,7 +4,7 @@ require 'ffi'
4
4
 
5
5
  module LLVM::C
6
6
  extend FFI::Library
7
- ffi_lib ["libLLVM-13.so.1", "libLLVM.so.13", "LLVM-13"]
7
+ ffi_lib ["libLLVM-15.so.1", "libLLVM.so.15", "LLVM-15"]
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 ["libLLVM-13.so.1", "libLLVM.so.13", "LLVM-13"]
7
+ ffi_lib ["libLLVM-15.so.1", "libLLVM.so.15", "LLVM-15"]
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 ["libLLVM-13.so.1", "libLLVM.so.13", "LLVM-13"]
7
+ ffi_lib ["libLLVM-15.so.1", "libLLVM.so.15", "LLVM-15"]
8
8
 
9
9
  def self.attach_function(name, *_)
10
10
  begin; super; rescue FFI::NotFoundError => e
@@ -86,18 +86,7 @@ module LLVM
86
86
  # Populate an LTO pass manager.
87
87
  # @param [PassManager] pass_manager
88
88
  def build_with_lto(pass_manager, internalize = false, run_inliner = false)
89
- if pass_manager.is_a?(FunctionPassManager)
90
- raise ArgumentError, "FunctionPassManager does not support LTO"
91
- end
92
-
93
- if internalize.kind_of?(Integer) || run_inliner.kind_of?(Integer)
94
- warn 'Warning: Passing Integer value to LLVM::PassManagerBuilder#build_with_lto is deprecated.'
95
- internalize = !internalize.zero? if internalize.kind_of?(Integer)
96
- run_inliner = !run_inliner.zero? if run_inliner.kind_of?(Integer)
97
- end
98
-
99
- C.pass_manager_builder_populate_lto_pass_manager(self,
100
- pass_manager, flag(internalize), flag(run_inliner))
89
+ raise "build_with_lto is not currently supported"
101
90
  end
102
91
 
103
92
  private
@@ -4,7 +4,7 @@ require 'ffi'
4
4
 
5
5
  module LLVM::C
6
6
  extend FFI::Library
7
- ffi_lib ["libLLVM-13.so.1", "libLLVM.so.13", "LLVM-13"]
7
+ ffi_lib ["libLLVM-15.so.1", "libLLVM.so.15", "LLVM-15"]
8
8
 
9
9
  def self.attach_function(name, *_)
10
10
  begin; super; rescue FFI::NotFoundError => e
@@ -103,15 +103,4 @@ module LLVM::C
103
103
  # @return [nil]
104
104
  # @scope class
105
105
  attach_function :pass_manager_builder_populate_module_pass_manager, :LLVMPassManagerBuilderPopulateModulePassManager, [OpaquePassManagerBuilder, :pointer], :void
106
-
107
- # See llvm::PassManagerBuilder::populateLTOPassManager.
108
- #
109
- # @method pass_manager_builder_populate_lto_pass_manager(pmb, pm, internalize, run_inliner)
110
- # @param [OpaquePassManagerBuilder] pmb
111
- # @param [FFI::Pointer(PassManagerRef)] pm
112
- # @param [Integer] internalize
113
- # @param [Integer] run_inliner
114
- # @return [nil]
115
- # @scope class
116
- attach_function :pass_manager_builder_populate_lto_pass_manager, :LLVMPassManagerBuilderPopulateLTOPassManager, [OpaquePassManagerBuilder, :pointer, :int, :int], :void
117
106
  end
@@ -4,7 +4,7 @@ require 'ffi'
4
4
 
5
5
  module LLVM::C
6
6
  extend FFI::Library
7
- ffi_lib ["libLLVM-13.so.1", "libLLVM.so.13", "LLVM-13"]
7
+ ffi_lib ["libLLVM-15.so.1", "libLLVM.so.15", "LLVM-15"]
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 ["libLLVM-13.so.1", "libLLVM.so.13", "LLVM-13"]
7
+ ffi_lib ["libLLVM-15.so.1", "libLLVM.so.15", "LLVM-15"]
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 ["libLLVM-13.so.1", "libLLVM.so.13", "LLVM-13"]
7
+ ffi_lib ["libLLVM-15.so.1", "libLLVM.so.15", "LLVM-15"]
8
8
 
9
9
  def self.attach_function(name, *_)
10
10
  begin; super; rescue FFI::NotFoundError => e
data/lib/llvm/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LLVM
4
- LLVM_VERSION = "13"
5
- LLVM_REQUIRED_VERSION = "13.0"
6
- RUBY_LLVM_VERSION = "13.0.2"
4
+ LLVM_VERSION = "15"
5
+ LLVM_REQUIRED_VERSION = "15.0"
6
+ RUBY_LLVM_VERSION = "15.0.0"
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-llvm
3
3
  version: !ruby/object:Gem::Version
4
- version: 13.0.2
4
+ version: 15.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesse Johnson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2022-06-02 00:00:00.000000000 Z
12
+ date: 2022-10-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi
@@ -45,62 +45,76 @@ dependencies:
45
45
  - - "<"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '14'
48
+ - !ruby/object:Gem::Dependency
49
+ name: debug
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
48
62
  - !ruby/object:Gem::Dependency
49
63
  name: ffi_gen
50
64
  requirement: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: 1.2.0
68
+ version: '1.2'
55
69
  type: :development
56
70
  prerelease: false
57
71
  version_requirements: !ruby/object:Gem::Requirement
58
72
  requirements:
59
73
  - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: 1.2.0
75
+ version: '1.2'
62
76
  - !ruby/object:Gem::Dependency
63
77
  name: minitest
64
78
  requirement: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: 5.15.0
82
+ version: '5.16'
69
83
  type: :development
70
84
  prerelease: false
71
85
  version_requirements: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: 5.15.0
89
+ version: '5.16'
76
90
  - !ruby/object:Gem::Dependency
77
91
  name: minitest-reporters
78
92
  requirement: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: 1.5.0
96
+ version: '1.5'
83
97
  type: :development
84
98
  prerelease: false
85
99
  version_requirements: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: 1.5.0
103
+ version: '1.5'
90
104
  - !ruby/object:Gem::Dependency
91
105
  name: rubocop
92
106
  requirement: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: 1.30.0
110
+ version: '1.31'
97
111
  type: :development
98
112
  prerelease: false
99
113
  version_requirements: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: 1.30.0
117
+ version: '1.31'
104
118
  - !ruby/object:Gem::Dependency
105
119
  name: rubocop-minitest
106
120
  requirement: !ruby/object:Gem::Requirement
@@ -149,14 +163,14 @@ dependencies:
149
163
  requirements:
150
164
  - - "~>"
151
165
  - !ruby/object:Gem::Version
152
- version: 0.9.8
166
+ version: '0.9'
153
167
  type: :development
154
168
  prerelease: false
155
169
  version_requirements: !ruby/object:Gem::Requirement
156
170
  requirements:
157
171
  - - "~>"
158
172
  - !ruby/object:Gem::Version
159
- version: 0.9.8
173
+ version: '0.9'
160
174
  description: Ruby-LLVM is a Ruby language binding to the LLVM compiler infrastructure
161
175
  library.
162
176
  email:
@@ -183,6 +197,7 @@ files:
183
197
  - lib/llvm/core/builder.rb
184
198
  - lib/llvm/core/context.rb
185
199
  - lib/llvm/core/module.rb
200
+ - lib/llvm/core/opaque_pointer_builder.rb
186
201
  - lib/llvm/core/pass_manager.rb
187
202
  - lib/llvm/core/type.rb
188
203
  - lib/llvm/core/value.rb