blob: 67f642c8c52c463bec41c74aa9e009928187a990 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
module Unit (unitTests) where
import Control.Lens
import qualified Data.Graph.Inductive as G
import Data.Text (Text)
import qualified Data.Text as T
import Test.Tasty
import Test.Tasty.HUnit
import Test.VeriFuzz
unitTests = testGroup "Unit tests"
[ testCase "Transformation of AST" $
assertEqual "Successful transformation" transformExpectedResult
(transformOf traverseExpr trans transformTestData)
]
primExpr :: Text -> Expression
primExpr = PrimExpr . PrimId . Identifier
transformTestData :: Expression
transformTestData = OpExpr (OpExpr (OpExpr (primExpr "id1") BinAnd (primExpr "id2")) BinAnd
(OpExpr (primExpr "id1") BinAnd (primExpr "id2"))) BinAnd
(OpExpr (OpExpr (primExpr "id1") BinAnd (primExpr "id2")) BinAnd
(OpExpr (primExpr "id1") BinAnd (OpExpr (OpExpr (primExpr "id1") BinAnd (primExpr "id2")) BinAnd
(OpExpr (primExpr "id1") BinAnd (primExpr "id2")))))
transformExpectedResult :: Expression
transformExpectedResult = OpExpr (OpExpr (OpExpr (primExpr "id1") BinAnd (primExpr "Replaced")) BinAnd
(OpExpr (primExpr "id1") BinAnd (primExpr "Replaced"))) BinAnd
(OpExpr (OpExpr (primExpr "id1") BinAnd (primExpr "Replaced")) BinAnd
(OpExpr (primExpr "id1") BinAnd (OpExpr (OpExpr (primExpr "id1") BinAnd
(primExpr "Replaced")) BinAnd
(OpExpr (primExpr "id1") BinAnd (primExpr "Replaced")))))
trans e =
case e of
PrimExpr (PrimId id) -> if id == Identifier "id2" then
PrimExpr . PrimId $ Identifier "Replaced"
else PrimExpr (PrimId id)
_ -> e
runMain = do
gr <- genRandomDAG 100 :: IO (G.Gr Gate ())
-- _ <- runGraphviz (graphToDot quickParams $ emap (const "") gr) Png "output.png",
-- T.putStrLn $ generate gr
--g <- QC.generate (QC.arbitrary :: QC.Gen VerilogSrc)
let x = generateAST $ Circuit gr
let y = head . reverse $ x ^.. getVerilogSrc . traverse . getDescription . moduleItems . traverse . _ModCA . contAssignExpr
print $ transformOf traverseExpr trans y
|