-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fdf0667
commit 14f75bb
Showing
8 changed files
with
337 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,6 +49,7 @@ library | |
base, | ||
mtl, | ||
array, | ||
lattices, | ||
hedgehog, | ||
containers, | ||
bytestring, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,59 @@ | ||
{-# LANGUAGE RecursiveDo #-} | ||
{-# LANGUAGE DataKinds #-} | ||
module Main where | ||
|
||
import Data.Bool (bool) | ||
|
||
import Clash.Prelude (Signed) | ||
|
||
import Clash.Testbench | ||
|
||
import Calculator (OPC(..)) | ||
import qualified Calculator (topEntity) | ||
|
||
import Clash.Hedgehog.Sized.Signed | ||
import Hedgehog | ||
import qualified Hedgehog.Gen as Gen | ||
import qualified Hedgehog.Range as Range | ||
|
||
genIO :: Gen [(OPC (Signed 4), Maybe (Signed 4))] | ||
genIO = do | ||
-- generate 7 constants | ||
cs <- Gen.list (Range.singleton 7) (genSigned Range.constantBounded) | ||
-- generate 6 operations | ||
ops <- map (bool (ADD, (+)) (MUL, (*))) <$> Gen.list (Range.singleton 6) Gen.bool | ||
|
||
let | ||
-- push the constants to the stack | ||
in1 = concatMap ((: [Push]) . Imm) cs -- inputs | ||
eo1 = concatMap ((: [Nothing]) . Just) cs -- expected outputs | ||
|
||
-- calculate the results of the applied operations | ||
x : xr = reverse cs | ||
rs = [ foldl (\a (op, b) -> op a b) x $ zip (map snd ops) $ take n xr | ||
| n <- [1,2..length xr] | ||
] | ||
|
||
-- apply the operations | ||
in2 = concatMap ((replicate 3 Pop <>) . pure . fst) ops -- inputs | ||
eo2 = concatMap ((replicate 3 Nothing <>) . pure . Just) rs -- expected outputs | ||
|
||
return $ zip (in1 <> in2) (eo1 <> eo2) | ||
|
||
myTestbench | ||
:: TB () | ||
myTestbench = mdo | ||
input <- fromList Pop [Imm 1, Push, Imm 2, Push, Pop, Pop, Pop, ADD] | ||
-- input <- fromList Pop [Imm 1, Push, Imm 2, Push, Pop, Pop, Pop, ADD] | ||
input <- matchIOGenN output genIO | ||
output <- ("topEntity" @@ Calculator.topEntity) auto auto auto input | ||
watch input | ||
watch output | ||
|
||
main :: IO () | ||
main = simulate 10 myTestbench | ||
main = simulate 38 myTestbench | ||
|
||
foreign export ccall "clash_ffi_main" | ||
ffiMain :: IO () | ||
|
||
ffiMain :: IO () | ||
ffiMain = simulateFFI 10 myTestbench | ||
ffiMain = simulateFFI 38 myTestbench |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
packages: . .. ../../clash-ghc ../../clash-lib ../../clash-prelude ../../clash-ffi | ||
packages: . .. ../../clash-ghc ../../clash-lib ../../clash-prelude ../../clash-ffi ../../clash-prelude-hedgehog | ||
|
||
write-ghc-environment-files: always |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.