Skip to content

Commit 735d7e2

Browse files
committed
Update deps and fix aarch
1 parent 3742c96 commit 735d7e2

2 files changed

Lines changed: 28 additions & 23 deletions

File tree

‎Cargo.toml‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ edition = "2018"
99

1010
[dependencies]
1111
peg = "0.6"
12-
cranelift = "0.85.1"
13-
cranelift-module = "0.85.1"
14-
cranelift-jit = "0.85.1"
12+
cranelift = "0.93.0"
13+
cranelift-module = "0.93.0"
14+
cranelift-jit = "0.93.0"
15+
cranelift-native = "0.93.0"

‎src/jit.rs‎

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,18 @@ pub struct JIT {
2626

2727
impl Default for JIT {
2828
fn default() -> Self {
29-
let builder = JITBuilder::new(cranelift_module::default_libcall_names());
30-
let module = JITModule::new(builder.unwrap());
29+
let mut flag_builder = settings::builder();
30+
flag_builder.set("use_colocated_libcalls", "false").unwrap();
31+
flag_builder.set("is_pic", "false").unwrap();
32+
let isa_builder = cranelift_native::builder().unwrap_or_else(|msg| {
33+
panic!("host machine is not supported: {}", msg);
34+
});
35+
let isa = isa_builder
36+
.finish(settings::Flags::new(flag_builder))
37+
.unwrap();
38+
let builder = JITBuilder::with_isa(isa, cranelift_module::default_libcall_names());
39+
40+
let module = JITModule::new(builder);
3141
Self {
3242
builder_context: FunctionBuilderContext::new(),
3343
ctx: module.make_context(),
@@ -64,9 +74,7 @@ impl JIT {
6474
// defined. For this toy demo for now, we'll just finalize the
6575
// function below.
6676
self.module
67-
.define_function(
68-
id,
69-
&mut self.ctx)
77+
.define_function(id, &mut self.ctx)
7078
.map_err(|e| e.to_string())?;
7179

7280
// Now that compilation is finished, we can clear out the context state.
@@ -75,7 +83,7 @@ impl JIT {
7583
// Finalize the functions which we just defined, which resolves any
7684
// outstanding relocations (patching in addresses, now that they're
7785
// available).
78-
self.module.finalize_definitions();
86+
self.module.finalize_definitions().unwrap();
7987

8088
// We can now retrieve a pointer to the machine code.
8189
let code = self.module.get_finalized_function(id);
@@ -97,7 +105,7 @@ impl JIT {
97105
.define_data(id, &self.data_ctx)
98106
.map_err(|e| e.to_string())?;
99107
self.data_ctx.clear();
100-
self.module.finalize_definitions();
108+
self.module.finalize_definitions().unwrap();
101109
let buffer = self.module.get_finalized_data(id);
102110
// TODO: Can we move the unsafe into cranelift?
103111
Ok(unsafe { slice::from_raw_parts(buffer.0, buffer.1) })
@@ -252,8 +260,7 @@ impl<'a> FunctionTranslator<'a> {
252260
fn translate_icmp(&mut self, cmp: IntCC, lhs: Expr, rhs: Expr) -> Value {
253261
let lhs = self.translate_expr(lhs);
254262
let rhs = self.translate_expr(rhs);
255-
let c = self.builder.ins().icmp(cmp, lhs, rhs);
256-
self.builder.ins().bint(self.int, c)
263+
self.builder.ins().icmp(cmp, lhs, rhs)
257264
}
258265

259266
fn translate_if_else(
@@ -276,9 +283,9 @@ impl<'a> FunctionTranslator<'a> {
276283
self.builder.append_block_param(merge_block, self.int);
277284

278285
// Test the if condition and conditionally branch.
279-
self.builder.ins().brz(condition_value, else_block, &[]);
280-
// Fall through to then block.
281-
self.builder.ins().jump(then_block, &[]);
286+
self.builder
287+
.ins()
288+
.brif(condition_value, then_block, &[], else_block, &[]);
282289

283290
self.builder.switch_to_block(then_block);
284291
self.builder.seal_block(then_block);
@@ -322,8 +329,9 @@ impl<'a> FunctionTranslator<'a> {
322329
self.builder.switch_to_block(header_block);
323330

324331
let condition_value = self.translate_expr(condition);
325-
self.builder.ins().brz(condition_value, exit_block, &[]);
326-
self.builder.ins().jump(body_block, &[]);
332+
self.builder
333+
.ins()
334+
.brif(condition_value, body_block, &[], exit_block, &[]);
327335

328336
self.builder.switch_to_block(body_block);
329337
self.builder.seal_block(body_block);
@@ -360,9 +368,7 @@ impl<'a> FunctionTranslator<'a> {
360368
.module
361369
.declare_function(&name, Linkage::Import, &sig)
362370
.expect("problem declaring function");
363-
let local_callee = self
364-
.module
365-
.declare_func_in_func(callee, &mut self.builder.func);
371+
let local_callee = self.module.declare_func_in_func(callee, self.builder.func);
366372

367373
let mut arg_values = Vec::new();
368374
for arg in args {
@@ -377,9 +383,7 @@ impl<'a> FunctionTranslator<'a> {
377383
.module
378384
.declare_data(&name, Linkage::Export, true, false)
379385
.expect("problem declaring data object");
380-
let local_id = self
381-
.module
382-
.declare_data_in_func(sym, &mut self.builder.func);
386+
let local_id = self.module.declare_data_in_func(sym, self.builder.func);
383387

384388
let pointer = self.module.target_config().pointer_type();
385389
self.builder.ins().symbol_value(pointer, local_id)

0 commit comments

Comments
 (0)