Files
8086-rs/src/main.rs
2025-05-28 16:00:18 +09:00

55 lines
1.2 KiB
Rust

use clap::{Parser, Subcommand};
use disasm::Disassembler;
mod aout;
mod disasm;
mod disasm_macros;
mod instructions;
mod operands;
mod register;
#[derive(Subcommand, Debug)]
enum Command {
/// Disassemble the binary into 8086 instructions
Disasm,
/// Interpret the 8086 instructions
Interpret,
}
/// Simple program to disassemble and interpret 8086 a.out compilates, e.g.
/// such for MINIX.
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
#[command(subcommand)]
command: Command,
/// Path of the binary
#[arg(short, long, global = true)]
path: Option<String>,
/// Dump progress of disassembly, in case of encountering an error.
#[arg(short, long, global = true, action)]
dump: bool,
}
fn main() {
env_logger::init();
let args = Args::parse();
log::debug!("{:?}", args);
match args.command {
Command::Disasm => {
let mut disasm = Disassembler::new(&args);
let instructions = disasm.disassemble(args.dump);
match instructions {
Ok(instrs) => instrs.iter().for_each(|i| println!("{i}")),
_ => {}
}
}
_ => panic!("Command not yet implemented"),
}
}