aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mssola@mssola.com>2026-04-30 12:21:20 +0200
committerMiquel Sabaté Solà <mssola@mssola.com>2026-04-30 12:42:55 +0200
commita7bf22ce402256c3a056ac278629552ef4978da2 (patch)
tree952b6fd0df8f3a5d2614d67b90b683689352a295
parent6a9dea943c078876061eda0f6203647b0c5aadd4 (diff)
downloadtools.nes-a7bf22ce402256c3a056ac278629552ef4978da2.tar.gz
tools.nes-a7bf22ce402256c3a056ac278629552ef4978da2.zip
nasm/xa65: add the --allow-unused option
Since the addition of the check() function in commit 6a9dea943c07 ("Add a new 'check' stage in assemble()"), it can be annoying to some users that the check for unused/unreferenced object applies by default. Hence, add a flag so this can be disabled. Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
-rw-r--r--crates/nasm/src/main.rs4
-rw-r--r--crates/xa65/src/main.rs6
-rw-r--r--lib/xixanta/src/assembler.rs23
3 files changed, 31 insertions, 2 deletions
diff --git a/crates/nasm/src/main.rs b/crates/nasm/src/main.rs
index 6541d9c..b865fa7 100644
--- a/crates/nasm/src/main.rs
+++ b/crates/nasm/src/main.rs
@@ -21,6 +21,7 @@ struct Args {
defines: Vec<(String, u8)>,
asan: bool,
info: bool,
+ allow_unused: bool,
}
// Print the help message and quit.
@@ -29,6 +30,7 @@ fn print_help() {
println!("usage: nasm [OPTIONS] <FILE>\n");
println!("Options:");
println!(" -a, --asan\t\tEnable the Address Sanitizer.");
+ println!(" --allow-unused\t\tAllow unused .proc's or unreferenced objects.");
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 ('VALUE' defaults to '1')"
@@ -108,6 +110,7 @@ fn parse_arguments() -> Args {
while let Some(arg) = args.next() {
match arg.as_str() {
"-a" | "--asan" => res.asan = true,
+ "--allow-unused" => res.allow_unused = true,
"-c" | "--config" => match res.config {
Some(_) => die("only specify the '-C/--config' flag once".to_string()),
None => match args.next() {
@@ -330,6 +333,7 @@ fn main() {
args.config.unwrap_or("nrom".to_string()).as_str(),
&args.defines,
&source,
+ args.allow_unused,
args.asan,
);
diff --git a/crates/xa65/src/main.rs b/crates/xa65/src/main.rs
index abf866b..77e5127 100644
--- a/crates/xa65/src/main.rs
+++ b/crates/xa65/src/main.rs
@@ -18,6 +18,7 @@ struct Args {
no_errors: bool,
strict: bool,
stats: bool,
+ allow_unused: bool,
}
// Print the help message and quit.
@@ -25,6 +26,7 @@ fn print_help() {
println!("Bridge between 'nasm' and 'ca65'.\n");
println!("usage: xa65 [OPTIONS] <FILE>\n");
println!("Options:");
+ println!(" --allow-unused\tPass the '--allow-unused' flag to 'nasm'.");
println!(" -b, --bin <PROGRAM>\tAlternative to the binary for 'nasm'.");
println!(" -C, --config <FILE>\tLinker configuration to be used, whether an identifier or a file path.");
println!(" -h, --help\t\tPrint this message.");
@@ -48,6 +50,7 @@ fn parse_arguments() -> Args {
while let Some(arg) = args.next() {
match arg.as_str() {
+ "--allow-unused" => res.allow_unused = true,
"-b" | "--bin" => match res.bin {
Some(_) => die("only specify the '-b/--bin' flag once".to_string()),
None => match args.next() {
@@ -263,6 +266,9 @@ fn main() {
if args.stats {
cmd.arg("--stats");
}
+ if args.allow_unused {
+ cmd.arg("--allow-unused");
+ }
// Actually run the command.
match cmd.status() {
diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs
index 67d1340..47c662b 100644
--- a/lib/xixanta/src/assembler.rs
+++ b/lib/xixanta/src/assembler.rs
@@ -136,6 +136,10 @@ struct Assembler<'a> {
// (0x6000-0x7FFF).
accessing_working_ram: bool,
+ // Allow unused .proc's or unreferenced objects on the final binary. In
+ // other words, don't look for unreferenced bundles at the 'check' stage.
+ allow_unused: bool,
+
// Whether the Address Sanitizer is enabled or not.
asan_enabled: bool,
@@ -217,6 +221,7 @@ pub fn assemble(
mapping: &str,
defines: &[(String, u8)],
source: &SourceInfo,
+ allow_unused: bool,
asan: bool,
) -> AssemblerResult {
let config = match get_mapping_configuration(mapping) {
@@ -239,7 +244,7 @@ pub fn assemble(
}
};
- assemble_with_mapping(reader, config, defines, source, asan)
+ assemble_with_mapping(reader, config, defines, source, allow_unused, asan)
}
/// Read the contents from the `reader` as a source file and produce a list of
@@ -253,6 +258,7 @@ pub fn assemble_with_mapping(
mapping: Vec<Mapping>,
defines: &[(String, u8)],
source: &SourceInfo,
+ allow_unused: bool,
asan: bool,
) -> AssemblerResult {
// Save the original current working directory in case it changes after a
@@ -262,6 +268,7 @@ pub fn assemble_with_mapping(
let mut asm = Assembler::new(mapping);
let mut memory = MemoryResult::default();
asm.asan_enabled = asan;
+ asm.allow_unused = allow_unused;
// First of all, parse the input so we get a list of nodes we can work
// with.
@@ -415,6 +422,7 @@ impl<'a> Assembler<'a> {
warnings: vec![],
sources: vec![],
accessing_working_ram: false,
+ allow_unused: false,
asan_enabled: false,
asan_next_ignore: false,
asan_next_reserve: 1,
@@ -1176,7 +1184,7 @@ impl<'a> Assembler<'a> {
};
// Check if this variable/proc was ever accessed.
- if bundle.accessed == 0 {
+ if !self.allow_unused && bundle.accessed == 0 {
// If this was a .proc definition then we are certain that
// this is dead code, which is a really crappy situation.
if matches!(bundle.object_type, ObjectType::Proc) {
@@ -3455,6 +3463,7 @@ mod tests {
&[],
&SourceInfo::default(),
false,
+ false,
)
}
@@ -3845,6 +3854,7 @@ mod tests {
empty(),
&[],
&SourceInfo::default(),
+ false,
true,
);
@@ -3868,6 +3878,7 @@ mod tests {
empty(),
&[],
&SourceInfo::default(),
+ false,
true,
);
@@ -3890,6 +3901,7 @@ mod tests {
empty(),
&[],
&SourceInfo::default(),
+ false,
true,
);
@@ -3914,6 +3926,7 @@ mod tests {
empty(),
&[],
&SourceInfo::default(),
+ false,
true,
);
@@ -5552,6 +5565,7 @@ lda #Variable
&[],
&SourceInfo::default(),
false,
+ false,
);
assert_eq!(res.bundles.len(), 0x11);
@@ -5595,6 +5609,7 @@ lda #Variable
&[],
&SourceInfo::default(),
false,
+ false,
);
let bundles = &res.bundles[0x11..];
@@ -5670,6 +5685,7 @@ lda #Variable
&[],
&SourceInfo::default(),
false,
+ false,
);
let bundles = &res.bundles[0x12..]; // Ignoring HEADER + first two ONE
@@ -5719,6 +5735,7 @@ lda #Variable
&[],
&SourceInfo::default(),
false,
+ false,
);
let bundles = &res.bundles[0x11..]; // Ignoring HEADER + first nop
@@ -5775,6 +5792,7 @@ lda #Variable
&[],
&SourceInfo::default(),
false,
+ false,
);
let bundles = &res.bundles[0x10..];
@@ -5803,6 +5821,7 @@ lda #Variable
&[],
&SourceInfo::default(),
false,
+ false,
);
assert_eq!(