2019-04-04 02:24:09 +02:00
|
|
|
{- sv2v
|
|
|
|
|
- Author: Zachary Snow <zach@zachjs.com>
|
|
|
|
|
- Initial Verilog AST Author: Tom Hawkins <tomahawkins@gmail.com>
|
|
|
|
|
-
|
|
|
|
|
- SystemVerilog top-level items (descriptions, package items)
|
|
|
|
|
-}
|
|
|
|
|
|
|
|
|
|
module Language.SystemVerilog.AST.Description
|
|
|
|
|
( Description (..)
|
|
|
|
|
, PackageItem (..)
|
|
|
|
|
, PartKW (..)
|
|
|
|
|
, Lifetime (..)
|
|
|
|
|
) where
|
|
|
|
|
|
|
|
|
|
import Text.Printf (printf)
|
|
|
|
|
|
|
|
|
|
import Language.SystemVerilog.AST.ShowHelp
|
|
|
|
|
|
2019-09-16 05:17:14 +02:00
|
|
|
import Language.SystemVerilog.AST.Attr (Attr)
|
2019-04-04 02:24:09 +02:00
|
|
|
import Language.SystemVerilog.AST.Decl (Decl)
|
|
|
|
|
import Language.SystemVerilog.AST.Stmt (Stmt)
|
|
|
|
|
import Language.SystemVerilog.AST.Type (Type, Identifier)
|
|
|
|
|
import {-# SOURCE #-} Language.SystemVerilog.AST.ModuleItem (ModuleItem)
|
|
|
|
|
|
|
|
|
|
data Description
|
2019-12-22 18:01:05 +01:00
|
|
|
= Part [Attr] Bool PartKW Lifetime Identifier [Identifier] [ModuleItem]
|
2019-04-04 02:24:09 +02:00
|
|
|
| PackageItem PackageItem
|
2019-12-22 18:01:05 +01:00
|
|
|
| Package Lifetime Identifier [PackageItem]
|
2019-04-04 02:24:09 +02:00
|
|
|
deriving Eq
|
|
|
|
|
|
|
|
|
|
instance Show Description where
|
2020-12-11 20:41:59 +01:00
|
|
|
showList l _ = unlines' $ map show l
|
2019-09-16 05:17:14 +02:00
|
|
|
show (Part attrs True kw lifetime name _ items) =
|
|
|
|
|
printf "%sextern %s %s%s %s;"
|
|
|
|
|
(concatMap showPad attrs)
|
2019-12-22 18:01:05 +01:00
|
|
|
(show kw) (showPad lifetime) name (indentedParenList itemStrs)
|
2019-04-04 02:24:09 +02:00
|
|
|
where itemStrs = map (init . show) items
|
2019-09-16 05:17:14 +02:00
|
|
|
show (Part attrs False kw lifetime name ports items) =
|
|
|
|
|
printf "%s%s %s%s%s;\n%s\nend%s"
|
|
|
|
|
(concatMap showPad attrs)
|
2019-12-22 18:01:05 +01:00
|
|
|
(show kw) (showPad lifetime) name portsStr bodyStr (show kw)
|
2019-04-04 02:24:09 +02:00
|
|
|
where
|
|
|
|
|
portsStr = if null ports
|
|
|
|
|
then ""
|
|
|
|
|
else " " ++ indentedParenList ports
|
|
|
|
|
bodyStr = indent $ unlines' $ map show items
|
2019-04-23 21:53:51 +02:00
|
|
|
show (Package lifetime name items) =
|
|
|
|
|
printf "package %s%s;\n%s\nendpackage"
|
2019-12-22 18:01:05 +01:00
|
|
|
(showPad lifetime) name bodyStr
|
2019-04-23 21:53:51 +02:00
|
|
|
where
|
|
|
|
|
bodyStr = indent $ unlines' $ map show items
|
2019-04-04 02:24:09 +02:00
|
|
|
show (PackageItem i) = show i
|
|
|
|
|
|
|
|
|
|
data PackageItem
|
2021-01-24 18:07:35 +01:00
|
|
|
= Function Lifetime Type Identifier [Decl] [Stmt]
|
2019-12-22 18:01:05 +01:00
|
|
|
| Task Lifetime Identifier [Decl] [Stmt]
|
2021-01-24 00:50:06 +01:00
|
|
|
| Import Identifier Identifier
|
|
|
|
|
| Export Identifier Identifier
|
2019-04-23 23:12:56 +02:00
|
|
|
| Decl Decl
|
2019-10-11 02:53:49 +02:00
|
|
|
| Directive String
|
2019-04-04 02:24:09 +02:00
|
|
|
deriving Eq
|
|
|
|
|
|
|
|
|
|
instance Show PackageItem where
|
|
|
|
|
show (Function ml t x i b) =
|
2020-12-11 20:41:59 +01:00
|
|
|
printf "function %s%s%s;\n%s\nendfunction" (showPad ml) (showPad t) x
|
|
|
|
|
(showBlock i b)
|
2019-04-04 02:24:09 +02:00
|
|
|
show (Task ml x i b) =
|
2020-12-11 20:41:59 +01:00
|
|
|
printf "task %s%s;\n%s\nendtask"
|
|
|
|
|
(showPad ml) x (showBlock i b)
|
2021-01-24 00:50:06 +01:00
|
|
|
show (Import x y) = printf "import %s::%s;" x (showWildcard y)
|
|
|
|
|
show (Export x y) = printf "export %s::%s;" (showWildcard x) (showWildcard y)
|
2019-04-23 23:12:56 +02:00
|
|
|
show (Decl decl) = show decl
|
2019-10-11 02:53:49 +02:00
|
|
|
show (Directive str) = str
|
2019-04-04 02:24:09 +02:00
|
|
|
|
2021-01-24 00:50:06 +01:00
|
|
|
showWildcard :: Identifier -> String
|
|
|
|
|
showWildcard "" = "*"
|
|
|
|
|
showWildcard x = x
|
|
|
|
|
|
2019-04-04 02:24:09 +02:00
|
|
|
data PartKW
|
|
|
|
|
= Module
|
|
|
|
|
| Interface
|
|
|
|
|
deriving Eq
|
|
|
|
|
|
|
|
|
|
instance Show PartKW where
|
|
|
|
|
show Module = "module"
|
|
|
|
|
show Interface = "interface"
|
|
|
|
|
|
|
|
|
|
data Lifetime
|
|
|
|
|
= Static
|
|
|
|
|
| Automatic
|
2019-12-22 18:01:05 +01:00
|
|
|
| Inherit
|
2019-04-04 02:24:09 +02:00
|
|
|
deriving (Eq, Ord)
|
|
|
|
|
|
|
|
|
|
instance Show Lifetime where
|
|
|
|
|
show Static = "static"
|
|
|
|
|
show Automatic = "automatic"
|
2019-12-22 18:01:05 +01:00
|
|
|
show Inherit = ""
|