Commit cf232677 by Zachary Snow

split up Yosys and VTR targeting

parent 3a507d5f
{-# LANGUAGE DeriveDataTypeable #-}
{- sv2v
- Author: Zachary Snow <zach@zachjs.com>
-
- Command line arguments.
-}
module Args where
import System.Console.CmdArgs
data Target = VTR | YOSYS
deriving (Show, Typeable, Data)
data Job = Job
{ target :: Target
, file :: FilePath
} deriving (Show, Typeable, Data)
defaultJob :: Job
defaultJob = Job
{ target = YOSYS &= typ "TARGET"
&= help "target sythesizer (yosys, vtr; defaults to yosys)"
, file = def &= args &= typFile
}
&= program "sv2v"
&= summary "sv2v v0.0.1, (C) Zachary Snow 2019, Tom Hawkins, 2011-2015"
&= details [ "sv2v converts SystemVerilog to Verilog."
, "More info: https://github.com/zachjs/sv2v" ]
readArgs :: IO Job
readArgs = cmdArgs defaultJob
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
module Convert (convert) where module Convert (convert) where
import Language.SystemVerilog.AST import Language.SystemVerilog.AST
import qualified Args as Args
import qualified Convert.AlwaysKW import qualified Convert.AlwaysKW
import qualified Convert.CaseKW import qualified Convert.CaseKW
...@@ -18,24 +19,29 @@ import qualified Convert.StarPort ...@@ -18,24 +19,29 @@ import qualified Convert.StarPort
type Phase = AST -> AST type Phase = AST -> AST
phases :: [Phase] phases :: Args.Target -> [Phase]
phases = phases Args.YOSYS =
[ Convert.Typedef.convert
, Convert.PackedArrayFlatten.convert
, Convert.StarPort.convert
]
phases Args.VTR =
(phases Args.YOSYS) ++
[ Convert.AlwaysKW.convert [ Convert.AlwaysKW.convert
, Convert.CaseKW.convert , Convert.CaseKW.convert
, Convert.Logic.convert , Convert.Logic.convert
, Convert.Typedef.convert
, Convert.PackedArrayFlatten.convert
, Convert.SplitPortDecl.convert , Convert.SplitPortDecl.convert
, Convert.StarPort.convert
] ]
run :: Phase run :: Args.Target -> Phase
run = foldr (.) id phases run target = foldr (.) id $ phases target
convert :: Phase convert :: Args.Target -> Phase
convert descriptions = convert target = convert'
let descriptions' = run descriptions where
in convert' :: Phase
if descriptions == descriptions' convert' descriptions =
then descriptions if descriptions == descriptions'
else convert descriptions' then descriptions
else convert' descriptions'
where descriptions' = run target descriptions
# sv2v: SystemVerilog to Verilog # sv2v: SystemVerilog to Verilog
sv2v is a tool for converting synthesizable SystemVerilog into Verilog that is sv2v is a tool for converting synthesizable SystemVerilog into Verilog that is
synthesizable by tools with more limited feature sets. This project was synthesizable by tools with more limited feature sets. This project is primarily
originally created for converting SystemVerilog into the [limited subset of focused on converting SystemVerilog into the subset of Verilog supported by
Verilog] supported by [VTR]. However, sv2v is intended to be configurable and [Yosys]. However, sv2v also has support for targeting the [limited subset of
extensible so that it can be used with new and different toolchains and as Verilog] supported by [VTR]. In the long term, we hope for sv2v to be more
Verilog keyword support evolves. configurable and extensible so that it can be used with new and different
toolchains and as Verilog support evolves.
[limited subset of Verilog]: https://vtr-verilog-to-routing.readthedocs.io/en/latest/odin/index.html#verilog-hdl-file-keyword-support
[Yosys]: http://www.clifford.at/yosys/
[limited subset of Verilog]: https://docs.verilogtorouting.org/en/latest/odin/#verilog-synthesizable-keyword-support
[VTR]: https://github.com/verilog-to-routing/vtr-verilog-to-routing [VTR]: https://github.com/verilog-to-routing/vtr-verilog-to-routing
...@@ -36,8 +38,23 @@ This creates the executable at `./bin/sv2v` ...@@ -36,8 +38,23 @@ This creates the executable at `./bin/sv2v`
## Usage ## Usage
The interface for this tool has not yet been finalized. Currently, running The interface for this tool has not yet been finalized. Currently, running `sv2v
`bin/sv2v path/to/file.sv` will output the converted file to `stdout`. path/to/file.sv` will output the converted file to `stdout`.
```
sv2v [OPTIONS] [FILE]
Common flags:
-t --target=TARGET target sythesizer (yosys, vtr; defaults to yosys)
-? --help Display help message
```
## VTR Support
sv2v can target VTR by specifying `--target=vtr` on the command line. Note that
VTR does not support `generate` blocks, and this tool is not capable of
converting those at this time.
## SystemVerilog Parser/AST ## SystemVerilog Parser/AST
......
...@@ -50,9 +50,11 @@ executable sv2v ...@@ -50,9 +50,11 @@ executable sv2v
build-depends: build-depends:
array, array,
base, base,
cmdargs,
containers, containers,
mtl mtl
other-modules: other-modules:
Args
Language.SystemVerilog Language.SystemVerilog
Language.SystemVerilog.AST Language.SystemVerilog.AST
Language.SystemVerilog.Parser Language.SystemVerilog.Parser
......
{-# LANGUAGE DeriveDataTypeable #-}
{- sv2v {- sv2v
- Author: Zachary Snow <zach@zachjs.com> - Author: Zachary Snow <zach@zachjs.com>
- -
...@@ -6,18 +7,18 @@ ...@@ -6,18 +7,18 @@
import System.IO import System.IO
import System.Exit import System.Exit
import System.Environment
import Language.SystemVerilog.Parser
import Args (readArgs, target, file)
import Convert (convert) import Convert (convert)
import Language.SystemVerilog.Parser
main :: IO () main :: IO ()
main = do main = do
[filePath] <- getArgs args <- readArgs
let filePath = file args
content <- readFile filePath content <- readFile filePath
let ast = parseFile [] filePath content let ast = parseFile [] filePath content
let res = Right (convert ast) let res = Right (convert (target args) ast)
case res of case res of
Left _ -> do Left _ -> do
--hPrint stderr err --hPrint stderr err
......
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