Implement IR equivalence checker

This commit is contained in:
Jeehoon Kang
2020-06-10 22:27:54 +09:00
parent 6146714112
commit c2380efbb0
5 changed files with 265 additions and 38 deletions

View File

@@ -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)