Add file output write mode

This commit is contained in:
Zachary Yedidia 2021-06-14 15:45:24 -04:00 committed by Zachary Snow
parent c0cb401abe
commit 5eef44c8f4
2 changed files with 6 additions and 1 deletions

View File

@ -26,6 +26,7 @@ data Exclude
data Write
= Stdout
| Adjacent
| File
deriving (Show, Typeable, Data, Eq)
instance Default Write where
@ -66,7 +67,8 @@ defaultJob = Job
, verbose = nam "verbose" &= help "Retain certain conversion artifacts"
, write = nam_ "write" &= name "w" &= typ "MODE"
&= help ("How to write output; default is 'stdout'; use 'adjacent' to"
++ " create a .v file next to each input")
++ " create a .v file next to each input; use 'file' to create a"
++ " sv2v_output.v file")
}
&= program "sv2v"
&= summary ("sv2v " ++ version)

View File

@ -64,6 +64,9 @@ writeOutput _ [] [] =
hPutStrLn stderr "Warning: No input files specified (try `sv2v --help`)"
writeOutput Stdout _ asts =
hPrint stdout $ concat asts
writeOutput File _ asts =
writeFile f $ show $ concat asts
where f = "sv2v_output.v"
writeOutput Adjacent inPaths asts = do
outPaths <- mapM rewritePath inPaths
badPaths <- filterM doesFileExist outPaths