From 9b9ecfdedd10fd96322e231a21b9337f050b9128 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Mon, 2 Feb 2026 19:59:23 +0100 Subject: Warn on pointless (un)conditional branching MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sometimes performing some 'jmp'/'jsr' can be quite pointless, and the programmer might not be fully aware of this because of the layout of the code. Imagine: .proc foo ;; code jmp bar .endproc ;; Documentation, comments, extra space, etc. .proc bar ;; whatever .endproc The 'jmp' in the code above tries to perform a call stack optimization, but it's actually not needed because the next instruction after 'jmp' is the one inside of 'bar', but that's obfuscated because of the layout. In these sort of cases (and also for 'jsr' and branches) warn the programmer about it so it can remove that instruction. Signed-off-by: Miquel Sabaté Solà --- lib/xixanta/src/object.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'lib/xixanta/src/object.rs') diff --git a/lib/xixanta/src/object.rs b/lib/xixanta/src/object.rs index 5904b56..170d872 100644 --- a/lib/xixanta/src/object.rs +++ b/lib/xixanta/src/object.rs @@ -98,6 +98,18 @@ impl Bundle { ]) } } + + /// Considering that the first element of the 'bytes' property is the + /// instruction identifier, returns the two last bytes as if they were a + /// 16-bit value. + pub fn arg(&self) -> u16 { + self.bytes[1] as u16 + ((self.bytes[2] as u16) << 8) + } + + /// Returns the address to the next instruction after this bundle. + pub fn next_address(&self) -> usize { + self.address + self.size as usize + } } /// The type of object being referenced, which is either a value as-is, or an -- cgit v1.2.3