use std::{fs::File, path::PathBuf};
use bincode::Options;
use clap::Parser;
use come::{backend::riscv::simple_instruction, binary_format::clef::Clef};
use shadow_rs::shadow;
shadow!(build);
#[derive(Parser, Debug)]
#[command(version, long_version = build::CLAP_LONG_VERSION, about, long_about = None)]
struct Args {
#[arg(short, long)]
input: PathBuf,
}
fn main() {
let args = Args::parse();
let clef_file = File::open(args.input).unwrap();
let loader = bincode::DefaultOptions::new().with_fixint_encoding();
let clef: Clef = loader.deserialize_from(&clef_file).unwrap();
println!("architecture: {}", clef.architecture);
println!("os: {}", clef.os);
for section in clef.sections {
println!("section: {}", section.meta.name);
println!("linkable: {}", section.meta.linkable);
println!(
"loadable: {}",
if let Some(address) = section.meta.loadable {
format!("should be loaded to 0x{address:0x}")
} else {
"no".to_string()
}
);
println!("symbols:");
for symbol in §ion.meta.symbols {
println!(" {symbol}");
}
println!("pending symbols:");
if section.meta.pending_symbols.is_empty() {
println!(" <none>")
} else {
for pending_symbol in §ion.meta.pending_symbols {
println!(" {pending_symbol}");
}
}
println!("content:",);
let instructions =
simple_instruction::parse_whole_binary(§ion.content, §ion.meta.pending_symbols);
for instruction in instructions {
println!(" {instruction}");
}
}
}