Move the cli into it’s own library

This commit is contained in:
Syrus
2020-07-22 21:32:45 -07:00
parent ad58fea8ae
commit 8cab73e34f
29 changed files with 253 additions and 71 deletions

View 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();
}
}
}
}