Skip to content

Commit 8ac7ed5

Browse files
committed
Remove direct llvm-sys dependency, cleanup imports
Should fix any double-linking problems at the cost of a bit of tech debt
1 parent 64ab86d commit 8ac7ed5

File tree

15 files changed

+107
-99
lines changed

15 files changed

+107
-99
lines changed

Cargo.lock

Lines changed: 4 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ edition = "2018"
66

77
[dependencies]
88
flexi_logger = "0.14.4"
9-
llvm-sys = "90.0.0"
109
llvm-alt = { git = "https://github.com/Others/llvm-rs.git"}
1110
log = "0.4.8"
1211
structopt = "0.3.2"

code_benches/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
import timeit
66

7-
# Note: This is a major configuration option, you probably want to set this if you're doing anything advanced
7+
# Note: This is a major configuration option, you probably want to set this if you're doing anything non-trivial
88
SILVERFISH_TARGET = None
99
# SILVERFISH_TARGET = "thumbv7em-none-unknown-eabi"
1010
# SILVERFISH_TARGET = "x86_64-apple-macosx10.15.0"

src/codegen/block.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ use llvm::Value;
77

88
use wasmparser::Type;
99

10-
use super::super::wasm::Instruction;
10+
use crate::codegen::ModuleCtx;
1111

12-
use super::ModuleCtx;
12+
use crate::codegen::breakout::BreakoutTarget;
13+
use crate::codegen::breakout::WBreakoutTarget;
1314

14-
use super::breakout::BreakoutTarget;
15-
use super::breakout::WBreakoutTarget;
15+
use crate::codegen::function::FunctionCtx;
1616

17-
use super::function::FunctionCtx;
17+
use crate::codegen::runtime_stubs::*;
1818

19-
use super::runtime_stubs::*;
19+
use crate::codegen::type_conversions::llvm_type_to_wasm_type;
20+
use crate::codegen::type_conversions::wasm_func_type_to_llvm_type;
2021

21-
use super::type_conversions::llvm_type_to_wasm_type;
22-
use super::type_conversions::wasm_func_type_to_llvm_type;
22+
use crate::wasm::Instruction;
2323

2424
// TODO: Double check each instruction to make sure it does the right thing in both the safe and unsafe case
2525

src/codegen/breakout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use llvm::Value;
88

99
use wasmparser::TypeOrFuncType;
1010

11-
use super::type_conversions::llvm_type_to_zeroed_value;
12-
use super::type_conversions::wasm_type_to_zeroed_value;
11+
use crate::codegen::type_conversions::llvm_type_to_zeroed_value;
12+
use crate::codegen::type_conversions::wasm_type_to_zeroed_value;
1313

1414
pub struct BreakoutTarget<'a> {
1515
pub bb: &'a BasicBlock,

src/codegen/function.rs

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
use std::cell::Cell;
22
use std::ffi::CString;
33
use std::mem;
4+
use std::sync::atomic::{AtomicBool, Ordering};
45

56
use llvm::{BasicBlock, Sub};
67
use llvm::Builder;
78
use llvm::Function;
89
use llvm::Value;
910

10-
use super::super::wasm::ImplementedFunction;
11-
12-
use super::block::compile_block;
13-
use super::breakout::BreakoutTarget;
14-
use super::type_conversions::wasm_type_to_zeroed_value;
15-
use super::ModuleCtx;
1611
use wasmparser::TypeOrFuncType;
1712

13+
use crate::codegen::block::compile_block;
14+
use crate::codegen::breakout::BreakoutTarget;
15+
use crate::codegen::type_conversions::wasm_type_to_zeroed_value;
16+
use crate::codegen::ModuleCtx;
17+
18+
use crate::wasm::ImplementedFunction;
19+
1820
pub struct FunctionCtx<'a> {
1921
pub llvm_f: &'a Function,
2022
pub builder: &'a Builder,
@@ -31,29 +33,33 @@ impl<'a> FunctionCtx<'a> {
3133
}
3234
}
3335

34-
unsafe fn add_string_attr(k: &str, v: &str, v_ref: *mut llvm_sys::LLVMValue, ctx: &ModuleCtx) {
35-
let idx = llvm_sys::LLVMAttributeFunctionIndex;
36+
unsafe fn add_string_attr(k: &str, v: &str, v_ref: *mut llvm::ffi::LLVMValue, ctx: &ModuleCtx) {
37+
let idx = crate::llvm_externs::LLVMAttributeFunctionIndex;
3638

3739
let target_features_key = CString::new(k).unwrap();
3840
let target_features_value = CString::new(v).unwrap();
3941

40-
let llvm_ctx: *mut llvm_sys::LLVMContext = mem::transmute(ctx.llvm_ctx as &llvm::Context);
41-
let attr_ref = llvm_sys::core::LLVMCreateStringAttribute(
42+
let llvm_ctx: *mut llvm::ffi::LLVMContext = mem::transmute(ctx.llvm_ctx as &llvm::Context);
43+
let attr_ref = crate::llvm_externs::LLVMCreateStringAttribute(
4244
llvm_ctx,
4345
target_features_key.as_ptr(),
4446
target_features_key.as_bytes().len() as u32,
4547
target_features_value.as_ptr(),
4648
target_features_value.as_bytes().len() as u32,
4749
);
4850

49-
llvm_sys::core::LLVMAddAttributeAtIndex(
51+
crate::llvm_externs::LLVMAddAttributeAtIndex(
5052
v_ref,
5153
idx,
5254
attr_ref
5355
);
5456

5557
}
5658

59+
// HACK: We only want to emit a note about the cortex-m override once
60+
// TODO: Is this clearer than doing it up a level in the code?
61+
static CORTEX_OVERRIDE_MESSAGE_SENT: AtomicBool = AtomicBool::new(false);
62+
5763
pub fn compile_function(ctx: &ModuleCtx, f: &ImplementedFunction) {
5864
let llvm_f = ctx.llvm_module.get_function(&f.generated_name).unwrap();
5965

@@ -86,20 +92,25 @@ pub fn compile_function(ctx: &ModuleCtx, f: &ImplementedFunction) {
8692
};
8793

8894
unsafe {
89-
let v_ref: *mut llvm_sys::LLVMValue = mem::transmute(llvm_f.to_super() as &Value);
90-
let llvm_ctx: *mut llvm_sys::LLVMContext = mem::transmute(ctx.llvm_ctx as &llvm::Context);
95+
let v_ref: *mut llvm::ffi::LLVMValue = mem::transmute(llvm_f.to_super() as &Value);
96+
let llvm_ctx: *mut llvm::ffi::LLVMContext = mem::transmute(ctx.llvm_ctx as &llvm::Context);
9197

9298
let nounwind = CString::new("nounwind").unwrap();
93-
let kind = llvm_sys::core::LLVMGetEnumAttributeKindForName(nounwind.as_ptr(), nounwind.as_bytes().len());
94-
let attr_ref = llvm_sys::core::LLVMCreateEnumAttribute(llvm_ctx, kind, 0);
99+
let kind = crate::llvm_externs::LLVMGetEnumAttributeKindForName(nounwind.as_ptr(), nounwind.as_bytes().len());
100+
let attr_ref = crate::llvm_externs::LLVMCreateEnumAttribute(llvm_ctx, kind, 0);
95101

96-
llvm_sys::core::LLVMAddAttributeAtIndex(
102+
crate::llvm_externs::LLVMAddAttributeAtIndex(
97103
v_ref,
98-
llvm_sys::LLVMAttributeFunctionIndex,
104+
crate::llvm_externs::LLVMAttributeFunctionIndex,
99105
attr_ref
100106
);
101107
if cm_override {
102-
info!("engaging cortex-m override");
108+
if !CORTEX_OVERRIDE_MESSAGE_SENT.load(Ordering::Relaxed) {
109+
info!("engaging cortex-m override");
110+
111+
// Only send the message once!
112+
CORTEX_OVERRIDE_MESSAGE_SENT.store(true, Ordering::Relaxed);
113+
}
103114

104115
add_string_attr(
105116
"correctly-rounded-divide-sqrt-fp-math",

src/codegen/globals.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ use llvm::Value;
88

99
use wasmparser::Type;
1010

11-
use super::super::wasm::Global;
12-
use super::super::wasm::Instruction;
13-
use super::super::Opt;
11+
use crate::wasm::Global;
12+
use crate::wasm::Instruction;
13+
use crate::Opt;
1414

15-
use super::runtime_stubs::*;
16-
use super::type_conversions::llvm_type_to_wasm_type;
17-
use super::type_conversions::wasm_type_to_llvm_type;
18-
use super::ModuleCtx;
15+
use crate::codegen::ModuleCtx;
16+
use crate::codegen::runtime_stubs::*;
17+
use crate::codegen::type_conversions::llvm_type_to_wasm_type;
18+
use crate::codegen::type_conversions::wasm_type_to_llvm_type;
1919

2020
pub enum GlobalValue<'a> {
2121
InlinedConstant(&'a Value),

src/codegen/memory.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
1-
use llvm;
21
use llvm::Builder;
32
use llvm::Compile;
43
use llvm::FunctionType;
54
use llvm::PointerType;
65
use llvm::Sub;
76
use llvm::Value;
87

9-
use wasmparser;
108
use wasmparser::ResizableLimits;
119

12-
use super::super::wasm::DataInitializer;
13-
use super::super::wasm::ImplementedFunction;
14-
use super::super::wasm::Instruction;
10+
use crate::wasm::DataInitializer;
11+
use crate::wasm::ImplementedFunction;
12+
use crate::wasm::Instruction;
1513

16-
use super::function::compile_function;
17-
use super::type_conversions::wasm_func_type_to_llvm_type;
18-
use super::ModuleCtx;
14+
use crate::codegen::ModuleCtx;
15+
use crate::codegen::function::compile_function;
16+
use crate::codegen::type_conversions::wasm_func_type_to_llvm_type;
1917

2018
// We add in globals to tell the runtime how much memory to allocate and startup
2119
// (And what the max amount of allocated memory should be)

src/codegen/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ use llvm::Module as LLVMModule;
66

77
use wasmparser::FuncType;
88

9+
use crate::Opt;
10+
911
use crate::wasm::Export;
1012
use crate::wasm::Function;
1113
use crate::wasm::WasmModule;
1214

13-
use super::Opt;
14-
1515
mod block;
1616

1717
mod breakout;

src/codegen/runtime_stubs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use llvm::Module as LLVMModule;
66
use llvm::PointerType;
77
use llvm::Sub;
88

9-
use super::ModuleCtx;
10-
use super::Opt;
9+
use crate::codegen::ModuleCtx;
10+
use crate::codegen::Opt;
1111

1212
// Backing functions for wasm operations
1313
pub const INITIALIZE_REGION_STUB: &str = "initialize_region";

0 commit comments

Comments
 (0)