diff options
| -rw-r--r-- | crates/nasm/src/main.rs | 24 | ||||
| -rw-r--r-- | lib/xixanta/src/assembler.rs | 9 |
2 files changed, 33 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); } diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs index c12773b..1d08b57 100644 --- a/lib/xixanta/src/assembler.rs +++ b/lib/xixanta/src/assembler.rs @@ -88,6 +88,7 @@ pub struct AssemblerResult { pub bundles: Vec<Bundle>, pub errors: Vec<Error>, pub warnings: Vec<Error>, + pub mappings: Vec<Mapping>, } /// Read the contents from the `reader` as a source file and produce a list of @@ -114,6 +115,7 @@ pub fn assemble( source, }], warnings: vec![], + mappings: vec![], }; } }; @@ -143,6 +145,7 @@ pub fn assemble_with_mapping( bundles: vec![], errors, warnings: asm.warnings, + mappings: asm.mappings, }; } @@ -157,6 +160,7 @@ pub fn assemble_with_mapping( bundles: vec![], errors: e.into(), warnings: vec![], + mappings: asm.mappings, }; } } @@ -168,6 +172,7 @@ pub fn assemble_with_mapping( bundles: vec![], errors, warnings: asm.warnings, + mappings: asm.mappings, }; } @@ -180,6 +185,7 @@ pub fn assemble_with_mapping( bundles: vec![], errors, warnings: asm.warnings, + mappings: asm.mappings, }; } @@ -190,6 +196,7 @@ pub fn assemble_with_mapping( bundles: vec![], errors, warnings: asm.warnings, + mappings: asm.mappings, }; } @@ -199,11 +206,13 @@ pub fn assemble_with_mapping( bundles, errors: vec![], warnings: asm.warnings, + mappings: asm.mappings, }, Err(errors) => AssemblerResult { bundles: vec![], errors, warnings: asm.warnings, + mappings: asm.mappings, }, } } |
