mirror of https://github.com/zachjs/sv2v.git
cleaned up command line args module a bit
This commit is contained in:
parent
7bc81ef67b
commit
945923b3fd
|
|
@ -7,7 +7,7 @@
|
|||
module Convert (convert) where
|
||||
|
||||
import Language.SystemVerilog.AST
|
||||
import qualified Args as Args
|
||||
import Job (Target(..))
|
||||
|
||||
import qualified Convert.AlwaysKW
|
||||
import qualified Convert.CaseKW
|
||||
|
|
@ -19,24 +19,24 @@ import qualified Convert.StarPort
|
|||
|
||||
type Phase = AST -> AST
|
||||
|
||||
phases :: Args.Target -> [Phase]
|
||||
phases Args.YOSYS =
|
||||
phases :: Target -> [Phase]
|
||||
phases YOSYS =
|
||||
[ Convert.Typedef.convert
|
||||
, Convert.PackedArray.convert
|
||||
, Convert.StarPort.convert
|
||||
]
|
||||
phases Args.VTR =
|
||||
(phases Args.YOSYS) ++
|
||||
phases VTR =
|
||||
(phases YOSYS) ++
|
||||
[ Convert.AlwaysKW.convert
|
||||
, Convert.CaseKW.convert
|
||||
, Convert.Logic.convert
|
||||
, Convert.SplitPortDecl.convert
|
||||
]
|
||||
|
||||
run :: Args.Target -> Phase
|
||||
run :: Target -> Phase
|
||||
run target = foldr (.) id $ phases target
|
||||
|
||||
convert :: Args.Target -> Phase
|
||||
convert :: Target -> Phase
|
||||
convert target = convert'
|
||||
where
|
||||
convert' :: Phase
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
- Command line arguments.
|
||||
-}
|
||||
|
||||
module Args where
|
||||
module Job where
|
||||
|
||||
import System.Console.CmdArgs
|
||||
|
||||
|
|
@ -28,5 +28,5 @@ defaultJob = Job
|
|||
&= details [ "sv2v converts SystemVerilog to Verilog."
|
||||
, "More info: https://github.com/zachjs/sv2v" ]
|
||||
|
||||
readArgs :: IO Job
|
||||
readArgs = cmdArgs defaultJob
|
||||
readJob :: IO Job
|
||||
readJob = cmdArgs defaultJob
|
||||
21
src/sv2v.hs
21
src/sv2v.hs
|
|
@ -1,4 +1,3 @@
|
|||
{-# LANGUAGE DeriveDataTypeable #-}
|
||||
{- sv2v
|
||||
- Author: Zachary Snow <zach@zachjs.com>
|
||||
-
|
||||
|
|
@ -8,21 +7,19 @@
|
|||
import System.IO
|
||||
import System.Exit
|
||||
|
||||
import Args (readArgs, target, file)
|
||||
import Job (readJob, file, target)
|
||||
import Convert (convert)
|
||||
import Language.SystemVerilog.Parser
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
args <- readArgs
|
||||
let filePath = file args
|
||||
job <- readJob
|
||||
-- parse the input file
|
||||
let filePath = file job
|
||||
content <- readFile filePath
|
||||
let ast = parseFile [] filePath content
|
||||
let res = Right (convert (target args) ast)
|
||||
case res of
|
||||
Left _ -> do
|
||||
--hPrint stderr err
|
||||
exitFailure
|
||||
Right str -> do
|
||||
hPrint stdout str
|
||||
exitSuccess
|
||||
-- convert the file
|
||||
let ast' = convert (target job) ast
|
||||
-- print the converted file out
|
||||
hPrint stdout ast'
|
||||
exitSuccess
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ executable sv2v
|
|||
Convert.Typedef
|
||||
Convert.Traverse
|
||||
-- sv2v CLI modules
|
||||
Args
|
||||
Job
|
||||
ghc-options:
|
||||
-O3
|
||||
-threaded
|
||||
|
|
|
|||
Loading…
Reference in New Issue