mirror of https://github.com/zachjs/sv2v.git
updated CLI (backwards compatible)
This commit is contained in:
parent
2a51d20f11
commit
c0e38f793d
19
README.md
19
README.md
|
|
@ -67,15 +67,18 @@ Below is the current usage printout. This interface is subject to change.
|
|||
```
|
||||
sv2v [OPTIONS] [FILES]
|
||||
|
||||
Common flags:
|
||||
-e --exclude=CONV exclude a particular conversion (always,
|
||||
Preprocessing:
|
||||
-I --incdir=DIR Add directory to include search path
|
||||
-D --define=NAME[=VALUE] Define a macro for preprocessing
|
||||
--siloed Lex input files separately, so macros from
|
||||
earlier files are not defined in later files
|
||||
Conversion:
|
||||
-E --exclude=CONV Exclude a particular conversion (always,
|
||||
interface, or logic)
|
||||
-i --incdir=DIR add directory to include search path
|
||||
-d --define=NAME[=VALUE] define a macro for preprocessing
|
||||
-o --oneunit put all files in one compilation unit, so macros
|
||||
from earlier files remain defined in later files
|
||||
-? --help Display help message
|
||||
-V --version Print version information
|
||||
-v --verbose Retain certain conversion artifacts
|
||||
Other:
|
||||
--help Display help message
|
||||
--version Print version information
|
||||
--numeric-version Print just the version number
|
||||
```
|
||||
|
||||
|
|
|
|||
78
src/Job.hs
78
src/Job.hs
|
|
@ -7,7 +7,9 @@
|
|||
|
||||
module Job where
|
||||
|
||||
import System.IO (stderr, hPutStr)
|
||||
import System.Console.CmdArgs
|
||||
import System.Environment (getArgs, withArgs)
|
||||
|
||||
data Exclude
|
||||
= Always
|
||||
|
|
@ -17,34 +19,84 @@ data Exclude
|
|||
deriving (Show, Typeable, Data, Eq)
|
||||
|
||||
data Job = Job
|
||||
{ exclude :: [Exclude]
|
||||
, files :: [FilePath]
|
||||
{ files :: [FilePath]
|
||||
, incdir :: [FilePath]
|
||||
, define :: [String]
|
||||
, oneunit :: Bool
|
||||
, siloed :: Bool
|
||||
, exclude :: [Exclude]
|
||||
, verbose :: Bool
|
||||
} deriving (Show, Typeable, Data)
|
||||
|
||||
defaultJob :: Job
|
||||
defaultJob = Job
|
||||
{ exclude = [] &= typ "CONV"
|
||||
&= help "exclude a particular conversion (always, interface, or logic)"
|
||||
, files = def &= args &= typ "FILES"
|
||||
, incdir = def &= typDir &= help "add directory to include search path"
|
||||
, define = def &= typ "NAME[=VALUE]" &= help ("define a macro for"
|
||||
++ " preprocessing")
|
||||
, oneunit = False &= help ("put all files in one compilation unit, so"
|
||||
++ " macros from earlier files remain defined in later files")
|
||||
, verbose = False &= help "retain certain conversion artifacts"
|
||||
{ files = def &= args &= typ "FILES"
|
||||
, incdir = nam_ "I" &= name "incdir" &= typDir
|
||||
&= help "Add directory to include search path"
|
||||
&= groupname "Preprocessing"
|
||||
, define = nam_ "D" &= name "define" &= typ "NAME[=VALUE]"
|
||||
&= help "Define a macro for preprocessing"
|
||||
, siloed = nam_ "siloed" &= help ("Lex input files separately, so"
|
||||
++ " macros from earlier files are not defined in later files")
|
||||
, exclude = nam_ "exclude" &= name "E" &= typ "CONV"
|
||||
&= help "Exclude a particular conversion (always, interface, or logic)"
|
||||
&= groupname "Conversion"
|
||||
, verbose = nam "verbose" &= help "Retain certain conversion artifacts"
|
||||
}
|
||||
&= program "sv2v"
|
||||
&= summary "sv2v v0.0.1, (C) 2019 Zachary Snow, 2011-2015 Tom Hawkins"
|
||||
&= details [ "sv2v converts SystemVerilog to Verilog."
|
||||
, "More info: https://github.com/zachjs/sv2v" ]
|
||||
&= helpArg [explicit, name "help", groupname "Other"]
|
||||
&= versionArg [explicit, name "version"]
|
||||
&= verbosityArgs [ignore] [ignore]
|
||||
where
|
||||
-- borrowed from: https://github.com/ndmitchell/hlint
|
||||
nam xs = nam_ xs &= name [head xs]
|
||||
nam_ xs = def &= name xs &= explicit
|
||||
|
||||
type DeprecationPhase = [String] -> IO [String]
|
||||
|
||||
oneunit :: DeprecationPhase
|
||||
oneunit strs = do
|
||||
let strs' = filter (not . isOneunitArg) strs
|
||||
if strs == strs'
|
||||
then return strs
|
||||
else do
|
||||
hPutStr stderr $ "Deprecation warning: --oneunit has been removed, "
|
||||
++ "and is now on by default\n"
|
||||
return strs'
|
||||
where
|
||||
isOneunitArg :: String -> Bool
|
||||
isOneunitArg "-o" = True
|
||||
isOneunitArg "--oneunit" = True
|
||||
isOneunitArg _ = False
|
||||
|
||||
flagRename :: String -> String -> DeprecationPhase
|
||||
flagRename before after strs = do
|
||||
let strs' = map rename strs
|
||||
if strs == strs'
|
||||
then return strs
|
||||
else do
|
||||
hPutStr stderr $ "Deprecation warning: " ++ before ++
|
||||
" has been renamed to " ++ after ++ "\n"
|
||||
return strs'
|
||||
where
|
||||
rename :: String -> String
|
||||
rename arg =
|
||||
if before == take (length before) arg
|
||||
then after ++ drop (length before) arg
|
||||
else arg
|
||||
|
||||
readJob :: IO Job
|
||||
readJob = do
|
||||
job <- cmdArgs defaultJob
|
||||
strs <- getArgs
|
||||
strs' <- oneunit strs
|
||||
>>= flagRename "-i" "-I"
|
||||
>>= flagRename "-d" "-D"
|
||||
>>= flagRename "-e" "-E"
|
||||
>>= flagRename "-V" "--version"
|
||||
>>= flagRename "-?" "--help"
|
||||
job <- withArgs (strs') $ cmdArgs defaultJob
|
||||
return $ if verbose job
|
||||
then job { exclude = Succinct : exclude job }
|
||||
else job
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import System.IO
|
|||
import System.Exit
|
||||
|
||||
import Data.List (elemIndex)
|
||||
import Job (readJob, files, exclude, incdir, define, oneunit)
|
||||
import Job (readJob, files, exclude, incdir, define, siloed)
|
||||
import Convert (convert)
|
||||
import Language.SystemVerilog.Parser (parseFiles)
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ main = do
|
|||
let includePaths = incdir job
|
||||
let defines = map splitDefine $ define job
|
||||
let singleton = \x -> [x]
|
||||
let toFileLists = if oneunit job then singleton else map singleton
|
||||
let toFileLists = if siloed job then map singleton else singleton
|
||||
astLists <- mapM
|
||||
(parseFiles includePaths defines)
|
||||
(toFileLists $ files job)
|
||||
|
|
|
|||
Loading…
Reference in New Issue