mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-06 20:58:28 +00:00
Move the cli into it’s own library
This commit is contained in:
42
lib/cli/src/compilers/llvm.rs
Normal file
42
lib/cli/src/compilers/llvm.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
/// LLVM backend flags.
|
||||
pub struct LLVMCLIOptions {
|
||||
/// Emit LLVM IR before optimization pipeline.
|
||||
#[structopt(long = "llvm-pre-opt-ir", parse(from_os_str))]
|
||||
pre_opt_ir: Option<PathBuf>,
|
||||
|
||||
/// Emit LLVM IR after optimization pipeline.
|
||||
#[structopt(long = "llvm-post-opt-ir", parse(from_os_str))]
|
||||
post_opt_ir: Option<PathBuf>,
|
||||
|
||||
/// Emit LLVM generated native code object file.
|
||||
#[structopt(long = "llvm-object-file", parse(from_os_str))]
|
||||
obj_file: Option<PathBuf>,
|
||||
}
|
||||
|
||||
|
||||
impl LLVMCallbacks for LLVMCLIOptions {
|
||||
fn preopt_ir_callback(&mut self, module: &InkwellModule) {
|
||||
if let Some(filename) = &self.pre_opt_ir {
|
||||
module.print_to_file(filename).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn postopt_ir_callback(&mut self, module: &InkwellModule) {
|
||||
if let Some(filename) = &self.post_opt_ir {
|
||||
module.print_to_file(filename).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
fn obj_memory_buffer_callback(&mut self, memory_buffer: &InkwellMemoryBuffer) {
|
||||
if let Some(filename) = &self.obj_file {
|
||||
let mem_buf_slice = memory_buffer.as_slice();
|
||||
let mut file = fs::File::create(filename).unwrap();
|
||||
let mut pos = 0;
|
||||
while pos < mem_buf_slice.len() {
|
||||
pos += file.write(&mem_buf_slice[pos..]).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user