28 lines
783 B
Rust
28 lines
783 B
Rust
use std::{fs, io::Write, path::PathBuf};
|
|
|
|
fn main() {
|
|
// parse args:
|
|
let args: Vec<String> = std::env::args().collect();
|
|
if args.len() != 5 || args[1] != "-i" || args[3] != "-o" {
|
|
eprintln!("Usage: binary_name -i input_path -o output_path");
|
|
std::process::exit(1);
|
|
}
|
|
let input_path = &args[2];
|
|
let output_path = &args[4];
|
|
|
|
let src = PathBuf::from(input_path);
|
|
let mut output_file = fs::File::create(output_path).unwrap();
|
|
|
|
match assembler::assemble(&src) {
|
|
Ok(res) => {
|
|
res.iter().map(|i| i.encode()).for_each(|i| {
|
|
output_file.write_all(&i.to_le_bytes()).unwrap();
|
|
});
|
|
}
|
|
Err(e) => {
|
|
eprintln!("{e}");
|
|
std::process::exit(1);
|
|
}
|
|
}
|
|
}
|