diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-07-15 07:58:08 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-07-15 08:10:45 +0200 |
| commit | 61b9ce33d54bc643b0ece227101d8bf571fd86e5 (patch) | |
| tree | e3fce800a82adac700997b02d4ab37a80f4fd97b /crates/nasm | |
| parent | 10b2276829b31c117eb3276dca11503248801cdd (diff) | |
| download | tools.nes-61b9ce33d54bc643b0ece227101d8bf571fd86e5.tar.gz tools.nes-61b9ce33d54bc643b0ece227101d8bf571fd86e5.zip | |
Save known addresses into .nasm/addresses.txt
This new file contains all the addresses that are known to the
assembler, belonging to either proc's or plain labels. For the former we
will further be able to tell the "end" of the proc. With that, the file
follows a simple CSV format, with the name, start and end.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'crates/nasm')
| -rw-r--r-- | crates/nasm/README.md | 16 | ||||
| -rw-r--r-- | crates/nasm/src/main.rs | 19 |
2 files changed, 35 insertions, 0 deletions
diff --git a/crates/nasm/README.md b/crates/nasm/README.md index 2675bfb..750e795 100644 --- a/crates/nasm/README.md +++ b/crates/nasm/README.md @@ -246,6 +246,22 @@ fit in a byte. Hence, you could have a code like follows: If you compile the code with `-D PAL=1`, then the first branch will be taken instead of the second one. +## The .nasm/ directory + +When you enable the `--write-info` flag, some files will be written into a +hidden `.nasm/` directory. This directory will contain debug information that +can be later used by other tools. That being said, some of these files can also +be useful to programmers. They are as follows: + +- `segments.txt`: summary of the segments being used and how much they have been + filled. Note that you need to also pass `--stats` to get this file. +- `memory.txt`: list of variables being used, expressed as ranges to account for + reservation via the `asan:reserve` special comment. Note that you need to also + pass `--asan` to get this file. +- `addresses.txt`: list of addresses known by the assembler, expressed as ranges + to account for blocks of code like proc's. You don't need any other flag for + this file. + ## Unused code This assembler will also issue a warning whenever it finds unreferenced diff --git a/crates/nasm/src/main.rs b/crates/nasm/src/main.rs index 55a8f21..010e7d5 100644 --- a/crates/nasm/src/main.rs +++ b/crates/nasm/src/main.rs @@ -270,6 +270,20 @@ fn print_memory_summary(mut output: Box<dyn Write>, memory: &MemoryResult, has_w } } +// Save the 'addresses' list into the `<source>/.nasm/addresses.txt` file. +fn save_addresses(source: &SourceInfo, mut addresses: Vec<xixanta::assembler::Range>) { + let Ok(mut file) = File::create(get_directory_from_source(source).join("addresses.txt")) else { + return die("could not write memory.txt file".to_string()); + }; + + addresses.sort_by_key(|a| a.range.start); + for a in addresses { + if let Err(e) = writeln!(file, "{},{:04X},{:04X}", a.name, a.range.start, a.range.end) { + return die(format!("could not write addresses.txt file: {e}")); + } + } +} + // Print to the `output` stream the statistics that can be gathered from the // given `mappings`. fn print_segments_stats(mut output: Box<dyn Write>, mappings: &[Mapping]) { @@ -463,4 +477,9 @@ fn main() { print_memory_summary(Box::new(io::stdout()), &memory, has_working_ram); } } + + // Print addresses. + if args.info { + save_addresses(&source, res.addresses); + } } |
