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