aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2025-08-27 23:38:18 +0200
committerMiquel Sabaté Solà <mikisabate@gmail.com>2025-08-27 23:38:18 +0200
commit159a4ec4a64a8a5d791f40eb577afcbe7ee7303e (patch)
treeec3bcc4929d5eb4155f1c5ebbb8ab01ccf37f907 /crates
parent533a48b19a083104c90e90042404cc61ada47744 (diff)
downloadtools.nes-159a4ec4a64a8a5d791f40eb577afcbe7ee7303e.tar.gz
tools.nes-159a4ec4a64a8a5d791f40eb577afcbe7ee7303e.zip
nasm: Implement the -s/--stats option
This option prints further information on how segments are laid out. In particular, for now it prints the amount of space being filled for each segment. Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'crates')
-rw-r--r--crates/nasm/src/main.rs24
1 files changed, 24 insertions, 0 deletions
diff --git a/crates/nasm/src/main.rs b/crates/nasm/src/main.rs
index be1a386..3864587 100644
--- a/crates/nasm/src/main.rs
+++ b/crates/nasm/src/main.rs
@@ -14,6 +14,7 @@ struct Args {
out: Option<String>,
werror: bool,
stdout: bool,
+ stats: bool,
defines: Vec<(String, u8)>,
}
@@ -25,6 +26,7 @@ fn print_help() {
println!(" -c, --config <FILE>\tLinker configuration to be used, whether an identifier or a file path.");
println!(" -D <NAME>(=VALUE)\tDefine an 8-bit variable on the global scope (default: 1)");
println!(" -o, --out <FILE>\tFile path where the output should be located after execution.");
+ println!(" -s, --stats\t\tPrint the statistics on how segments have been filled.");
println!(" --stdout\t\tPrint the output binary to the standard output.");
println!(" -Werror\t\tWarnings should be treated as errors.");
std::process::exit(0);
@@ -100,6 +102,7 @@ fn parse_arguments() -> Args {
}
}
},
+ "-s" | "--stats" => res.stats = true,
"--stdout" => match res.out {
Some(_) => die("you cannot mix '-o/--out' and '--stdout'".to_string()),
None => {
@@ -214,5 +217,26 @@ fn main() {
}
}
+ if args.stats {
+ println!("== Statistics ==\n");
+ println!("=> Amount of space on each segment (in bytes):\n");
+
+ for mapping in res.mappings {
+ let perc = (mapping.offset * 100) as f64 / mapping.size as f64;
+
+ if perc.fract().abs() < f64::EPSILON {
+ println!(
+ "{}: {}/{} ({:.0}%)",
+ mapping.name, mapping.offset, mapping.size, perc
+ );
+ } else {
+ println!(
+ "{}: {}/{} ({:.2}%)",
+ mapping.name, mapping.offset, mapping.size, perc
+ );
+ }
+ }
+ }
+
std::process::exit(error_count);
}