Skip to content

Commit

Permalink
Output a header file
Browse files Browse the repository at this point in the history
  • Loading branch information
jac3km4 committed Mar 23, 2022
1 parent a3a97de commit 38c50de
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/codegen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::io::Write;

use crate::error::Error;
use crate::symbols::FunctionSymbol;

pub fn write_header<W: Write>(symbols: &[FunctionSymbol], mut out: W) -> Result<(), Error> {
for symbol in symbols {
writeln!(
out,
"#define {}_ADDR 0x{:X}",
symbol.name().to_uppercase(),
symbol.addr()
)?;
}

Ok(())
}
3 changes: 3 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use object::{Object, ObjectSection};
use crate::error::Error;
use crate::symbols::ObjectProperties;

pub mod codegen;
pub mod defns;
pub mod error;
pub mod patterns;
Expand Down Expand Up @@ -58,7 +59,9 @@ fn run(source_path: &Path, exe_path: &Path, out_path: &Path) -> Result<(), Error
log::warn!("Some of the patterns have failed:\n{message}",);
}

codegen::write_header(&syms, File::create(out_path.with_extension("h"))?)?;
symbols::generate(syms, props, File::create(out_path)?)?;

log::info!("Written the debug symbols to {}", out_path.display());
} else {
log::error!("Code section missing from the executable, nothing to do")
Expand Down
8 changes: 8 additions & 0 deletions src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,14 @@ impl FunctionSymbol {
pub(crate) fn new(name: String, typ: FunctionType, addr: u64) -> Self {
Self { name, typ, addr }
}

pub fn name(&self) -> &str {
&self.name
}

pub fn addr(&self) -> u64 {
self.addr
}
}

#[derive(Debug)]
Expand Down

0 comments on commit 38c50de

Please sign in to comment.