-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allows BlackBox Haskell functions to specify synthesis attributes on component instantations.
- Loading branch information
1 parent
5b65cf4
commit a8feb19
Showing
16 changed files
with
140 additions
and
25 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* New features (API): | ||
* [#1482](https://github.com/clash-lang/clash-compiler/pull/1482): Additional field with synthesis attributes added to `InstDecl` in `Clash.Netlist.Types` |
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
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
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
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
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
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
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
100 changes: 100 additions & 0 deletions
100
tests/shouldwork/SynthesisAttributes/InstDeclAnnotations.hs
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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module InstDeclAnnotations where | ||
|
||
import Clash.Annotations.Primitive (HDL (..), Primitive (..)) | ||
import Clash.Backend | ||
import Clash.Core.Var (Attr' (..)) | ||
import Clash.Netlist.Id | ||
import Clash.Netlist.Types | ||
import Clash.Prelude | ||
import Control.Monad.State | ||
import GHC.Stack | ||
import Data.List (isInfixOf) | ||
import Data.String.Interpolate (i) | ||
import Data.String.Interpolate.Util (unindent) | ||
import Data.Semigroup.Monad (getMon) | ||
import qualified Data.Text as T | ||
import qualified Data.Text.IO as T | ||
import Data.Text.Prettyprint.Doc.Extra (Doc (..)) | ||
import qualified Prelude as P | ||
import System.Environment (getArgs) | ||
|
||
|
||
myTF :: TemplateFunction | ||
myTF = TemplateFunction used valid myTemplate | ||
where | ||
used = [] | ||
valid _ = True | ||
|
||
myTemplate | ||
:: Backend s | ||
=> BlackBoxContext | ||
-> State s Doc | ||
myTemplate bbCtx = do | ||
blkName <- mkUniqueIdentifier Basic "blkName" | ||
compInst <- mkUniqueIdentifier Basic "test_inst" | ||
let | ||
compName = "TEST" | ||
attrs = | ||
[ IntegerAttr' "my_int_attr" 7 | ||
, StringAttr' "my_string_attr" "Hello World!" | ||
] | ||
getMon | ||
$ blockDecl blkName [InstDecl Comp Nothing attrs compName compInst [] [] ] | ||
|
||
|
||
myBlackBox | ||
:: Signal System Int | ||
-> Signal System Int | ||
myBlackBox _ = pure (errorX "not implemented") | ||
{-# NOINLINE myBlackBox #-} | ||
{-# ANN myBlackBox (InlinePrimitive [VHDL,Verilog,SystemVerilog] $ unindent [i| | ||
[ { "BlackBox" : | ||
{ "name" : "InstDeclAnnotations.myBlackBox", | ||
"kind" : "Declaration", | ||
"format": "Haskell", | ||
"templateFunction": "InstDeclAnnotations.myTF" | ||
} | ||
} | ||
] | ||
|]) #-} | ||
|
||
|
||
topEntity | ||
:: SystemClockResetEnable | ||
=> Signal System Int | ||
-> Signal System Int | ||
topEntity = myBlackBox | ||
|
||
|
||
--------------- Actual tests for generated HDL ------------------- | ||
assertIn :: String -> String -> IO () | ||
assertIn needle haystack | ||
| needle `isInfixOf` haystack = return () | ||
| otherwise = P.error $ P.concat [ "Expected:\n\n ", needle | ||
, "\n\nIn:\n\n", haystack ] | ||
|
||
-- VHDL test | ||
mainVHDL :: IO () | ||
mainVHDL = do | ||
[topFile] <- getArgs | ||
content <- P.readFile topFile | ||
|
||
assertIn "attribute my_int_attr : integer;" content | ||
assertIn "attribute my_int_attr of TEST : component is 7;" content | ||
|
||
assertIn "attribute my_string_attr : string;" content | ||
assertIn "attribute my_string_attr of TEST : component is \"Hello World!\";" content | ||
|
||
-- Verilog test | ||
mainVerilog :: IO () | ||
mainVerilog = do | ||
[topFile] <- getArgs | ||
content <- P.readFile topFile | ||
|
||
assertIn "(* my_int_attr = 7, my_string_attr = \"Hello World!\" *)" content | ||
|
||
-- Verilog and SystemVerilog should share annotation syntax | ||
mainSystemVerilog = mainVerilog | ||
|
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