cranelift_ruby 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b7c82084d7d1c3df6fdea5cbf87a28d7984b6f2e81cbb83e9ed56389f334b8e
4
- data.tar.gz: 79d48d591abe63680b5ff844c3e2ffbe39b5a604655c2abaada90598622de36f
3
+ metadata.gz: '039ede96c7d734182f363ea730befc04ae5cd9dd13e2564219e6dd03beae4d64'
4
+ data.tar.gz: 164e40e024c40bf14df62dad63189a4d428eed20ffcfb13f3c584dc91eb8d586
5
5
  SHA512:
6
- metadata.gz: e23767df92a9adf4b7a25feff24e7dae695f4a8735b268e7badbc9fa40e3dce6468943f69dde350ceefbdfe29d92bd6393d651354fa1dd653ec65e7ae136403a
7
- data.tar.gz: 63e61a3f1890cb29802e701c6a38b6281662b218a6f14e76b8fa08a13a00693e1a0181c5bf94b900c7423998fae2c1fb3566ce4ce18f167f8b1a4709f8363030
6
+ metadata.gz: 81228c2a238389ffa49236b29cb8f3017afbd90f47237d2a03cf966c67b6657ecd94538f0ce0000779d0779b1d1ca995fd4120f4628641fdb54f542e94ab2f13
7
+ data.tar.gz: f57c3c484724faf31e3738311cdfaa3bcf3f2b3dcdf6f8bed1a77e53724b6040689fd12c615325da440cb74cfbfc9ad1746c9828fb17150058811f9efcb340ff
@@ -1,3 +1,3 @@
1
1
  module CraneliftRuby
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
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
- AnyException, AnyObject, Array, Class, Exception, Integer, NilClass, Object, Proc, RString,
19
- Symbol, VM,
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
- // ctx.set_disasm(true);
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
- // println!("code: {}", ctx.mach_compile_result.unwrap().disasm.unwrap());
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cranelift_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marco Concetto Rudilosso