Commit 3baa9cba by Zachary Snow

simplify typedef conversion

parent 9adb7522
...@@ -18,29 +18,16 @@ import Language.SystemVerilog.AST ...@@ -18,29 +18,16 @@ import Language.SystemVerilog.AST
type Types = Map.Map Identifier Type type Types = Map.Map Identifier Type
convert :: [AST] -> [AST] convert :: [AST] -> [AST]
convert = convert = map $ traverseDescriptions convertDescription
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
convertDescription :: Types -> Description -> Description convertDescription :: Description -> Description
convertDescription globalTypes description = convertDescription (description @ Part{}) =
traverseModuleItems (convertTypedef types) description' traverseModuleItems (convertTypedef types) description'
where where
description' = description' =
traverseModuleItems (traverseGenItems convertGenItem) description traverseModuleItems (traverseGenItems convertGenItem) description
types = Map.union globalTypes $ types = execWriter $ collectModuleItemsM collectTypedefM description'
execWriter $ collectModuleItemsM collectTypedefM description' convertDescription other = other
convertTypedef :: Types -> ModuleItem -> ModuleItem convertTypedef :: Types -> ModuleItem -> ModuleItem
convertTypedef types = convertTypedef types =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment