summaryrefslogtreecommitdiff
path: root/src/translators/symbols_generator.rs
diff options
context:
space:
mode:
authorBen Bridle <bridle.benjamin@gmail.com>2024-10-28 19:52:29 +1300
committerBen Bridle <bridle.benjamin@gmail.com>2024-10-28 19:52:47 +1300
commitf4027cae775e3c9c237675f9df35a744d54f3f2e (patch)
tree733fa3af9e1bd44d61dd83983a2da86cb75c53e9 /src/translators/symbols_generator.rs
parent16ee0e9e8dce2c88acc88ba5ffd97e013624fa5e (diff)
downloadbedrock-asm-f4027cae775e3c9c237675f9df35a744d54f3f2e.zip
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.
Diffstat (limited to 'src/translators/symbols_generator.rs')
-rw-r--r--src/translators/symbols_generator.rs28
1 files changed, 28 insertions, 0 deletions
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;
+}