From 3baa9cbac7e6d48d9a06ab9d70ddaafea44a1dc3 Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Thu, 11 Jun 2020 20:37:53 -0400 Subject: [PATCH] simplify typedef conversion --- src/Convert/Typedef.hs | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/src/Convert/Typedef.hs b/src/Convert/Typedef.hs index 2d8d69a..10e17ba 100644 --- a/src/Convert/Typedef.hs +++ b/src/Convert/Typedef.hs @@ -18,29 +18,16 @@ import Language.SystemVerilog.AST type Types = Map.Map Identifier Type convert :: [AST] -> [AST] -convert = - traverseFiles - (collectDescriptionsM getTypedef) - (\a -> traverseDescriptions $ removeTypedef . convertDescription a) - where - getTypedef :: Description -> Writer Types () - getTypedef (PackageItem (Typedef a b)) = tell $ Map.singleton b a - getTypedef (Part _ _ Interface _ x _ _) = - tell $ Map.singleton x (InterfaceT x Nothing []) - getTypedef _ = return () - removeTypedef :: Description -> Description - removeTypedef (PackageItem (Typedef _ x)) = - PackageItem $ Decl $ CommentDecl $ "removed typedef: " ++ x - removeTypedef other = other +convert = map $ traverseDescriptions convertDescription -convertDescription :: Types -> Description -> Description -convertDescription globalTypes description = +convertDescription :: Description -> Description +convertDescription (description @ Part{}) = traverseModuleItems (convertTypedef types) description' where description' = traverseModuleItems (traverseGenItems convertGenItem) description - types = Map.union globalTypes $ - execWriter $ collectModuleItemsM collectTypedefM description' + types = execWriter $ collectModuleItemsM collectTypedefM description' +convertDescription other = other convertTypedef :: Types -> ModuleItem -> ModuleItem convertTypedef types =