diff --git a/Cargo.toml b/Cargo.toml index 0558ecd..d5d9c3e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,5 +2,6 @@ members = [ "lib-ltcore", "ltcc", - "ltvm" + "ltvm", + "ltobjdump", ] diff --git a/ltobjdump/Cargo.toml b/ltobjdump/Cargo.toml new file mode 100644 index 0000000..689ed6f --- /dev/null +++ b/ltobjdump/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "ltobjdump" +version = "0.1.0" +edition = "2021" + +[dependencies] +laddertypes = { path = "../../lib-laddertypes" } +ltcore = { path = "../lib-ltcore" } +tisc = { path = "../../lib-tisc" } +clap = { version = "4.5.15", features = ["derive"] } +tiny-ansi = "0.1.0" +iterate-text = "0.0.1" +bincode = "1.3.3" + diff --git a/ltobjdump/src/main.rs b/ltobjdump/src/main.rs new file mode 100644 index 0000000..6e83928 --- /dev/null +++ b/ltobjdump/src/main.rs @@ -0,0 +1,50 @@ +use { + std::io::Read, + clap::Parser, + tiny_ansi::TinyAnsi, +}; + +#[derive(Parser, Debug)] +#[command(version, about, long_about = None)] +struct Args { + /// source files + sources: Vec< String >, +} + +fn main() { + let args = Args::parse(); + + for source_path in args.sources.iter() { + let mut input = std::io::BufReader::new( + std::fs::File::open(source_path).expect("Failed to open file") + ); + + let obj_file : tisc::linker::ObjectFile + = bincode::deserialize_from( input ).expect(""); + + println!("{}\n{}", source_path.bold().yellow(), "------------".green()); + println!("{}", "Symbols".bold().white()); + + for (name, addr) in obj_file.symbols.iter() { + println!("{} @ {}", name.bold().yellow(), format!("{:#010x}", addr).blue()); + } + + println!("{}\n{}", "------------".green(), + "Code".bold().white()); + + for (i,l) in tisc::assembler::disassemble( &obj_file.code ) + .into_iter().enumerate() + { + for (name, addr) in obj_file.symbols.iter() { + if *addr == i as tisc::VM_Word { + println!("{}:", name.bold().yellow()); + } + } + + println!("{} {}", format!("{:#06x}",i).blue(), l.green()); + } + + println!("{}\n", "============".green()); + } +} +