-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from clash-lang/small-fixes
Replace topEntity and enable extra extensions
- Loading branch information
Showing
13 changed files
with
298 additions
and
89 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 |
---|---|---|
@@ -1,12 +1,27 @@ | ||
# Stack Templates | ||
Templates for `stack new` command. If you wish to alter a template, edit them in `projects/` and run `./render.hs`. To instantiate one the projects: | ||
|
||
Templates for `stack new` command. To use this template perform the following steps: | ||
1. [Install Stack](https://docs.haskellstack.org/en/stable/README/#how-to-install) | ||
2. Run `stack new my-clash-project clash-lang/simple`. Replace `simple` by the template you'd like to use. | ||
3. Read `my-clash-project/README.md`. Enjoy! | ||
|
||
## Cabal users | ||
All starter projects are also available on [clash-lang/clash-starters](https://github.com/clash-lang/clash-starters). | ||
|
||
## Contributing | ||
If you wish to contribute to this template, edit them in `projects/` and perform the following steps to test the template: | ||
1. Edit the template | ||
2. Run `./render.hs` to instantiate them. | ||
3. Go to the parent directory: `cd ..` and instantiate the template using the rendered `.hsfiles`. | ||
``` | ||
cd .. | ||
stack new my-template stack-templates/simple.hsfiles | ||
``` | ||
4. Use the template: | ||
``` | ||
cd my-template | ||
cabal build | ||
cabal test | ||
``` | ||
|
||
## License | ||
The default license for each of the starter project is BSD2. However, this whole repository -including every starter project- is licensed under CC0. That means the authors, to the extent possible under law, have waived all copyright and related or neighboring rights to this "Clash Example Project". Feel free to choose any license for the starter projects that you want. |
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 was deleted.
Oops, something went wrong.
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 @@ | ||
../simple/stack.yaml |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,54 @@ | ||
module Example.Project (topEntity, plus) where | ||
-- @createDomain@ below generates a warning about orphan instances, but we like | ||
-- our code to be warning-free. | ||
{-# OPTIONS_GHC -Wno-orphans #-} | ||
|
||
module Example.Project where | ||
|
||
import Clash.Prelude | ||
|
||
-- | Add two numbers. Example: | ||
-- Create a domain with the frequency of your input clock. For this example we used | ||
-- 50 MHz. | ||
createDomain vSystem{vName="Dom50", vPeriod=hzToPeriod 50e6} | ||
|
||
-- | @topEntity@ is Clash@s equivalent of @main@ in other programming languages. | ||
-- Clash will look for it when compiling "Example.Project" and translate it to | ||
-- HDL. While polymorphism can be used freely in Clash projects, a @topEntity@ | ||
-- must be monomorphic and must use non- recursive types. Or, to put it | ||
-- hand-wavily, a @topEntity@ must be translatable to a static number of wires. | ||
-- | ||
-- >>> plus 3 5 | ||
-- 8 | ||
plus :: Signed 8 -> Signed 8 -> Signed 8 | ||
plus a b = a + b | ||
-- Top entities must be monomorphic, meaning we have to specify all type variables. | ||
-- In this case, we are using the @Dom50@ domain, which we created with @createDomain@ | ||
-- and we are using 8-bit unsigned numbers. | ||
topEntity :: | ||
Clock Dom50 -> | ||
Reset Dom50 -> | ||
Enable Dom50 -> | ||
Signal Dom50 (Unsigned 8) -> | ||
Signal Dom50 (Unsigned 8) | ||
topEntity = exposeClockResetEnable accum | ||
|
||
-- To specify the names of the ports of our top entity, we create a @Synthesize@ annotation. | ||
{-# ANN topEntity | ||
(Synthesize | ||
{ t_name = "accum" | ||
, t_inputs = [ PortName "CLK" | ||
, PortName "RST" | ||
, PortName "EN" | ||
, PortName "DIN" | ||
] | ||
, t_output = PortName "DOUT" | ||
}) #-} | ||
|
||
-- Make sure GHC does not apply any optimizations to the boundaries of the design. | ||
-- For GHC versions 9.2 or older, use: {-# NOINLINE topEntity #-} | ||
{-# OPAQUE topEntity #-} | ||
|
||
-- | 'topEntity' is Clash's equivalent of 'main' in other programming | ||
-- languages. Clash will look for it when compiling 'Example.Project' | ||
-- and translate it to HDL. While polymorphism can be used freely in | ||
-- Clash projects, a 'topEntity' must be monomorphic and must use non- | ||
-- recursive types. Or, to put it hand-wavily, a 'topEntity' must be | ||
-- translatable to a static number of wires. | ||
topEntity :: Signed 8 -> Signed 8 -> Signed 8 | ||
topEntity = plus | ||
-- | A simple accumulator that works on unsigned numbers of any size. | ||
-- It has hidden clock, reset, and enable signals. | ||
accum :: | ||
(HiddenClockResetEnable dom, KnownNat n) => | ||
Signal dom (Unsigned n) -> | ||
Signal dom (Unsigned n) | ||
accum = mealy accumT 0 | ||
where | ||
accumT s i = (s + i, s) |
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
Oops, something went wrong.