aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/lib.rs
diff options
context:
space:
mode:
authorJohannes Stoelp <johannes.stoelp@gmail.com>2024-12-06 23:32:58 +0100
committerJohannes Stoelp <johannes.stoelp@gmail.com>2024-12-07 00:57:12 +0100
commit2699292790476eccd726fc5dae179b3a688a1468 (patch)
tree6ddc18ddabb5449cf4809b0ffb46175ee1bdb93b /src/lib.rs
parent36345d8ab93d23d9f94372863e3747a07222b6ce (diff)
downloadjuicebox-asm-2699292790476eccd726fc5dae179b3a688a1468.tar.gz
juicebox-asm-2699292790476eccd726fc5dae179b3a688a1468.zip
asm: add initial support for memory operand only instructions
* add dec, inc instruction for with memory operand
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 131440a..6bbfcbf 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -88,6 +88,7 @@ pub use reg::{Reg16, Reg32, Reg64, Reg8};
pub use rt::Runtime;
/// Type representing a memory operand.
+#[derive(Clone, Copy)]
pub enum MemOp {
/// An indirect memory operand, eg `mov [rax], rcx`.
Indirect(Reg64),
@@ -123,3 +124,41 @@ impl MemOp {
}
}
}
+
+/// Trait to give size hints for memory operands.
+trait MemOpSized {
+ fn mem_op(&self) -> MemOp;
+}
+
+macro_rules! impl_memop_sized {
+ ($(#[$doc:meta] $name:ident)+) => {
+ $(
+ #[$doc]
+ pub struct $name(MemOp);
+
+ impl $name {
+ /// Create a memory with size hint from a raw memory operand.
+ pub fn from(op: MemOp) -> Self {
+ Self(op)
+ }
+ }
+
+ impl MemOpSized for $name {
+ fn mem_op(&self) -> MemOp {
+ self.0
+ }
+ }
+ )+
+ };
+}
+
+impl_memop_sized!(
+ /// A memory operand with a word (8 bit) size hint.
+ MemOp8
+ /// A memory operand with a word (16 bit) size hint.
+ MemOp16
+ /// A memory operand with a dword (32 bit) size hint.
+ MemOp32
+ /// A memory operand with a qword (64 bit) size hint.
+ MemOp64
+);