aboutsummaryrefslogtreecommitdiffstats
path: root/src/VeriFuzz/Config.hs
diff options
context:
space:
mode:
authorYann Herklotz <git@ymhg.org>2019-05-09 14:36:28 +0100
committerYann Herklotz <git@ymhg.org>2019-05-09 14:36:28 +0100
commit110d1392882cff9618997acad85af78017688c86 (patch)
tree5982e3d54321f89af1d1b694ed7db35fca03858a /src/VeriFuzz/Config.hs
parentfa2703bb983c2dd72fea3863980a7c589b57f0a4 (diff)
downloadverismith-110d1392882cff9618997acad85af78017688c86.tar.gz
verismith-110d1392882cff9618997acad85af78017688c86.zip
Add NFData to force evaluation of config file
Diffstat (limited to 'src/VeriFuzz/Config.hs')
-rw-r--r--src/VeriFuzz/Config.hs189
1 files changed, 55 insertions, 134 deletions
diff --git a/src/VeriFuzz/Config.hs b/src/VeriFuzz/Config.hs
index f4656ec..46cc721 100644
--- a/src/VeriFuzz/Config.hs
+++ b/src/VeriFuzz/Config.hs
@@ -70,6 +70,7 @@ module VeriFuzz.Config
, parseConfig
, encodeConfig
, encodeConfigFile
+ , versionInfo
)
where
@@ -77,9 +78,12 @@ import Control.Applicative (Alternative)
import Control.Lens hiding ((.=))
import Data.List.NonEmpty (NonEmpty (..))
import Data.Maybe (fromMaybe)
-import Data.Text (Text)
+import Data.Text (Text, pack)
import qualified Data.Text.IO as T
+import Data.Version (showVersion)
+import Development.GitRev
import Hedgehog.Internal.Seed (Seed)
+import Paths_verifuzz (version)
import Shelly (toTextIgnore)
import Toml (TomlCodec, (.=))
import qualified Toml
@@ -126,47 +130,6 @@ import VeriFuzz.Sim.Yosys
-- - <https://www.xilinx.com/products/design-tools/ise-design-suite.html ISE Design Suite>
-- - <https://www.xilinx.com/products/design-tools/ise-design-suite.html Vivado Design Suite>
-- - <http://www.clifford.at/yosys/ Yosys Open SYnthesis Suite>
---
--- === Default Configuration
---
--- >>> T.putStrLn $ encodeConfig defaultConfig
--- <BLANKLINE>
--- [probability]
--- expr.binary = 5
--- expr.concatenation = 3
--- expr.number = 1
--- expr.rangeselect = 5
--- expr.signed = 5
--- expr.string = 0
--- expr.ternary = 5
--- expr.unary = 5
--- expr.unsigned = 5
--- expr.variable = 5
--- moditem.assign = 5
--- moditem.combinational = 1
--- moditem.instantiation = 1
--- moditem.sequential = 1
--- statement.blocking = 0
--- statement.conditional = 1
--- statement.forloop = 0
--- statement.nonblocking = 3
--- <BLANKLINE>
--- [property]
--- module.depth = 2
--- module.max = 5
--- size = 20
--- statement.depth = 3
--- <BLANKLINE>
--- [[synthesiser]]
--- name = "yosys"
--- yosys.description = "yosys"
--- yosys.output = "syn_yosys.v"
--- <BLANKLINE>
--- [[synthesiser]]
--- name = "vivado"
--- vivado.description = "vivado"
--- vivado.output = "syn_vivado.v"
--- <BLANKLINE>
-- | Probability of different expressions nodes.
data ProbExpr = ProbExpr { _probExprNum :: {-# UNPACK #-} !Int
@@ -234,38 +197,36 @@ data Property = Property { _propSize :: {-# UNPACK #-} !Int
}
deriving (Eq, Show)
+data Info = Info { _infoCommit :: !Text
+ , _infoVersion :: !Text
+ }
+ deriving (Eq, Show)
+
data SimDescription = SimDescription { simName :: {-# UNPACK #-} !Text }
deriving (Eq, Show)
-data SynthDescription = SynthDescription { synthName :: {-# UNPACK #-} !Text
- , synthYosysBin :: Maybe Text
- , synthYosysDesc :: Maybe Text
- , synthYosysOutput :: Maybe Text
- , synthXstBin :: Maybe Text
- , synthXstDesc :: Maybe Text
- , synthXstOutput :: Maybe Text
- , synthVivadoBin :: Maybe Text
- , synthVivadoDesc :: Maybe Text
- , synthVivadoOutput :: Maybe Text
- , synthQuartusBin :: Maybe Text
- , synthQuartusDesc :: Maybe Text
- , synthQuartusOutput :: Maybe Text
+data SynthDescription = SynthDescription { synthName :: {-# UNPACK #-} !Text
+ , synthBin :: Maybe Text
+ , synthDesc :: Maybe Text
+ , synthOut :: Maybe Text
}
deriving (Eq, Show)
-data Config = Config { _configProbability :: {-# UNPACK #-} !Probability
+data Config = Config { _configInfo :: Info
+ , _configProbability :: {-# UNPACK #-} !Probability
, _configProperty :: {-# UNPACK #-} !Property
, _configSimulators :: [SimDescription]
, _configSynthesisers :: [SynthDescription]
}
deriving (Eq, Show)
-makeLenses ''ProbExpr
-makeLenses ''ProbModItem
-makeLenses ''ProbStatement
-makeLenses ''Probability
-makeLenses ''Property
-makeLenses ''Config
+$(makeLenses ''ProbExpr)
+$(makeLenses ''ProbModItem)
+$(makeLenses ''ProbStatement)
+$(makeLenses ''Probability)
+$(makeLenses ''Property)
+$(makeLenses ''Info)
+$(makeLenses ''Config)
defaultValue
:: (Alternative r, Applicative w)
@@ -278,18 +239,9 @@ fromXST :: XST -> SynthDescription
fromXST (XST a b c) =
SynthDescription
"xst"
- Nothing
- Nothing
- Nothing
(toTextIgnore <$> a)
(Just b)
(Just $ toTextIgnore c)
- Nothing
- Nothing
- Nothing
- Nothing
- Nothing
- Nothing
fromYosys :: Yosys -> SynthDescription
fromYosys (Yosys a b c) =
@@ -298,55 +250,29 @@ fromYosys (Yosys a b c) =
(toTextIgnore <$> a)
(Just b)
(Just $ toTextIgnore c)
- Nothing
- Nothing
- Nothing
- Nothing
- Nothing
- Nothing
- Nothing
- Nothing
- Nothing
fromVivado :: Vivado -> SynthDescription
fromVivado (Vivado a b c) =
SynthDescription
"vivado"
- Nothing
- Nothing
- Nothing
- Nothing
- Nothing
- Nothing
(toTextIgnore <$> a)
(Just b)
(Just $ toTextIgnore c)
- Nothing
- Nothing
- Nothing
fromQuartus :: Quartus -> SynthDescription
fromQuartus (Quartus a b c) =
SynthDescription
"quartus"
- Nothing
- Nothing
- Nothing
- Nothing
- Nothing
- Nothing
- Nothing
- Nothing
- Nothing
(toTextIgnore <$> a)
(Just b)
(Just $ toTextIgnore c)
defaultConfig :: Config
-defaultConfig = Config (Probability defModItem defStmnt defExpr)
- (Property 20 Nothing 3 2 5)
- []
- [fromYosys defaultYosys, fromVivado defaultVivado]
+defaultConfig = Config (Info (pack $(gitHash)) (pack $ showVersion version))
+ (Probability defModItem defStmnt defExpr)
+ (Property 20 Nothing 3 2 5)
+ []
+ [fromYosys defaultYosys, fromVivado defaultVivado]
where
defModItem =
ProbModItem 5 -- Assign
@@ -469,43 +395,28 @@ simulator = Toml.textBy pprint parseIcarus "name"
synthesiser :: TomlCodec SynthDescription
synthesiser =
SynthDescription
- <$> Toml.textBy id parseSynth "name"
+ <$> Toml.text "name"
.= synthName
- <*> Toml.dioptional (Toml.text $ twoKey "yosys" "bin")
- .= synthYosysBin
- <*> Toml.dioptional (Toml.text $ twoKey "yosys" "description")
- .= synthYosysDesc
- <*> Toml.dioptional (Toml.text $ twoKey "yosys" "output")
- .= synthYosysOutput
- <*> Toml.dioptional (Toml.text $ twoKey "xst" "bin")
- .= synthXstBin
- <*> Toml.dioptional (Toml.text $ twoKey "xst" "description")
- .= synthXstDesc
- <*> Toml.dioptional (Toml.text $ twoKey "xst" "output")
- .= synthXstOutput
- <*> Toml.dioptional (Toml.text $ twoKey "vivado" "bin")
- .= synthVivadoBin
- <*> Toml.dioptional (Toml.text $ twoKey "vivado" "description")
- .= synthVivadoDesc
- <*> Toml.dioptional (Toml.text $ twoKey "vivado" "output")
- .= synthVivadoOutput
- <*> Toml.dioptional (Toml.text $ twoKey "quartus" "bin")
- .= synthQuartusBin
- <*> Toml.dioptional (Toml.text $ twoKey "quartus" "description")
- .= synthQuartusDesc
- <*> Toml.dioptional (Toml.text $ twoKey "quartus" "output")
- .= synthQuartusOutput
- where
- parseSynth s@"yosys" = Right s
- parseSynth s@"vivado" = Right s
- parseSynth s@"quartus" = Right s
- parseSynth s@"xst" = Right s
- parseSynth s = Left $ "Could not match '" <> s <> "' with a synthesiser."
+ <*> Toml.dioptional (Toml.text "bin")
+ .= synthBin
+ <*> Toml.dioptional (Toml.text "description")
+ .= synthDesc
+ <*> Toml.dioptional (Toml.text "output")
+ .= synthOut
+
+infoCodec :: TomlCodec Info
+infoCodec = Info
+ <$> defaultValue (defaultConfig ^. configInfo . infoCommit) (Toml.text "commit")
+ .= _infoCommit
+ <*> defaultValue (defaultConfig ^. configInfo . infoVersion) (Toml.text "version")
+ .= _infoVersion
configCodec :: TomlCodec Config
configCodec =
Config
- <$> defaultValue (defaultConfig ^. configProbability)
+ <$> defaultValue (defaultConfig ^. configInfo) (Toml.table infoCodec "info")
+ .= _configInfo
+ <*> defaultValue (defaultConfig ^. configProbability)
(Toml.table probCodec "probability")
.= _configProbability
<*> defaultValue (defaultConfig ^. configProperty)
@@ -536,3 +447,13 @@ encodeConfig = Toml.encode configCodec
encodeConfigFile :: FilePath -> Config -> IO ()
encodeConfigFile f = T.writeFile f . encodeConfig
+
+versionInfo :: String
+versionInfo =
+ "VeriFuzz "
+ <> showVersion version
+ <> " ("
+ <> $(gitCommitDate)
+ <> " "
+ <> $(gitHash)
+ <> ")"