mirror of
https://github.com/kmc7468/cs420.git
synced 2025-12-16 15:38:48 +00:00
Implement IR equivalence checker
This commit is contained in:
@@ -1,15 +1,7 @@
|
||||
#![allow(unused_variables)]
|
||||
|
||||
use lang_c::ast::*;
|
||||
use lang_c::span::Node;
|
||||
|
||||
use core::ops::Deref;
|
||||
|
||||
use itertools::izip;
|
||||
|
||||
trait IsEquiv {
|
||||
fn is_equiv(&self, other: &Self) -> bool;
|
||||
}
|
||||
use crate::utils::IsEquiv;
|
||||
|
||||
impl<T: IsEquiv> IsEquiv for Node<T> {
|
||||
fn is_equiv(&self, other: &Self) -> bool {
|
||||
@@ -17,34 +9,6 @@ impl<T: IsEquiv> IsEquiv for Node<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IsEquiv> IsEquiv for Box<T> {
|
||||
fn is_equiv(&self, other: &Self) -> bool {
|
||||
self.deref().is_equiv(other.deref())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IsEquiv> IsEquiv for &T {
|
||||
fn is_equiv(&self, other: &Self) -> bool {
|
||||
(*self).is_equiv(*other)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IsEquiv> IsEquiv for Option<T> {
|
||||
fn is_equiv(&self, other: &Self) -> bool {
|
||||
match (self, other) {
|
||||
(Some(lhs), Some(rhs)) => lhs.is_equiv(rhs),
|
||||
(None, None) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: IsEquiv> IsEquiv for Vec<T> {
|
||||
fn is_equiv(&self, other: &Self) -> bool {
|
||||
self.len() == other.len() && izip!(self, other).all(|(lhs, rhs)| lhs.is_equiv(rhs))
|
||||
}
|
||||
}
|
||||
|
||||
impl IsEquiv for TranslationUnit {
|
||||
fn is_equiv(&self, other: &Self) -> bool {
|
||||
self.0.is_equiv(&other.0)
|
||||
|
||||
Reference in New Issue
Block a user