Add support for backend flags. Backend flags are opaque to src/bin/wasmer.rs.

Use them to implement three features in the LLVM backend, getting a valid ELF object file, the post-optimization LLVM IR and the pre-optimization LLVM IR.

Presently they are also global to the backend which is not ideal.
This commit is contained in:
Nick Lewycky
2019-08-08 16:05:17 -07:00
parent 77fe15db31
commit b2c4501357
5 changed files with 56 additions and 1 deletions

View File

@ -10,6 +10,8 @@ use libc::c_char;
use std::{
any::Any,
ffi::{c_void, CString},
fs::File,
io::Write,
mem,
ops::Deref,
ptr::{self, NonNull},
@ -177,6 +179,14 @@ impl LLVMBackend {
.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();
}
}
let callbacks = get_callbacks();
let mut module: *mut LLVMModule = ptr::null_mut();