use alloc::string::String;
use core::fmt;
use miden_debug_types::Location;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(all(feature = "arbitrary", test), miden_test_serde_macros::serde_test)]
pub struct AssemblyOp {
#[cfg_attr(feature = "serde", serde(default))]
location: Option<Location>,
context_name: String,
op: String,
num_cycles: u8,
should_break: bool,
}
impl AssemblyOp {
pub fn new(
location: Option<Location>,
context_name: String,
num_cycles: u8,
op: String,
should_break: bool,
) -> Self {
Self {
location,
context_name,
op,
num_cycles,
should_break,
}
}
pub fn location(&self) -> Option<&Location> {
self.location.as_ref()
}
pub fn context_name(&self) -> &str {
&self.context_name
}
pub const fn num_cycles(&self) -> u8 {
self.num_cycles
}
pub fn op(&self) -> &str {
&self.op
}
pub const fn should_break(&self) -> bool {
self.should_break
}
pub fn set_num_cycles(&mut self, num_cycles: u8) {
self.num_cycles = num_cycles;
}
pub fn set_location(&mut self, location: Location) {
self.location = Some(location);
}
}
impl fmt::Display for AssemblyOp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"context={}, operation={}, cost={}",
self.context_name, self.op, self.num_cycles,
)
}
}