ruby-llvm 20.1.7 → 22.1.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/README.md +2 -2
- data/ext/ruby-llvm-support/Rakefile +5 -4
- data/ext/ruby-llvm-support/support.cpp +75 -4
- data/lib/llvm/analysis.rb +9 -0
- data/lib/llvm/analysis_ffi.rb +1 -2
- data/lib/llvm/core/attribute.rb +41 -2
- data/lib/llvm/core/bitcode.rb +24 -6
- data/lib/llvm/core/bitcode_ffi.rb +1 -2
- data/lib/llvm/core/builder.rb +140 -21
- data/lib/llvm/core/context.rb +7 -2
- data/lib/llvm/core/module.rb +79 -23
- data/lib/llvm/core/pass_manager.rb +1 -0
- data/lib/llvm/core/type.rb +139 -63
- data/lib/llvm/core/value.rb +156 -42
- data/lib/llvm/core.rb +7 -4
- data/lib/llvm/core_ffi.rb +11 -34
- data/lib/llvm/core_ffi_v2.rb +5 -0
- data/lib/llvm/execution_engine.rb +59 -39
- data/lib/llvm/execution_engine_ffi.rb +5 -6
- data/lib/llvm/linker.rb +13 -5
- data/lib/llvm/linker_ffi.rb +1 -2
- data/lib/llvm/lljit.rb +9 -9
- data/lib/llvm/owned_string.rb +48 -0
- data/lib/llvm/pass_builder.rb +21 -18
- data/lib/llvm/support.rb +11 -7
- data/lib/llvm/target.rb +40 -23
- data/lib/llvm/target_ffi.rb +5 -6
- data/lib/llvm/transforms/ipo.rb +1 -0
- data/lib/llvm/transforms/pass_manager_builder.rb +1 -0
- data/lib/llvm/transforms/scalar.rb +1 -0
- data/lib/llvm/transforms/utils.rb +1 -0
- data/lib/llvm/transforms/vectorize.rb +1 -0
- data/lib/llvm/version.rb +24 -3
- data/lib/llvm.rb +10 -3
- metadata +11 -55
- data/lib/llvm/config.rb +0 -14
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a6062a6e6b85cdcad5129b1c41205736606b7ed8067e93295784cbb5767c7c9c
|
|
4
|
+
data.tar.gz: affccd431e0047aed850a6af6c21420a766235972dc38deb6442174a9b5900b1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ffc8253d118f6f703ba59024ac2e2b5d39eb487095cd242b0d8ecc88567247cef302992874f2bba1d204401e52f3d43a99e671a77985562859510314a6c05f33
|
|
7
|
+
data.tar.gz: 5d3ac41a9c8a1193baf8b5bbdb54360854007d72d480e6a20c23b758fb873fd4db273e99d92e55ba981eac8dcbb24eb370efd4942505ea1bcfc5d1632d8ad7ac
|
data/README.md
CHANGED
|
@@ -14,7 +14,7 @@ computationally intensive algorithms on the fly.
|
|
|
14
14
|
Current version
|
|
15
15
|
---------------
|
|
16
16
|
|
|
17
|
-
This library currently binds to LLVM
|
|
17
|
+
This library currently binds to LLVM 22.1.x (specifically llvm-c 22).
|
|
18
18
|
|
|
19
19
|
About version numbers
|
|
20
20
|
---------------------
|
|
@@ -32,7 +32,7 @@ Debian/Ubuntu
|
|
|
32
32
|
Homebrew
|
|
33
33
|
--------
|
|
34
34
|
|
|
35
|
-
LLVM can be installed with Homebrew by executing `brew install llvm
|
|
35
|
+
LLVM can be installed with Homebrew by executing `brew install llvm@22`
|
|
36
36
|
|
|
37
37
|
Source and other binaries
|
|
38
38
|
-------------------------
|
|
@@ -26,8 +26,8 @@ end
|
|
|
26
26
|
|
|
27
27
|
def find_llvm_config
|
|
28
28
|
check_for('llvm-config',
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
%W[llvm-config-#{LLVM_VERSION} llvm-config],
|
|
30
|
+
'LLVM_CONFIG') do |llvm_config|
|
|
31
31
|
begin
|
|
32
32
|
actual_version = `#{llvm_config} --version`.strip
|
|
33
33
|
actual_maj, actual_min, _ = actual_version.split('.')
|
|
@@ -44,7 +44,6 @@ end
|
|
|
44
44
|
def find_cxx
|
|
45
45
|
check_for('C++ compiler', %W[clang++-#{LLVM_VERSION} clang++ g++], 'CXX') do |cxx|
|
|
46
46
|
system(cxx, '--version', out: File::NULL, err: File::NULL)
|
|
47
|
-
$?.success?
|
|
48
47
|
end
|
|
49
48
|
end
|
|
50
49
|
|
|
@@ -69,6 +68,7 @@ end
|
|
|
69
68
|
|
|
70
69
|
SUPPORT_LIB = FFI.map_library_name("RubyLLVMSupport-#{LLVM_VERSION}")
|
|
71
70
|
CONFIG_MOD = File.expand_path('../../lib/llvm/config.rb', File.dirname(__FILE__))
|
|
71
|
+
VERSION_RB = File.expand_path('../../lib/llvm/version.rb', File.dirname(__FILE__))
|
|
72
72
|
|
|
73
73
|
CLEAN.include(SUPPORT_LIB, CONFIG_MOD)
|
|
74
74
|
|
|
@@ -92,7 +92,8 @@ LLVM_CONFIG_OPTS = [
|
|
|
92
92
|
['LIBS', :string, '--libs'],
|
|
93
93
|
].freeze
|
|
94
94
|
|
|
95
|
-
|
|
95
|
+
# regenerate when version.rb changes, so a version bump does not leave a stale config
|
|
96
|
+
file CONFIG_MOD => [VERSION_RB] do
|
|
96
97
|
open(CONFIG_MOD, 'w') do |f|
|
|
97
98
|
f.puts '# Generated by ruby-llvm. Please do not change this file by hand.'
|
|
98
99
|
f.puts 'module LLVM'
|
|
@@ -3,7 +3,23 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
#include <llvm/Support/TargetSelect.h>
|
|
6
|
+
#include <llvm/Support/raw_ostream.h>
|
|
6
7
|
#include <llvm/IR/Attributes.h>
|
|
8
|
+
#include <llvm/IR/Module.h>
|
|
9
|
+
#include <llvm/IR/Value.h>
|
|
10
|
+
#include <llvm/IR/Type.h>
|
|
11
|
+
#include <llvm-c/Core.h>
|
|
12
|
+
#include <string>
|
|
13
|
+
|
|
14
|
+
// Allocates a caller-owned copy of s, to be released with LLVMDisposeMessage.
|
|
15
|
+
//
|
|
16
|
+
// Uses LLVMCreateMessage rather than strdup so the allocation happens inside
|
|
17
|
+
// LLVM's own module, pairing with the free() that LLVMDisposeMessage performs
|
|
18
|
+
// there. Every string this file hands back is declared `char *` (not `const
|
|
19
|
+
// char *`) and goes through here, so ownership is stated in one place.
|
|
20
|
+
static char* owned_message(const std::string &s) {
|
|
21
|
+
return LLVMCreateMessage(s.c_str());
|
|
22
|
+
}
|
|
7
23
|
|
|
8
24
|
extern "C" {
|
|
9
25
|
void LLVMInitializeAllTargetInfos() {
|
|
@@ -40,10 +56,65 @@ extern "C" {
|
|
|
40
56
|
|
|
41
57
|
// std::string Attribute::getAsString(bool InAttrGrp = false) const
|
|
42
58
|
// https://llvm.org/doxygen/classllvm_1_1Attribute.html
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
59
|
+
char* LLVMGetAttributeAsString(LLVMAttributeRef A) {
|
|
60
|
+
return owned_message(llvm::unwrap(A).getAsString());
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// void Type::print(raw_ostream &O, bool IsForDebug = false,
|
|
64
|
+
// bool NoDetails = false) const
|
|
65
|
+
// https://llvm.org/doxygen/classllvm_1_1Type.html
|
|
66
|
+
//
|
|
67
|
+
// As LLVMPrintTypeToString, but with IsForDebug=true, matching what
|
|
68
|
+
// LLVMDumpType writes to stderr. As of LLVM 21 this renders identically to
|
|
69
|
+
// IsForDebug=false for every type kind; it exists so the API matches Module
|
|
70
|
+
// and Value, and so a future divergence is picked up rather than missed.
|
|
71
|
+
// String must be disposed with LLVMDisposeMessage.
|
|
72
|
+
char* LLVMPrintTypeToStringDebug(LLVMTypeRef Ty) {
|
|
73
|
+
std::string buf;
|
|
74
|
+
llvm::raw_string_ostream os(buf);
|
|
75
|
+
if (llvm::unwrap(Ty))
|
|
76
|
+
llvm::unwrap(Ty)->print(os, /*IsForDebug=*/true);
|
|
77
|
+
else
|
|
78
|
+
os << "Printing <null> Type";
|
|
79
|
+
os.flush();
|
|
80
|
+
return owned_message(buf);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// void Value::print(raw_ostream &O, bool IsForDebug = false) const
|
|
84
|
+
// https://llvm.org/doxygen/classllvm_1_1Value.html
|
|
85
|
+
//
|
|
86
|
+
// As LLVMPrintValueToString, but with IsForDebug=true, matching what
|
|
87
|
+
// LLVMDumpValue writes to stderr. Only affects function declarations, whose
|
|
88
|
+
// parameters LLVMPrintValueToString omits.
|
|
89
|
+
// String must be disposed with LLVMDisposeMessage.
|
|
90
|
+
char* LLVMPrintValueToStringDebug(LLVMValueRef V) {
|
|
91
|
+
std::string buf;
|
|
92
|
+
llvm::raw_string_ostream os(buf);
|
|
93
|
+
if (llvm::unwrap(V))
|
|
94
|
+
llvm::unwrap(V)->print(os, /*IsForDebug=*/true);
|
|
95
|
+
else
|
|
96
|
+
os << "Printing <null> Value";
|
|
97
|
+
os.flush();
|
|
98
|
+
return owned_message(buf);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// void Module::print(raw_ostream &OS, AssemblyAnnotationWriter *AAW,
|
|
102
|
+
// bool ShouldPreserveUseListOrder = false,
|
|
103
|
+
// bool IsForDebug = false) const
|
|
104
|
+
// https://llvm.org/doxygen/classllvm_1_1Module.html
|
|
105
|
+
//
|
|
106
|
+
// As LLVMPrintModuleToString, but with IsForDebug=true, matching what
|
|
107
|
+
// LLVMDumpModule writes to stderr. Only affects declarations, whose
|
|
108
|
+
// parameters LLVMPrintModuleToString omits.
|
|
109
|
+
// String must be disposed with LLVMDisposeMessage.
|
|
110
|
+
char* LLVMPrintModuleToStringDebug(LLVMModuleRef M) {
|
|
111
|
+
std::string buf;
|
|
112
|
+
llvm::raw_string_ostream os(buf);
|
|
113
|
+
llvm::unwrap(M)->print(os, nullptr,
|
|
114
|
+
/*ShouldPreserveUseListOrder=*/false,
|
|
115
|
+
/*IsForDebug=*/true);
|
|
116
|
+
os.flush();
|
|
117
|
+
return owned_message(buf);
|
|
47
118
|
}
|
|
48
119
|
}
|
|
49
120
|
|
data/lib/llvm/analysis.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# typed: strict
|
|
2
3
|
|
|
3
4
|
require 'llvm'
|
|
4
5
|
require 'llvm/core'
|
|
@@ -10,24 +11,28 @@ module LLVM
|
|
|
10
11
|
# Verify that the module is valid.
|
|
11
12
|
# @return [nil, String] human-readable description of any invalid
|
|
12
13
|
# constructs if invalid.
|
|
14
|
+
#: -> String?
|
|
13
15
|
def verify
|
|
14
16
|
do_verification(:return_status)
|
|
15
17
|
end
|
|
16
18
|
|
|
17
19
|
# Verify that a module is valid, and abort the process if not.
|
|
18
20
|
# @return [nil]
|
|
21
|
+
#: -> String?
|
|
19
22
|
def verify!
|
|
20
23
|
# :nocov:
|
|
21
24
|
do_verification(:abort_process)
|
|
22
25
|
# :nocov:
|
|
23
26
|
end
|
|
24
27
|
|
|
28
|
+
#: -> bool
|
|
25
29
|
def valid?
|
|
26
30
|
verify.nil?
|
|
27
31
|
end
|
|
28
32
|
|
|
29
33
|
private
|
|
30
34
|
|
|
35
|
+
#: (Symbol) -> String?
|
|
31
36
|
def do_verification(action)
|
|
32
37
|
LLVM.with_message_output do |str|
|
|
33
38
|
C.verify_module(self, action, str)
|
|
@@ -38,24 +43,28 @@ module LLVM
|
|
|
38
43
|
class Function
|
|
39
44
|
# Verify that a function is valid.
|
|
40
45
|
# @return [true, false]
|
|
46
|
+
#: -> bool
|
|
41
47
|
def verify
|
|
42
48
|
do_verification(:return_status)
|
|
43
49
|
end
|
|
44
50
|
|
|
45
51
|
# Verify that a function is valid, and abort the process if not.
|
|
46
52
|
# @return [true, false]
|
|
53
|
+
#: -> bool
|
|
47
54
|
def verify!
|
|
48
55
|
# :nocov:
|
|
49
56
|
do_verification(:abort_process)
|
|
50
57
|
# :nocov:
|
|
51
58
|
end
|
|
52
59
|
|
|
60
|
+
#: -> bool
|
|
53
61
|
def valid?
|
|
54
62
|
verify
|
|
55
63
|
end
|
|
56
64
|
|
|
57
65
|
private
|
|
58
66
|
|
|
67
|
+
#: (Symbol) -> bool
|
|
59
68
|
def do_verification(action)
|
|
60
69
|
C.verify_function(self, action).zero?
|
|
61
70
|
end
|
data/lib/llvm/analysis_ffi.rb
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
# Generated by ffi_gen. Please do not change this file by hand.
|
|
2
2
|
|
|
3
3
|
require 'ffi'
|
|
4
|
+
require 'llvm/core_ffi'
|
|
4
5
|
|
|
5
6
|
module LLVM::C
|
|
6
|
-
extend FFI::Library
|
|
7
|
-
ffi_lib ["LLVM-20", "libLLVM-20.so.1", "libLLVM.so.20", "libLLVM.so.20.1"]
|
|
8
7
|
# @defgroup LLVMCAnalysis Analysis
|
|
9
8
|
# @ingroup LLVMC
|
|
10
9
|
#
|
data/lib/llvm/core/attribute.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# typed: strict
|
|
2
3
|
|
|
3
4
|
module LLVM
|
|
4
5
|
# wrapper for LLVMAttributeRef
|
|
@@ -6,6 +7,7 @@ module LLVM
|
|
|
6
7
|
include PointerIdentity
|
|
7
8
|
|
|
8
9
|
class << self
|
|
10
|
+
#: (String | Symbol) -> Attribute?
|
|
9
11
|
def new(from)
|
|
10
12
|
case from
|
|
11
13
|
when String, Symbol
|
|
@@ -19,13 +21,20 @@ module LLVM
|
|
|
19
21
|
# argmem, inaccessiblemem, memory
|
|
20
22
|
# and the valid values are:
|
|
21
23
|
# read, write, readwrite
|
|
24
|
+
#: (?Hash[untyped, untyped]) -> Attribute?
|
|
22
25
|
def memory(opts = {})
|
|
23
26
|
opts = opts.transform_keys(&:to_sym)
|
|
24
27
|
val = bit_value(opts[:argmem]) | (bit_value(opts[:inaccessiblemem]) << 2) | (bit_value(opts[:memory]) << 4)
|
|
25
28
|
enum(:memory, val)
|
|
26
29
|
end
|
|
27
30
|
|
|
31
|
+
#: -> Attribute?
|
|
32
|
+
def captures_none
|
|
33
|
+
enum(:captures)
|
|
34
|
+
end
|
|
35
|
+
|
|
28
36
|
# create enum attribute with optional value and context
|
|
37
|
+
#: (String | Symbol, ?Integer, ?Context) -> Attribute?
|
|
29
38
|
def enum(kind, value = 0, context = Context.global)
|
|
30
39
|
attr_id = attribute_id(kind)
|
|
31
40
|
ptr = C.create_enum_attribute(context, attr_id, value)
|
|
@@ -33,6 +42,7 @@ module LLVM
|
|
|
33
42
|
end
|
|
34
43
|
|
|
35
44
|
# create string attribute with key and value
|
|
45
|
+
#: (String | Symbol, untyped, ?Context) -> Attribute?
|
|
36
46
|
def string(key, value, context = Context.global)
|
|
37
47
|
key = key.to_s
|
|
38
48
|
value = value.to_s
|
|
@@ -40,12 +50,14 @@ module LLVM
|
|
|
40
50
|
from_ptr(ptr)
|
|
41
51
|
end
|
|
42
52
|
|
|
53
|
+
#: -> Integer
|
|
43
54
|
def last_enum
|
|
44
55
|
C.get_last_enum_attribute_kind
|
|
45
56
|
end
|
|
46
57
|
|
|
47
58
|
private
|
|
48
59
|
|
|
60
|
+
#: (FFI::Pointer) -> Attribute?
|
|
49
61
|
def from_ptr(ptr)
|
|
50
62
|
return if ptr.null?
|
|
51
63
|
val = allocate
|
|
@@ -53,6 +65,7 @@ module LLVM
|
|
|
53
65
|
val
|
|
54
66
|
end
|
|
55
67
|
|
|
68
|
+
#: (String | Symbol) -> String
|
|
56
69
|
def attribute_name(attr_name)
|
|
57
70
|
attr_name = attr_name.to_s
|
|
58
71
|
if /_attribute$/.match?(attr_name)
|
|
@@ -62,6 +75,7 @@ module LLVM
|
|
|
62
75
|
end
|
|
63
76
|
end
|
|
64
77
|
|
|
78
|
+
#: (String | Symbol) -> Integer
|
|
65
79
|
def attribute_id(attr_name)
|
|
66
80
|
attr_mem = FFI::MemoryPointer.from_string(attribute_name(attr_name))
|
|
67
81
|
attr_kind_id = C.get_enum_attribute_kind_for_name(attr_mem, attr_mem.size - 1)
|
|
@@ -75,6 +89,7 @@ module LLVM
|
|
|
75
89
|
# 1 = read
|
|
76
90
|
# 2 = write
|
|
77
91
|
# 3 = readwrite
|
|
92
|
+
#: (String | Symbol)-> Integer
|
|
78
93
|
def bit_value(maybe_value)
|
|
79
94
|
case maybe_value.to_s
|
|
80
95
|
when 'read'
|
|
@@ -89,42 +104,51 @@ module LLVM
|
|
|
89
104
|
end
|
|
90
105
|
end
|
|
91
106
|
|
|
107
|
+
#: -> (Integer | String)
|
|
92
108
|
def kind
|
|
93
109
|
return enum_kind if enum?
|
|
94
110
|
return string_kind if string?
|
|
95
111
|
raise
|
|
96
112
|
end
|
|
97
113
|
|
|
114
|
+
#: -> (Integer | String)
|
|
98
115
|
def value
|
|
99
116
|
return enum_value if enum?
|
|
100
117
|
return string_value if string?
|
|
101
118
|
raise
|
|
102
119
|
end
|
|
103
120
|
|
|
121
|
+
#: -> bool
|
|
104
122
|
def enum?
|
|
105
123
|
C.is_enum_attribute(self)
|
|
106
124
|
end
|
|
107
125
|
|
|
126
|
+
#: -> bool
|
|
108
127
|
def string?
|
|
109
128
|
C.is_string_attribute(self)
|
|
110
129
|
end
|
|
111
130
|
|
|
131
|
+
#: -> bool
|
|
112
132
|
def type?
|
|
113
133
|
C.is_type_attribute(self)
|
|
114
134
|
end
|
|
115
135
|
|
|
136
|
+
#: -> String
|
|
116
137
|
def inspect
|
|
117
138
|
to_s
|
|
118
139
|
end
|
|
119
140
|
|
|
141
|
+
#: -> String
|
|
120
142
|
def to_s
|
|
121
143
|
Support::C.get_attribute_as_string(self)
|
|
122
144
|
end
|
|
123
145
|
|
|
146
|
+
#: -> Integer
|
|
124
147
|
def kind_id
|
|
125
148
|
enum_kind_id
|
|
126
149
|
end
|
|
127
150
|
|
|
151
|
+
#: (untyped) -> bool
|
|
128
152
|
def ==(other)
|
|
129
153
|
super if self.class == other.class
|
|
130
154
|
|
|
@@ -134,56 +158,71 @@ module LLVM
|
|
|
134
158
|
false
|
|
135
159
|
end
|
|
136
160
|
|
|
161
|
+
#: -> bool
|
|
137
162
|
def readnone?
|
|
138
163
|
enum_kind == 'readnone' || (enum_kind == 'memory' && enum_value_mem_none?)
|
|
139
164
|
end
|
|
140
165
|
|
|
166
|
+
#: -> bool
|
|
141
167
|
def readonly?
|
|
142
168
|
enum_kind == 'readonly' || (enum_kind == 'memory' && enum_value_mem_read?)
|
|
143
169
|
end
|
|
144
170
|
|
|
171
|
+
#: -> bool
|
|
145
172
|
def writeonly?
|
|
146
173
|
enum_kind == 'writeonly' || (enum_kind == 'memory' && enum_value_mem_write?)
|
|
147
174
|
end
|
|
148
175
|
|
|
149
176
|
private
|
|
150
177
|
|
|
178
|
+
#: -> bool
|
|
151
179
|
def enum_value_mem_none?
|
|
152
180
|
enum_value.nobits?(63)
|
|
153
181
|
end
|
|
154
182
|
|
|
183
|
+
#: -> bool
|
|
155
184
|
def enum_value_mem_read?
|
|
156
185
|
enum_value.anybits?(21)
|
|
157
186
|
end
|
|
158
187
|
|
|
188
|
+
#: -> bool
|
|
159
189
|
def enum_value_mem_write?
|
|
160
190
|
enum_value.anybits?(42)
|
|
161
191
|
end
|
|
162
192
|
|
|
193
|
+
#: -> Integer
|
|
163
194
|
def enum_kind_id
|
|
164
195
|
C.get_enum_attribute_kind(self)
|
|
165
196
|
end
|
|
166
197
|
|
|
198
|
+
#: -> String
|
|
167
199
|
def enum_kind
|
|
168
200
|
Support::C.get_enum_attribute_name_for_kind(enum_kind_id)
|
|
169
201
|
end
|
|
170
202
|
|
|
203
|
+
#: -> Integer
|
|
171
204
|
def enum_value
|
|
172
205
|
C.get_enum_attribute_value(self)
|
|
173
206
|
end
|
|
174
207
|
|
|
175
208
|
# wraps get_string_attribute_kind
|
|
209
|
+
#: -> String
|
|
176
210
|
def string_kind
|
|
211
|
+
ret = ''
|
|
177
212
|
FFI::MemoryPointer.new(:uint64) do |size_ptr|
|
|
178
|
-
|
|
213
|
+
ret = C.get_string_attribute_kind(self, size_ptr) #: as String
|
|
179
214
|
end
|
|
215
|
+
ret
|
|
180
216
|
end
|
|
181
217
|
|
|
182
218
|
# wraps get_string_attribute_value
|
|
219
|
+
#: -> String
|
|
183
220
|
def string_value
|
|
221
|
+
ret = ''
|
|
184
222
|
FFI::MemoryPointer.new(:uint) do |size_ptr|
|
|
185
|
-
|
|
223
|
+
ret = C.get_string_attribute_value(self, size_ptr) #: as String
|
|
186
224
|
end
|
|
225
|
+
ret
|
|
187
226
|
end
|
|
188
227
|
end
|
|
189
228
|
end
|
data/lib/llvm/core/bitcode.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
|
+
# typed: strict
|
|
2
3
|
|
|
3
4
|
require 'llvm/core/bitcode_ffi'
|
|
4
5
|
|
|
@@ -7,29 +8,33 @@ module LLVM
|
|
|
7
8
|
# Parse a module from a memory buffer
|
|
8
9
|
# @param [String, LLVM::MemoryBuffer] path_or_memory_buffer
|
|
9
10
|
# @return [LLVM::Module]
|
|
11
|
+
#: (untyped) -> LLVM::Module
|
|
10
12
|
def self.parse_bitcode(path_or_memory_buffer)
|
|
11
13
|
memory_buffer = case path_or_memory_buffer
|
|
12
14
|
when MemoryBuffer then path_or_memory_buffer
|
|
13
15
|
else MemoryBuffer.from_file(path_or_memory_buffer)
|
|
14
16
|
end
|
|
17
|
+
llvm_module = nil #: LLVM::Module?
|
|
15
18
|
FFI::MemoryPointer.new(:pointer) do |mod_ref|
|
|
16
19
|
FFI::MemoryPointer.new(:pointer) do |msg_ref|
|
|
17
20
|
status = C.parse_bitcode(memory_buffer, mod_ref, msg_ref)
|
|
18
21
|
raise msg_ref.get_pointer(0).get_string(0) if status != 0
|
|
19
|
-
|
|
22
|
+
llvm_module = from_ptr(mod_ref.get_pointer(0))
|
|
20
23
|
end
|
|
21
24
|
end
|
|
25
|
+
llvm_module #: as !nil
|
|
22
26
|
end
|
|
23
27
|
|
|
24
28
|
# Write bitcode to the given path, IO object or file descriptor
|
|
25
29
|
# @param [String, IO, Integer] path_or_io Pathname, IO object or file descriptor
|
|
26
30
|
# @return [true, false] Success
|
|
31
|
+
#: (untyped) -> bool
|
|
27
32
|
def write_bitcode(path_or_io)
|
|
28
33
|
status = if path_or_io.respond_to?(:path)
|
|
29
34
|
C.write_bitcode_to_file(self, path_or_io.path)
|
|
30
35
|
elsif path_or_io.respond_to?(:fileno)
|
|
31
36
|
C.write_bitcode_to_fd(self, path_or_io.fileno, 0, 1)
|
|
32
|
-
elsif path_or_io.
|
|
37
|
+
elsif path_or_io.is_a?(Integer)
|
|
33
38
|
C.write_bitcode_to_fd(self, path_or_io, 0, 1)
|
|
34
39
|
else
|
|
35
40
|
C.write_bitcode_to_file(self, path_or_io.to_str)
|
|
@@ -37,20 +42,24 @@ module LLVM
|
|
|
37
42
|
status.zero?
|
|
38
43
|
end
|
|
39
44
|
|
|
45
|
+
#: (untyped, ?LLVM::Context) -> LLVM::Module
|
|
40
46
|
def self.parse_ir(path_or_memory_buffer, context = Context.global)
|
|
41
47
|
memory_buffer = case path_or_memory_buffer
|
|
42
48
|
when MemoryBuffer then path_or_memory_buffer
|
|
43
49
|
else MemoryBuffer.from_file(path_or_memory_buffer)
|
|
44
50
|
end
|
|
51
|
+
llvm_module = nil #: LLVM::Module?
|
|
45
52
|
FFI::MemoryPointer.new(:pointer) do |mod_ref|
|
|
46
53
|
FFI::MemoryPointer.new(:pointer) do |msg_ref|
|
|
47
54
|
status = C.parse_ir_in_context(context, memory_buffer, mod_ref, msg_ref)
|
|
48
55
|
raise msg_ref.get_pointer(0).get_string(0) if status
|
|
49
|
-
|
|
56
|
+
llvm_module = from_ptr(mod_ref.get_pointer(0))
|
|
50
57
|
end
|
|
51
58
|
end
|
|
59
|
+
llvm_module #: as !nil
|
|
52
60
|
end
|
|
53
61
|
|
|
62
|
+
#: (String) -> self
|
|
54
63
|
def write_ir!(filename)
|
|
55
64
|
FFI::MemoryPointer.new(:pointer) do |msg_ref|
|
|
56
65
|
status = C.print_module_to_file(self, filename, msg_ref)
|
|
@@ -65,11 +74,13 @@ module LLVM
|
|
|
65
74
|
private_class_method :new
|
|
66
75
|
|
|
67
76
|
# @private
|
|
77
|
+
#: (FFI::Pointer) -> void
|
|
68
78
|
def initialize(ptr)
|
|
69
|
-
@ptr = ptr
|
|
79
|
+
@ptr = ptr #: FFI::Pointer?
|
|
70
80
|
end
|
|
71
81
|
|
|
72
82
|
# @private
|
|
83
|
+
#: -> FFI::Pointer?
|
|
73
84
|
def to_ptr
|
|
74
85
|
@ptr
|
|
75
86
|
end
|
|
@@ -77,28 +88,35 @@ module LLVM
|
|
|
77
88
|
# Read the contents of a file into a memory buffer
|
|
78
89
|
# @param [String] path
|
|
79
90
|
# @return [LLVM::MemoryBuffer]
|
|
91
|
+
#: (String) -> LLVM::MemoryBuffer
|
|
80
92
|
def self.from_file(path)
|
|
93
|
+
buffer = nil #: LLVM::MemoryBuffer?
|
|
81
94
|
FFI::MemoryPointer.new(:pointer) do |buf_ref|
|
|
82
95
|
FFI::MemoryPointer.new(:pointer) do |msg_ref|
|
|
83
96
|
status = C.create_memory_buffer_with_contents_of_file(path.to_str, buf_ref, msg_ref)
|
|
84
97
|
raise msg_ref.get_pointer(0).get_string(0) if status != 0
|
|
85
|
-
|
|
98
|
+
buffer = new(buf_ref.get_pointer(0))
|
|
86
99
|
end
|
|
87
100
|
end
|
|
101
|
+
buffer #: as !nil
|
|
88
102
|
end
|
|
89
103
|
|
|
90
104
|
# Read STDIN into a memory buffer
|
|
91
105
|
# @return [LLVM::MemoryBuffer]
|
|
106
|
+
#: -> LLVM::MemoryBuffer
|
|
92
107
|
def self.from_stdin
|
|
108
|
+
buffer = nil #: LLVM::MemoryBuffer?
|
|
93
109
|
FFI::Buffer.new(:pointer) do |buf_ref|
|
|
94
110
|
FFI::Buffer.new(:pointer) do |msg_ref|
|
|
95
111
|
status = C.create_memory_buffer_with_stdin(buf_ref, msg_ref)
|
|
96
112
|
raise msg_ref.get_pointer(0).get_string(0) if status != 0
|
|
97
|
-
|
|
113
|
+
buffer = new(buf_ref.get_pointer(0))
|
|
98
114
|
end
|
|
99
115
|
end
|
|
116
|
+
buffer #: as !nil
|
|
100
117
|
end
|
|
101
118
|
|
|
119
|
+
#: -> void
|
|
102
120
|
def dispose
|
|
103
121
|
return if @ptr.nil?
|
|
104
122
|
C.dispose_memory_buffer(@ptr)
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
# Generated by ffi_gen. Please do not change this file by hand.
|
|
2
2
|
|
|
3
3
|
require 'ffi'
|
|
4
|
+
require 'llvm/core_ffi'
|
|
4
5
|
|
|
5
6
|
module LLVM::C
|
|
6
|
-
extend FFI::Library
|
|
7
|
-
ffi_lib ["LLVM-20", "libLLVM-20.so.1", "libLLVM.so.20", "libLLVM.so.20.1"]
|
|
8
7
|
# (Not documented)
|
|
9
8
|
#
|
|
10
9
|
# @method parse_bitcode(mem_buf, out_module, out_message)
|