miden_core/operations/decorators/
assembly_op.rs1use alloc::string::String;
2use core::fmt;
3
4use miden_debug_types::Location;
5#[cfg(feature = "serde")]
6use serde::{Deserialize, Serialize};
7
8#[derive(Clone, Debug, Eq, PartialEq)]
13#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
14#[cfg_attr(all(feature = "arbitrary", test), miden_test_serde_macros::serde_test)]
15pub struct AssemblyOp {
16 #[cfg_attr(feature = "serde", serde(default))]
17 location: Option<Location>,
18 context_name: String,
19 op: String,
20 num_cycles: u8,
21}
22
23impl AssemblyOp {
24 pub fn new(
27 location: Option<Location>,
28 context_name: String,
29 num_cycles: u8,
30 op: String,
31 ) -> Self {
32 Self { location, context_name, op, num_cycles }
33 }
34
35 pub fn location(&self) -> Option<&Location> {
37 self.location.as_ref()
38 }
39
40 pub fn context_name(&self) -> &str {
42 &self.context_name
43 }
44
45 pub const fn num_cycles(&self) -> u8 {
47 self.num_cycles
48 }
49
50 pub fn op(&self) -> &str {
52 &self.op
53 }
54
55 pub fn set_num_cycles(&mut self, num_cycles: u8) {
60 self.num_cycles = num_cycles;
61 }
62
63 pub fn set_location(&mut self, location: Location) {
65 self.location = Some(location);
66 }
67}
68
69impl fmt::Display for AssemblyOp {
70 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
71 write!(
72 f,
73 "context={}, operation={}, cost={}",
74 self.context_name, self.op, self.num_cycles,
75 )
76 }
77}