Skip to content

Commit

Permalink
Add option to set custom output directory
Browse files Browse the repository at this point in the history
  • Loading branch information
veera-sivarajan committed Feb 11, 2024
1 parent b5cc0b8 commit 5768065
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion driver/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ struct Args {
/// Print the parsed AST
#[arg(short, long)]
print_ast: bool,
/// Sets a custom output directory
#[arg(short, long, value_name = "FILE")]
output: Option<PathBuf>,
}

fn run(args: Args) -> std::io::Result<()> {
let source = read_to_string(&args.filename)?;
let mut file = PathBuf::from(args.filename);
file.set_extension("s");
let mut output = std::env::current_dir()?;
let mut output = args.output.unwrap_or(std::env::current_dir()?);
output.push(file.file_name().unwrap());
match compiler::compile(source.trim_end(), args.print_ast) {
Ok(assembly) => write(output, assembly.to_string().as_bytes()),
Expand Down

0 comments on commit 5768065

Please sign in to comment.