#![allow(unused)]
use super::utils;
#[derive(
Clone, Debug, Default, Hash, PartialEq, Eq, PartialOrd, serde::Serialize, serde::Deserialize,
)]
pub struct ScenarioConfig {
pub(crate) valgrind_path: Option<String>,
pub(crate) cache: Option<CacheOptions>,
pub(crate) branch_sim: Option<bool>,
pub(crate) is_aslr_enabled: Option<bool>,
pub(crate) cleanup_files: Option<bool>,
pub(crate) collect_bus: Option<bool>,
pub(crate) filters: Option<Vec<String>>,
pub(crate) output_file: Option<Option<String>>,
}
impl ScenarioConfig {
fn new() -> Self {
Self::default()
}
pub fn valgrind(mut self, path: impl Into<String>) -> Self {
self.valgrind_path = Some(path.into());
self
}
pub fn cache(mut self, settings: impl Into<Option<CacheOptions>>) -> Self {
self.cache = settings.into();
self
}
pub fn branch_sim(mut self, is_enabled: bool) -> Self {
self.branch_sim = Some(is_enabled);
self
}
pub fn aslr(mut self, is_enabled: bool) -> Self {
self.is_aslr_enabled = Some(is_enabled);
self
}
pub fn cleanup_files(mut self, is_enabled: bool) -> Self {
self.cleanup_files = Some(is_enabled);
self
}
pub fn collect_bus(mut self, is_enabled: bool) -> Self {
self.collect_bus = Some(is_enabled);
self
}
pub fn filters(mut self, filters: impl IntoIterator<Item = impl Into<String>>) -> Self {
self.filters = Some(filters.into_iter().map(|s| s.into()).collect());
self
}
pub fn output(mut self, path: impl Into<String>) -> Self {
self.output_file = Some(Some(path.into()));
self
}
pub fn get_valgrind(&self) -> &str {
if let Some(v) = &self.valgrind_path {
v
} else {
"valgrind"
}
}
pub fn get_collect_bus(&self) -> bool {
self.collect_bus.unwrap_or(false)
}
pub fn get_cleanup_files(&self) -> bool {
self.cleanup_files.unwrap_or(true)
}
pub fn get_aslr(&self) -> bool {
self.is_aslr_enabled.unwrap_or(false)
}
pub fn get_branch_sim(&self) -> bool {
self.branch_sim.unwrap_or(false)
}
pub fn get_output_file(&self) -> Option<&str> {
self.output_file
.as_ref()
.map(|o| o.as_deref())
.unwrap_or(None)
}
pub fn get_filters(&self) -> &[String] {
self.filters.as_deref().unwrap_or(&[])
}
pub(crate) fn overwrite(self, other: Self) -> Self {
Self {
branch_sim: other.branch_sim.or(self.branch_sim),
is_aslr_enabled: other.is_aslr_enabled.or(self.is_aslr_enabled),
cleanup_files: other.cleanup_files.or(self.cleanup_files),
collect_bus: other.collect_bus.or(self.collect_bus),
valgrind_path: other.valgrind_path.or(self.valgrind_path),
cache: other.cache.or(self.cache),
filters: other.filters.or(self.filters),
output_file: other.output_file.or(self.output_file),
}
}
}
#[derive(
Clone, Debug, Default, Hash, PartialEq, Eq, PartialOrd, serde::Serialize, serde::Deserialize,
)]
pub struct CacheOptions {
pub first_level_data: Option<CacheParameters>,
pub first_level_code: Option<CacheParameters>,
pub last_level: Option<CacheParameters>,
}
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, serde::Serialize, serde::Deserialize)]
pub struct CacheParameters {
pub size: usize,
pub associativity: usize,
pub line_size: usize,
}