summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2023-12-19 18:52:57 +1300
committerBen Bridle <bridle.benjamin@gmail.com>2023-12-19 18:52:57 +1300
commitd9fbcd874def30d2ac0e950d80862118acce8f71 (patch)
treeff92c5cfc507bb2f339bfeb7db81922c8e3f0e76
parent5e83592b5d5a50fb36f128980a08d04fdae3bd5f (diff)
downloadbedrock-asm-d9fbcd874def30d2ac0e950d80862118acce8f71.zip
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.
-rw-r--r--src/main.rs11
1 files changed, 11 insertions, 0 deletions
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 {