assembler: begin wrangling

This commit is contained in:
2025-06-25 02:25:46 +01:00
parent f72f36cd47
commit ce76820b6d
19 changed files with 79 additions and 2884 deletions
+45 -50
View File
@@ -2,67 +2,62 @@ use common as _;
use num_cpus as _;
use threadpool as _;
use assembler::{
prelude::*,
tooling::{brainf, project},
};
use clap::Parser;
use std::{fs, io::Write, path::PathBuf};
// use clap::Parser;
// use std::{fs, io::Write, path::PathBuf};
fn main() {
// Parse command line arguments
let args: Vec<String> = std::env::args().collect();
// // Parse command line arguments
// let args: Vec<String> = std::env::args().collect();
let _clap_args = assembler::args::Args::parse();
// let _clap_args = assembler::args::Args::parse();
if args.len() == 2 && args[1] == "init" {
project::tool_libcreate();
std::process::exit(0);
}
// if args.len() == 2 && args[1] == "init" {
// // project::tool_libcreate();
// std::process::exit(0);
// }
if args.len() == 2 && args[1] == "brainf" {
let src = PathBuf::from("brainf.bf");
let result = brainf::build(&src);
// if args.len() == 2 && args[1] == "brainf" {
// let src = PathBuf::from("brainf.bf");
// // let result = brainf::build(&src);
let mut file = match fs::File::create("brainf.dsb") {
Err(e) => {
eprintln!("Failed to create output file: {e}");
std::process::exit(1);
}
Ok(file) => file,
};
// let mut file = match fs::File::create("brainf.dsb") {
// Err(e) => {
// eprintln!("Failed to create output file: {e}");
// std::process::exit(1);
// }
// Ok(file) => file,
// };
for instruction in result {
if let Err(e) = file.write(&instruction.encode().to_be_bytes()) {
eprintln!("Failed to write to output file: {e}");
std::process::exit(1);
}
}
// // for instruction in result {
// // if let Err(e) = file.write(&instruction.encode().to_be_bytes()) {
// // eprintln!("Failed to write to output file: {e}");
// // std::process::exit(1);
// // }
// // }
std::process::exit(0);
}
// std::process::exit(0);
// }
if args.len() != 5 || args[1] != "-i" || args[3] != "-o" {
eprintln!("Usage: {} -i input_path -o output_path", args[0]);
std::process::exit(1);
}
// if args.len() != 5 || args[1] != "-i" || args[3] != "-o" {
// eprintln!("Usage: {} -i input_path -o output_path", args[0]);
// std::process::exit(1);
// }
let input_path = &args[2];
let output_path = &args[4];
let src = PathBuf::from(input_path);
// let input_path = &args[2];
// let output_path = &args[4];
// let src = PathBuf::from(input_path);
// Initialize the compiler engine
let mut compiler = CompilerEngine::new();
compiler.start_compilation(&src);
// // Initialize the compiler engine
// let mut compiler = CompilerEngine::new();
// compiler.start_compilation(&src);
// Or block until done
let result = compiler.wait_for_result().unwrap();
// // Or block until done
// let result = compiler.wait_for_result().unwrap();
for instruction in result {
if let Err(e) = fs::write(output_path, instruction.encode().to_be_bytes()) {
eprintln!("Failed to write to output file: {e}");
std::process::exit(1);
}
}
// for instruction in result {
// if let Err(e) = fs::write(output_path, instruction.encode().to_be_bytes()) {
// eprintln!("Failed to write to output file: {e}");
// std::process::exit(1);
// }
// }
}