From 928a54419aeac611555b3c15493db00010cbb46e Mon Sep 17 00:00:00 2001 From: Yann Herklotz Grave Date: Sun, 17 Feb 2019 12:37:46 +0000 Subject: Indent by 4 --- app/Main.hs | 158 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 85 insertions(+), 73 deletions(-) (limited to 'app') diff --git a/app/Main.hs b/app/Main.hs index 1249c41..de6af9a 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -28,121 +28,133 @@ data Opts = Fuzz { fuzzOutput :: Text myForkIO :: IO () -> IO (MVar ()) myForkIO io = do - mvar <- newEmptyMVar - _ <- forkFinally io (\_ -> putMVar mvar ()) - return mvar + mvar <- newEmptyMVar + _ <- forkFinally io (\_ -> putMVar mvar ()) + return mvar textOption :: Mod OptionFields String -> Parser Text textOption = fmap T.pack . strOption optReader :: (String -> Maybe a) -> ReadM a -optReader f = eitherReader $ \arg -> - case f arg of +optReader f = eitherReader $ \arg -> case f arg of Just a -> Right a Nothing -> Left $ "Cannot parse option: " <> arg parseSynth :: String -> Maybe Tool -parseSynth val - | val == "yosys" = Just Yosys - | val == "xst"= Just XST - | otherwise = Nothing +parseSynth val | val == "yosys" = Just Yosys + | val == "xst" = Just XST + | otherwise = Nothing parseSim :: String -> Maybe Tool -parseSim val - | val == "icarus" = Just Icarus - | otherwise = Nothing +parseSim val | val == "icarus" = Just Icarus + | otherwise = Nothing fuzzOpts :: Parser Opts -fuzzOpts = Fuzz - <$> textOption - ( long "output" +fuzzOpts = Fuzz <$> textOption + ( long "output" <> short 'o' <> metavar "DIR" <> help "Output directory that the fuzz run takes place in." <> showDefault <> value "output" - ) + ) rerunOpts :: Parser Opts -rerunOpts = Rerun - <$> ( option (optReader parseSynth) - ( long "synth" - <> metavar "SYNTH" - <> help "Rerun using a synthesiser (yosys|xst)." - <> showDefault - <> value Yosys - ) - <|> option (optReader parseSim) - ( long "sim" - <> metavar "SIM" - <> help "Rerun using a simulator (icarus)." - <> showDefault - <> value Icarus - ) - ) +rerunOpts = + Rerun + <$> ( option + (optReader parseSynth) + ( long "synth" + <> metavar "SYNTH" + <> help "Rerun using a synthesiser (yosys|xst)." + <> showDefault + <> value Yosys + ) + <|> option + (optReader parseSim) + ( long "sim" + <> metavar "SIM" + <> help "Rerun using a simulator (icarus)." + <> showDefault + <> value Icarus + ) + ) genOpts :: Parser Opts genOpts = Generate . S.fromText <$> textOption - ( long "output" + ( long "output" <> short 'o' <> metavar "FILE" <> help "Verilog output file." <> showDefault <> value "main.v" - ) + ) parseOpts :: Parser Opts -parseOpts = Parse . S.fromText . T.pack <$> strArgument - ( metavar "FILE" - <> help "Verilog input file." - ) +parseOpts = + Parse . S.fromText . T.pack <$> strArgument (metavar "FILE" <> help "Verilog input file.") argparse :: Parser Opts argparse = - hsubparser (command "fuzz" - (info fuzzOpts - (progDesc "Run fuzzing on the specified simulators and synthesisers.")) - <> metavar "fuzz") - <|> hsubparser (command "rerun" - (info rerunOpts - (progDesc "Rerun a Verilog file with a simulator or a synthesiser.")) - <> metavar "rerun") - <|> hsubparser (command "generate" - (info genOpts - (progDesc "Generate a random Verilog program.")) - <> metavar "generate") - <|> hsubparser (command "parse" - (info parseOpts - (progDesc "Parse a verilog file and output a pretty printed version.")) - <> metavar "parse") + hsubparser + ( command + "fuzz" + (info fuzzOpts + (progDesc "Run fuzzing on the specified simulators and synthesisers.") + ) + <> metavar "fuzz" + ) + <|> hsubparser + ( command + "rerun" + (info + rerunOpts + (progDesc "Rerun a Verilog file with a simulator or a synthesiser.") + ) + <> metavar "rerun" + ) + <|> hsubparser + ( command "generate" (info genOpts (progDesc "Generate a random Verilog program.")) + <> metavar "generate" + ) + <|> hsubparser + ( command + "parse" + (info + parseOpts + (progDesc "Parse a verilog file and output a pretty printed version.") + ) + <> metavar "parse" + ) opts :: ParserInfo Opts -opts = info (argparse <**> helper) - ( fullDesc - <> progDesc "Fuzz different simulators and synthesisers." - <> header "VeriFuzz - A hardware simulator and synthesiser Verilog fuzzer." ) +opts = info + (argparse <**> helper) + (fullDesc <> progDesc "Fuzz different simulators and synthesisers." <> header + "VeriFuzz - A hardware simulator and synthesiser Verilog fuzzer." + ) handleOpts :: Opts -> IO () handleOpts (Fuzz _) = do - num <- getNumCapabilities - vars <- sequence $ (\x -> myForkIO $ - V.runEquivalence (V.randomMod 10 100) - ("test_" <> T.pack (show x)) 0) <$> [1..num] - sequence_ $ takeMVar <$> vars + num <- getNumCapabilities + vars <- + sequence + $ (\x -> myForkIO $ V.runEquivalence (V.randomMod 10 100) ("test_" <> T.pack (show x)) 0) + <$> [1 .. num] + sequence_ $ takeMVar <$> vars handleOpts (Generate f) = do - g <- QC.generate $ V.randomMod 50 1000 - S.shelly . S.writefile f $ V.genSource g + g <- QC.generate $ V.randomMod 50 1000 + S.shelly . S.writefile f $ V.genSource g handleOpts (Parse f) = do - verilogSrc <- readFile file - case V.parseVerilog file verilogSrc of - Left l -> print l - Right v -> print $ V.GenVerilog v - where - file = T.unpack . S.toTextIgnore $ f + verilogSrc <- readFile file + case V.parseVerilog file verilogSrc of + Left l -> print l + Right v -> print $ V.GenVerilog v + where file = T.unpack . S.toTextIgnore $ f handleOpts (Rerun _) = undefined main :: IO () --main = sample (arbitrary :: Gen (Circuit Input)) main = do - optsparsed <- execParser opts - handleOpts optsparsed + optsparsed <- execParser opts + handleOpts optsparsed -- cgit