aboutsummaryrefslogtreecommitdiff
path: root/lib/xixanta/src/assembler.rs
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mssola@mssola.com>2026-09-29 23:37:48 +0200
committerMiquel Sabaté Solà <mssola@mssola.com>2026-09-29 23:37:48 +0200
commit54e3fc561add5ce9d776a11a286b988aacb59daa (patch)
tree0e1eca3d85988d389e14525c85917646dd8796ac /lib/xixanta/src/assembler.rs
parent438c379b9ce4c6a6e4da445c3bf7f94458b1c816 (diff)
downloadtools.nes-54e3fc561add5ce9d776a11a286b988aacb59daa.tar.gz
tools.nes-54e3fc561add5ce9d776a11a286b988aacb59daa.zip
nasm: warn on labels that point out of bounds
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'lib/xixanta/src/assembler.rs')
-rw-r--r--lib/xixanta/src/assembler.rs21
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/xixanta/src/assembler.rs b/lib/xixanta/src/assembler.rs
index afd8429..6006234 100644
--- a/lib/xixanta/src/assembler.rs
+++ b/lib/xixanta/src/assembler.rs
@@ -918,7 +918,7 @@ impl<'a> Assembler<'a> {
negative: false,
safe: false,
},
- node: None,
+ node: Some(node.clone()),
mapping: self.current_mapping,
segment: self.current_segment,
object_type,
@@ -1459,8 +1459,25 @@ impl<'a> Assembler<'a> {
// badly formatted addresses. This will not happen at
// this point.
let resolved = self.context.resolve_label(&self.mappings, bundle).unwrap();
-
let val = resolved.bundle.value() as usize;
+
+ // If this is an address, is it pointing out of bounds?
+ if matches!(bundle.object_type, ObjectType::Address) {
+ let mapping = &self.mappings[resolved.mapping];
+ let filled_mapping = mapping.start as usize + mapping.offset;
+ if val >= filled_mapping {
+ self.warnings.push(Error {
+ line: resolved.node.as_ref().unwrap().value.line,
+ message: format!("label '{full_name}' is pointing to out of bounds"),
+ source: self.sources[0].clone(),
+ expanded_from: self.macro_context.clone(),
+ global: false,
+ });
+ }
+ }
+
+ // If not, then create a range out of this object and
+ // push the address.
let end = match self.address_ends.get(&full_name) {
Some(v) => v,
None => &val,