From 37d03cec336751dc0dca3b6f045b6680dd5bd820 Mon Sep 17 00:00:00 2001 From: Jacob Lifshay Date: Mon, 22 Jul 2024 00:52:48 -0700 Subject: [PATCH] change `#[hdl] if` to only accept Expr instead of accepting bool, this prevents using == by accident --- crates/fayalite/src/module.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/crates/fayalite/src/module.rs b/crates/fayalite/src/module.rs index ac38ee8..144ca96 100644 --- a/crates/fayalite/src/module.rs +++ b/crates/fayalite/src/module.rs @@ -11,7 +11,7 @@ use crate::{ ops::VariantAccess, Expr, Flow, Target, TargetBase, TargetPathArrayElement, TargetPathBundleField, TargetPathElement, ToExpr, }, - int::{DynUInt, DynUIntType, FixedOrDynIntType, UInt}, + int::{DynUInt, DynUIntType, FixedOrDynIntType, IntValue, UInt}, intern::{Intern, Interned}, memory::{Mem, MemBuilder, MemBuilderTarget, PortName}, reg::Reg, @@ -2259,8 +2259,10 @@ where ) -> RegBuilder<'a, (), (), ()> { self.reg_builder_with_loc(implicit_name.0, SourceLocation::caller()) } + // intentionally takes Expr instead of impl ToExpr to help prevent + // `#[hdl] if a == b {}` instead of using `cmp_eq` #[track_caller] - pub fn if_(&mut self, cond: impl ToExpr) -> IfScope + pub fn if_(&mut self, cond: Expr>) -> IfScope where Ty: FixedOrDynIntType< 1, @@ -2273,7 +2275,7 @@ where } pub fn if_with_loc( &mut self, - cond: impl ToExpr, + cond: Expr>, source_location: SourceLocation, ) -> IfScope where @@ -2284,7 +2286,7 @@ where CanonicalValue = DynUInt, >, { - let cond = cond.to_expr().as_bool(); + let cond = cond.as_bool(); let outer_block = self.block_stack.top(); let then_block = self.new_block(); let else_block = self.new_block();