miden_core/operations/debug_metadata/
assembly_op.rs1use alloc::sync::Arc;
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: Arc<str>,
19 op: Arc<str>,
20 num_cycles: u8,
21}
22
23impl AssemblyOp {
24 pub fn new(
27 location: Option<Location>,
28 context_name: impl Into<Arc<str>>,
29 num_cycles: u8,
30 op: impl Into<Arc<str>>,
31 ) -> Self {
32 Self {
33 location,
34 context_name: context_name.into(),
35 op: op.into(),
36 num_cycles,
37 }
38 }
39
40 pub fn location(&self) -> Option<&Location> {
42 self.location.as_ref()
43 }
44
45 pub fn context_name(&self) -> &Arc<str> {
47 &self.context_name
48 }
49
50 pub const fn num_cycles(&self) -> u8 {
52 self.num_cycles
53 }
54
55 pub fn op(&self) -> &Arc<str> {
57 &self.op
58 }
59
60 pub fn set_num_cycles(&mut self, num_cycles: u8) {
65 self.num_cycles = num_cycles;
66 }
67
68 pub fn set_location(&mut self, location: Location) {
70 self.location = Some(location);
71 }
72}
73
74impl fmt::Display for AssemblyOp {
75 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
76 write!(
77 f,
78 "context={}, operation={}, cost={}",
79 self.context_name, self.op, self.num_cycles,
80 )
81 }
82}