diff --git a/juno_frontend/src/main.rs b/juno_frontend/src/main.rs index 67c89255fb6b869bace5b0dd9ae1b6906fae736b..2b0dc6b74313bc930e07bc4e7b231b32e7d0041d 100644 --- a/juno_frontend/src/main.rs +++ b/juno_frontend/src/main.rs @@ -14,7 +14,7 @@ mod types; use codegen::*; -use std::path::PathBuf; +use std::path::Path; extern crate hercules_ir; @@ -62,7 +62,9 @@ fn main() { pm.add_pass(hercules_opt::pass::Pass::Verify); } add_verified_pass!(pm, args, PhiElim); - pm.add_pass(hercules_opt::pass::Pass::Xdot(true)); + if args.x_dot { + pm.add_pass(hercules_opt::pass::Pass::Xdot(true)); + } add_pass!(pm, args, CCP); add_pass!(pm, args, DCE); add_pass!(pm, args, GVN); @@ -77,17 +79,15 @@ fn main() { if args.x_dot { pm.add_pass(hercules_opt::pass::Pass::Xdot(true)); } - match args.output { - Some(file) => pm.add_pass(hercules_opt::pass::Pass::Codegen(file)), - None => { - let mut path = PathBuf::from(src_file); - path.set_extension("hbin"); - println!("{:?}", path); - pm.add_pass(hercules_opt::pass::Pass::Codegen( - path.to_str().unwrap().to_string(), - )); - } - } + + let src_file_path = Path::new(&src_file); + let module_name = String::from(src_file_path.file_stem().unwrap().to_str().unwrap()); + let output_folder = match args.output { + Some(output_folder) => output_folder, + None => String::from(src_file_path.parent().unwrap().to_str().unwrap()) + }; + pm.add_pass(hercules_opt::pass::Pass::Codegen(output_folder, module_name)); + let _ = pm.run_passes(); } Err(errs) => {