From 3e3da53bd2655b30de83592181a55a9a3022c8ca Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Mon, 25 Nov 2024 00:01:02 -0800 Subject: [PATCH] working on deduce_resets --- .../src/module/transform/deduce_resets.rs | 59 ++++++++++++++++--- 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/crates/fayalite/src/module/transform/deduce_resets.rs b/crates/fayalite/src/module/transform/deduce_resets.rs index ecc2c43..4308efa 100644 --- a/crates/fayalite/src/module/transform/deduce_resets.rs +++ b/crates/fayalite/src/module/transform/deduce_resets.rs @@ -20,7 +20,7 @@ use crate::{ }, prelude::*, }; -use std::{convert::Infallible, fmt}; +use std::{convert::Infallible, fmt, mem}; #[derive(Debug)] pub enum DeduceResetsError { @@ -415,17 +415,62 @@ impl RunProcessStep for ConnectAndLhsInstantiatedModule { source_location, } = self; match Expr::ty(lhs) { - CanonicalType::UInt(ty) => todo!(), - CanonicalType::SInt(ty) => todo!(), - CanonicalType::Bool(ty) => todo!(), + CanonicalType::UInt(_) => {} + CanonicalType::SInt(_) => {} + CanonicalType::Bool(_) => {} CanonicalType::AsyncReset(ty) => todo!(), CanonicalType::SyncReset(ty) => todo!(), CanonicalType::Reset(ty) => todo!(), - CanonicalType::Clock(ty) => todo!(), + CanonicalType::Clock(_) => {} CanonicalType::Array(ty) => todo!(), - CanonicalType::Enum(ty) => todo!(), - CanonicalType::Bundle(ty) => todo!(), + CanonicalType::Enum(ty) => { + for (variant_index, EnumVariant { ty, .. }) in ty.variants().into_iter().enumerate() + { + if ty.is_none() { + continue; + } + let lhs = + ops::VariantAccess::new_by_index(Expr::from_canonical(lhs), variant_index) + .to_expr(); + let rhs = + ops::VariantAccess::new_by_index(Expr::from_canonical(rhs), variant_index) + .to_expr(); + ConnectAndLhsInstantiatedModule { + lhs_instantiated_module, + lhs, + rhs, + source_location, + } + .run_process_step(rhs_instantiated_module, state, step)?; + } + } + CanonicalType::Bundle(ty) => { + for (field_index, BundleField { flipped, .. }) in + ty.fields().into_iter().enumerate() + { + let mut lhs = + ops::FieldAccess::new_by_index(Expr::from_canonical(lhs), field_index) + .to_expr(); + let mut rhs = + ops::FieldAccess::new_by_index(Expr::from_canonical(rhs), field_index) + .to_expr(); + let mut lhs_instantiated_module = lhs_instantiated_module; + let mut rhs_instantiated_module = rhs_instantiated_module; + if flipped { + mem::swap(&mut lhs, &mut rhs); + mem::swap(&mut lhs_instantiated_module, &mut rhs_instantiated_module); + } + ConnectAndLhsInstantiatedModule { + lhs_instantiated_module, + lhs, + rhs, + source_location, + } + .run_process_step(rhs_instantiated_module, state, step)?; + } + } } + Ok(Processed(())) } }