cranelift_ruby 0.1.0 → 0.1.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/Rakefile +1 -1
- data/lib/cranelift_ruby/version.rb +2 -2
- data/src/lib.rs +74 -16
- 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: '039ede96c7d734182f363ea730befc04ae5cd9dd13e2564219e6dd03beae4d64'
|
4
|
+
data.tar.gz: 164e40e024c40bf14df62dad63189a4d428eed20ffcfb13f3c584dc91eb8d586
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81228c2a238389ffa49236b29cb8f3017afbd90f47237d2a03cf966c67b6657ecd94538f0ce0000779d0779b1d1ca995fd4120f4628641fdb54f542e94ab2f13
|
7
|
+
data.tar.gz: f57c3c484724faf31e3738311cdfaa3bcf3f2b3dcdf6f8bed1a77e53724b6040689fd12c615325da440cb74cfbfc9ad1746c9828fb17150058811f9efcb340ff
|
data/Rakefile
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module CraneliftRuby
|
2
|
-
VERSION = "0.1.
|
3
|
-
end
|
2
|
+
VERSION = "0.1.4"
|
3
|
+
end
|
data/src/lib.rs
CHANGED
@@ -5,6 +5,7 @@ extern crate rutie;
|
|
5
5
|
extern crate lazy_static;
|
6
6
|
|
7
7
|
use std::convert::TryInto;
|
8
|
+
use std::mem;
|
8
9
|
use std::num::TryFromIntError;
|
9
10
|
|
10
11
|
use cranelift::codegen::binemit::{NullStackMapSink, NullTrapSink};
|
@@ -14,18 +15,19 @@ use cranelift::prelude::*;
|
|
14
15
|
use cranelift_jit::{JITBuilder, JITModule};
|
15
16
|
use cranelift_module::{default_libcall_names, FuncId, Linkage, Module};
|
16
17
|
use eyre::{eyre, Result};
|
17
|
-
use rutie::
|
18
|
-
|
19
|
-
|
20
|
-
};
|
18
|
+
use rutie::rubysys::class;
|
19
|
+
use rutie::types::Argc;
|
20
|
+
use rutie::util::str_to_cstring;
|
21
|
+
use rutie::{AnyException, AnyObject, Array, Boolean, Class, Exception, Integer, NilClass, Object, Proc, RString, Symbol, VM};
|
21
22
|
class!(Cranelift);
|
22
23
|
|
23
24
|
pub struct Builder {
|
24
25
|
pub module: JITModule,
|
26
|
+
pub verbose: bool
|
25
27
|
}
|
26
28
|
|
27
29
|
impl Builder {
|
28
|
-
fn new() -> Result<Self> {
|
30
|
+
fn new(verbose: bool) -> Result<Self> {
|
29
31
|
let mut flag_builder = settings::builder();
|
30
32
|
flag_builder.set("use_colocated_libcalls", "false")?;
|
31
33
|
// FIXME set back to true once the x64 backend supports it.
|
@@ -35,6 +37,7 @@ impl Builder {
|
|
35
37
|
let isa = isa_builder.finish(settings::Flags::new(flag_builder));
|
36
38
|
Ok(Self {
|
37
39
|
module: JITModule::new(JITBuilder::with_isa(isa, default_libcall_names())),
|
40
|
+
verbose: verbose
|
38
41
|
})
|
39
42
|
}
|
40
43
|
}
|
@@ -43,6 +46,36 @@ wrappable_struct!(Builder, BuilderWrapper, BUILDER_WRAPPER);
|
|
43
46
|
|
44
47
|
class!(CraneliftBuilder);
|
45
48
|
|
49
|
+
pub extern fn cranelift_builder_new(argc: Argc, argv: *const AnyObject, _rtself: AnyObject) -> AnyObject {
|
50
|
+
let args = rutie::types::Value::from(0);
|
51
|
+
|
52
|
+
unsafe {
|
53
|
+
let p_argv: *const rutie::types::Value = mem::transmute(argv);
|
54
|
+
|
55
|
+
class::rb_scan_args(
|
56
|
+
argc,
|
57
|
+
p_argv,
|
58
|
+
str_to_cstring("*").as_ptr(),
|
59
|
+
&args
|
60
|
+
)
|
61
|
+
};
|
62
|
+
|
63
|
+
let arguments = Array::from(args);
|
64
|
+
let verbose = {
|
65
|
+
if arguments.length() == 1 {
|
66
|
+
arguments.at(0).try_convert_to::<Boolean>().map_err(|e| VM::raise_ex(e)).unwrap().to_bool()
|
67
|
+
} else {
|
68
|
+
false
|
69
|
+
}
|
70
|
+
};
|
71
|
+
let builder = Builder::new(verbose)
|
72
|
+
.map_err(|e| VM::raise_ex(AnyException::new("StandardError", Some(&e.to_string()))))
|
73
|
+
.unwrap();
|
74
|
+
Class::from_existing("CraneliftRuby")
|
75
|
+
.get_nested_class("CraneliftBuilder")
|
76
|
+
.wrap_data(builder, &*BUILDER_WRAPPER)
|
77
|
+
}
|
78
|
+
|
46
79
|
methods!(
|
47
80
|
CraneliftBuilder,
|
48
81
|
itself,
|
@@ -58,14 +91,6 @@ methods!(
|
|
58
91
|
.get_nested_class("Signature")
|
59
92
|
.wrap_data(sig, &*SIGNATURE_WRAPPER)
|
60
93
|
},
|
61
|
-
fn cranelift_builder_new() -> AnyObject {
|
62
|
-
let builder = Builder::new()
|
63
|
-
.map_err(|e| VM::raise_ex(AnyException::new("StandardError", Some(&e.to_string()))))
|
64
|
-
.unwrap();
|
65
|
-
Class::from_existing("CraneliftRuby")
|
66
|
-
.get_nested_class("CraneliftBuilder")
|
67
|
-
.wrap_data(builder, &*BUILDER_WRAPPER)
|
68
|
-
},
|
69
94
|
fn make_function(name: RString, signature: AnyObject, callback: Proc) -> Integer {
|
70
95
|
let builder = itself.get_data_mut(&*BUILDER_WRAPPER);
|
71
96
|
let name = name.map_err(|e| VM::raise_ex(e)).unwrap();
|
@@ -152,7 +177,7 @@ fn make_function_impl(
|
|
152
177
|
let mut func_ctx = FunctionBuilderContext::new();
|
153
178
|
ctx.func.signature = signature.clone();
|
154
179
|
ctx.func.name = ExternalName::user(0, func.as_u32());
|
155
|
-
|
180
|
+
ctx.set_disasm(builder.verbose);
|
156
181
|
let bcx: FunctionBuilder = FunctionBuilder::new(&mut ctx.func, &mut func_ctx);
|
157
182
|
let cranelift_bcx: AnyObject = Class::from_existing("CraneliftRuby")
|
158
183
|
.get_nested_class("CraneliftFunctionBuilder")
|
@@ -160,12 +185,14 @@ fn make_function_impl(
|
|
160
185
|
callback.call(&[cranelift_bcx]);
|
161
186
|
let mut trap_sink = NullTrapSink {};
|
162
187
|
let mut stack_map_sink = NullStackMapSink {};
|
163
|
-
// println!("{}", ctx.func.display(None).to_string());
|
164
188
|
builder
|
165
189
|
.module
|
166
190
|
.define_function(func, &mut ctx, &mut trap_sink, &mut stack_map_sink)
|
167
191
|
.map_err(|e| AnyException::new("StandardError", Some(&format!("{:?}", e))))?;
|
168
|
-
|
192
|
+
if builder.verbose {
|
193
|
+
println!("\n{}", ctx.func.display(None).to_string());
|
194
|
+
println!("{}\n", ctx.mach_compile_result.unwrap().disasm.unwrap());
|
195
|
+
}
|
169
196
|
Ok(func.as_u32())
|
170
197
|
}
|
171
198
|
|
@@ -343,6 +370,34 @@ methods!(
|
|
343
370
|
let res = bcx.ins().iadd(x, y);
|
344
371
|
Integer::new(res.as_u32().into())
|
345
372
|
},
|
373
|
+
fn band(x: Integer, y: Integer) -> Integer {
|
374
|
+
let bcx = itself.get_data_mut(&*FUNCTION_BUILDER_WRAPPER);
|
375
|
+
let x = x.map_err(|e| VM::raise_ex(e)).unwrap();
|
376
|
+
let x = from_integer_to_value(x)
|
377
|
+
.map_err(|e| VM::raise_ex(e))
|
378
|
+
.unwrap();
|
379
|
+
let y = y.map_err(|e| VM::raise_ex(e)).unwrap();
|
380
|
+
let y = from_integer_to_value(y)
|
381
|
+
.map_err(|e| VM::raise_ex(e))
|
382
|
+
.unwrap();
|
383
|
+
|
384
|
+
let res = bcx.ins().band(x, y);
|
385
|
+
Integer::new(res.as_u32().into())
|
386
|
+
},
|
387
|
+
fn bor(x: Integer, y: Integer) -> Integer {
|
388
|
+
let bcx = itself.get_data_mut(&*FUNCTION_BUILDER_WRAPPER);
|
389
|
+
let x = x.map_err(|e| VM::raise_ex(e)).unwrap();
|
390
|
+
let x = from_integer_to_value(x)
|
391
|
+
.map_err(|e| VM::raise_ex(e))
|
392
|
+
.unwrap();
|
393
|
+
let y = y.map_err(|e| VM::raise_ex(e)).unwrap();
|
394
|
+
let y = from_integer_to_value(y)
|
395
|
+
.map_err(|e| VM::raise_ex(e))
|
396
|
+
.unwrap();
|
397
|
+
|
398
|
+
let res = bcx.ins().bor(x, y);
|
399
|
+
Integer::new(res.as_u32().into())
|
400
|
+
},
|
346
401
|
fn return_(values: Array) -> NilClass {
|
347
402
|
let bcx = itself.get_data_mut(&*FUNCTION_BUILDER_WRAPPER);
|
348
403
|
let values = values.map_err(|e| VM::raise_ex(e)).unwrap();
|
@@ -591,9 +646,12 @@ pub extern "C" fn Init_cranelift_ruby() {
|
|
591
646
|
klass.def("def_var", def_var);
|
592
647
|
klass.def("use_var", use_var);
|
593
648
|
klass.def("icmp", icmp);
|
649
|
+
klass.def("select", select);
|
594
650
|
klass.def("import_signature", import_signature);
|
595
651
|
klass.def("call_indirect", call_indirect);
|
596
652
|
klass.def("inst_results", inst_results);
|
653
|
+
klass.def("band", band);
|
654
|
+
klass.def("bor", bor);
|
597
655
|
});
|
598
656
|
});
|
599
657
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cranelift_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marco Concetto Rudilosso
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-07-
|
11
|
+
date: 2021-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rutie
|