mod generics;
mod lookup;
mod metadata;
mod methods;
mod types;
use std::sync::Arc;
use dashmap::DashMap;
use crate::{
assembly::Instruction,
metadata::{method::ExceptionHandler, token::Token, typesystem::CilFlavor},
CilObject,
};
#[derive(Debug, Clone)]
pub struct SyntheticMethodBody {
pub instructions: Vec<Instruction>,
pub local_types: Vec<CilFlavor>,
pub param_types: Vec<CilFlavor>,
pub is_static: bool,
pub returns_value: bool,
pub exception_handlers: Vec<ExceptionHandler>,
}
pub struct EmulationContext {
pub(crate) assembly: Arc<CilObject>,
pub(crate) synthetic_methods: Arc<DashMap<Token, SyntheticMethodBody>>,
}
impl EmulationContext {
#[must_use]
pub fn new(
assembly: Arc<CilObject>,
synthetic_methods: Arc<DashMap<Token, SyntheticMethodBody>>,
) -> Self {
EmulationContext {
assembly,
synthetic_methods,
}
}
#[must_use]
pub fn assembly(&self) -> Arc<CilObject> {
self.assembly.clone()
}
#[must_use]
pub fn is_synthetic_method(&self, token: Token) -> bool {
self.synthetic_methods.contains_key(&token)
}
#[must_use]
pub fn get_synthetic_exception_handlers(&self, token: Token) -> Option<Vec<ExceptionHandler>> {
self.synthetic_methods
.get(&token)
.map(|s| s.exception_handlers.clone())
}
}