ruby-llvm 15.0.4 → 16.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/ruby-llvm-support/Rakefile +4 -2
- data/ext/ruby-llvm-support/support.cpp +7 -0
- data/lib/llvm/analysis_ffi.rb +1 -1
- data/lib/llvm/config.rb +7 -4
- data/lib/llvm/core/attribute.rb +158 -0
- data/lib/llvm/core/bitcode_ffi.rb +1 -1
- data/lib/llvm/core/builder.rb +36 -7
- data/lib/llvm/core/value.rb +22 -5
- data/lib/llvm/core.rb +15 -3
- data/lib/llvm/core_ffi.rb +1 -1
- data/lib/llvm/execution_engine.rb +2 -2
- data/lib/llvm/execution_engine_ffi.rb +1 -1
- data/lib/llvm/linker_ffi.rb +1 -1
- data/lib/llvm/support.rb +2 -0
- data/lib/llvm/target.rb +25 -14
- data/lib/llvm/target_ffi.rb +1 -1
- data/lib/llvm/transforms/builder_ffi.rb +1 -1
- data/lib/llvm/transforms/ipo.rb +1 -1
- data/lib/llvm/transforms/ipo_ffi.rb +1 -1
- data/lib/llvm/transforms/scalar_ffi.rb +1 -1
- data/lib/llvm/transforms/vectorize_ffi.rb +1 -1
- data/lib/llvm/version.rb +3 -3
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c6e1b8f07e635723694d6a987397f074c5433bcfad6867cb1832e71333c7a13e
|
4
|
+
data.tar.gz: 730e751e566373dc30950c08b12eafa665403ac635ffa6d33bb5324b56cd906d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1bbf9522c2c6a9782d46760138ff35ad5ed41b571bdd93425b3bc4d0d89992ec04cf904ec59fda21793a9edfa14ecb749128ccb4d03fa2a4b0801c5a22a61f9
|
7
|
+
data.tar.gz: 917666ebfceda78a79299df2849bf653dfdd2d723615ba6e105bf56f54ab95f3580158903a8b9b4702ffd32e0764b79d246bd1aecac35faac12eabd049f2d54d
|
@@ -77,17 +77,19 @@ 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.match?(/^clang++/) ? "-stdlib=libc++" : ""
|
81
80
|
sh "#{CXX} -O3 -shared #{task.prerequisites.join(' ')} -l#{llvm_lib_name} " \
|
82
|
-
"#{invoke_llvm_config('--cxxflags --ldflags')} -fPIC
|
81
|
+
"#{invoke_llvm_config('--cxxflags --ldflags')} -fPIC -o #{SUPPORT_LIB}"
|
83
82
|
end
|
84
83
|
|
85
84
|
LLVM_CONFIG_OPTS = [
|
85
|
+
['VERSION', :string, '--version'],
|
86
86
|
['COMPONENTS', :array, '--components'],
|
87
87
|
['TARGETS_BUILT', :array, '--targets-built'],
|
88
88
|
['HOST_TARGET', :string, '--host-target'],
|
89
89
|
['BUILD_MODE', :string, '--build-mode'],
|
90
90
|
['CFLAGS', :string, '--cflags'],
|
91
|
+
['CXXFLAGS', :string, '--cxxflags'],
|
92
|
+
['LDFLAGS', :string, '--ldflags'],
|
91
93
|
].freeze
|
92
94
|
|
93
95
|
file CONFIG_MOD do
|
@@ -3,6 +3,7 @@
|
|
3
3
|
*/
|
4
4
|
|
5
5
|
#include <llvm/Support/TargetSelect.h>
|
6
|
+
#include <llvm/IR/Attributes.h>
|
6
7
|
|
7
8
|
extern "C" {
|
8
9
|
void LLVMInitializeAllTargetInfos() {
|
@@ -28,5 +29,11 @@ extern "C" {
|
|
28
29
|
void LLVMInitializeNativeAsmPrinter() {
|
29
30
|
llvm::InitializeNativeTargetAsmPrinter();
|
30
31
|
}
|
32
|
+
|
33
|
+
const char* LLVMGetEnumAttributeNameForKind(const unsigned KindID) {
|
34
|
+
const auto AttrKind = (llvm::Attribute::AttrKind) KindID;
|
35
|
+
const auto S = llvm::Attribute::getNameFromAttrKind(AttrKind);
|
36
|
+
return S.data();
|
37
|
+
}
|
31
38
|
}
|
32
39
|
|
data/lib/llvm/analysis_ffi.rb
CHANGED
data/lib/llvm/config.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
# Generated by ruby-llvm. Please do not change this file by hand.
|
2
2
|
module LLVM
|
3
3
|
module CONFIG
|
4
|
-
|
5
|
-
|
4
|
+
VERSION = "17.0.6"
|
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", "dwarflinkerparallel", "dwp", "engine", "executionengine", "extensions", "filecheck", "frontendhlsl", "frontendopenacc", "frontendopenmp", "fuzzercli", "fuzzmutate", "globalisel", "hexagon", "hexagonasmparser", "hexagoncodegen", "hexagondesc", "hexagondisassembler", "hexagoninfo", "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", "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", "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
|
+
TARGETS_BUILT = ["AArch64", "AMDGPU", "ARM", "AVR", "BPF", "Hexagon", "Lanai", "LoongArch", "Mips", "MSP430", "NVPTX", "PowerPC", "RISCV", "Sparc", "SystemZ", "VE", "WebAssembly", "X86", "XCore", "M68k", "Xtensa"]
|
6
7
|
HOST_TARGET = "x86_64-pc-linux-gnu"
|
7
|
-
BUILD_MODE = "
|
8
|
-
CFLAGS = "-I/usr/lib/llvm-
|
8
|
+
BUILD_MODE = "RelWithDebInfo"
|
9
|
+
CFLAGS = "-I/usr/lib/llvm-17/include -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS"
|
10
|
+
CXXFLAGS = "-I/usr/lib/llvm-17/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-17/lib"
|
9
12
|
end
|
10
13
|
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module LLVM
|
4
|
+
class Attribute
|
5
|
+
|
6
|
+
include PointerIdentity
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def new(from)
|
11
|
+
case from
|
12
|
+
when String, Symbol
|
13
|
+
enum(from)
|
14
|
+
else
|
15
|
+
raise "Not implemented to create Attribute from #{from.class}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# create a memory attribute from a hash where the keys are:
|
20
|
+
# argmem, inaccessiblemem, memory
|
21
|
+
# and the valid values are:
|
22
|
+
# read, write, readwrite
|
23
|
+
def memory(opts = {})
|
24
|
+
opts = opts.transform_keys(&:to_sym)
|
25
|
+
val = bit_value(opts[:argmem]) | (bit_value(opts[:inaccessiblemem]) << 2) | (bit_value(opts[:memory]) << 4)
|
26
|
+
enum(:memory, val)
|
27
|
+
end
|
28
|
+
|
29
|
+
# create enum attribute with optional value and context
|
30
|
+
def enum(kind, value = 0, context = Context.global)
|
31
|
+
attr_id = attribute_id(kind)
|
32
|
+
ptr = C.create_enum_attribute(context, attr_id, value)
|
33
|
+
from_ptr(ptr)
|
34
|
+
end
|
35
|
+
|
36
|
+
# create string attribute with key and value
|
37
|
+
def string(key, value, context = Context.global)
|
38
|
+
key = key.to_s
|
39
|
+
value = value.to_s
|
40
|
+
ptr = C.create_string_attribute(context, key, key.size, value, value.size)
|
41
|
+
from_ptr(ptr)
|
42
|
+
end
|
43
|
+
|
44
|
+
def last_enum
|
45
|
+
C.get_last_enum_attribute_kind
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def from_ptr(ptr)
|
51
|
+
return if ptr.null?
|
52
|
+
val = allocate
|
53
|
+
val.instance_variable_set(:@ptr, ptr)
|
54
|
+
val
|
55
|
+
end
|
56
|
+
|
57
|
+
def attribute_name(attr_name)
|
58
|
+
attr_name = attr_name.to_s
|
59
|
+
if /_attribute$/.match?(attr_name)
|
60
|
+
attr_name.chomp('_attribute').tr('_', '')
|
61
|
+
else
|
62
|
+
attr_name
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def attribute_id(attr_name)
|
67
|
+
attr_mem = FFI::MemoryPointer.from_string(attribute_name(attr_name))
|
68
|
+
attr_kind_id = C.get_enum_attribute_kind_for_name(attr_mem, attr_mem.size - 1)
|
69
|
+
|
70
|
+
raise "No attribute named: #{attr_name}" if attr_kind_id.zero?
|
71
|
+
attr_kind_id
|
72
|
+
end
|
73
|
+
|
74
|
+
# returns correct 2 bits of memory value:
|
75
|
+
# 0 = none
|
76
|
+
# 1 = read
|
77
|
+
# 2 = write
|
78
|
+
# 3 = readwrite
|
79
|
+
def bit_value(maybe_value)
|
80
|
+
case maybe_value.to_s
|
81
|
+
when 'read'
|
82
|
+
1
|
83
|
+
when 'write'
|
84
|
+
2
|
85
|
+
when 'readwrite'
|
86
|
+
3
|
87
|
+
else
|
88
|
+
0
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
def kind
|
95
|
+
return enum_kind if enum?
|
96
|
+
return string_kind if string?
|
97
|
+
raise
|
98
|
+
end
|
99
|
+
|
100
|
+
def value
|
101
|
+
return C.get_enum_attribute_value(self) if enum?
|
102
|
+
return string_value if string?
|
103
|
+
raise
|
104
|
+
end
|
105
|
+
|
106
|
+
def enum?
|
107
|
+
C.is_enum_attribute(self)
|
108
|
+
end
|
109
|
+
|
110
|
+
def string?
|
111
|
+
C.is_string_attribute(self)
|
112
|
+
end
|
113
|
+
|
114
|
+
def type?
|
115
|
+
C.is_type_attribute(self)
|
116
|
+
end
|
117
|
+
|
118
|
+
def inspect
|
119
|
+
return "\"#{kind}\" = \"#{value}\"" if string?
|
120
|
+
return "#{kind}(#{value})" if enum?
|
121
|
+
super
|
122
|
+
end
|
123
|
+
|
124
|
+
def to_s
|
125
|
+
return kind if enum?
|
126
|
+
super
|
127
|
+
end
|
128
|
+
|
129
|
+
def kind_id
|
130
|
+
enum_kind_id
|
131
|
+
end
|
132
|
+
|
133
|
+
private
|
134
|
+
|
135
|
+
def enum_kind_id
|
136
|
+
C.get_enum_attribute_kind(self)
|
137
|
+
end
|
138
|
+
|
139
|
+
def enum_kind
|
140
|
+
Support::C.get_enum_attribute_name_for_kind(enum_kind_id)
|
141
|
+
end
|
142
|
+
|
143
|
+
# wraps get_string_attribute_kind
|
144
|
+
def string_kind
|
145
|
+
FFI::MemoryPointer.new(:uint64) do |size_ptr|
|
146
|
+
return C.get_string_attribute_kind(self, size_ptr)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# wraps get_string_attribute_value
|
151
|
+
def string_value
|
152
|
+
FFI::MemoryPointer.new(:uint) do |size_ptr|
|
153
|
+
return C.get_string_attribute_value(self, size_ptr)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
end
|
data/lib/llvm/core/builder.rb
CHANGED
@@ -127,7 +127,7 @@ module LLVM
|
|
127
127
|
C.build_cond_br(self, cond2, iftrue, iffalse))
|
128
128
|
end
|
129
129
|
|
130
|
-
private def cond_condition(cond)
|
130
|
+
private def cond_condition(cond)
|
131
131
|
case cond
|
132
132
|
when LLVM::Value
|
133
133
|
cond_type = cond.type
|
@@ -389,6 +389,16 @@ module LLVM
|
|
389
389
|
Instruction.from_ptr(C.build_f_rem(self, lhs, rhs, name))
|
390
390
|
end
|
391
391
|
|
392
|
+
# The ‘fneg’ instruction returns the negation of its operand.
|
393
|
+
# @param [LLVM::Value] lhs Floating point or vector of floating points
|
394
|
+
# @param [String] name Name of the result in LLVM IR
|
395
|
+
# @return [LLVM::Instruction] The floating point negation
|
396
|
+
# @LLVMinst fneg
|
397
|
+
# https://llvm.org/docs/LangRef.html#fneg-instruction
|
398
|
+
def fneg(lhs, name = "")
|
399
|
+
Instruction.from_ptr(C.build_f_neg(self, lhs, name))
|
400
|
+
end
|
401
|
+
|
392
402
|
# @param [LLVM::Value] lhs Integer or vector of integers
|
393
403
|
# @param [LLVM::Value] rhs Integer or vector of integers
|
394
404
|
# @param [String] name Name of the result in LLVM IR
|
@@ -928,22 +938,41 @@ module LLVM
|
|
928
938
|
call2(nil, fun, *args)
|
929
939
|
end
|
930
940
|
|
931
|
-
def
|
932
|
-
|
941
|
+
private def call2_infer_function_and_type(type, fun)
|
942
|
+
fun = insert_block.parent.global_parent.functions[fun.to_s] unless fun.is_a?(LLVM::Value)
|
943
|
+
|
944
|
+
msg = "Function provided to call instruction was neither a value nor a function name: #{fun.inspect}"
|
945
|
+
raise ArgumentError, msg if fun.nil?
|
946
|
+
|
947
|
+
msg = "Type must be provided to call2 when function argument is not a function type: #{fun.inspect}"
|
948
|
+
raise ArgumentError, msg if !fun.is_a?(Function) && type.nil?
|
933
949
|
|
934
950
|
type ||= fun.function_type
|
935
951
|
must_be_type!(type)
|
936
952
|
|
937
|
-
|
938
|
-
|
953
|
+
[type, fun]
|
954
|
+
end
|
955
|
+
|
956
|
+
def call2(type, fun, *args)
|
957
|
+
type, fun = call2_infer_function_and_type(type, fun)
|
958
|
+
|
959
|
+
name = if args.last.kind_of? String
|
960
|
+
args.pop
|
939
961
|
else
|
940
|
-
|
962
|
+
""
|
941
963
|
end
|
942
964
|
|
943
965
|
args_ptr = FFI::MemoryPointer.new(FFI.type_size(:pointer) * args.size)
|
944
966
|
args_ptr.write_array_of_pointer(args)
|
945
967
|
ins = C.build_call2(self, type, fun, args_ptr, args.size, name)
|
946
|
-
|
968
|
+
|
969
|
+
call_inst = CallInst.from_ptr(ins)
|
970
|
+
|
971
|
+
if fun.is_a?(Function)
|
972
|
+
call_inst.call_conv = fun.call_conv
|
973
|
+
end
|
974
|
+
|
975
|
+
call_inst
|
947
976
|
end
|
948
977
|
|
949
978
|
# Return a value based on a condition. This differs from 'cond' in that
|
data/lib/llvm/core/value.rb
CHANGED
@@ -121,6 +121,11 @@ module LLVM
|
|
121
121
|
fun.remove_attribute(attr, index)
|
122
122
|
end
|
123
123
|
|
124
|
+
# Get the parent module of a global variable, including functions
|
125
|
+
def global_parent
|
126
|
+
LLVM::Module.from_ptr(C.get_global_parent(self))
|
127
|
+
end
|
128
|
+
|
124
129
|
private
|
125
130
|
|
126
131
|
# get function this param belongs to
|
@@ -595,7 +600,7 @@ module LLVM
|
|
595
600
|
|
596
601
|
# Negation.
|
597
602
|
def -@
|
598
|
-
|
603
|
+
raise "constant fneg removed in LLVM 16"
|
599
604
|
end
|
600
605
|
|
601
606
|
# Returns the result of adding this ConstantReal to rhs.
|
@@ -800,6 +805,11 @@ module LLVM
|
|
800
805
|
conv
|
801
806
|
end
|
802
807
|
|
808
|
+
# gets the calling convention of the function
|
809
|
+
def call_conv
|
810
|
+
C.get_function_call_conv(self)
|
811
|
+
end
|
812
|
+
|
803
813
|
# Returns an Enumerable of the BasicBlocks in this function.
|
804
814
|
def basic_blocks
|
805
815
|
@basic_block_collection ||= BasicBlockCollection.new(self)
|
@@ -856,9 +866,16 @@ module LLVM
|
|
856
866
|
end
|
857
867
|
|
858
868
|
def add(attr)
|
859
|
-
|
860
|
-
|
861
|
-
|
869
|
+
attr_ref = case attr
|
870
|
+
when Attribute
|
871
|
+
attr
|
872
|
+
when Symbol
|
873
|
+
attr_kind_id = attribute_id(attr)
|
874
|
+
ctx = Context.global
|
875
|
+
C.create_enum_attribute(ctx, attr_kind_id, 0)
|
876
|
+
else
|
877
|
+
raise "Adding unknown attribute type"
|
878
|
+
end
|
862
879
|
C.add_attribute_at_index(@fun, @index, attr_ref)
|
863
880
|
end
|
864
881
|
|
@@ -879,7 +896,7 @@ module LLVM
|
|
879
896
|
attr_refs = p.read_array_of_type(:pointer, :read_pointer, n)
|
880
897
|
end
|
881
898
|
|
882
|
-
attr_refs.map { |e|
|
899
|
+
attr_refs.map { |e| Attribute.send(:from_ptr, e) }
|
883
900
|
end
|
884
901
|
|
885
902
|
private
|
data/lib/llvm/core.rb
CHANGED
@@ -24,10 +24,17 @@ module LLVM
|
|
24
24
|
# (LLVMContextRef C, unsigned KindID, uint64_t Val);
|
25
25
|
attach_function :create_enum_attribute, :LLVMCreateEnumAttribute, [:pointer, :uint, :uint64], :pointer
|
26
26
|
|
27
|
+
# LLVMAttributeRef LLVMCreateStringAttribute(LLVMContextRef C,
|
28
|
+
# const char *K, unsigned KLength,
|
29
|
+
# const char *V, unsigned VLength);
|
30
|
+
attach_function :create_string_attribute, :LLVMCreateStringAttribute, [:pointer, :string, :uint, :string, :uint], :pointer
|
31
|
+
|
27
32
|
# unsigned LLVMGetEnumAttributeKindForName
|
28
33
|
# (const char *Name, size_t SLen);
|
29
34
|
attach_function :get_enum_attribute_kind_for_name, :LLVMGetEnumAttributeKindForName, [:pointer, :size_t], :uint
|
30
35
|
|
36
|
+
attach_function :get_last_enum_attribute_kind, :LLVMGetLastEnumAttributeKind, [], :uint
|
37
|
+
|
31
38
|
# unsigned LLVMGetAttributeCountAtIndex
|
32
39
|
# (LLVMValueRef F, LLVMAttributeIndex Idx);
|
33
40
|
attach_function :get_attribute_count_at_index, :LLVMGetAttributeCountAtIndex, [:pointer, :llvmattributeindex], :uint
|
@@ -42,15 +49,19 @@ module LLVM
|
|
42
49
|
|
43
50
|
# uint64_t LLVMGetEnumAttributeValue
|
44
51
|
# (LLVMAttributeRef A);
|
45
|
-
attach_function :get_enum_attribute_value, :
|
52
|
+
attach_function :get_enum_attribute_value, :LLVMGetEnumAttributeValue, [:pointer], :uint64
|
46
53
|
|
47
54
|
# const char *LLVMGetStringAttributeKind
|
48
55
|
# (LLVMAttributeRef A, unsigned *Length);
|
49
|
-
attach_function :get_string_attribute_kind, :LLVMGetStringAttributeKind, [:pointer, :pointer], :
|
56
|
+
attach_function :get_string_attribute_kind, :LLVMGetStringAttributeKind, [:pointer, :pointer], :string
|
50
57
|
|
51
58
|
# const char *LLVMGetStringAttributeValue
|
52
59
|
# (LLVMAttributeRef A, unsigned *Length);
|
53
|
-
attach_function :get_string_attribute_value, :LLVMGetStringAttributeValue, [:pointer, :pointer], :
|
60
|
+
attach_function :get_string_attribute_value, :LLVMGetStringAttributeValue, [:pointer, :pointer], :string
|
61
|
+
|
62
|
+
attach_function :is_enum_attribute, :LLVMIsEnumAttribute, [:pointer], :bool
|
63
|
+
attach_function :is_string_attribute, :LLVMIsStringAttribute, [:pointer], :bool
|
64
|
+
attach_function :is_type_attribute, :LLVMIsTypeAttribute, [:pointer], :bool
|
54
65
|
|
55
66
|
# LLVMValueRef LLVMBuildLoad2(LLVMBuilderRef, LLVMTypeRef Ty, LLVMValueRef PointerVal, const char *Name);
|
56
67
|
attach_function :build_load2, :LLVMBuildLoad2, [:pointer, :pointer, :pointer, :string], :pointer
|
@@ -229,4 +240,5 @@ module LLVM
|
|
229
240
|
require 'llvm/core/builder'
|
230
241
|
require 'llvm/core/pass_manager'
|
231
242
|
require 'llvm/core/bitcode'
|
243
|
+
require 'llvm/core/attribute'
|
232
244
|
end
|
data/lib/llvm/core_ffi.rb
CHANGED
@@ -204,7 +204,7 @@ module LLVM
|
|
204
204
|
if type.width <= 8
|
205
205
|
:int8
|
206
206
|
else
|
207
|
-
"int#{type.width}"
|
207
|
+
:"int#{type.width}"
|
208
208
|
end
|
209
209
|
else
|
210
210
|
type.kind
|
@@ -280,7 +280,7 @@ module LLVM
|
|
280
280
|
|
281
281
|
# Creates a GenericValue from a Ruby boolean.
|
282
282
|
def self.from_b(b)
|
283
|
-
from_i(b ? 1 : 0, LLVM::Int1, false)
|
283
|
+
from_i(b ? 1 : 0, type: LLVM::Int1, signed: false)
|
284
284
|
end
|
285
285
|
|
286
286
|
# Creates a GenericValue from an FFI::Pointer pointing to some arbitrary value.
|
data/lib/llvm/linker_ffi.rb
CHANGED
data/lib/llvm/support.rb
CHANGED
@@ -27,6 +27,8 @@ module LLVM
|
|
27
27
|
:LLVMInitializeNativeTarget, [], :void
|
28
28
|
attach_function :initialize_native_asm_printer,
|
29
29
|
:LLVMInitializeNativeAsmPrinter, [], :void
|
30
|
+
|
31
|
+
attach_function :get_enum_attribute_name_for_kind, :LLVMGetEnumAttributeNameForKind, [:uint], :string
|
30
32
|
end
|
31
33
|
end
|
32
34
|
|
data/lib/llvm/target.rb
CHANGED
@@ -22,23 +22,34 @@ module LLVM
|
|
22
22
|
#
|
23
23
|
# @param [String] target Target name in LLVM format, e.g. "X86", "ARM" or "PowerPC".
|
24
24
|
# @param [true, false] asm_printer Initialize corresponding AsmPrinter.
|
25
|
+
|
26
|
+
module TargetModule
|
27
|
+
extend FFI::Library
|
28
|
+
ffi_lib ["libLLVM-16.so.1", "libLLVM.so.16", "LLVM-16"]
|
29
|
+
|
30
|
+
def self.safe_attach_function(*args)
|
31
|
+
attach_function(*args)
|
32
|
+
rescue FFI::NotFoundError => e
|
33
|
+
warn(e)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
25
37
|
def self.init(target, asm_printer = false)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
attach_function :"initialize_target_#{target}",
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
:"LLVMInitialize#{target}AsmParser", [], :void
|
38
|
-
attach_function :"initialize_#{target}_disassembler",
|
39
|
-
:"LLVMInitialize#{target}Disassembler", [], :void
|
38
|
+
target_module = TargetModule.dup
|
39
|
+
target_module.module_eval do
|
40
|
+
attach_function :"initialize_target_info_#{target}", :"LLVMInitialize#{target}TargetInfo", [], :void
|
41
|
+
attach_function :"initialize_target_#{target}", :"LLVMInitialize#{target}Target", [], :void
|
42
|
+
attach_function :"initialize_target_#{target}_mc", :"LLVMInitialize#{target}TargetMC", [], :void
|
43
|
+
|
44
|
+
if asm_printer
|
45
|
+
attach_function(:"initialize_#{target}_asm_printer", :"LLVMInitialize#{target}AsmPrinter", [], :void)
|
46
|
+
end
|
47
|
+
safe_attach_function :"initialize_#{target}_asm_parser", :"LLVMInitialize#{target}AsmParser", [], :void
|
48
|
+
safe_attach_function :"initialize_#{target}_disassembler", :"LLVMInitialize#{target}Disassembler", [], :void
|
40
49
|
end
|
41
50
|
|
51
|
+
C.extend(target_module)
|
52
|
+
|
42
53
|
begin
|
43
54
|
%W(initialize_target_info_#{target}
|
44
55
|
initialize_target_#{target}
|
data/lib/llvm/target_ffi.rb
CHANGED
data/lib/llvm/transforms/ipo.rb
CHANGED
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:
|
4
|
+
version: 16.0.1
|
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-12-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
@@ -192,6 +192,7 @@ files:
|
|
192
192
|
- lib/llvm/analysis_ffi.rb
|
193
193
|
- lib/llvm/config.rb
|
194
194
|
- lib/llvm/core.rb
|
195
|
+
- lib/llvm/core/attribute.rb
|
195
196
|
- lib/llvm/core/bitcode.rb
|
196
197
|
- lib/llvm/core/bitcode_ffi.rb
|
197
198
|
- lib/llvm/core/builder.rb
|
@@ -237,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
237
238
|
- !ruby/object:Gem::Version
|
238
239
|
version: '0'
|
239
240
|
requirements: []
|
240
|
-
rubygems_version: 3.
|
241
|
+
rubygems_version: 3.4.21
|
241
242
|
signing_key:
|
242
243
|
specification_version: 4
|
243
244
|
summary: LLVM bindings for Ruby
|