Commit d7b36a03 by Zachary Snow

removed enum complex type cast hack

parent 710da1a6
...@@ -33,8 +33,10 @@ convertDescription (description @ (Part _ _ _ _)) = ...@@ -33,8 +33,10 @@ convertDescription (description @ (Part _ _ _ _)) =
where where
enumPairs = concat $ map (uncurry enumVals) $ Set.toList enums enumPairs = concat $ map (uncurry enumVals) $ Set.toList enums
enumItems = map (\(x, v) -> MIDecl $ Localparam (Implicit []) x v) enumPairs enumItems = map (\(x, v) -> MIDecl $ Localparam (Implicit []) x v) enumPairs
(Part kw name ports items, enums) = runWriter $ (Part kw name ports items, enums) =
traverseModuleItemsM (traverseTypesM traverseType) description runWriter $ traverseModuleItemsM (traverseTypesM traverseType) $
traverseModuleItems (traverseExprs traverseExpr) $
description
traverseType :: Type -> Writer Enums Type traverseType :: Type -> Writer Enums Type
traverseType (Enum t v r) = do traverseType (Enum t v r) = do
() <- tell $ Set.singleton (t, v) () <- tell $ Set.singleton (t, v)
...@@ -42,6 +44,11 @@ convertDescription (description @ (Part _ _ _ _)) = ...@@ -42,6 +44,11 @@ convertDescription (description @ (Part _ _ _ _)) =
let (tf, rs) = typeRanges baseType let (tf, rs) = typeRanges baseType
return $ tf (rs ++ r) return $ tf (rs ++ r)
traverseType other = return other traverseType other = return other
-- drop any enum type casts in favor of implicit conversion from the
-- converted type
traverseExpr :: Expr -> Expr
traverseExpr (Cast (Enum _ _ _) e) = e
traverseExpr other = other
convertDescription other = other convertDescription other = other
enumVals :: Maybe Type -> [(Identifier, Maybe Expr)] -> [(Identifier, Expr)] enumVals :: Maybe Type -> [(Identifier, Maybe Expr)] -> [(Identifier, Expr)]
......
...@@ -380,14 +380,8 @@ traverseTypesM mapper item = ...@@ -380,14 +380,8 @@ traverseTypesM mapper item =
types <- mapM fullMapper $ map fst fields types <- mapM fullMapper $ map fst fields
let idents = map snd fields let idents = map snd fields
return $ Struct p (zip types idents) r return $ Struct p (zip types idents) r
exprMapper (Cast t e) = do exprMapper (Cast t e) =
t' <- fullMapper t fullMapper t >>= \t' -> return $ Cast t' e
-- TODO HACK: If the cast type is no longer "simple", we just drop
-- the case altogether. This probably doesn't work great in all
-- cases.
return $ if elem ' ' (show t')
then e
else Cast t' e
exprMapper other = return other exprMapper other = return other
declMapper (Parameter t x e) = declMapper (Parameter t x e) =
fullMapper t >>= \t' -> return $ Parameter t' x e fullMapper t >>= \t' -> return $ Parameter t' x e
......
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