2019-03-25 18:29:35 +01:00
|
|
|
{- sv2v
|
|
|
|
|
- Author: Zachary Snow <zach@zachjs.com>
|
|
|
|
|
- Initial Verilog AST Author: Tom Hawkins <tomahawkins@gmail.com>
|
|
|
|
|
-
|
2021-02-19 18:24:56 +01:00
|
|
|
- SystemVerilog data, net, and parameter declarations
|
2019-03-25 18:29:35 +01:00
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
module Language.SystemVerilog.AST.Decl
|
2019-09-07 04:29:14 +02:00
|
|
|
( Decl (..)
|
|
|
|
|
, Direction (..)
|
|
|
|
|
, ParamScope (..)
|
2019-03-25 18:29:35 +01:00
|
|
|
) where
|
|
|
|
|
|
|
|
|
|
import Text.Printf (printf)
|
|
|
|
|
|
2021-07-02 23:59:21 +02:00
|
|
|
import Language.SystemVerilog.AST.ShowHelp (showPad, showPadBefore, unlines')
|
|
|
|
|
import Language.SystemVerilog.AST.Type (Type(TypedefRef, UnpackedType), Identifier, pattern UnknownType, NetType, Strength)
|
2019-03-25 18:29:35 +01:00
|
|
|
import Language.SystemVerilog.AST.Expr (Expr, Range, showRanges, showAssignment)
|
|
|
|
|
|
|
|
|
|
data Decl
|
2019-09-07 04:29:14 +02:00
|
|
|
= Param ParamScope Type Identifier Expr
|
2021-01-24 17:55:03 +01:00
|
|
|
| ParamType ParamScope Identifier Type
|
2020-06-14 21:56:09 +02:00
|
|
|
| Variable Direction Type Identifier [Range] Expr
|
2021-07-02 23:59:21 +02:00
|
|
|
| Net Direction NetType Strength Type Identifier [Range] Expr
|
2020-01-31 04:17:17 +01:00
|
|
|
| CommentDecl String
|
2021-03-09 20:18:37 +01:00
|
|
|
deriving Eq
|
2019-03-25 18:29:35 +01:00
|
|
|
|
|
|
|
|
instance Show Decl where
|
|
|
|
|
showList l _ = unlines' $ map show l
|
2021-01-21 19:48:36 +01:00
|
|
|
show (Param s t x e) = printf "%s %s%s%s;" (show s) (showPad t) x (showAssignment e)
|
2021-06-25 20:53:03 +02:00
|
|
|
show (ParamType Localparam x (TypedefRef e)) =
|
|
|
|
|
printf "typedef %s %s;" (show e) x
|
2021-05-25 05:06:07 +02:00
|
|
|
show (ParamType Localparam x (UnpackedType t rs)) =
|
|
|
|
|
printf "typedef %s %s%s;" (show t) x (showRanges rs)
|
2021-01-24 17:55:03 +01:00
|
|
|
show (ParamType s x t) = printf "%s type %s%s;" (show s) x tStr
|
|
|
|
|
where tStr = if t == UnknownType then "" else " = " ++ show t
|
2020-06-14 21:56:09 +02:00
|
|
|
show (Variable d t x a e) = printf "%s%s%s%s%s;" (showPad d) (showPad t) x (showRanges a) (showAssignment e)
|
2021-07-02 23:59:21 +02:00
|
|
|
show (Net d n s t x a e) = printf "%s%s%s %s%s%s%s;" (showPad d) (show n) (showPadBefore s) (showPad t) x (showRanges a) (showAssignment e)
|
2021-07-16 18:30:35 +02:00
|
|
|
show (CommentDecl c) = "// " ++ c
|
2019-03-25 18:29:35 +01:00
|
|
|
|
|
|
|
|
data Direction
|
|
|
|
|
= Input
|
|
|
|
|
| Output
|
|
|
|
|
| Inout
|
|
|
|
|
| Local
|
2021-03-09 20:18:37 +01:00
|
|
|
deriving Eq
|
2019-03-25 18:29:35 +01:00
|
|
|
|
|
|
|
|
instance Show Direction where
|
|
|
|
|
show Input = "input"
|
|
|
|
|
show Output = "output"
|
|
|
|
|
show Inout = "inout"
|
|
|
|
|
show Local = ""
|
2019-09-07 04:29:14 +02:00
|
|
|
|
|
|
|
|
data ParamScope
|
|
|
|
|
= Parameter
|
|
|
|
|
| Localparam
|
2021-03-09 20:18:37 +01:00
|
|
|
deriving Eq
|
2019-09-07 04:29:14 +02:00
|
|
|
|
|
|
|
|
instance Show ParamScope where
|
|
|
|
|
show Parameter = "parameter"
|
|
|
|
|
show Localparam = "localparam"
|