use crate::ir::*; use serde::{Deserialize, Serialize}; use std::fmt; #[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] pub struct Dereference { expression: Expression, } impl Dereference { pub fn new(expression: Expression) -> Dereference { Dereference { expression } } pub fn bits(&self) -> usize { self.expression.bits() } pub fn expression(&self) -> &Expression { &self.expression } pub fn into_expression(self) -> Expression { self.expression } } impl From> for LValue { fn from(dereference: Dereference) -> LValue { LValue::Dereference(dereference) } } impl From> for Expression { fn from(dereference: Dereference) -> Expression { Expression::LValue(Box::new(dereference.into())) } } impl fmt::Display for Dereference { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "*{}", self.expression()) } }