ruby-llvm 18.1.8 → 18.2.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.
- checksums.yaml +4 -4
- data/ext/ruby-llvm-support/Rakefile +0 -1
- data/lib/llvm/config.rb +6 -5
- data/lib/llvm/core/attribute.rb +0 -4
- data/lib/llvm/core/builder.rb +66 -19
- data/lib/llvm/core/module.rb +1 -2
- data/lib/llvm/core/type.rb +150 -13
- data/lib/llvm/core/value.rb +200 -153
- data/lib/llvm/core.rb +2 -199
- data/lib/llvm/core_ffi.rb +0 -42
- data/lib/llvm/core_ffi_v2.rb +353 -0
- data/lib/llvm/execution_engine.rb +1 -1
- data/lib/llvm/lljit.rb +0 -1
- data/lib/llvm/{transforms/pass_builder.rb → pass_builder.rb} +45 -16
- data/lib/llvm/support.rb +0 -1
- data/lib/llvm/target_ffi.rb +0 -1
- data/lib/llvm/transforms/ipo.rb +0 -1
- data/lib/llvm/transforms/scalar.rb +0 -1
- data/lib/llvm/transforms/utils.rb +0 -1
- data/lib/llvm/version.rb +1 -1
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e48eb7aeebc6f8fb6de9c900065168d2b2ed555ca4e294bf1a96e47959344069
|
4
|
+
data.tar.gz: c61c5cbf456724538e18cbc9b70660fba586e9af8cc5811a98e74f589166e808
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faac90c796d9eab92633734c0c323a1b959118ae4558c7ac2dbffbe3f019dc64b876de72a678ced189a31b2fa34cd04fe7d3352cb3571638618c181844186f33
|
7
|
+
data.tar.gz: 7a3549ffad064a6aedfe6a84146ab4be41434d093c5856315d49ca854bd8ba17bd0bd543e9c396b292b399ddcfd230d35cbfbb302c6cdde2642532b923bc7ea9
|
data/lib/llvm/config.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
# Generated by ruby-llvm. Please do not change this file by hand.
|
2
2
|
module LLVM
|
3
3
|
module CONFIG
|
4
|
-
VERSION = "
|
5
|
-
COMPONENTS = ["aarch64", "aarch64asmparser", "aarch64codegen", "aarch64desc", "aarch64disassembler", "aarch64info", "aarch64utils", "aggressiveinstcombine", "all", "all-targets", "amdgpu", "amdgpuasmparser", "amdgpucodegen", "amdgpudesc", "amdgpudisassembler", "amdgpuinfo", "amdgputargetmca", "amdgpuutils", "analysis", "arm", "armasmparser", "armcodegen", "armdesc", "armdisassembler", "arminfo", "armutils", "asmparser", "asmprinter", "avr", "avrasmparser", "avrcodegen", "avrdesc", "avrdisassembler", "avrinfo", "binaryformat", "bitreader", "bitstreamreader", "bitwriter", "bpf", "bpfasmparser", "bpfcodegen", "bpfdesc", "bpfdisassembler", "bpfinfo", "cfguard", "codegen", "codegentypes", "core", "coroutines", "coverage", "debuginfobtf", "debuginfocodeview", "debuginfodwarf", "debuginfogsym", "debuginfologicalview", "debuginfomsf", "debuginfopdb", "demangle", "dlltooldriver", "dwarflinker", "dwarflinkerclassic", "dwarflinkerparallel", "dwp", "engine", "executionengine", "extensions", "filecheck", "frontenddriver", "frontendhlsl", "frontendoffloading", "frontendopenacc", "frontendopenmp", "fuzzercli", "fuzzmutate", "globalisel", "hexagon", "hexagonasmparser", "hexagoncodegen", "hexagondesc", "hexagondisassembler", "hexagoninfo", "hipstdpar", "instcombine", "instrumentation", "interfacestub", "interpreter", "ipo", "irprinter", "irreader", "jitlink", "lanai", "lanaiasmparser", "lanaicodegen", "lanaidesc", "lanaidisassembler", "lanaiinfo", "libdriver", "lineeditor", "linker", "loongarch", "loongarchasmparser", "loongarchcodegen", "loongarchdesc", "loongarchdisassembler", "loongarchinfo", "lto", "m68k", "m68kasmparser", "m68kcodegen", "m68kdesc", "m68kdisassembler", "m68kinfo", "mc", "mca", "mcdisassembler", "mcjit", "mcparser", "mips", "mipsasmparser", "mipscodegen", "mipsdesc", "mipsdisassembler", "mipsinfo", "mirparser", "msp430", "msp430asmparser", "msp430codegen", "msp430desc", "msp430disassembler", "msp430info", "native", "nativecodegen", "nvptx", "nvptxcodegen", "nvptxdesc", "nvptxinfo", "objcarcopts", "objcopy", "object", "objectyaml", "option", "orcdebugging", "orcjit", "orcshared", "orctargetprocess", "passes", "perfjitevents", "powerpc", "powerpcasmparser", "powerpccodegen", "powerpcdesc", "powerpcdisassembler", "powerpcinfo", "profiledata", "remarks", "riscv", "riscvasmparser", "riscvcodegen", "riscvdesc", "riscvdisassembler", "riscvinfo", "riscvtargetmca", "runtimedyld", "scalaropts", "selectiondag", "sparc", "sparcasmparser", "sparccodegen", "sparcdesc", "sparcdisassembler", "sparcinfo", "support", "symbolize", "systemz", "systemzasmparser", "systemzcodegen", "systemzdesc", "systemzdisassembler", "systemzinfo", "tablegen", "target", "targetparser", "textapi", "textapibinaryreader", "transformutils", "ve", "veasmparser", "vecodegen", "vectorize", "vedesc", "vedisassembler", "veinfo", "webassembly", "webassemblyasmparser", "webassemblycodegen", "webassemblydesc", "webassemblydisassembler", "webassemblyinfo", "webassemblyutils", "windowsdriver", "windowsmanifest", "x86", "x86asmparser", "x86codegen", "x86desc", "x86disassembler", "x86info", "x86targetmca", "xcore", "xcorecodegen", "xcoredesc", "xcoredisassembler", "xcoreinfo", "xray", "xtensa", "xtensaasmparser", "xtensacodegen", "xtensadesc", "xtensadisassembler", "xtensainfo"]
|
4
|
+
VERSION = "19.1.0"
|
5
|
+
COMPONENTS = ["aarch64", "aarch64asmparser", "aarch64codegen", "aarch64desc", "aarch64disassembler", "aarch64info", "aarch64utils", "aggressiveinstcombine", "all", "all-targets", "amdgpu", "amdgpuasmparser", "amdgpucodegen", "amdgpudesc", "amdgpudisassembler", "amdgpuinfo", "amdgputargetmca", "amdgpuutils", "analysis", "arm", "armasmparser", "armcodegen", "armdesc", "armdisassembler", "arminfo", "armutils", "asmparser", "asmprinter", "avr", "avrasmparser", "avrcodegen", "avrdesc", "avrdisassembler", "avrinfo", "binaryformat", "bitreader", "bitstreamreader", "bitwriter", "bpf", "bpfasmparser", "bpfcodegen", "bpfdesc", "bpfdisassembler", "bpfinfo", "cfguard", "codegen", "codegendata", "codegentypes", "core", "coroutines", "coverage", "debuginfobtf", "debuginfocodeview", "debuginfodwarf", "debuginfogsym", "debuginfologicalview", "debuginfomsf", "debuginfopdb", "demangle", "dlltooldriver", "dwarflinker", "dwarflinkerclassic", "dwarflinkerparallel", "dwp", "engine", "executionengine", "extensions", "filecheck", "frontenddriver", "frontendhlsl", "frontendoffloading", "frontendopenacc", "frontendopenmp", "fuzzercli", "fuzzmutate", "globalisel", "hexagon", "hexagonasmparser", "hexagoncodegen", "hexagondesc", "hexagondisassembler", "hexagoninfo", "hipstdpar", "instcombine", "instrumentation", "interfacestub", "interpreter", "ipo", "irprinter", "irreader", "jitlink", "lanai", "lanaiasmparser", "lanaicodegen", "lanaidesc", "lanaidisassembler", "lanaiinfo", "libdriver", "lineeditor", "linker", "loongarch", "loongarchasmparser", "loongarchcodegen", "loongarchdesc", "loongarchdisassembler", "loongarchinfo", "lto", "m68k", "m68kasmparser", "m68kcodegen", "m68kdesc", "m68kdisassembler", "m68kinfo", "mc", "mca", "mcdisassembler", "mcjit", "mcparser", "mips", "mipsasmparser", "mipscodegen", "mipsdesc", "mipsdisassembler", "mipsinfo", "mirparser", "msp430", "msp430asmparser", "msp430codegen", "msp430desc", "msp430disassembler", "msp430info", "native", "nativecodegen", "nvptx", "nvptxcodegen", "nvptxdesc", "nvptxinfo", "objcarcopts", "objcopy", "object", "objectyaml", "option", "orcdebugging", "orcjit", "orcshared", "orctargetprocess", "passes", "perfjitevents", "powerpc", "powerpcasmparser", "powerpccodegen", "powerpcdesc", "powerpcdisassembler", "powerpcinfo", "profiledata", "remarks", "riscv", "riscvasmparser", "riscvcodegen", "riscvdesc", "riscvdisassembler", "riscvinfo", "riscvtargetmca", "runtimedyld", "sandboxir", "scalaropts", "selectiondag", "sparc", "sparcasmparser", "sparccodegen", "sparcdesc", "sparcdisassembler", "sparcinfo", "support", "symbolize", "systemz", "systemzasmparser", "systemzcodegen", "systemzdesc", "systemzdisassembler", "systemzinfo", "tablegen", "target", "targetparser", "textapi", "textapibinaryreader", "transformutils", "ve", "veasmparser", "vecodegen", "vectorize", "vedesc", "vedisassembler", "veinfo", "webassembly", "webassemblyasmparser", "webassemblycodegen", "webassemblydesc", "webassemblydisassembler", "webassemblyinfo", "webassemblyutils", "windowsdriver", "windowsmanifest", "x86", "x86asmparser", "x86codegen", "x86desc", "x86disassembler", "x86info", "x86targetmca", "xcore", "xcorecodegen", "xcoredesc", "xcoredisassembler", "xcoreinfo", "xray", "xtensa", "xtensaasmparser", "xtensacodegen", "xtensadesc", "xtensadisassembler", "xtensainfo"]
|
6
6
|
TARGETS_BUILT = ["AArch64", "AMDGPU", "ARM", "AVR", "BPF", "Hexagon", "Lanai", "LoongArch", "Mips", "MSP430", "NVPTX", "PowerPC", "RISCV", "Sparc", "SystemZ", "VE", "WebAssembly", "X86", "XCore", "M68k", "Xtensa"]
|
7
7
|
HOST_TARGET = "x86_64-pc-linux-gnu"
|
8
8
|
BUILD_MODE = "RelWithDebInfo"
|
9
|
-
CFLAGS = "-I/usr/lib/llvm-
|
10
|
-
CXXFLAGS = "-I/usr/lib/llvm-
|
11
|
-
LDFLAGS = "-L/usr/lib/llvm-
|
9
|
+
CFLAGS = "-I/usr/lib/llvm-19/include -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"
|
10
|
+
CXXFLAGS = "-I/usr/lib/llvm-19/include -std=c++17 -fno-exceptions -funwind-tables -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"
|
11
|
+
LDFLAGS = "-L/usr/lib/llvm-19/lib"
|
12
|
+
LIBS = "-lLLVM-19"
|
12
13
|
end
|
13
14
|
end
|
data/lib/llvm/core/attribute.rb
CHANGED
@@ -3,11 +3,9 @@
|
|
3
3
|
module LLVM
|
4
4
|
# wrapper for LLVMAttributeRef
|
5
5
|
class Attribute
|
6
|
-
|
7
6
|
include PointerIdentity
|
8
7
|
|
9
8
|
class << self
|
10
|
-
|
11
9
|
def new(from)
|
12
10
|
case from
|
13
11
|
when String, Symbol
|
@@ -89,7 +87,6 @@ module LLVM
|
|
89
87
|
0
|
90
88
|
end
|
91
89
|
end
|
92
|
-
|
93
90
|
end
|
94
91
|
|
95
92
|
def kind
|
@@ -188,6 +185,5 @@ module LLVM
|
|
188
185
|
return C.get_string_attribute_value(self, size_ptr)
|
189
186
|
end
|
190
187
|
end
|
191
|
-
|
192
188
|
end
|
193
189
|
end
|
data/lib/llvm/core/builder.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module LLVM
|
4
4
|
class Builder
|
5
|
+
extend Gem::Deprecate
|
6
|
+
|
5
7
|
# Important: Call #dispose to free backend memory after use.
|
6
8
|
def initialize
|
7
9
|
@ptr = C.create_builder()
|
@@ -494,9 +496,11 @@ module LLVM
|
|
494
496
|
# @param [String] name Name of the result in LLVM IR
|
495
497
|
# @return [LLVM::Instruction] The negated operand
|
496
498
|
# @LLVMinst sub
|
499
|
+
# @deprecated
|
497
500
|
def nuw_neg(arg, name = "")
|
498
501
|
Instruction.from_ptr(C.build_nuw_neg(self, arg, name))
|
499
502
|
end
|
503
|
+
deprecate :nuw_neg, "neg", 2025, 3
|
500
504
|
|
501
505
|
# Boolean negation.
|
502
506
|
# @param [LLVM::Value] arg Integer or vector of integers
|
@@ -520,7 +524,15 @@ module LLVM
|
|
520
524
|
# @param [String] name The name of the result in LLVM IR
|
521
525
|
# @return [LLVM::Instruction] A pointer to the malloced array
|
522
526
|
def array_malloc(ty, sz, name = "")
|
523
|
-
|
527
|
+
size = case sz
|
528
|
+
when LLVM::Value
|
529
|
+
sz
|
530
|
+
when Integer
|
531
|
+
LLVM.i(32, sz)
|
532
|
+
else
|
533
|
+
raise ArgumentError, "Unknown size parameter for array_malloc: #{sz}"
|
534
|
+
end
|
535
|
+
Instruction.from_ptr(C.build_array_malloc(self, LLVM::Type(ty), size, name))
|
524
536
|
end
|
525
537
|
|
526
538
|
# Stack allocation.
|
@@ -603,7 +615,7 @@ module LLVM
|
|
603
615
|
# @LLVMinst gep2
|
604
616
|
# @see http://llvm.org/docs/GetElementPtr.html
|
605
617
|
# may return Instruction or GlobalVariable
|
606
|
-
def gep2(type, ptr, indices, name)
|
618
|
+
def gep2(type, ptr, indices, name = '')
|
607
619
|
must_be_value!(ptr)
|
608
620
|
|
609
621
|
type ||= must_infer_type!(ptr)
|
@@ -633,7 +645,7 @@ module LLVM
|
|
633
645
|
def inbounds_gep2(type, ptr, indices, name = "")
|
634
646
|
must_be_value!(ptr)
|
635
647
|
|
636
|
-
type
|
648
|
+
type ||= must_infer_type!(ptr)
|
637
649
|
must_be_type!(type)
|
638
650
|
|
639
651
|
indices = Array(indices)
|
@@ -657,13 +669,13 @@ module LLVM
|
|
657
669
|
struct_gep2(nil, ptr, idx, name)
|
658
670
|
end
|
659
671
|
|
660
|
-
def struct_gep2(type, ptr, idx, name)
|
672
|
+
def struct_gep2(type, ptr, idx, name = "")
|
661
673
|
must_be_value!(ptr)
|
662
674
|
|
663
675
|
type ||= must_infer_type!(ptr)
|
664
676
|
must_be_type!(type)
|
665
677
|
|
666
|
-
ins = C.build_struct_gep2(self, type, ptr, idx, name)
|
678
|
+
ins = C.build_struct_gep2(self, type, ptr, idx.to_i, name)
|
667
679
|
Instruction.from_ptr(ins)
|
668
680
|
end
|
669
681
|
|
@@ -853,6 +865,7 @@ module LLVM
|
|
853
865
|
# @param [LLVM::Type, #ty] ty
|
854
866
|
# @param [String] name The name of the result in LLVM IR
|
855
867
|
# @return [LLVM::Instruction]
|
868
|
+
# Cast pointer to other type
|
856
869
|
def pointer_cast(val, ty, name = "")
|
857
870
|
Instruction.from_ptr(C.build_pointer_cast(self, val, LLVM::Type(ty), name))
|
858
871
|
end
|
@@ -865,6 +878,15 @@ module LLVM
|
|
865
878
|
Instruction.from_ptr(C.build_int_cast(self, val, LLVM::Type(ty), name))
|
866
879
|
end
|
867
880
|
|
881
|
+
# @param [LLVM::Value] val
|
882
|
+
# @param [LLVM::Type, #ty] ty
|
883
|
+
# @param [String] name The name of the result in LLVM IR
|
884
|
+
# @param [bool] signed whether to sign or zero extend
|
885
|
+
# @return [LLVM::Instruction]
|
886
|
+
def int_cast2(val, ty, signed, name = "")
|
887
|
+
Instruction.from_ptr(C.build_int_cast2(self, val, LLVM::Type(ty), signed, name))
|
888
|
+
end
|
889
|
+
|
868
890
|
# @param [LLVM::Value] val
|
869
891
|
# @param [LLVM::Type, #ty] ty
|
870
892
|
# @param [String] name The name of the result in LLVM IR
|
@@ -1013,6 +1035,8 @@ module LLVM
|
|
1013
1035
|
# @return [LLVM::Instruction] The extracted element
|
1014
1036
|
# @LLVMinst extractelement
|
1015
1037
|
def extract_element(vector, idx, name = "")
|
1038
|
+
must_be_value!(vector)
|
1039
|
+
must_be_value!(idx)
|
1016
1040
|
error = element_error(vector, idx)
|
1017
1041
|
|
1018
1042
|
raise ArgumentError, "Error building extract_element with #{error}" if error
|
@@ -1029,12 +1053,11 @@ module LLVM
|
|
1029
1053
|
# @return [LLVM::Instruction] A vector the same type as 'vector'
|
1030
1054
|
# @LLVMinst insertelement
|
1031
1055
|
def insert_element(vector, elem, idx, name = "")
|
1056
|
+
must_be_value!(vector)
|
1057
|
+
must_be_value!(elem)
|
1058
|
+
must_be_value!(idx)
|
1032
1059
|
error = element_error(vector, idx)
|
1033
1060
|
|
1034
|
-
error ||= if !elem.is_a?(LLVM::Value)
|
1035
|
-
"elem: #{elem.inspect}"
|
1036
|
-
end
|
1037
|
-
|
1038
1061
|
raise ArgumentError, "Error building insert_element with #{error}" if error
|
1039
1062
|
|
1040
1063
|
ins = C.build_insert_element(self, vector, elem, idx, name)
|
@@ -1060,6 +1083,7 @@ module LLVM
|
|
1060
1083
|
# @return [LLVM::Instruction] The extracted value
|
1061
1084
|
# @LLVMinst extractvalue
|
1062
1085
|
def extract_value(aggregate, idx, name = "")
|
1086
|
+
must_be_value!(aggregate)
|
1063
1087
|
error = value_error(aggregate, idx)
|
1064
1088
|
|
1065
1089
|
raise ArgumentError, "Error building extract_value with #{error}" if error
|
@@ -1076,12 +1100,10 @@ module LLVM
|
|
1076
1100
|
# @return [LLVM::Instruction] An aggregate value of the same type as 'aggregate'
|
1077
1101
|
# @LLVMinst insertvalue
|
1078
1102
|
def insert_value(aggregate, elem, idx, name = "")
|
1103
|
+
must_be_value!(aggregate)
|
1104
|
+
must_be_value!(elem)
|
1079
1105
|
error = value_error(aggregate, idx)
|
1080
1106
|
|
1081
|
-
error ||= if !elem.is_a?(LLVM::Value)
|
1082
|
-
"elem: #{elem.inspect}"
|
1083
|
-
end
|
1084
|
-
|
1085
1107
|
raise ArgumentError, "Error building insert_value with #{error}" if error
|
1086
1108
|
|
1087
1109
|
ins = C.build_insert_value(self, aggregate, elem, idx, name)
|
@@ -1111,18 +1133,34 @@ module LLVM
|
|
1111
1133
|
# @return [LLVM::Instruction] The integer difference between the two
|
1112
1134
|
# pointers
|
1113
1135
|
def ptr_diff(lhs, rhs, name = "")
|
1114
|
-
|
1136
|
+
ptr_diff2(nil, lhs, rhs, name)
|
1137
|
+
end
|
1138
|
+
|
1139
|
+
def ptr_diff2(type, lhs, rhs, name = "")
|
1140
|
+
must_be_value!(lhs)
|
1141
|
+
must_be_value!(rhs)
|
1142
|
+
|
1143
|
+
type ||= begin
|
1144
|
+
lhs_type = must_infer_type!(lhs)
|
1145
|
+
rhs_type = must_infer_type!(lhs)
|
1146
|
+
raise ArgumentError, "ptr_diff types must match: [#{lhs_type}] [#{rhs_type}]" if lhs_type != rhs_type
|
1147
|
+
|
1148
|
+
lhs_type
|
1149
|
+
end
|
1150
|
+
must_be_type!(type)
|
1151
|
+
|
1152
|
+
Instruction.from_ptr(C.build_ptr_diff2(self, type, lhs, rhs, name))
|
1115
1153
|
end
|
1116
1154
|
|
1117
1155
|
private
|
1118
1156
|
|
1119
1157
|
def must_be_value!(value)
|
1120
|
-
raise "must be a Value, got #{value.class.name}" unless Value === value
|
1158
|
+
raise ArgumentError, "must be a Value, got #{value.class.name}" unless Value === value
|
1121
1159
|
end
|
1122
1160
|
|
1123
1161
|
def must_be_type!(type)
|
1124
1162
|
type2 = LLVM.Type(type)
|
1125
|
-
raise "must be a Type (LLVMTypeRef), got #{type2.class.name}" unless Type === type2
|
1163
|
+
raise ArgumentError, "must be a Type (LLVMTypeRef), got #{type2.class.name}" unless Type === type2
|
1126
1164
|
end
|
1127
1165
|
|
1128
1166
|
def must_infer_type!(value)
|
@@ -1136,7 +1174,7 @@ module LLVM
|
|
1136
1174
|
when Instruction
|
1137
1175
|
must_infer_instruction_type!(ptr)
|
1138
1176
|
else
|
1139
|
-
raise "#{ptr
|
1177
|
+
raise ArgumentError, "Cannot infer type from [#{ptr}] with type [#{ptr.type}]"
|
1140
1178
|
end
|
1141
1179
|
end
|
1142
1180
|
|
@@ -1145,7 +1183,7 @@ module LLVM
|
|
1145
1183
|
when :get_element_ptr
|
1146
1184
|
must_infer_gep!(ptr)
|
1147
1185
|
when :alloca
|
1148
|
-
|
1186
|
+
ptr.allocated_type
|
1149
1187
|
when :load
|
1150
1188
|
ptr.type
|
1151
1189
|
else
|
@@ -1163,23 +1201,32 @@ module LLVM
|
|
1163
1201
|
when :array, :vector
|
1164
1202
|
source_type.element_type
|
1165
1203
|
else
|
1166
|
-
|
1204
|
+
raise ArgumentError
|
1167
1205
|
end
|
1168
1206
|
end
|
1169
1207
|
|
1170
1208
|
def element_error(vector, idx)
|
1171
1209
|
if !vector.is_a?(LLVM::Value)
|
1210
|
+
# :nocov:
|
1211
|
+
# already handled
|
1172
1212
|
"non-value: #{vector.inspect}"
|
1213
|
+
# :nocov:
|
1173
1214
|
elsif vector.type.kind != :vector
|
1174
1215
|
"non-vector: #{vector.type.kind}"
|
1175
1216
|
elsif !idx.is_a?(LLVM::Value)
|
1217
|
+
# :nocov:
|
1218
|
+
# already handled
|
1176
1219
|
"index: #{idx}"
|
1220
|
+
# :nocov:
|
1177
1221
|
end
|
1178
1222
|
end
|
1179
1223
|
|
1180
1224
|
def value_error(aggregate, idx)
|
1181
1225
|
if !aggregate.is_a?(LLVM::Value)
|
1226
|
+
# :nocov:
|
1227
|
+
# already handled
|
1182
1228
|
"non-value: #{aggregate.inspect}"
|
1229
|
+
# :nocov:
|
1183
1230
|
# TODO: fix this
|
1184
1231
|
elsif !aggregate.type.aggregate?
|
1185
1232
|
"non-aggregate: #{aggregate.type.kind}"
|
data/lib/llvm/core/module.rb
CHANGED
@@ -81,7 +81,7 @@ module LLVM
|
|
81
81
|
Type.from_ptr(C.get_type_by_name(@module, name.to_s), nil)
|
82
82
|
end
|
83
83
|
|
84
|
-
|
84
|
+
alias_method :[], :named
|
85
85
|
end
|
86
86
|
|
87
87
|
# Returns an Enumerable of all the GlobalVariables in the module.
|
@@ -251,6 +251,5 @@ module LLVM
|
|
251
251
|
def dump
|
252
252
|
C.dump_module(self)
|
253
253
|
end
|
254
|
-
|
255
254
|
end
|
256
255
|
end
|
data/lib/llvm/core/type.rb
CHANGED
@@ -11,6 +11,8 @@ module LLVM
|
|
11
11
|
ty = case kind
|
12
12
|
when :integer
|
13
13
|
IntType.allocate
|
14
|
+
when :float, :double
|
15
|
+
RealType.allocate
|
14
16
|
when :function
|
15
17
|
FunctionType.allocate
|
16
18
|
when :struct
|
@@ -24,9 +26,7 @@ module LLVM
|
|
24
26
|
end
|
25
27
|
|
26
28
|
# Returns a symbol representation of the types kind (ex. :pointer, :vector, :array.)
|
27
|
-
|
28
|
-
@kind
|
29
|
-
end
|
29
|
+
attr_reader :kind
|
30
30
|
|
31
31
|
# Returns the size of the type.
|
32
32
|
def size
|
@@ -46,7 +46,7 @@ module LLVM
|
|
46
46
|
when :pointer
|
47
47
|
LLVM.Void
|
48
48
|
else
|
49
|
-
raise "element_type not supported for kind: #{kind}"
|
49
|
+
raise ArgumentError, "element_type not supported for kind: #{kind}"
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -57,11 +57,18 @@ module LLVM
|
|
57
57
|
|
58
58
|
# Returns a null ConstantExpr of this type.
|
59
59
|
def null
|
60
|
-
ConstantExpr.from_ptr(C.const_null(self))
|
60
|
+
# ConstantExpr.from_ptr(C.const_null(self))
|
61
|
+
Constant.null(self)
|
61
62
|
end
|
62
63
|
|
63
64
|
def poison
|
64
|
-
ConstantExpr.from_ptr(C.get_poison(self))
|
65
|
+
# ConstantExpr.from_ptr(C.get_poison(self))
|
66
|
+
Constant.poison(self)
|
67
|
+
end
|
68
|
+
|
69
|
+
def undef
|
70
|
+
# ConstantExpr.from_ptr(C.get_undef(self))
|
71
|
+
Constant.undef(self)
|
65
72
|
end
|
66
73
|
|
67
74
|
# Creates a pointer type with this type and the given address space.
|
@@ -71,7 +78,9 @@ module LLVM
|
|
71
78
|
|
72
79
|
# Print the type's representation to stdout.
|
73
80
|
def dump
|
81
|
+
# :nocov:
|
74
82
|
C.dump_type(self)
|
83
|
+
# :nocov:
|
75
84
|
end
|
76
85
|
|
77
86
|
# Build string of LLVM type representation.
|
@@ -95,6 +104,14 @@ module LLVM
|
|
95
104
|
C.is_literal_struct(self)
|
96
105
|
end
|
97
106
|
|
107
|
+
def ===(other)
|
108
|
+
if other.is_a?(LLVM::Value)
|
109
|
+
return self == other.type
|
110
|
+
end
|
111
|
+
|
112
|
+
super
|
113
|
+
end
|
114
|
+
|
98
115
|
# Creates an array type of Type with the given size.
|
99
116
|
# arrays can be size >= 0, https://llvm.org/docs/LangRef.html#array-type
|
100
117
|
def self.array(ty, sz = 0)
|
@@ -178,18 +195,98 @@ module LLVM
|
|
178
195
|
# from_ptr(C.opaque_type, :pointer)
|
179
196
|
# end
|
180
197
|
|
181
|
-
def self.rec
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
198
|
+
# def self.rec
|
199
|
+
# h = opaque
|
200
|
+
# ty = yield h
|
201
|
+
# h.refine(ty)
|
202
|
+
# ty
|
203
|
+
# end
|
204
|
+
|
205
|
+
def self.integer(width)
|
206
|
+
IntType.from_ptr(C.int_type(width), :integer)
|
207
|
+
end
|
208
|
+
|
209
|
+
class << self
|
210
|
+
alias_method :i, :integer
|
211
|
+
end
|
212
|
+
|
213
|
+
def self.float
|
214
|
+
RealType.from_ptr(C.float_type, kind: :float)
|
215
|
+
end
|
216
|
+
|
217
|
+
def self.double
|
218
|
+
RealType.from_ptr(C.double_type, kind: :double)
|
186
219
|
end
|
187
220
|
end
|
188
221
|
|
189
222
|
class IntType < Type
|
223
|
+
def all_ones
|
224
|
+
from_ptr(C.const_all_ones(self))
|
225
|
+
end
|
226
|
+
|
190
227
|
def width
|
191
228
|
C.get_int_type_width(self)
|
192
229
|
end
|
230
|
+
|
231
|
+
def from_i(int, options = {})
|
232
|
+
signed = case options
|
233
|
+
when true, false
|
234
|
+
options
|
235
|
+
when Hash
|
236
|
+
options.fetch(:signed, true)
|
237
|
+
else
|
238
|
+
raise ArgumentError
|
239
|
+
end
|
240
|
+
# return poison if !fits_width?(int, width, signed)
|
241
|
+
|
242
|
+
ptr = C.const_int(self, int, signed ? 1 : 0)
|
243
|
+
val = from_ptr(ptr)
|
244
|
+
val.to_i(signed) == int ? val : poison
|
245
|
+
end
|
246
|
+
|
247
|
+
# unused
|
248
|
+
private def fits_width?(int, width, signed)
|
249
|
+
# :nocov:
|
250
|
+
if signed
|
251
|
+
int.bit_length < width || int == 1
|
252
|
+
else
|
253
|
+
int >= 0 && int.bit_length <= width
|
254
|
+
end
|
255
|
+
# :nocov:
|
256
|
+
end
|
257
|
+
|
258
|
+
def from_ptr(ptr)
|
259
|
+
ConstantInt.from_ptr(ptr)
|
260
|
+
end
|
261
|
+
|
262
|
+
def parse(str, radix = 10)
|
263
|
+
# from_ptr(C.const_int_of_string(self, str, radix))
|
264
|
+
from_i(str.to_i(radix))
|
265
|
+
end
|
266
|
+
|
267
|
+
def type
|
268
|
+
self
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
class RealType < Type
|
273
|
+
# given an array of values, return the type that will fit all of them
|
274
|
+
# currently only works for floats and doubles
|
275
|
+
def self.fits(values)
|
276
|
+
values.detect { |v| v.type.to_s == 'double' } ? double : float
|
277
|
+
end
|
278
|
+
|
279
|
+
def from_f(value)
|
280
|
+
ConstantReal.from_ptr(C.const_real(self, value))
|
281
|
+
end
|
282
|
+
|
283
|
+
def parse(str)
|
284
|
+
ConstantReal.from_ptr(C.const_real_of_string(self, str))
|
285
|
+
end
|
286
|
+
|
287
|
+
def type
|
288
|
+
self
|
289
|
+
end
|
193
290
|
end
|
194
291
|
|
195
292
|
class FunctionType < Type
|
@@ -247,8 +344,10 @@ module LLVM
|
|
247
344
|
# Creates a Type from the given object.
|
248
345
|
def Type(ty)
|
249
346
|
case ty
|
250
|
-
when LLVM::Type
|
251
|
-
|
347
|
+
when LLVM::Type
|
348
|
+
ty
|
349
|
+
else
|
350
|
+
ty.type
|
252
351
|
end
|
253
352
|
end
|
254
353
|
|
@@ -287,4 +386,42 @@ module LLVM
|
|
287
386
|
LLVM::Type.void
|
288
387
|
end
|
289
388
|
|
389
|
+
def void
|
390
|
+
LLVM::Type.void
|
391
|
+
end
|
392
|
+
|
393
|
+
def i(width, value = nil)
|
394
|
+
type = LLVM::Type.i(width)
|
395
|
+
value ? type.from_i(value) : type
|
396
|
+
end
|
397
|
+
|
398
|
+
def double(value = nil)
|
399
|
+
type = LLVM::Type.double
|
400
|
+
value ? type.from_f(value) : type
|
401
|
+
end
|
402
|
+
|
403
|
+
def float(value = nil)
|
404
|
+
type = LLVM::Type.float
|
405
|
+
value ? type.from_f(value) : type
|
406
|
+
end
|
407
|
+
|
408
|
+
def ptr
|
409
|
+
LLVM::Type.pointer
|
410
|
+
end
|
411
|
+
|
412
|
+
# for compatibility
|
413
|
+
# Create a float LLVM::ContantReal from a Ruby Float (value).
|
414
|
+
def Float(value)
|
415
|
+
float(value)
|
416
|
+
end
|
417
|
+
|
418
|
+
# for compatibility
|
419
|
+
# Create a double LLVM::ContantReal from a Ruby Float (value).
|
420
|
+
def Double(value)
|
421
|
+
double(value)
|
422
|
+
end
|
423
|
+
|
424
|
+
# for compatibility
|
425
|
+
Float = float.freeze
|
426
|
+
Double = double.freeze
|
290
427
|
end
|