mirror of https://github.com/zachjs/sv2v.git
Added ParamType decl; combined parameter and localparam under Param
This commit is contained in:
parent
9cc211d51e
commit
d11e898edb
|
|
@ -36,8 +36,8 @@ traverseDeclM :: Decl -> State Info Decl
|
|||
traverseDeclM decl = do
|
||||
case decl of
|
||||
Variable _ t ident a _ -> modify $ Map.insert ident (t, a)
|
||||
Parameter t ident _ -> modify $ Map.insert ident (t, [])
|
||||
Localparam t ident _ -> modify $ Map.insert ident (t, [])
|
||||
Param _ t ident _ -> modify $ Map.insert ident (t, [])
|
||||
ParamType _ _ _ -> return ()
|
||||
item <- traverseModuleItemM (MIPackageItem $ Decl decl)
|
||||
let MIPackageItem (Decl decl') = item
|
||||
return decl'
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ convergeUsage items enums =
|
|||
|
||||
toItem :: EnumItem -> PackageItem
|
||||
toItem ((mr, x), v) =
|
||||
Decl $ Localparam itemType x v'
|
||||
Decl $ Param Localparam itemType x v'
|
||||
where
|
||||
v' = if mr == Nothing
|
||||
then simplify v
|
||||
|
|
|
|||
|
|
@ -192,8 +192,8 @@ prefixModuleItems prefix =
|
|||
where
|
||||
prefixDecl :: Decl -> Decl
|
||||
prefixDecl (Variable d t x a me) = Variable d t (prefix ++ x) a me
|
||||
prefixDecl (Parameter t x e) = Parameter t (prefix ++ x) e
|
||||
prefixDecl (Localparam t x e) = Localparam t (prefix ++ x) e
|
||||
prefixDecl (Param s t x e) = Param s t (prefix ++ x) e
|
||||
prefixDecl (ParamType s x mt) = ParamType s (prefix ++ x) mt
|
||||
prefixExpr :: Expr -> Expr
|
||||
prefixExpr (Ident x) = Ident (prefix ++ x)
|
||||
prefixExpr other = other
|
||||
|
|
|
|||
|
|
@ -122,10 +122,8 @@ convertDescription ports orig =
|
|||
convertModuleItem other = other
|
||||
-- all other logics (i.e. inside of functions) become regs
|
||||
convertDecl :: Decl -> Decl
|
||||
convertDecl (Parameter (IntegerVector _ sg rs) x e) =
|
||||
Parameter (Implicit sg rs) x e
|
||||
convertDecl (Localparam (IntegerVector _ sg rs) x e) =
|
||||
Localparam (Implicit sg rs) x e
|
||||
convertDecl (Param s (IntegerVector _ sg rs) x e) =
|
||||
Param s (Implicit sg rs) x e
|
||||
convertDecl (Variable d (IntegerVector TLogic sg rs) x a me) =
|
||||
Variable d (IntegerVector TReg sg rs) x a me
|
||||
convertDecl other = other
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ convertDescription =
|
|||
traverseDeclM :: Decl -> State Info Decl
|
||||
traverseDeclM decl = do
|
||||
case decl of
|
||||
Localparam _ x e -> modify $ Map.insert x e
|
||||
Param Localparam _ x e -> modify $ Map.insert x e
|
||||
_ -> return ()
|
||||
return decl
|
||||
|
||||
|
|
|
|||
|
|
@ -90,8 +90,8 @@ piName (Function _ _ ident _ _) = Just ident
|
|||
piName (Task _ ident _ _) = Just ident
|
||||
piName (Typedef _ ident ) = Just ident
|
||||
piName (Decl (Variable _ _ ident _ _)) = Just ident
|
||||
piName (Decl (Parameter _ ident _)) = Just ident
|
||||
piName (Decl (Localparam _ ident _)) = Just ident
|
||||
piName (Decl (Param _ _ ident _)) = Just ident
|
||||
piName (Decl (ParamType _ ident _)) = Just ident
|
||||
piName (Import x y) = Just $ show $ Import x y
|
||||
piName (Export _) = Nothing
|
||||
piName (Comment _) = Nothing
|
||||
|
|
|
|||
|
|
@ -91,8 +91,8 @@ prefixPackageItem packageName idents item =
|
|||
Task a x c d -> Task a (prefix x) c d
|
||||
Typedef a x -> Typedef a (prefix x)
|
||||
Decl (Variable a b x c d) -> Decl (Variable a b (prefix x) c d)
|
||||
Decl (Parameter a x b) -> Decl (Parameter a (prefix x) b)
|
||||
Decl (Localparam a x b) -> Decl (Localparam a (prefix x) b)
|
||||
Decl (Param a b x c ) -> Decl (Param a b (prefix x) c )
|
||||
Decl (ParamType a x b ) -> Decl (ParamType a (prefix x) b )
|
||||
other -> other
|
||||
convertType (Alias Nothing x rs) = Alias Nothing (prefix x) rs
|
||||
convertType (Enum mt items rs) = Enum mt items' rs
|
||||
|
|
@ -181,8 +181,8 @@ piName (Function _ _ ident _ _) = Just ident
|
|||
piName (Task _ ident _ _) = Just ident
|
||||
piName (Typedef _ ident ) = Just ident
|
||||
piName (Decl (Variable _ _ ident _ _)) = Just ident
|
||||
piName (Decl (Parameter _ ident _)) = Just ident
|
||||
piName (Decl (Localparam _ ident _)) = Just ident
|
||||
piName (Decl (Param _ _ ident _)) = Just ident
|
||||
piName (Decl (ParamType _ ident _)) = Just ident
|
||||
piName (Import _ _) = Nothing
|
||||
piName (Export _) = Nothing
|
||||
piName (Comment _) = Nothing
|
||||
|
|
|
|||
|
|
@ -51,12 +51,11 @@ traverseDeclM (Variable dir t ident a me) = do
|
|||
else do
|
||||
t' <- traverseDeclM' t ident
|
||||
return $ Variable dir t' ident a me
|
||||
traverseDeclM (Parameter t ident e) = do
|
||||
traverseDeclM (Param s t ident e) = do
|
||||
t' <- traverseDeclM' t ident
|
||||
return $ Parameter t' ident e
|
||||
traverseDeclM (Localparam t ident e) = do
|
||||
t' <- traverseDeclM' t ident
|
||||
return $ Localparam t' ident e
|
||||
return $ Param s t' ident e
|
||||
traverseDeclM (ParamType s ident mt) =
|
||||
return $ ParamType s ident mt
|
||||
|
||||
traverseDeclM' :: Type -> Identifier -> State Info Type
|
||||
traverseDeclM' t ident = do
|
||||
|
|
|
|||
|
|
@ -176,14 +176,12 @@ traverseDeclM structs origDecl = do
|
|||
Just e -> do
|
||||
e' <- convertDeclExpr x e
|
||||
return $ Variable d t x a (Just e')
|
||||
Parameter t x e -> do
|
||||
Param s t x e -> do
|
||||
modify $ Map.insert x t
|
||||
e' <- convertDeclExpr x e
|
||||
return $ Parameter t x e'
|
||||
Localparam t x e -> do
|
||||
modify $ Map.insert x t
|
||||
e' <- convertDeclExpr x e
|
||||
return $ Localparam t x e'
|
||||
return $ Param s t x e'
|
||||
ParamType s x mt ->
|
||||
return $ ParamType s x mt
|
||||
where
|
||||
convertDeclExpr :: Identifier -> Expr -> State Types Expr
|
||||
convertDeclExpr x e = do
|
||||
|
|
|
|||
|
|
@ -486,14 +486,17 @@ exprMapperHelpers exprMapper =
|
|||
return $ tf rs'
|
||||
typeMapper = traverseNestedTypesM typeMapper'
|
||||
|
||||
declMapper (Parameter t x e) = do
|
||||
maybeTypeMapper Nothing = return Nothing
|
||||
maybeTypeMapper (Just t) =
|
||||
typeMapper t >>= return . Just
|
||||
|
||||
declMapper (Param s t x e) = do
|
||||
t' <- typeMapper t
|
||||
e' <- exprMapper e
|
||||
return $ Parameter t' x e'
|
||||
declMapper (Localparam t x e) = do
|
||||
t' <- typeMapper t
|
||||
e' <- exprMapper e
|
||||
return $ Localparam t' x e'
|
||||
return $ Param s t' x e'
|
||||
declMapper (ParamType s x mt) = do
|
||||
mt' <- maybeTypeMapper mt
|
||||
return $ ParamType s x mt'
|
||||
declMapper (Variable d t x a me) = do
|
||||
t' <- typeMapper t
|
||||
a' <- mapM rangeMapper a
|
||||
|
|
@ -820,15 +823,17 @@ traverseTypesM mapper item =
|
|||
traverseExprsM (traverseNestedExprsM exprMapper)
|
||||
where
|
||||
fullMapper = traverseNestedTypesM mapper
|
||||
maybeMapper Nothing = return Nothing
|
||||
maybeMapper (Just t) = fullMapper t >>= return . Just
|
||||
exprMapper (Cast (Left t) e) =
|
||||
fullMapper t >>= \t' -> return $ Cast (Left t') e
|
||||
exprMapper (Bits (Left t)) =
|
||||
fullMapper t >>= return . Bits . Left
|
||||
exprMapper other = return other
|
||||
declMapper (Parameter t x e) =
|
||||
fullMapper t >>= \t' -> return $ Parameter t' x e
|
||||
declMapper (Localparam t x e) =
|
||||
fullMapper t >>= \t' -> return $ Localparam t' x e
|
||||
declMapper (Param s t x e) =
|
||||
fullMapper t >>= \t' -> return $ Param s t' x e
|
||||
declMapper (ParamType s x mt) =
|
||||
maybeMapper mt >>= \mt' -> return $ ParamType s x mt'
|
||||
declMapper (Variable d t x a me) =
|
||||
fullMapper t >>= \t' -> return $ Variable d t' x a me
|
||||
miMapper (MIPackageItem (Typedef t x)) =
|
||||
|
|
|
|||
|
|
@ -3,11 +3,14 @@
|
|||
- Initial Verilog AST Author: Tom Hawkins <tomahawkins@gmail.com>
|
||||
-
|
||||
- SystemVerilog left-hand sides (aka lvals)
|
||||
-
|
||||
- TODO: Normal parameters can be declared with no default valu.
|
||||
-}
|
||||
|
||||
module Language.SystemVerilog.AST.Decl
|
||||
( Decl (..)
|
||||
, Direction (..)
|
||||
( Decl (..)
|
||||
, Direction (..)
|
||||
, ParamScope (..)
|
||||
) where
|
||||
|
||||
import Text.Printf (printf)
|
||||
|
|
@ -17,15 +20,15 @@ import Language.SystemVerilog.AST.Type (Type, Identifier)
|
|||
import Language.SystemVerilog.AST.Expr (Expr, Range, showRanges, showAssignment)
|
||||
|
||||
data Decl
|
||||
= Parameter Type Identifier Expr
|
||||
| Localparam Type Identifier Expr
|
||||
= Param ParamScope Type Identifier Expr
|
||||
| ParamType ParamScope Identifier (Maybe Type)
|
||||
| Variable Direction Type Identifier [Range] (Maybe Expr)
|
||||
deriving Eq
|
||||
|
||||
instance Show Decl where
|
||||
showList l _ = unlines' $ map show l
|
||||
show (Parameter t x e) = printf "parameter %s%s = %s;" (showPad t) x (show e)
|
||||
show (Localparam t x e) = printf "localparam %s%s = %s;" (showPad t) x (show e)
|
||||
show (Param s t x e) = printf "%s %s%s = %s;" (show s) (showPad t) x (show e)
|
||||
show (ParamType s x mt) = printf "%s type %s%s;" (show s) x (showAssignment mt)
|
||||
show (Variable d t x a me) = printf "%s%s%s%s%s;" (showPad d) (showPad t) x (showRanges a) (showAssignment me)
|
||||
|
||||
data Direction
|
||||
|
|
@ -40,3 +43,12 @@ instance Show Direction where
|
|||
show Output = "output"
|
||||
show Inout = "inout"
|
||||
show Local = ""
|
||||
|
||||
data ParamScope
|
||||
= Parameter
|
||||
| Localparam
|
||||
deriving Eq
|
||||
|
||||
instance Show ParamScope where
|
||||
show Parameter = "parameter"
|
||||
show Localparam = "localparam"
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ instance Show PartSelectMode where
|
|||
show IndexedPlus = "+:"
|
||||
show IndexedMinus = "-:"
|
||||
|
||||
showAssignment :: Maybe Expr -> String
|
||||
showAssignment :: Show a => Maybe a -> String
|
||||
showAssignment Nothing = ""
|
||||
showAssignment (Just val) = " = " ++ show val
|
||||
|
||||
|
|
|
|||
|
|
@ -896,10 +896,18 @@ ParameterDecl(delim) :: { [Decl] }
|
|||
| ParameterDeclKW ParamType DeclAsgns delim { makeParamDecls $1 ($2 ) $3 }
|
||||
| ParameterDeclKW Identifier Dimensions DeclAsgns delim { makeParamDecls $1 (Alias (Nothing) $2 $3) $4 }
|
||||
| ParameterDeclKW Identifier "::" Identifier Dimensions DeclAsgns delim { makeParamDecls $1 (Alias (Just $2) $4 $5) $6 }
|
||||
ParameterDeclKW :: { Type -> Identifier -> Expr -> Decl }
|
||||
| ParameterDeclKW "type" TypeAsgns delim { map (uncurry $ ParamType $1) $3 }
|
||||
ParameterDeclKW :: { ParamScope }
|
||||
: "parameter" { Parameter }
|
||||
| "localparam" { Localparam }
|
||||
|
||||
TypeAsgns :: { [(Identifier, Maybe Type)] }
|
||||
: TypeAsgn { [$1] }
|
||||
| TypeAsgns "," TypeAsgn { $1 ++ [$3] }
|
||||
TypeAsgn :: { (Identifier, Maybe Type) }
|
||||
: Identifier "=" Type { ($1, Just $3) }
|
||||
| Identifier { ($1, Nothing) }
|
||||
|
||||
-- TODO: This does not allow for @identifier
|
||||
ClockingEvent :: { Sense }
|
||||
: "@" "(" Senses ")" { $3 }
|
||||
|
|
@ -1172,14 +1180,14 @@ toLHS expr =
|
|||
++ show expr
|
||||
|
||||
makeParamDecls
|
||||
:: (Type -> Identifier -> Expr -> Decl)
|
||||
:: ParamScope
|
||||
-> Type
|
||||
-> [(Identifier, Expr, [Range])]
|
||||
-> [Decl]
|
||||
makeParamDecls kw t items =
|
||||
makeParamDecls s t items =
|
||||
map mapper items
|
||||
where
|
||||
(tf, rs) = typeRanges t
|
||||
mapper (x, e, a) = kw (tf $ a ++ rs) x e
|
||||
mapper (x, e, a) = Param s (tf $ a ++ rs) x e
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue