mirror of https://github.com/zachjs/sv2v.git
add support for specifying compile-time defines
This commit is contained in:
parent
5351dee80a
commit
f59ed11ef5
13
README.md
13
README.md
|
|
@ -44,12 +44,13 @@ path/to/file.sv` will output the converted file to `stdout`.
|
|||
sv2v [OPTIONS] [FILES]
|
||||
|
||||
Common flags:
|
||||
-e --exclude=CONV conversion to exclude (always, interface, logic); can
|
||||
be specified multiple times
|
||||
-i --incdir=DIR add directory to include search path
|
||||
-? --help Display help message
|
||||
-V --version Print version information
|
||||
--numeric-version Print just the version number
|
||||
-e --exclude=CONV conversion to exclude (always, interface, logic);
|
||||
can be specified multiple times
|
||||
-i --incdir=DIR add directory to include search path
|
||||
-d --define=NAME[=VALUE] define value for compilation
|
||||
-? --help Display help message
|
||||
-V --version Print version information
|
||||
--numeric-version Print just the version number
|
||||
```
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ data Job = Job
|
|||
{ exclude :: [Exclude]
|
||||
, files :: [FilePath]
|
||||
, incdir :: [FilePath]
|
||||
, define :: [String]
|
||||
} deriving (Show, Typeable, Data)
|
||||
|
||||
defaultJob :: Job
|
||||
|
|
@ -29,6 +30,7 @@ defaultJob = Job
|
|||
++ "; can be specified multiple times")
|
||||
, files = def &= args &= typ "FILES"
|
||||
, incdir = def &= typDir &= help "add directory to include search path"
|
||||
, define = def &= typ "NAME[=VALUE]" &= help "define value for compilation"
|
||||
}
|
||||
&= program "sv2v"
|
||||
&= summary "sv2v v0.0.1, (C) Zachary Snow 2019, Tom Hawkins, 2011-2015"
|
||||
|
|
|
|||
12
src/sv2v.hs
12
src/sv2v.hs
|
|
@ -7,16 +7,24 @@
|
|||
import System.IO
|
||||
import System.Exit
|
||||
|
||||
import Job (readJob, files, exclude, incdir)
|
||||
import Data.List (elemIndex)
|
||||
import Job (readJob, files, exclude, incdir, define)
|
||||
import Convert (convert)
|
||||
import Language.SystemVerilog.Parser
|
||||
|
||||
splitDefine :: String -> (String, String)
|
||||
splitDefine str =
|
||||
case elemIndex '=' str of
|
||||
Nothing -> (str, "")
|
||||
Just idx -> (take idx str, drop (idx + 1) str)
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
job <- readJob
|
||||
-- parse the input file
|
||||
let includePaths = incdir job
|
||||
asts <- mapM (parseFile includePaths []) (files job)
|
||||
let defines = map splitDefine $ define job
|
||||
asts <- mapM (parseFile includePaths defines) (files job)
|
||||
let ast = concat asts
|
||||
-- convert the file
|
||||
let ast' = convert (exclude job) ast
|
||||
|
|
|
|||
Loading…
Reference in New Issue