add ltobjdump
This commit is contained in:
parent
6b577e91f8
commit
388454e083
3 changed files with 66 additions and 1 deletions
|
@ -2,5 +2,6 @@
|
|||
members = [
|
||||
"lib-ltcore",
|
||||
"ltcc",
|
||||
"ltvm"
|
||||
"ltvm",
|
||||
"ltobjdump",
|
||||
]
|
||||
|
|
14
ltobjdump/Cargo.toml
Normal file
14
ltobjdump/Cargo.toml
Normal file
|
@ -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"
|
||||
|
50
ltobjdump/src/main.rs
Normal file
50
ltobjdump/src/main.rs
Normal file
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in a new issue