From d9fbcd874def30d2ac0e950d80862118acce8f71 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Tue, 19 Dec 2023 18:52:57 +1300 Subject: Report unused label definitions When the assembler successfully assembles a program, it will now report the names of all label definitions for which there are no label references. This is to aid the user in finding dead code within their programs. --- src/main.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index ead1268..159b725 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,17 @@ fn main() { for token in &tokens { if token.print_error(&source_code) { is_error = true }; } + if !is_error { + for token in &tokens { + if let SemanticTokenType::LabelDefinition(def) = &token.r#type { + if def.references.is_empty() { + eprintln!("Unused label definition: {}", def.name); + } + } + } + eprintln!(); + } + eprintln!("Assembled program in {} bytes.", bytecode.len()); if is_error { -- cgit v1.2.3-70-g09d2