Commit 378ede9e by Zachary Snow

standardize internal representation of unknown types

parent 58e5bfa6
......@@ -490,7 +490,7 @@ inlineInstance ranges modportBindings items
parameterBinds = map makeParameterBind instanceParams
makeParameterBind :: ParamBinding -> Decl
makeParameterBind (x, Left t) =
ParamType Localparam (paramTmp ++ x) (Just t)
ParamType Localparam (paramTmp ++ x) t
makeParameterBind (x, Right e) =
Param Localparam (TypeOf e) (paramTmp ++ x) e
......@@ -501,11 +501,11 @@ inlineInstance ranges modportBindings items
Just (Right _) -> Param Localparam t x (Ident $ paramTmp ++ x)
Just (Left t') -> error $ inlineKind ++ " param " ++ x
++ " expected expr, found type: " ++ show t'
overrideParam (ParamType Parameter x mt) =
overrideParam (ParamType Parameter x t) =
case lookup x instanceParams of
Nothing -> ParamType Localparam x mt
Nothing -> ParamType Localparam x t
Just (Left _) ->
ParamType Localparam x (Just $ Alias (paramTmp ++ x) [])
ParamType Localparam x $ Alias (paramTmp ++ x) []
Just (Right e') -> error $ inlineKind ++ " param " ++ x
++ " expected type, found expr: " ++ show e'
overrideParam other = other
......
......@@ -55,12 +55,12 @@ traverseDeclM (Param Parameter t x e) = do
return $ if e == Nil
then Param Parameter t x $ RawNum 0
else Param Parameter t x e
traverseDeclM (ParamType Localparam x Nothing) =
traverseDeclM (ParamType Localparam x UnknownType) =
error $ "localparam type " ++ show x ++ " has no default value"
traverseDeclM (ParamType Parameter x mt) = do
traverseDeclM (ParamType Parameter x t) = do
-- parameter types are rewritten separately, so no fake default here
tell [(x, mt == Nothing)]
return $ ParamType Parameter x mt
tell [(x, t == UnknownType)]
return $ ParamType Parameter x t
traverseDeclM other = return other
-- check for instances missing values for parameters without defaults
......
......@@ -116,7 +116,7 @@ convert files =
traverseModuleItems (traverseDecls rewriteDecl) part
rewriteDecl :: Decl -> Decl
rewriteDecl (ParamType Parameter x _) =
ParamType Parameter x Nothing
ParamType Parameter x UnknownType
rewriteDecl other = other
removeDefaultTypeParams _ = error "not possible"
......@@ -152,7 +152,7 @@ convert files =
items' = map (traverseDecls rewriteDecl) items
rewriteDecl :: Decl -> Decl
rewriteDecl (ParamType Parameter x _) =
ParamType Localparam x (Just $ fst $ typeMap Map.! x)
ParamType Localparam x (fst $ typeMap Map.! x)
rewriteDecl other = other
additionalParamItems = concatMap makeAddedParams $
Map.toList $ Map.map snd typeMap
......@@ -170,7 +170,7 @@ convert files =
typ = Alias (addedParamTypeName paramName ident) []
name = addedParamName paramName ident
toTypeParam :: Identifier -> Decl
toTypeParam ident = ParamType Parameter name Nothing
toTypeParam ident = ParamType Parameter name UnknownType
where name = addedParamTypeName paramName ident
-- write down module parameter names and type parameters
......@@ -184,9 +184,13 @@ collectDescriptionM (part @ (Part _ _ _ _ name _ _)) =
maybeTypeMap = Map.fromList $
map (\(x, y) -> (x, fromJust y)) $
filter (isJust . snd) params
--- TODO FIXME XXX
collectDeclM :: Decl -> Writer [(Identifier, Maybe (Maybe Type))] ()
collectDeclM (Param Parameter _ x _) = tell [(x, Nothing)]
collectDeclM (ParamType Parameter x v) = tell [(x, Just v )]
collectDeclM (ParamType Parameter x v) =
if v == UnknownType
then tell [(x, Just Nothing)]
else tell [(x, Just $ Just v)]
collectDeclM _ = return ()
collectDescriptionM _ = return ()
......
{-# LANGUAGE PatternSynonyms #-}
{- sv2v
- Author: Zachary Snow <zach@zachjs.com>
-
......@@ -52,9 +51,6 @@ parameterNames =
collectDeclM (ParamType Parameter x _) = tell [x]
collectDeclM _ = return ()
pattern UnknownType :: Type
pattern UnknownType = Implicit Unspecified []
-- rewrite an existing string parameter
traverseModuleItemM :: ModuleItem -> Writer [Identifier] ModuleItem
traverseModuleItemM (orig @ (MIPackageItem (Decl (Param Parameter t x e)))) =
......
......@@ -913,9 +913,9 @@ traverseDeclExprsM exprMapper =
t' <- typeMapper t
e' <- exprMapper e
return $ Param s t' x e'
declMapper (ParamType s x mt) = do
mt' <- mapM typeMapper mt
return $ ParamType s x mt'
declMapper (ParamType s x t) = do
t' <- typeMapper t
return $ ParamType s x t'
declMapper (Variable d t x a e) = do
t' <- typeMapper t
a' <- mapM (mapBothM exprMapper) a
......@@ -932,8 +932,8 @@ collectDeclExprsM = collectify traverseDeclExprsM
traverseDeclTypesM :: Monad m => MapperM m Type -> MapperM m Decl
traverseDeclTypesM mapper (Param s t x e) =
mapper t >>= \t' -> return $ Param s t' x e
traverseDeclTypesM mapper (ParamType s x mt) =
mapM mapper mt >>= \mt' -> return $ ParamType s x mt'
traverseDeclTypesM mapper (ParamType s x t) =
mapper t >>= \t' -> return $ ParamType s x t'
traverseDeclTypesM mapper (Variable d t x a e) =
mapper t >>= \t' -> return $ Variable d t' x a e
traverseDeclTypesM _ (CommentDecl c) = return $ CommentDecl c
......
......@@ -27,10 +27,6 @@ convert :: [AST] -> [AST]
convert = map $ traverseDescriptions $ partScoper
traverseDeclM traverseModuleItemM traverseGenItemM traverseStmtM
-- internal representation of a fully implicit type
pattern UnknownType :: Type
pattern UnknownType = Implicit Unspecified []
-- single bit 4-state `logic` type
pattern UnitType :: Type
pattern UnitType = IntegerVector TLogic Unspecified []
......
......@@ -70,7 +70,7 @@ traverseDeclM decl = do
case decl' of
Variable{} -> return decl'
Param{} -> return decl'
ParamType Localparam x (Just t) -> do
ParamType Localparam x t -> do
t' <- traverseNestedTypesM traverseTypeM t
insertElem x t'
return $ CommentDecl $ "removed localparam type " ++ x
......
{-# LANGUAGE PatternSynonyms #-}
{- sv2v
- Author: Zachary Snow <zach@zachjs.com>
- Initial Verilog AST Author: Tom Hawkins <tomahawkins@gmail.com>
......@@ -16,12 +17,12 @@ module Language.SystemVerilog.AST.Decl
import Text.Printf (printf)
import Language.SystemVerilog.AST.ShowHelp (showPad, unlines')
import Language.SystemVerilog.AST.Type (Type, Identifier)
import Language.SystemVerilog.AST.Type (Type, Identifier, pattern UnknownType)
import Language.SystemVerilog.AST.Expr (Expr, Range, showRanges, showAssignment)
data Decl
= Param ParamScope Type Identifier Expr
| ParamType ParamScope Identifier (Maybe Type)
| ParamType ParamScope Identifier Type
| Variable Direction Type Identifier [Range] Expr
| CommentDecl String
deriving (Eq, Ord)
......@@ -29,8 +30,8 @@ data Decl
instance Show Decl where
showList l _ = unlines' $ map show l
show (Param s t x e) = printf "%s %s%s%s;" (show s) (showPad t) x (showAssignment e)
show (ParamType s x mt) = printf "%s type %s%s;" (show s) x tStr
where tStr = maybe "" ((" = " ++) . show) mt
show (ParamType s x t) = printf "%s type %s%s;" (show s) x tStr
where tStr = if t == UnknownType then "" else " = " ++ show t
show (Variable d t x a e) = printf "%s%s%s%s%s;" (showPad d) (showPad t) x (showRanges a) (showAssignment e)
show (CommentDecl c) =
if elem '\n' c
......
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE PatternSynonyms #-}
{- sv2v
- Author: Zachary Snow <zach@zachjs.com>
- Initial Verilog AST Author: Tom Hawkins <tomahawkins@gmail.com>
......@@ -21,6 +22,7 @@ module Language.SystemVerilog.AST.Type
, Strength0 (..)
, Strength1 (..)
, ChargeStrength (..)
, pattern UnknownType
, typeRanges
, nullRange
, elaborateIntegerAtom
......@@ -80,6 +82,10 @@ showFields items = itemsStr
itemsStr = indent $ unlines' $ map showItem items
showItem (t, x) = printf "%s %s;" (show t) x
-- internal representation of a fully implicit or unknown type
pattern UnknownType :: Type
pattern UnknownType = Implicit Unspecified []
instance Show ([Range] -> Type) where
show tf = show (tf [])
instance Eq ([Range] -> Type) where
......
......@@ -1077,12 +1077,12 @@ ParameterDeclKW :: { ParamScope }
: "parameter" { Parameter }
| "localparam" { Localparam }
TypeAsgns :: { [(Identifier, Maybe Type)] }
TypeAsgns :: { [(Identifier, Type)] }
: TypeAsgn { [$1] }
| TypeAsgns "," TypeAsgn { $1 ++ [$3] }
TypeAsgn :: { (Identifier, Maybe Type) }
: Identifier "=" Type { ($1, Just $3) }
| Identifier { ($1, Nothing) }
TypeAsgn :: { (Identifier, Type) }
: Identifier "=" Type { ($1, $3) }
| Identifier { ($1, UnknownType) }
-- TODO: This does not allow for @identifier
ClockingEvent :: { Sense }
......@@ -1476,7 +1476,7 @@ validateGenCases items =
makeLocalparam :: Decl -> Decl
makeLocalparam (Param _ t x e) = Param Localparam t x e
makeLocalparam (ParamType _ x mt) = ParamType Localparam x mt
makeLocalparam (ParamType _ x t) = ParamType Localparam x t
makeLocalparam other = other
}
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