From 6c027c162bedad467bd0259d4a296dcbeff6d8aa Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Tue, 18 May 2021 19:16:41 +0100 Subject: Add top-level argument interface for EMI --- src/Verismith.hs | 8 ++++- src/Verismith/EMI.hs | 18 ++++++++++++ src/Verismith/OptParser.hs | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 1 deletion(-) diff --git a/src/Verismith.hs b/src/Verismith.hs index c329678..3d4f54b 100644 --- a/src/Verismith.hs +++ b/src/Verismith.hs @@ -101,7 +101,7 @@ randDelete i = do return $ if r then i else 0 randomise :: Config -> IO Config -randomise config@(Config a _ c d e) = do +randomise config@(Config emi a _ c d e) = do mia <- return $ cm ^. probModItemAssign misa <- return $ cm ^. probModItemSeqAlways mica <- return $ cm ^. probModItemCombAlways @@ -124,6 +124,7 @@ randomise config@(Config a _ c d e) = do eus <- randDelete $ ce ^. probExprUnsigned return $ Config + emi a ( Probability (ProbModItem mia misa mica mii) @@ -163,6 +164,11 @@ handleOpts (Fuzz o configF f k n nosim noequiv noreduction file top cc checker) defaultYosys (fuzzMultiple gen) return () +handleOpts (EMIOpts o configF f k n nosim noequiv noreduction) = do + config <- getConfig configF + datadir <- getDataDir + putStrLn "Starting EMI testing..." + return () handleOpts (Generate f c) = do config <- getConfig c source <- proceduralIO "top" config :: IO (Verilog ()) diff --git a/src/Verismith/EMI.hs b/src/Verismith/EMI.hs index 6891eda..555e371 100644 --- a/src/Verismith/EMI.hs +++ b/src/Verismith/EMI.hs @@ -97,3 +97,21 @@ proceduralEMI moddecl config = do proceduralEMIIO :: ModDecl () -> Config -> IO (ModDecl ()) proceduralEMIIO t = Hog.sample . proceduralEMI t + +-- m = (head . head $ [verilog| +-- module m; +-- always @(posedge clk) begin +-- if (z == 2) begin +-- ry = 2; +-- end +-- x <= y; +-- y <= z; +-- end +-- endmodule +-- |] ^.. _Wrapped ) +-- p :: Show a => ModDecl a -> IO () +-- p = T.putStrLn . genSource +-- +-- customConfig = defaultConfig & +-- (configEMI . confEMIGenerateProb .~ 1) +-- . (configEMI . confEMINoGenerateProb .~ 0) diff --git a/src/Verismith/OptParser.hs b/src/Verismith/OptParser.hs index c2b31fe..1692985 100644 --- a/src/Verismith/OptParser.hs +++ b/src/Verismith/OptParser.hs @@ -46,6 +46,16 @@ data Opts fuzzCrossCheck :: !Bool, fuzzChecker :: !(Maybe Text) } + | EMIOpts + { emiOutput :: Text, + emiConfigFile :: !(Maybe FilePath), + emiForced :: !Bool, + emiKeepAll :: !Bool, + emiNum :: {-# UNPACK #-} !Int, + emiNoSim :: !Bool, + emiNoEquiv :: !Bool, + emiNoReduction :: !Bool + } | Generate { generateFilename :: !(Maybe FilePath), generateConfigFile :: !(Maybe FilePath) @@ -182,6 +192,58 @@ fuzzOpts = <> Opt.help "Define the checker to use." ) +emiOpts :: Parser Opts +emiOpts = + EMIOpts + <$> textOption + ( Opt.long "output" + <> Opt.short 'o' + <> Opt.metavar "DIR" + <> Opt.help "Output directory that the fuzz run takes place in." + <> Opt.showDefault + <> Opt.value "output" + ) + <*> ( Opt.optional + . Opt.strOption + $ Opt.long "config" + <> Opt.short 'c' + <> Opt.metavar "FILE" + <> Opt.help "Config file for the current fuzz run." + ) + <*> ( Opt.switch $ + Opt.long "force" <> Opt.short 'f' + <> Opt.help + "Overwrite the specified directory." + ) + <*> ( Opt.switch $ + Opt.long "keep" <> Opt.short 'k' + <> Opt.help + "Keep all the directories." + ) + <*> ( Opt.option Opt.auto $ + Opt.long "num" + <> Opt.short 'n' + <> Opt.help "The number of fuzz runs that should be performed." + <> Opt.showDefault + <> Opt.value 1 + <> Opt.metavar "INT" + ) + <*> ( Opt.switch $ + Opt.long "no-sim" + <> Opt.help + "Do not run simulation on the output netlist." + ) + <*> ( Opt.switch $ + Opt.long "no-equiv" + <> Opt.help + "Do not run an equivalence check on the output netlist." + ) + <*> ( Opt.switch $ + Opt.long "no-reduction" + <> Opt.help + "Do not run reduction on a failed testcase." + ) + genOpts :: Parser Opts genOpts = Generate @@ -312,6 +374,17 @@ argparse = ) <> Opt.metavar "fuzz" ) + <|> Opt.hsubparser + ( Opt.command + "emi" + ( Opt.info + emiOpts + ( Opt.progDesc + "EMI testing using generated inputs, or existing Verilog designs." + ) + ) + <> Opt.metavar "emi" + ) <|> Opt.hsubparser ( Opt.command "generate" -- cgit