From f4027cae775e3c9c237675f9df35a744d54f3f2e Mon Sep 17 00:00:00 2001
From: Ben Bridle <bridle.benjamin@gmail.com>
Date: Mon, 28 Oct 2024 19:52:29 +1300
Subject: Rewrite assembler

This is an almost complete rewrite of the entire assembler from the
ground up, with a different parsing strategy and a whole new symbol
resolution mechanism for automatically including library files.

The assembly syntax has also been slightly modified, with padding
tokens now being prefixed with '#' instead of '$', and a block-style
anonymous-label syntax which uses the '{' and '}' characters.
---
 src/translators/symbols_generator.rs | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
 create mode 100644 src/translators/symbols_generator.rs

(limited to 'src/translators/symbols_generator.rs')

diff --git a/src/translators/symbols_generator.rs b/src/translators/symbols_generator.rs
new file mode 100644
index 0000000..06bbaa8
--- /dev/null
+++ b/src/translators/symbols_generator.rs
@@ -0,0 +1,28 @@
+use crate::*;
+
+use SemanticTokenVariant as SemVar;
+
+
+pub fn generate_symbols_file(semantic_tokens: &[SemanticToken]) -> String {
+    let mut symbols = String::new();
+
+    for token in semantic_tokens {
+        if let SemVar::LabelDefinition(definition) = &token.variant {
+            let address = token.bytecode.location.address;
+            if address > 0xffff { break; }
+            let name = &definition.name;
+            let path = match &token.source.in_source {
+                Some(source) => &source.path,
+                None => &token.source.in_merged.path,
+            };
+            if let Some(path) = path {
+                let path = path.as_os_str().to_string_lossy();
+                symbols.push_str(&format!("{address:04x} {name} {path}\n"));
+            } else {
+                symbols.push_str(&format!("{address:04x} {name}\n"));
+            }
+        }
+    }
+
+    return symbols;
+}
-- 
cgit v1.2.3-70-g09d2