From a170536382dd1b3613f94ef11102ff5309311ba7 Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Thu, 20 Aug 2020 20:07:26 -0400 Subject: [PATCH] unbased-unsized binding nested struct performance fix --- src/Convert/UnbasedUnsized.hs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Convert/UnbasedUnsized.hs b/src/Convert/UnbasedUnsized.hs index 892323b..ed208e5 100644 --- a/src/Convert/UnbasedUnsized.hs +++ b/src/Convert/UnbasedUnsized.hs @@ -83,7 +83,7 @@ convertModuleItem _ other = convertModuleItem' other determinePortSize :: Identifier -> [ParamBinding] -> [ModuleItem] -> Expr determinePortSize portName instanceParams moduleItems = - step initialMapping moduleItems + step (reverse initialMapping) moduleItems where moduleParams = parameterNames moduleItems initialMapping = catMaybes $ @@ -99,10 +99,10 @@ determinePortSize portName instanceParams moduleItems = step :: [(Identifier, Expr)] -> [ModuleItem] -> Expr step mapping (MIPackageItem (Decl (Param _ _ x e)) : rest) = - step (mapping ++ [(x, e)]) rest + step ((x, e) : mapping) rest step mapping (MIPackageItem (Decl (Variable _ t x a _)) : rest) = if x == portName - then substituteExpr mapping size + then substituteExpr (reverse mapping) size else step mapping rest where size = BinOp Mul (dimensionsSize a) (DimsFn FnBits $ Left t) step mapping (_ : rest) = step mapping rest @@ -111,6 +111,14 @@ determinePortSize portName instanceParams moduleItems = substituteExpr :: [(Identifier, Expr)] -> Expr -> Expr substituteExpr _ (Ident (':' : x)) = Ident x +substituteExpr mapping (Dot (Ident x) y) = + case lookup x mapping of + Nothing -> Dot (Ident x) y + Just (Pattern items) -> + case lookup y items of + Just item -> substituteExpr mapping item + Nothing -> Dot (substituteExpr mapping (Pattern items)) y + Just expr -> Dot (substituteExpr mapping expr) y substituteExpr mapping (Ident x) = case lookup x mapping of Nothing -> Ident x