ruby-llvm 15.0.3 → 15.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/llvm/analysis.rb +9 -1
- data/lib/llvm/core/bitcode.rb +22 -0
- data/lib/llvm/core/builder.rb +2 -0
- data/lib/llvm/core/module.rb +10 -0
- data/lib/llvm/core/value.rb +87 -8
- data/lib/llvm/core.rb +50 -0
- data/lib/llvm/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a9606baaed260920d087cafdc03a4524875a11378d9e15792128ec7df9946c7b
|
4
|
+
data.tar.gz: 0fba76718a8f7dfd2ee63993eb9ceecb94d0feb75d286997a3dc651ac966ecf7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c095bf095482f67ca94efc4e36c7d04fb5f82f65b9a483c79239e9bcb91fa4da0f6ed76b77259140a9d17e3a268d77fb05899b59a7469d5d664d808ff8be53a
|
7
|
+
data.tar.gz: 88b3dae5b535fdf9d7a6cd0225e3b809b7f54c2d072668516e53a18298953a9d4daa68669e7b01ddb0ddb03a044975828741eecf47b3683f66bfa229e44d3ead
|
data/lib/llvm/analysis.rb
CHANGED
@@ -20,6 +20,10 @@ module LLVM
|
|
20
20
|
do_verification(:abort_process)
|
21
21
|
end
|
22
22
|
|
23
|
+
def valid?
|
24
|
+
verify.nil?
|
25
|
+
end
|
26
|
+
|
23
27
|
private
|
24
28
|
|
25
29
|
def do_verification(action)
|
@@ -42,10 +46,14 @@ module LLVM
|
|
42
46
|
do_verification(:abort_process)
|
43
47
|
end
|
44
48
|
|
49
|
+
def valid?
|
50
|
+
verify
|
51
|
+
end
|
52
|
+
|
45
53
|
private
|
46
54
|
|
47
55
|
def do_verification(action)
|
48
|
-
C.verify_function(self, action)
|
56
|
+
C.verify_function(self, action).zero?
|
49
57
|
end
|
50
58
|
end
|
51
59
|
end
|
data/lib/llvm/core/bitcode.rb
CHANGED
@@ -36,6 +36,28 @@ module LLVM
|
|
36
36
|
end
|
37
37
|
status == 0
|
38
38
|
end
|
39
|
+
|
40
|
+
def self.parse_ir(path_or_memory_buffer, context = Context.global)
|
41
|
+
memory_buffer = case path_or_memory_buffer
|
42
|
+
when MemoryBuffer then path_or_memory_buffer
|
43
|
+
else MemoryBuffer.from_file(path_or_memory_buffer)
|
44
|
+
end
|
45
|
+
FFI::MemoryPointer.new(:pointer) do |mod_ref|
|
46
|
+
FFI::MemoryPointer.new(:pointer) do |msg_ref|
|
47
|
+
status = C.parse_ir_in_context(context, memory_buffer, mod_ref, msg_ref)
|
48
|
+
raise msg_ref.get_pointer(0).get_string(0) if status
|
49
|
+
return from_ptr(mod_ref.get_pointer(0))
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def write_ir!(filename)
|
55
|
+
FFI::MemoryPointer.new(:pointer) do |msg_ref|
|
56
|
+
status = C.print_module_to_file(self, filename, msg_ref)
|
57
|
+
raise msg_ref.get_pointer(0).get_string(0) if status != 0
|
58
|
+
end
|
59
|
+
self
|
60
|
+
end
|
39
61
|
end
|
40
62
|
|
41
63
|
# @private
|
data/lib/llvm/core/builder.rb
CHANGED
@@ -563,6 +563,7 @@ module LLVM
|
|
563
563
|
# @return [LLVM::Instruction] The resulting pointer
|
564
564
|
# @LLVMinst gep
|
565
565
|
# @see http://llvm.org/docs/GetElementPtr.html
|
566
|
+
# may return Instruction or GlobalVariable
|
566
567
|
def gep(ptr, indices, name = "")
|
567
568
|
gep2(nil, ptr, indices, name)
|
568
569
|
end
|
@@ -576,6 +577,7 @@ module LLVM
|
|
576
577
|
# @return [LLVM::Instruction] The resulting pointer
|
577
578
|
# @LLVMinst gep2
|
578
579
|
# @see http://llvm.org/docs/GetElementPtr.html
|
580
|
+
# may return Instruction or GlobalVariable
|
579
581
|
def gep2(type, ptr, indices, name)
|
580
582
|
must_be_value!(ptr)
|
581
583
|
|
data/lib/llvm/core/module.rb
CHANGED
@@ -24,6 +24,16 @@ module LLVM
|
|
24
24
|
@ptr = nil
|
25
25
|
end
|
26
26
|
|
27
|
+
def inspect
|
28
|
+
{
|
29
|
+
triple: triple,
|
30
|
+
globals: globals.count,
|
31
|
+
functions: functions.count,
|
32
|
+
lines: to_s.lines.size,
|
33
|
+
valid: valid?,
|
34
|
+
}.to_s
|
35
|
+
end
|
36
|
+
|
27
37
|
# Get module triple.
|
28
38
|
#
|
29
39
|
# @return [String]
|
data/lib/llvm/core/value.rb
CHANGED
@@ -12,6 +12,26 @@ module LLVM
|
|
12
12
|
val
|
13
13
|
end
|
14
14
|
|
15
|
+
def self.from_ptr_kind(ptr)
|
16
|
+
return if ptr.null?
|
17
|
+
|
18
|
+
kind = C.get_value_kind(ptr)
|
19
|
+
case kind
|
20
|
+
when :instruction
|
21
|
+
Instruction.from_ptr(ptr)
|
22
|
+
when :const_int
|
23
|
+
Int.from_ptr(ptr)
|
24
|
+
when :const_fp
|
25
|
+
Float.from_ptr(ptr)
|
26
|
+
when :poison
|
27
|
+
Poison.from_ptr(ptr)
|
28
|
+
when :global_variable
|
29
|
+
GlobalValue.from_ptr(ptr)
|
30
|
+
else
|
31
|
+
raise "from_ptr_kind cannot handle: #{kind}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
15
35
|
# Returns the Value type. This is abstract and is overidden by its subclasses.
|
16
36
|
def self.type
|
17
37
|
raise NotImplementedError, "#{name}.type() is abstract."
|
@@ -26,6 +46,11 @@ module LLVM
|
|
26
46
|
Type.from_ptr(C.type_of(self), nil)
|
27
47
|
end
|
28
48
|
|
49
|
+
# Returns the value's kind.
|
50
|
+
def kind
|
51
|
+
C.get_value_kind(self)
|
52
|
+
end
|
53
|
+
|
29
54
|
def allocated_type
|
30
55
|
Type.from_ptr(C.get_allocated_type(self), nil)
|
31
56
|
end
|
@@ -412,22 +437,22 @@ module LLVM
|
|
412
437
|
|
413
438
|
# Unsigned division.
|
414
439
|
def udiv(rhs)
|
415
|
-
|
440
|
+
raise "constant udiv removed in LLVM 15"
|
416
441
|
end
|
417
442
|
|
418
443
|
# Signed division.
|
419
444
|
def /(rhs)
|
420
|
-
|
445
|
+
raise "constant sdiv removed in LLVM 15"
|
421
446
|
end
|
422
447
|
|
423
448
|
# Unsigned remainder.
|
424
449
|
def urem(rhs)
|
425
|
-
|
450
|
+
raise "constant urem removed in LLVM 15"
|
426
451
|
end
|
427
452
|
|
428
453
|
# Signed remainder.
|
429
454
|
def rem(rhs)
|
430
|
-
|
455
|
+
raise "constant srem removed in LLVM 15"
|
431
456
|
end
|
432
457
|
|
433
458
|
# Boolean negation.
|
@@ -507,6 +532,17 @@ module LLVM
|
|
507
532
|
def sext(type)
|
508
533
|
self.class.from_ptr(C.const_s_ext(self, type))
|
509
534
|
end
|
535
|
+
alias_method :ext, :sext
|
536
|
+
|
537
|
+
# constant trunc
|
538
|
+
def trunc(type)
|
539
|
+
self.class.from_ptr(C.const_trunc(self, type))
|
540
|
+
end
|
541
|
+
|
542
|
+
# LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
|
543
|
+
def to_f(type)
|
544
|
+
self.class.from_ptr(C.const_si_to_fp(self, type))
|
545
|
+
end
|
510
546
|
end
|
511
547
|
|
512
548
|
def self.const_missing(const)
|
@@ -564,22 +600,22 @@ module LLVM
|
|
564
600
|
|
565
601
|
# Returns the result of adding this ConstantReal to rhs.
|
566
602
|
def +(rhs)
|
567
|
-
|
603
|
+
raise "constant fadd removed in LLVM 15"
|
568
604
|
end
|
569
605
|
|
570
606
|
# Returns the result of multiplying this ConstantReal by rhs.
|
571
607
|
def *(rhs)
|
572
|
-
|
608
|
+
raise "constant fmul removed in LLVM 15"
|
573
609
|
end
|
574
610
|
|
575
611
|
# Returns the result of dividing this ConstantReal by rhs.
|
576
612
|
def /(rhs)
|
577
|
-
|
613
|
+
raise "constant fdiv removed in LLVM 15"
|
578
614
|
end
|
579
615
|
|
580
616
|
# Remainder.
|
581
617
|
def rem(rhs)
|
582
|
-
|
618
|
+
raise "constant frem removed in LLVM 15"
|
583
619
|
end
|
584
620
|
|
585
621
|
# Floating point comparison using the predicate specified via the first
|
@@ -603,6 +639,24 @@ module LLVM
|
|
603
639
|
def fcmp(pred, rhs)
|
604
640
|
self.class.from_ptr(C.llmv_const_f_cmp(pred, self, rhs))
|
605
641
|
end
|
642
|
+
|
643
|
+
# constant FPToSI
|
644
|
+
# LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType);
|
645
|
+
def to_i(type)
|
646
|
+
self.class.from_ptr(C.const_fp_to_si(self, type))
|
647
|
+
end
|
648
|
+
|
649
|
+
# Constant FPExt
|
650
|
+
# this is a signed extension
|
651
|
+
def ext(type)
|
652
|
+
self.class.from_ptr(C.const_fp_ext(self, type))
|
653
|
+
end
|
654
|
+
alias_method :sext, :ext
|
655
|
+
|
656
|
+
def trunc(type)
|
657
|
+
self.class.from_ptr(C.const_fp_trunc(self, type))
|
658
|
+
end
|
659
|
+
|
606
660
|
end
|
607
661
|
|
608
662
|
class Float < ConstantReal
|
@@ -939,6 +993,17 @@ module LLVM
|
|
939
993
|
def gc
|
940
994
|
C.get_gc(self)
|
941
995
|
end
|
996
|
+
|
997
|
+
def inspect
|
998
|
+
{
|
999
|
+
signature: to_s.lines[attribute_count == 0 ? 0 : 1],
|
1000
|
+
type: type.to_s,
|
1001
|
+
attributes: attribute_count,
|
1002
|
+
valid: valid?,
|
1003
|
+
blocks: basic_blocks.size,
|
1004
|
+
lines: to_s.lines.size,
|
1005
|
+
}.to_s
|
1006
|
+
end
|
942
1007
|
end
|
943
1008
|
|
944
1009
|
class GlobalAlias < GlobalValue
|
@@ -966,6 +1031,12 @@ module LLVM
|
|
966
1031
|
end
|
967
1032
|
|
968
1033
|
class Instruction < User
|
1034
|
+
|
1035
|
+
def self.from_ptr(ptr)
|
1036
|
+
kind = C.get_value_kind(ptr)
|
1037
|
+
kind == :instruction ? super : LLVM::Value.from_ptr_kind(ptr)
|
1038
|
+
end
|
1039
|
+
|
969
1040
|
# Returns the parent of the instruction (a BasicBlock).
|
970
1041
|
def parent
|
971
1042
|
ptr = C.get_instruction_parent(self)
|
@@ -987,6 +1058,14 @@ module LLVM
|
|
987
1058
|
def opcode
|
988
1059
|
C.get_instruction_opcode(self)
|
989
1060
|
end
|
1061
|
+
|
1062
|
+
def inspect
|
1063
|
+
{ self.class.name => { opcode: opcode, ptr: @ptr } }.to_s
|
1064
|
+
end
|
1065
|
+
end
|
1066
|
+
|
1067
|
+
class Poison < Value
|
1068
|
+
|
990
1069
|
end
|
991
1070
|
|
992
1071
|
class CallInst < Instruction
|
data/lib/llvm/core.rb
CHANGED
@@ -134,6 +134,56 @@ module LLVM
|
|
134
134
|
# @return [Bool]
|
135
135
|
# @scope class
|
136
136
|
attach_function :is_literal_struct, :LLVMIsLiteralStruct, [:pointer], :bool
|
137
|
+
|
138
|
+
# /**
|
139
|
+
# * Read LLVM IR from a memory buffer and convert it into an in-memory Module
|
140
|
+
# * object. Returns 0 on success.
|
141
|
+
# * Optionally returns a human-readable description of any errors that
|
142
|
+
# * occurred during parsing IR. OutMessage must be disposed with
|
143
|
+
# * LLVMDisposeMessage.
|
144
|
+
# *
|
145
|
+
# * @see llvm::ParseIR()
|
146
|
+
# */
|
147
|
+
# LLVMBool LLVMParseIRInContext(LLVMContextRef ContextRef,
|
148
|
+
# LLVMMemoryBufferRef MemBuf, LLVMModuleRef *OutM,
|
149
|
+
# char **OutMessage);
|
150
|
+
attach_function :parse_ir_in_context, :LLVMParseIRInContext, [:pointer, :pointer, :pointer, :pointer], :bool
|
151
|
+
|
152
|
+
enum :value_kind, [
|
153
|
+
:argument, 0,
|
154
|
+
:basic_block, 1,
|
155
|
+
:memory_use, 2,
|
156
|
+
:memory_def, 3,
|
157
|
+
:memory_phi, 4,
|
158
|
+
:function, 5,
|
159
|
+
:global_alias, 6,
|
160
|
+
:global_ifunc, 7,
|
161
|
+
:global_variable, 8,
|
162
|
+
:block_address, 9,
|
163
|
+
:const_expr, 10,
|
164
|
+
:const_array, 11,
|
165
|
+
:const_struct, 12,
|
166
|
+
:const_vector, 13,
|
167
|
+
:undef, 14,
|
168
|
+
:const_aggregregate_zero, 15,
|
169
|
+
:const_data_array, 16,
|
170
|
+
:const_data_vector, 17,
|
171
|
+
:const_int, 18,
|
172
|
+
:const_fp, 19,
|
173
|
+
:const_null, 20,
|
174
|
+
:const_none, 21,
|
175
|
+
:metadata, 22,
|
176
|
+
:inline_asm, 23,
|
177
|
+
:instruction, 24,
|
178
|
+
:poison, 25,
|
179
|
+
]
|
180
|
+
|
181
|
+
# /**
|
182
|
+
# * Obtain the enumerated type of a Value instance.
|
183
|
+
# *
|
184
|
+
# * @see llvm::Value::getValueID()
|
185
|
+
# */
|
186
|
+
attach_function :get_value_kind, :LLVMGetValueKind, [:pointer], :value_kind
|
137
187
|
end
|
138
188
|
|
139
189
|
# Yields a pointer suitable for storing an LLVM output message.
|
data/lib/llvm/version.rb
CHANGED
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.
|
4
|
+
version: 15.0.4
|
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: 2023-
|
12
|
+
date: 2023-05-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|