From eca5677725a6843e5d4ffa72f2e1cca6a17177c4 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Grave Date: Fri, 1 Mar 2019 12:27:48 +0000 Subject: Add option to reduce file to Main --- app/Main.hs | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'app') 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 -- cgit