diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-08 12:34:47 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-09 16:01:39 +0100 |
| commit | 8b1c270910fce13077864bf39d6e88971a6eb062 (patch) | |
| tree | 2a441b58d46905f680749c1c074e9b55a27f0d6e /crates/nasm/src | |
| parent | 4f5710aa516ab149d132cdb5863db08f08c10563 (diff) | |
| download | tools.nes-8b1c270910fce13077864bf39d6e88971a6eb062.tar.gz tools.nes-8b1c270910fce13077864bf39d6e88971a6eb062.zip | |
Implement the .include statement
This needed some heavy lifting when it comes to how files were located.
This means that statements like .include/.incbin now take into
consideration a new list made out of SourceInfo, which holds enough
information to translate from which file a node comes from. This has
also been added into errors, so they are more informative on what went
wrong.
In order to tests this, besides all the regular unit tests, a new e2e
test has been added.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'crates/nasm/src')
| -rw-r--r-- | crates/nasm/src/main.rs | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/crates/nasm/src/main.rs b/crates/nasm/src/main.rs index 225a865..561e305 100644 --- a/crates/nasm/src/main.rs +++ b/crates/nasm/src/main.rs @@ -4,6 +4,7 @@ use std::fs::File; use std::io::{self, Read, Write}; use std::path::Path; use xixanta::assembler::assemble; +use xixanta::SourceInfo; /// Assembler for the 6502 microprocessor that targets the NES/Famicom. #[derive(ClapParser, Debug)] @@ -40,7 +41,7 @@ fn main() -> Result<()> { // Select the input stream and the current working directory. let input: Box<dyn Read>; - let working_directory = match &args.file { + let source_info = match &args.file { Some(file) => { let path = Path::new(file); if !path.is_file() { @@ -48,13 +49,22 @@ fn main() -> Result<()> { } input = Box::new(File::open(file)?); - path.parent() - .with_context(|| String::from("Failed to find directory for given file"))? + SourceInfo { + working_directory: path + .parent() + .with_context(|| String::from("Failed to find directory for given file"))? + .to_path_buf(), + name: path.file_name().unwrap().to_str().unwrap().to_string(), + } } None => { input = Box::new(std::io::stdin()); - &std::env::current_dir() - .with_context(|| String::from("Could not fetch current directory"))? + SourceInfo { + working_directory: std::env::current_dir() + .with_context(|| String::from("Could not fetch current directory"))? + .to_path_buf(), + name: "<stdin>".to_string(), + } } }; @@ -82,7 +92,7 @@ fn main() -> Result<()> { // And assemble. let mut error_count = 0; - let res = assemble(input, config.as_str(), working_directory.to_path_buf()); + let res = assemble(input, config.as_str(), source_info); // Print warnings and errors first, while also computing the amount of them // that exists. |
