Files
damn_simple_architecture/compiler/src/main.rs
T
2026-02-23 09:04:30 +00:00

34 lines
864 B
Rust

use std::path::{Path, PathBuf};
use common::{build::Builder, logging::info};
use compiler::Compiler;
fn main() {
// read from input file: syntax "c_compiler <src.c> [output.dsa]"
let args: Vec<String> = std::env::args().collect();
if args.len() < 2 {
eprintln!("Usage: c_compiler <src.dsc> [output.dsa]");
return;
}
let input_file = &args[1];
let output_file = if args.len() > 2 {
&args[2]
} else {
"output.dsa"
};
{
let mut builder = Compiler::new(PathBuf::from(input_file));
builder.start();
let result = builder.output().unwrap();
std::fs::write(output_file, &result).expect("Failed to write output");
info(&format!(
"Compilation Successful ✅ \n\tSource: {}\n\tOutput: {}\n",
input_file, output_file,
));
}
}