From 0356d5871afe7669f17bdb9853cc878248bfe7b9 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Fri, 20 Dec 2024 12:40:20 +0100 Subject: Add support for warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Warnings are mere xixanta::error::Error's which are not pushed into the Err of Result. That is, instead they are accumulated into an internal `warnings` vector inside of Assembler. On the binary side we now show warnings as well, and there is an option to turn warnings into errors. Signed-off-by: Miquel Sabaté Solà --- crates/nasm/src/main.rs | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'crates/nasm/src/main.rs') diff --git a/crates/nasm/src/main.rs b/crates/nasm/src/main.rs index fd97ca1..646e249 100644 --- a/crates/nasm/src/main.rs +++ b/crates/nasm/src/main.rs @@ -23,6 +23,10 @@ struct Args { #[arg(short = 'o', long)] out: Option, + /// Treat warnings as errors. + #[arg(short = 'W', value_name = "Error")] + w: Option, + /// Spit the output into the standard output instead. This ignores any given /// `out` flag. Disabled by default. #[arg(long, default_value_t = false)] @@ -59,6 +63,18 @@ fn main() -> Result<()> { Box::new(File::create(args.out.unwrap_or(String::from("out.nes")))?) }; + // Check if warnings have to be treated as errors. + let warn_as_errors = match args.w { + Some(value) => { + if value.to_lowercase() != "error" { + bail!("The '-W' flag can only be used as '-Werror'"); + } else { + true + } + } + None => false, + }; + // Select the linker configuration. let mapping: Vec = match args.config { Some(c) => match c.to_lowercase().as_str() { @@ -74,6 +90,7 @@ fn main() -> Result<()> { }; // And assemble. + let mut error_count = 0; let mut assembler = Assembler::new(mapping); match assembler.assemble(working_directory.to_path_buf(), input) { Ok(bundles) => { @@ -86,10 +103,16 @@ fn main() -> Result<()> { Err(errors) => { for err in errors { println!("{}", err); + error_count += 1; } - std::process::exit(1); + } + } + for warning in assembler.warnings() { + println!("Warning: {}", warning); + if warn_as_errors { + error_count += 1; } } - Ok(()) + std::process::exit(error_count); } -- cgit v1.2.3