aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <git@yannherklotz.com>2021-07-23 12:44:04 +0200
committerYann Herklotz <git@yannherklotz.com>2021-07-23 12:44:04 +0200
commite8cc0d0d2902ad06133f196ea23c23962ec55b0f (patch)
tree24d4e913e6f970aa58062a1c938941cece95bad2
parentaea37a788977ecc8cee811372d7f2a41b878e1e6 (diff)
downloadverismith-e8cc0d0d2902ad06133f196ea23c23962ec55b0f.tar.gz
verismith-e8cc0d0d2902ad06133f196ea23c23962ec55b0f.zip
Add command line variables
-rw-r--r--src/Verismith.hs14
-rw-r--r--src/Verismith/OptParser.hs49
-rw-r--r--src/Verismith/Shuffle.hs10
3 files changed, 71 insertions, 2 deletions
diff --git a/src/Verismith.hs b/src/Verismith.hs
index 726d6f9..53b2de6 100644
--- a/src/Verismith.hs
+++ b/src/Verismith.hs
@@ -210,6 +210,20 @@ handleOpts (Parse f t o rc) = do
where
file = T.unpack . toTextIgnore $ f
mapply i f = if i then f else id
+handleOpts (ShuffleOpt f t o nshuffle nrename) = do
+ verilogSrc <- T.readFile file
+ case parseVerilog (T.pack file) verilogSrc of
+ Left l -> print l
+ Right v -> do
+ let sv = SourceInfo t v
+ sv' <- if nshuffle then return sv else shuffleLines sv
+ sv'' <- if nrename then return sv' else renameVariables sv'
+ case ( o, GenVerilog sv'') of
+ (Nothing, a) -> print a
+ (Just o', a) -> writeFile (T.unpack $ toTextIgnore o') $ show a
+ where
+ file = T.unpack . toTextIgnore $ f
+ mapply i f = if i then f else id
handleOpts (Reduce f t _ ls' False) = do
src <- parseSourceInfoFile t (toTextIgnore f)
datadir <- getDataDir
diff --git a/src/Verismith/OptParser.hs b/src/Verismith/OptParser.hs
index a6b5fb9..64a4545 100644
--- a/src/Verismith/OptParser.hs
+++ b/src/Verismith/OptParser.hs
@@ -84,6 +84,13 @@ data Opts
{ distanceOptVerilogA :: !FilePath,
distanceOptVerilogB :: !FilePath
}
+ | ShuffleOpt
+ { shuffleOptFilename :: !FilePath,
+ shuffleOptTop :: !Text,
+ shuffleOptOutput :: !(Maybe FilePath),
+ shuffleOptShuffleLines :: !Bool,
+ shuffleOptRenameVars :: !Bool
+ }
textOption :: Mod OptionFields String -> Parser Text
textOption = fmap T.pack . Opt.strOption
@@ -301,6 +308,37 @@ parseOpts =
"Remove constants in concatenation to simplify the Verilog."
)
+shuffleOpts :: Parser Opts
+shuffleOpts =
+ ShuffleOpt
+ <$> ( fromText . T.pack
+ <$> Opt.strArgument
+ (Opt.metavar "FILE" <> Opt.help "Verilog input file.")
+ )
+ <*> textOption
+ ( Opt.short 't'
+ <> Opt.long "top"
+ <> Opt.metavar "TOP"
+ <> Opt.help "Name of top level module."
+ <> Opt.showDefault
+ <> Opt.value "top"
+ )
+ <*> ( Opt.optional
+ . Opt.strOption
+ $ Opt.long "output"
+ <> Opt.short 'o'
+ <> Opt.metavar "FILE"
+ <> Opt.help "Output file to write the parsed file to."
+ )
+ <*> ( Opt.switch $
+ Opt.long "no-shuffle-lines"
+ <> Opt.help
+ "Shuffle the lines in a Verilog file." )
+ <*> ( Opt.switch $
+ Opt.long "no-rename-vars"
+ <> Opt.help
+ "Rename the variables in a Verilog file." )
+
reduceOpts :: Parser Opts
reduceOpts =
Reduce
@@ -429,6 +467,17 @@ argparse =
)
<|> Opt.hsubparser
( Opt.command
+ "shuffle"
+ ( Opt.info
+ shuffleOpts
+ ( Opt.progDesc
+ "Shuffle a Verilog file."
+ )
+ )
+ <> Opt.metavar "shuffle"
+ )
+ <|> Opt.hsubparser
+ ( Opt.command
"config"
( Opt.info
configOpts
diff --git a/src/Verismith/Shuffle.hs b/src/Verismith/Shuffle.hs
index 4c72900..d53b18c 100644
--- a/src/Verismith/Shuffle.hs
+++ b/src/Verismith/Shuffle.hs
@@ -99,9 +99,15 @@ applyModules f s = do
ms = s^.infoSrc._Wrapped
shuffleLines, renameVariables, identityMod :: (SourceInfo a) -> Gen (SourceInfo a)
-shuffleLines = applyModules shuffleLinesModule
+shuffleLines = applyModules shuffleLinesModule
renameVariables = applyModules renameVariablesModule
-identityMod = applyModules identModule
+identityMod = applyModules identModule
+
+shuffleLinesIO :: (SourceInfo a) -> Gen (SourceInfo a)
+shuffleLinesIO = Hog.sample . shuffleLines
+
+renameVariablesIO :: (SourceInfo a) -> Gen (SourceInfo a)
+renameVariablesIO = Hog.sample . renameVariables
m' :: SourceInfo ()
m' = SourceInfo "m" [verilog|