fix struct/interface/logic conversion interactions

- interface conversion only waits for type resolution of modports
- typeof conversion resolves struct field accesses
- logic conversion only converts logic data declarations
- struct conversion only converts within modules
- fix nested type traversal order causing premature struct conversion
This commit is contained in:
Zachary Snow
2020-06-20 22:46:54 -04:00
parent bd1c07231f
commit 2535d689aa
7 changed files with 70 additions and 4 deletions
+7 -1
View File
@@ -62,8 +62,14 @@ convert =
fullyResolved :: ModuleItem -> Bool
fullyResolved =
not . any isTypeOf . execWriter .
collectNestedModuleItemsM (collectTypesM collectType)
collectNestedModuleItemsM collectModport
where
collectModport :: ModuleItem -> Writer [Type] ()
collectModport (Modport _ modportDecls) =
mapM collectModportDecl modportDecls >> return ()
collectModport _ = return ()
collectModportDecl :: ModportDecl -> Writer [Type] ()
collectModportDecl (_, _, t, _) = collectType t
collectType :: Type -> Writer [Type] ()
collectType t = tell [t]
isTypeOf TypeOf{} = True
+10 -1
View File
@@ -74,7 +74,16 @@ convertDescription ports orig =
PackageItem _ -> True
Package _ _ _ -> False
origIdents = execWriter (collectModuleItemsM regIdents orig)
logics = execWriter (collectModuleItemsM collectLogicM orig)
collectLogicM :: ModuleItem -> Writer Idents ()
collectLogicM (MIPackageItem (Decl (Variable _ t x _ _))) =
case t of
IntegerVector TLogic _ _ -> tell $ Set.singleton x
_ -> return ()
collectLogicM _ = return ()
origIdents = Set.intersection logics $
execWriter (collectModuleItemsM regIdents orig)
fixed = traverseModuleItems fixModuleItem orig
fixedIdents = execWriter (collectModuleItemsM regIdents fixed)
conversion = traverseDecls convertDecl . convertModuleItem
+1 -1
View File
@@ -26,7 +26,7 @@ convert :: [AST] -> [AST]
convert = map $ traverseDescriptions convertDescription
convertDescription :: Description -> Description
convertDescription (description @ Part{}) =
convertDescription (description @ (Part _ _ Module _ _ _ _)) =
traverseModuleItems (traverseTypes' ExcludeParamTypes $ convertType structs) $
Part attrs extern kw lifetime name ports (items ++ funcs)
where
+1 -1
View File
@@ -837,7 +837,7 @@ collectDeclsM = collectDeclsM' IncludeTFs
traverseNestedTypesM :: Monad m => MapperM m Type -> MapperM m Type
traverseNestedTypesM mapper = fullMapper
where
fullMapper t = tm t >>= mapper
fullMapper = mapper >=> tm
tm (Alias ps xx rs) = return $ Alias ps xx rs
tm (Net kw sg rs) = return $ Net kw sg rs
tm (Implicit sg rs) = return $ Implicit sg rs
+9
View File
@@ -15,6 +15,7 @@ import Control.Monad.State
import Data.List (elemIndex)
import Data.Maybe (fromMaybe, mapMaybe)
import Data.Int (Int32)
import Data.Tuple (swap)
import qualified Data.Map.Strict as Map
import Convert.Traverse
@@ -100,6 +101,14 @@ typeof (orig @ (Range e mode r)) = do
NonIndexed -> snd r
IndexedPlus -> BinOp Sub (uncurry (BinOp Add) r) (Number "1")
IndexedMinus -> BinOp Add (uncurry (BinOp Sub) r) (Number "1")
typeof (orig @ (Dot e x)) = do
t <- typeof e
return $ case t of
Struct _ fields [] ->
case lookup x $ map swap fields of
Just typ -> typ
Nothing -> TypeOf orig
_ -> TypeOf orig
typeof (orig @ (Cast (Right (Ident x)) _)) = do
typeMap <- get
if Map.member x typeMap