mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-26 07:01:33 +00:00
Add the ability to pass backend specific options through CompilerConfig.
Use this to replace wasmer_llvm_backend::GLOBAL_OPTIONS.
This commit is contained in:
@ -2,6 +2,7 @@ use super::stackmap::StackmapRegistry;
|
||||
use crate::{
|
||||
intrinsics::Intrinsics,
|
||||
structs::{Callbacks, LLVMModule, LLVMResult, MemProtect},
|
||||
LLVMCallbacks,
|
||||
};
|
||||
use inkwell::{
|
||||
memory_buffer::MemoryBuffer,
|
||||
@ -13,8 +14,6 @@ use std::{
|
||||
any::Any,
|
||||
cell::RefCell,
|
||||
ffi::{c_void, CString},
|
||||
fs::File,
|
||||
io::Write,
|
||||
mem,
|
||||
ops::Deref,
|
||||
ptr::{self, NonNull},
|
||||
@ -176,23 +175,22 @@ impl LLVMBackend {
|
||||
_stackmaps: &StackmapRegistry,
|
||||
_module_info: &ModuleInfo,
|
||||
target_machine: &TargetMachine,
|
||||
llvm_callbacks: &Option<Rc<RefCell<dyn LLVMCallbacks>>>,
|
||||
) -> (Self, LLVMCache) {
|
||||
let memory_buffer = target_machine
|
||||
.write_to_memory_buffer(&module.borrow_mut(), FileType::Object)
|
||||
.unwrap();
|
||||
let mem_buf_slice = memory_buffer.as_slice();
|
||||
|
||||
if let Some(path) = unsafe { &crate::GLOBAL_OPTIONS.obj_file } {
|
||||
let mut file = File::create(path).unwrap();
|
||||
let mut pos = 0;
|
||||
while pos < mem_buf_slice.len() {
|
||||
pos += file.write(&mem_buf_slice[pos..]).unwrap();
|
||||
}
|
||||
if let Some(callbacks) = llvm_callbacks {
|
||||
callbacks
|
||||
.borrow_mut()
|
||||
.obj_memory_buffer_callback(&memory_buffer);
|
||||
}
|
||||
|
||||
let callbacks = get_callbacks();
|
||||
let mut module: *mut LLVMModule = ptr::null_mut();
|
||||
|
||||
let mem_buf_slice = memory_buffer.as_slice();
|
||||
let res = unsafe {
|
||||
module_load(
|
||||
mem_buf_slice.as_ptr(),
|
||||
|
Reference in New Issue
Block a user