From 8ccb5b96f51bcf8e1a1c3e81d1305ff08825f9b1 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Tue, 4 Feb 2025 08:38:56 +1300 Subject: Rename locator sub-modules --- src/locators/bytecode.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/locators/bytecode.rs (limited to 'src/locators/bytecode.rs') 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, +} + + +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(()) + } +} -- cgit v1.2.3-70-g09d2