From 872cf6d06f4d77637b4627fdc583bab79ee2372f Mon Sep 17 00:00:00 2001 From: johannst Date: Mon, 27 Feb 2023 22:52:40 +0000 Subject: deploy: 6486b862edc2750dba83848f62d6c9f3d4c6d3c2 --- src/juicebox_asm/imm.rs.html | 72 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/juicebox_asm/imm.rs.html (limited to 'src/juicebox_asm/imm.rs.html') diff --git a/src/juicebox_asm/imm.rs.html b/src/juicebox_asm/imm.rs.html new file mode 100644 index 0000000..0990c92 --- /dev/null +++ b/src/juicebox_asm/imm.rs.html @@ -0,0 +1,72 @@ +imm.rs - source
1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+
/// Trait to interact with immediate operands.
+pub(crate) trait Imm {
+    /// Get immediate operand as slice of bytes.
+    fn bytes(&self) -> &[u8];
+}
+
+macro_rules! impl_imm {
+    ($name:ident, $size:expr, from: $( $from:ty ),* $(,)?) => {
+        /// Immediate operand.
+        pub struct $name([u8; $size]);
+
+        impl Imm for $name {
+            /// Get immediate operand as slice of bytes.
+            fn bytes(&self) -> &[u8] {
+                &self.0
+            }
+        }
+
+        $(
+        impl From<$from> for $name {
+            fn from(imm: $from) -> Self {
+                let mut buf = [0u8; $size];
+                let imm = imm.to_ne_bytes();
+                buf[0..imm.len()].copy_from_slice(&imm);
+                $name(buf)
+            }
+        }
+        )*
+    }
+}
+
+impl_imm!(Imm8, 1, from: u8, i8);
+impl_imm!(Imm16, 2, from: u16, i16, u8, i8);
+impl_imm!(Imm32, 4, from: u32, i32, u16, i16, u8, i8);
+impl_imm!(Imm64, 8, from: u64, i64, u32, i32, u16, i16, u8, i8);
+
+
\ No newline at end of file -- cgit v1.2.3