diff options
-rw-r--r-- | src/Verismith.hs | 34 | ||||
-rw-r--r-- | verismith.cabal | 25 |
2 files changed, 32 insertions, 27 deletions
diff --git a/src/Verismith.hs b/src/Verismith.hs index 19237ae..a6375f3 100644 --- a/src/Verismith.hs +++ b/src/Verismith.hs @@ -39,7 +39,6 @@ where import Control.Concurrent import Control.Lens hiding ((<.>)) import Control.Monad.IO.Class (liftIO) -import qualified Crypto.Random.DRBG as C import Data.ByteString (ByteString) import Data.ByteString.Builder (byteStringHex, toLazyByteString) import qualified Data.ByteString.Lazy as L @@ -50,6 +49,7 @@ import Data.Text (Text) import qualified Data.Text as T import Data.Text.Encoding (decodeUtf8) import qualified Data.Text.IO as T +import Data.Word (Word8) import Hedgehog (Gen) import qualified Hedgehog.Gen as Hog import Hedgehog.Internal.Seed (Seed) @@ -58,7 +58,8 @@ import Paths_verismith (getDataDir) import Prelude hiding (FilePath) import Shelly hiding (command) import Shelly.Lifted (liftSh) -import System.Random (randomIO) +import System.Random (mkStdGen, newStdGen, randomIO, + randoms) import Verismith.Circuit import Verismith.Config import Verismith.Fuzz @@ -218,18 +219,23 @@ defaultMain = do optsparsed <- execParser opts handleOpts optsparsed --- | Generate a specific number of random bytestrings of size 256. -randomByteString :: C.CtrDRBG -> Int -> [ByteString] -> [ByteString] -randomByteString gen n bytes - | n == 0 = ranBytes : bytes - | otherwise = randomByteString newGen (n - 1) $ ranBytes : bytes - where Right (ranBytes, newGen) = C.genBytes 32 gen - -- | generates the specific number of bytestring with a random seed. -generateByteString :: Int -> IO [ByteString] -generateByteString n = do - gen <- C.newGenIO :: IO C.CtrDRBG - return $ randomByteString gen n [] +generateByteString' :: Int -> [Word8] -> (ByteString, [Word8]) +generateByteString' size words = (B.pack $ take size words, drop size words) + +generateByteString :: (Maybe Int) -> Int -> Int -> IO [ByteString] +generateByteString mseed size n = do + gen <- case mseed of + Some seed' -> return $ mkStdGen seed' + Nothing -> newStdGen + randlist <- take (size * n) <$> randoms gen + return . fmap B.pack $ chunksOf size randlist + where + chunksOf i xs | i <= 0 = error $ "chunksOf, number must be positive, got " ++ show i + chunksOf i xs = repeatedly (splitAt i) xs + repeatedly f [] = [] + repeatedly f as = b : repeatedly f as' + where (b, as') = f as makeSrcInfo :: ModDecl -> SourceInfo makeSrcInfo m = SourceInfo (getIdentifier $ m ^. modId) (Verilog [m]) @@ -256,7 +262,7 @@ runSimulation = do -- shelly $ run_ "dot" ["-Tpng", "-o", "file.png", "file.dot"] -- let circ = -- head $ (nestUpTo 30 . generateAST $ Circuit gr) ^.. getVerilog . traverse . getDescription - rand <- generateByteString 20 + rand <- generateByteString Nothing 32 20 rand2 <- Hog.sample (randomMod 10 100) val <- shelly . runResultT $ runSim defaultIcarus (makeSrcInfo rand2) rand case val of diff --git a/verismith.cabal b/verismith.cabal index 61fd087..13a3d42 100644 --- a/verismith.cabal +++ b/verismith.cabal @@ -33,7 +33,7 @@ custom-setup setup-depends: base >= 4 && <5, cabal-doctest >= 1 && <1.1, - Cabal >= 1.10 && <2.5 + Cabal >= 1.10 && <3.1 library hs-source-dirs: src @@ -75,8 +75,7 @@ library , Verismith.Verilog.Preprocess , Verismith.Verilog.Quote , Verismith.Verilog.Token - build-depends: DRBG >=0.5 && <0.6 - , array >=0.5 && <0.6 + build-depends: array >=0.5 && <0.6 , base >=4.7 && <5 , binary >= 0.8.5.1 && <0.9 , blaze-html >=0.9.0.1 && <0.10 @@ -89,23 +88,23 @@ library , filepath >=1.4.2 && <1.5 , gitrev >= 1.3.1 && <1.4 , hedgehog >=1.0 && <1.2 - , lens >=4.16.1 && <4.18 + , lens >=4.16.1 && <4.19 , lifted-base >=0.2.3 && <0.3 - , memory >=0.14 && <0.15 + , memory >=0.14 && <0.16 , monad-control >=1.0.2 && <1.1 , mtl >=2.2.2 && <2.3 - , optparse-applicative >=0.14 && <0.15 + , optparse-applicative >=0.14 && <0.16 , parsec >=3.1 && <3.2 - , prettyprinter >=1.2.0.1 && <1.3 + , prettyprinter >=1.2.0.1 && <1.4 , random >=1.1 && <1.2 , recursion-schemes >=5.0.2 && <5.2 , shakespeare >=2 && <2.1 - , shelly >=1.8.0 && <1.9 + , shelly >=1.8.0 && <1.10 , statistics >=0.14.0.2 && <0.16 - , template-haskell >=2.13.0 && <2.15 + , template-haskell >=2.13.0 && <2.16 , text >=1.2 && <1.3 - , time >= 1.8.0.2 && <1.9 - , tomland >=1.0 && <1.2 + , time >= 1.8.0.2 && <1.10 + , tomland >=1.0 && <1.3 , transformers >=0.5 && <0.6 , transformers-base >=0.4.5 && <0.5 , unordered-containers >=0.2.10 && <0.3 @@ -129,7 +128,7 @@ benchmark benchmark build-depends: base >=4 && <5 , verismith , criterion >=1.5.5 && <1.6 - , lens >=4.16.1 && <4.18 + , lens >=4.16.1 && <4.19 default-extensions: OverloadedStrings test-suite test @@ -145,7 +144,7 @@ test-suite test , verismith , fgl >=5.6 && <5.8 , hedgehog >=1.0 && <1.2 - , lens >=4.16.1 && <4.18 + , lens >=4.16.1 && <4.19 , parsec >= 3.1 && < 3.2 , shakespeare >=2 && <2.1 , tasty >=1.0.1.1 && <1.3 |