From abd7ccf49af2450bfbd509406763f6aae07c6be0 Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Sat, 30 Mar 2019 02:33:31 -0400 Subject: [PATCH] don't prematurely unpack structs with complex types; support for convert patterns that use `default` --- src/Convert/Struct.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Convert/Struct.hs b/src/Convert/Struct.hs index fccd022..c477162 100644 --- a/src/Convert/Struct.hs +++ b/src/Convert/Struct.hs @@ -83,7 +83,14 @@ collectType (Struct (Packed sg) fields _) = do -- converting everything to a Logic type. This should work in cases of -- mixed `wire`/`logic` or `reg`/`logic`. fieldClasses = map (show . fst . typeRanges) fieldTypes - canUnstructure = all (head fieldClasses ==) fieldClasses + isComplex :: Type -> Bool + isComplex (Struct _ _ _ ) = True + isComplex (Enum _ _ _ ) = True + isComplex (Alias _ _) = True + isComplex _ = False + canUnstructure = + all (head fieldClasses ==) (map show fieldClasses) && + not (any isComplex fieldTypes) collectType _ = return () @@ -168,6 +175,8 @@ convertAsgn structs types (lhs, expr) = -- try expression conversion by looking at the *outermost* type first convertExpr :: Type -> Expr -> Expr + convertExpr (Struct _ fields []) (Pattern [(Just "default", e)]) = + Concat $ take (length fields) (repeat e) convertExpr (Struct (Packed sg) fields []) (Pattern items) = if Map.notMember structTf structs then Pattern items''