ruby-llvm 15.0.1 → 15.0.2

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: 1595f619407ef3dcb3bf455c4b14dc5843accc2f42854cf9b3bf46f378fcea40
4
- data.tar.gz: 1cf2978bf457a6f45b19483570bef9ef1a0b6730bb90786895a6dd86950ab24b
3
+ metadata.gz: 79169ec6b39406ef0c395bee5bbc02578340808b2728ba61b5b89c1532e05c94
4
+ data.tar.gz: 8fe97708a36b561acbd24433f1ddf5d940e6535a776d918eca463fd179a29aea
5
5
  SHA512:
6
- metadata.gz: 7a49ba3ff1bf07d0f529b54e82b696c1bb6c1dae57f126204f9fec56781e4a625a7d6f0b80d638598f63f009658f02e9a9dc4d7542bee10bae58501ab53220ec
7
- data.tar.gz: f0b87e6e18742252858ace4e0e2366f98270feebfc4d948291abe8ba0306a957c17b1b59cc7ae081a6c4c30e294892d899148ce3ed8ad4d6f7abdaadf0c64424
6
+ metadata.gz: 75303049be604101b44001f68264b0ba0e5902816cf8d001ed5302aa7b71067b1e8d4ac7f24cf3470e53f59aac5547391b31c5f1145dceb28661966e95c56928
7
+ data.tar.gz: 9bad15b50111baf7dd2804d9bd6e61d8a2d05b892eacbbbc52df0194662f961eba8c7f9b81f5ebf1b5e9ce796e4aaeb4b4b47e858874d474ea39e54d3a6dd042
@@ -77,7 +77,7 @@ desc "Build the shared library and config module"
77
77
  task :default => [SUPPORT_LIB, CONFIG_MOD]
78
78
 
79
79
  file SUPPORT_LIB => %w(support.cpp) do |task|
80
- clang_stdlib = CXX =~ /^clang++/ ? "-stdlib=libc++" : ""
80
+ clang_stdlib = CXX.match?(/^clang++/) ? "-stdlib=libc++" : ""
81
81
  sh "#{CXX} -O3 -shared #{task.prerequisites.join(' ')} -l#{llvm_lib_name} " \
82
82
  "#{invoke_llvm_config('--cxxflags --ldflags')} -fPIC #{clang_stdlib} -o #{SUPPORT_LIB}"
83
83
  end
@@ -1070,20 +1070,20 @@ module LLVM
1070
1070
 
1071
1071
  private
1072
1072
 
1073
- private def must_be_value!(value)
1073
+ def must_be_value!(value)
1074
1074
  raise "must be a Value, got #{value.class.name}" unless Value === value
1075
1075
  end
1076
1076
 
1077
- private def must_be_type!(type)
1077
+ def must_be_type!(type)
1078
1078
  type2 = LLVM.Type(type)
1079
1079
  raise "must be a Type (LLVMTypeRef), got #{type2.class.name}" unless Type === type2
1080
1080
  end
1081
1081
 
1082
- private def must_infer_type!(value)
1082
+ def must_infer_type!(value)
1083
1083
  infer_type(value)
1084
1084
  end
1085
1085
 
1086
- private def infer_type(ptr)
1086
+ def infer_type(ptr)
1087
1087
  case ptr
1088
1088
  when GlobalVariable
1089
1089
  Type.from_ptr(C.global_get_value_type(ptr))
@@ -1094,7 +1094,7 @@ module LLVM
1094
1094
  end
1095
1095
  end
1096
1096
 
1097
- private def must_infer_instruction_type!(ptr)
1097
+ def must_infer_instruction_type!(ptr)
1098
1098
  case ptr.opcode
1099
1099
  when :get_element_ptr
1100
1100
  must_infer_gep!(ptr)
@@ -1107,7 +1107,7 @@ module LLVM
1107
1107
  end
1108
1108
  end
1109
1109
 
1110
- private def must_infer_gep!(ptr)
1110
+ def must_infer_gep!(ptr)
1111
1111
  source_type = Type.from_ptr(C.get_gep_source_element_type(ptr))
1112
1112
  case source_type.kind
1113
1113
  when :integer
@@ -1121,7 +1121,7 @@ module LLVM
1121
1121
  end
1122
1122
  end
1123
1123
 
1124
- private def element_error(vector, idx) # rubocop:disable Style/AccessModifierDeclarations
1124
+ def element_error(vector, idx)
1125
1125
  if !vector.is_a?(LLVM::Value)
1126
1126
  "non-value: #{vector.inspect}"
1127
1127
  elsif vector.type.kind != :vector
@@ -1131,7 +1131,7 @@ module LLVM
1131
1131
  end
1132
1132
  end
1133
1133
 
1134
- private def value_error(aggregate, idx) # rubocop:disable Style/AccessModifierDeclarations
1134
+ def value_error(aggregate, idx)
1135
1135
  if !aggregate.is_a?(LLVM::Value)
1136
1136
  "non-value: #{aggregate.inspect}"
1137
1137
  # TODO: fix this
@@ -1,4 +1,5 @@
1
- # unmodule LLVM
1
+ # frozen_string_literal: true
2
+ # module LLVM
2
3
  # module OpaquePointerBuilder
3
4
  # # Builds a struct getelementptr Instruction.
4
5
  # #
@@ -79,18 +79,47 @@ module LLVM
79
79
  [:struct, :array].include?(kind)
80
80
  end
81
81
 
82
+ def opaque_struct?
83
+ C.is_opaque_struct(self)
84
+ end
85
+
86
+ def packed_struct?
87
+ C.is_packed_struct(self)
88
+ end
89
+
90
+ def literal_struct?
91
+ C.is_literal_struct(self)
92
+ end
93
+
82
94
  # Creates an array type of Type with the given size.
95
+ # arrays can be size >= 0, https://llvm.org/docs/LangRef.html#array-type
83
96
  def self.array(ty, sz = 0)
97
+ sz = sz.to_i
98
+ raise ArgumentError, "LLVM Array size must be >= 0" if sz.negative?
99
+
84
100
  from_ptr(C.array_type(LLVM::Type(ty), sz), :array)
85
101
  end
86
102
 
87
103
  # Creates the pointer type of Type with the given address space.
88
- def self.pointer(ty, address_space = 0)
89
- from_ptr(C.pointer_type(LLVM::Type(ty), address_space), :pointer)
104
+ def self.pointer(ty = nil, address_space = 0)
105
+ if ty
106
+ from_ptr(C.pointer_type(LLVM::Type(ty), address_space), :pointer)
107
+ else
108
+ ptr(address_space)
109
+ end
110
+ end
111
+
112
+ # opaque pointer
113
+ def self.ptr(address_space = 0)
114
+ from_ptr(C.pointer_type(void, address_space), :pointer)
90
115
  end
91
116
 
92
117
  # Creates a vector type of Type with the given element count.
118
+ # vectors can be size > 0, https://llvm.org/docs/LangRef.html#vector-type
93
119
  def self.vector(ty, element_count)
120
+ element_count = element_count.to_i
121
+ raise ArgumentError, "LLVM Vector size must be > 0" unless element_count.positive?
122
+
94
123
  from_ptr(C.vector_type(LLVM::Type(ty), element_count), :vector)
95
124
  end
96
125
 
@@ -117,6 +146,14 @@ module LLVM
117
146
  end
118
147
  end
119
148
 
149
+ def self.opaque_struct(name)
150
+ from_ptr(C.struct_create_named(Context.global, name.to_s), :struct)
151
+ end
152
+
153
+ def self.named(name)
154
+ from_ptr(C.get_type_by_name2(Context.global, name.to_s), nil)
155
+ end
156
+
120
157
  # Creates a void type.
121
158
  def self.void
122
159
  from_ptr(C.void_type, :void)
@@ -217,7 +254,7 @@ module LLVM
217
254
  end
218
255
 
219
256
  # Shortcut to Type.pointer.
220
- def Pointer(ty)
257
+ def Pointer(ty = nil)
221
258
  LLVM::Type.pointer(ty)
222
259
  end
223
260
 
@@ -291,7 +291,7 @@ module LLVM
291
291
  module Support
292
292
  def allocate_pointers(size_or_values, &block)
293
293
  if size_or_values.is_a?(Integer)
294
- raise ArgumentError, 'block not given' unless block_given?
294
+ raise ArgumentError, 'block not given' unless block
295
295
  size = size_or_values
296
296
  values = (0...size).map { |i| yield i }
297
297
  else
@@ -832,7 +832,7 @@ module LLVM
832
832
 
833
833
  def attribute_name(attr_name)
834
834
  attr_name = attr_name.to_s
835
- if attr_name =~ /_attribute$/
835
+ if /_attribute$/.match?(attr_name)
836
836
  attr_name.chomp('_attribute').tr('_', '')
837
837
  else
838
838
  attr_name
data/lib/llvm/core.rb CHANGED
@@ -102,6 +102,38 @@ module LLVM
102
102
 
103
103
  # LLVMValueRef LLVMGetAggregateElement(LLVMValueRef C, unsigned Idx);
104
104
  attach_function :get_aggregate_element, :LLVMGetAggregateElement, [:pointer, :int], :pointer
105
+
106
+ attach_function :get_type_by_name2, :LLVMGetTypeByName2, [:pointer, :string], :pointer
107
+
108
+ # Determine whether a structure is packed.
109
+ #
110
+ # @see llvm::StructType::isPacked()
111
+ #
112
+ # @method is_packed_struct(struct_ty)
113
+ # @param [FFI::Pointer(TypeRef)] struct_ty
114
+ # @return [Bool]
115
+ # @scope class
116
+ attach_function :is_packed_struct, :LLVMIsPackedStruct, [:pointer], :bool
117
+
118
+ # Determine whether a structure is opaque.
119
+ #
120
+ # @see llvm::StructType::isOpaque()
121
+ #
122
+ # @method is_opaque_struct(struct_ty)
123
+ # @param [FFI::Pointer(TypeRef)] struct_ty
124
+ # @return [Bool]
125
+ # @scope class
126
+ attach_function :is_opaque_struct, :LLVMIsOpaqueStruct, [:pointer], :bool
127
+
128
+ # Determine whether a structure is literal.
129
+ #
130
+ # @see llvm::StructType::isLiteral()
131
+ #
132
+ # @method is_literal_struct(struct_ty)
133
+ # @param [FFI::Pointer(TypeRef)] struct_ty
134
+ # @return [Bool]
135
+ # @scope class
136
+ attach_function :is_literal_struct, :LLVMIsLiteralStruct, [:pointer], :bool
105
137
  end
106
138
 
107
139
  # Yields a pointer suitable for storing an LLVM output message.
data/lib/llvm/core_ffi.rb CHANGED
@@ -1651,26 +1651,6 @@ module LLVM::C
1651
1651
  # @scope class
1652
1652
  attach_function :struct_get_type_at_index, :LLVMStructGetTypeAtIndex, [:pointer, :uint], :pointer
1653
1653
 
1654
- # Determine whether a structure is packed.
1655
- #
1656
- # @see llvm::StructType::isPacked()
1657
- #
1658
- # @method is_packed_struct(struct_ty)
1659
- # @param [FFI::Pointer(TypeRef)] struct_ty
1660
- # @return [Integer]
1661
- # @scope class
1662
- attach_function :is_packed_struct, :LLVMIsPackedStruct, [:pointer], :int
1663
-
1664
- # Determine whether a structure is opaque.
1665
- #
1666
- # @see llvm::StructType::isOpaque()
1667
- #
1668
- # @method is_opaque_struct(struct_ty)
1669
- # @param [FFI::Pointer(TypeRef)] struct_ty
1670
- # @return [Integer]
1671
- # @scope class
1672
- attach_function :is_opaque_struct, :LLVMIsOpaqueStruct, [:pointer], :int
1673
-
1674
1654
  # Obtain the type of elements within a sequential type.
1675
1655
  #
1676
1656
  # This works on array, vector, and pointer types.
data/lib/llvm/version.rb CHANGED
@@ -3,5 +3,5 @@
3
3
  module LLVM
4
4
  LLVM_VERSION = "15"
5
5
  LLVM_REQUIRED_VERSION = "15.0"
6
- RUBY_LLVM_VERSION = "15.0.1"
6
+ RUBY_LLVM_VERSION = "15.0.2"
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: 15.0.1
4
+ version: 15.0.2
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-12-03 00:00:00.000000000 Z
12
+ date: 2023-01-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi