Files
damn_simple_architecture/assembler/src/main.rs
T

93 lines
2.8 KiB
Rust

use std::sync::Arc;
use assembler::{
error::{AssembleError, AssembleErrorKind, ParserError},
model::module::Module,
source::{source_info::SourceInfo, token::TokenType, tokeniser::Tokeniser},
};
use common as _;
use num_cpus as _;
use threadpool as _;
// use clap::Parser;
// use std::{fs, io::Write, path::PathBuf};
fn main() -> Result<(), AssembleError> {
// // Parse command line arguments
// let args: Vec<String> = std::env::args().collect();
let contents = include_bytes!("../../resources/dsa/bf.dsa").to_vec();
let module = Arc::new(Module::new("resources/dsa/bf.dsa")?);
let tok = Tokeniser::from_data(contents, module.clone());
let ts = tok
.tokenise()?
.into_iter()
.filter(|t| !matches!(t.token_type, TokenType::Eof | TokenType::Newline));
for t in ts {
t.source_info.print_context_with_underline()?;
}
let test_error: AssembleError = AssembleError::new_source_error(
SourceInfo::new(45, module.clone(), 4..7),
AssembleErrorKind::Parser(ParserError::InvalidInstruction),
);
eprintln!("\n\n{test_error}");
Ok(())
// 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] == "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,
// };
// // 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);
// }
// 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);
// // Initialize the compiler engine
// let mut compiler = CompilerEngine::new();
// compiler.start_compilation(&src);
// // 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);
// }
// }
}