diff options
author | Yann Herklotz Grave <git@yannherklotzgrave.com> | 2019-03-01 12:27:48 +0000 |
---|---|---|
committer | Yann Herklotz Grave <git@yannherklotzgrave.com> | 2019-03-01 12:27:48 +0000 |
commit | eca5677725a6843e5d4ffa72f2e1cca6a17177c4 (patch) | |
tree | 0578190281443cb091d73603311f25e51c556e09 /app/Main.hs | |
parent | 2735618d3104ea0943ae4b2c9a72c752b02ace51 (diff) | |
download | verismith-eca5677725a6843e5d4ffa72f2e1cca6a17177c4.tar.gz verismith-eca5677725a6843e5d4ffa72f2e1cca6a17177c4.zip |
Add option to reduce file to Main
Diffstat (limited to 'app/Main.hs')
-rw-r--r-- | app/Main.hs | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/app/Main.hs b/app/Main.hs index 664deda..3d80c86 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -25,6 +25,9 @@ data Opts = Fuzz { fuzzOutput :: Text } | Parse { fileName :: S.FilePath } + | Reduce { fileName :: S.FilePath + , top :: Text + } myForkIO :: IO () -> IO (MVar ()) myForkIO io = do @@ -94,6 +97,21 @@ parseOpts :: Parser Opts parseOpts = Parse . S.fromText . T.pack <$> strArgument (metavar "FILE" <> help "Verilog input file.") +reduceOpts :: Parser Opts +reduceOpts = + Reduce + . S.fromText + . T.pack + <$> strArgument (metavar "FILE" <> help "Verilog input file.") + <*> textOption + ( short 't' + <> long "top" + <> metavar "TOP" + <> help "Name of top level module." + <> showDefault + <> value "main" + ) + argparse :: Parser Opts argparse = hsubparser @@ -138,6 +156,17 @@ argparse = ) <> metavar "parse" ) + <|> hsubparser + ( command + "reduce" + (info + reduceOpts + (progDesc + "Reduce a Verilog file by rerunning the fuzzer on the file." + ) + ) + <> metavar "reduce" + ) opts :: ParserInfo Opts opts = info @@ -168,10 +197,18 @@ handleOpts (Parse f) = do Left l -> print l Right v -> print $ V.GenVerilog v where file = T.unpack . S.toTextIgnore $ f -handleOpts (Rerun _) = undefined +handleOpts (Rerun _ ) = undefined +handleOpts (Reduce f t) = do + verilogSrc <- readFile file + case V.parseVerilog file verilogSrc of + Left l -> print l + Right v -> do + writeFile "main.v" . T.unpack $ V.genSource (V.SourceInfo t v) + vreduced <- V.runReduce (V.SourceInfo t v) + writeFile "reduced.v" . T.unpack $ V.genSource vreduced + where file = T.unpack $ S.toTextIgnore f main :: IO () - --main = sample (arbitrary :: Gen (Circuit Input)) main = do optsparsed <- execParser opts handleOpts optsparsed |