summaryrefslogtreecommitdiff
path: root/src/locators/bytecode.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/locators/bytecode.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/locators/bytecode.rs')
-rw-r--r--src/locators/bytecode.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/locators/bytecode.rs b/src/locators/bytecode.rs
new file mode 100644
index 0000000..500e9f0
--- /dev/null
+++ b/src/locators/bytecode.rs
@@ -0,0 +1,39 @@
+pub struct BytecodeSpan {
+ /// The location of this span in the assembled bytecode.
+ pub location: BytecodeLocation,
+ /// The bytes which this span represents.
+ pub bytes: Vec<u8>,
+}
+
+
+impl Default for BytecodeSpan {
+ fn default() -> Self {
+ Self {
+ location: BytecodeLocation {
+ address: 0,
+ length: 0,
+ },
+ bytes: Vec::new(),
+ }
+ }
+}
+
+
+#[derive(Clone, Copy)]
+pub struct BytecodeLocation {
+ // Address of the first byte.
+ pub address: usize,
+ // Length as a number of bytes.
+ pub length: usize,
+}
+
+
+impl std::fmt::Display for BytecodeLocation {
+ fn fmt(&self, f: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
+ write!(f, "0x{:>04x}", self.address)?;
+ if self.length > 0 {
+ write!(f, "-0x{:>04x}", self.address + self.length)?;
+ }
+ Ok(())
+ }
+}