Skip to content

Commit b411d7d

Browse files
authored
setup nix flake (poorly) (#40)
* mct * lift clash sources to root * update nix * ragequit nix * non-cabal nix works * base flake, downgrade clash 1.8.1, new ci * devShell -> devShells * retry ci * fixed fr * add clash-ghc * get ci off nix * cabal bs * remove --enable-tests * move cd * remove haskell ci
1 parent 7e6fc37 commit b411d7d

File tree

26 files changed

+356
-389
lines changed

26 files changed

+356
-389
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
2121
- name: Run Simulation
2222
run: |
23-
cd hdl/sv/moving_average_accumulator
23+
cd cores/moving_average_accumulator
2424
make test
2525
2626

cores/pipelined_order_book/README.md

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!-- omit in toc -->
2+
# Simple Nix Starter Project
3+
This starter project contains the scaffolding needed to integrate Clash with the Nix Stack build system. Read [Simple Starter Project](https://github.com/clash-lang/clash-starters/blob/main/simple/README.md) for more information on the various files.
4+
5+
<!-- omit in toc -->
6+
# Table of Contents
7+
- [Getting this project](#getting-this-project)
8+
- [Building and testing this project](#building-and-testing-this-project)
9+
- [REPL](#repl)
10+
- [Adding custom dependencies / updating nix](#adding-custom-dependencies--updating-nix)
11+
12+
# Getting this project
13+
Run `nix-shell --packages stack --run "stack new my-clash-project clash-lang/simple-nix"`.
14+
15+
# Building and testing this project
16+
Build the project with:
17+
18+
```bash
19+
nix-build
20+
```
21+
22+
Verilog code will be available under the `result/share/verilog` directory.
23+
Modify the `hdl` variable in `default.nix` to configure whether to generate
24+
SystemVerilog or VHDL.
25+
26+
However development itself is more streamlined by using a Nix shell. Start one
27+
by invoking:
28+
29+
```
30+
nix-shell
31+
```
32+
33+
Then, to run the tests defined in `tests/`:
34+
35+
```bash
36+
cabal run test-library
37+
cabal run doctests
38+
```
39+
40+
To compile the project to VHDL run:
41+
42+
```bash
43+
cabal run clash -- Example.Project --vhdl
44+
```
45+
46+
You can find the HDL files in `vhdl/`. The source can be found in `src/Example/Project.hs`.
47+
48+
# REPL
49+
Clash offers a [REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop) as a quick way to try things, similar to Python's `python` or Ruby's `irb`. Open the REPL by invoking:
50+
51+
```
52+
cabal run clashi
53+
```
54+
55+
# Adding custom dependencies / updating nix
56+
`niv` is available after opening `nix-shell`. See [niv on Hackage](https://hackage.haskell.org/package/niv) for more information.
File renamed without changes.
File renamed without changes.

hdl/haskell/src/cabal.project cores/pipelined_order_book/cabal.project

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
packages:
2-
punt-engine-haskell-cores.cabal
2+
pipelined-order-book.cabal
33

44
write-ghc-environment-files: always
55

cores/pipelined_order_book/hie.yaml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
cradle:
2+
cabal:
3+
- path: "./src"
4+
component: "lib:pipelined-order-book"
5+
- path: "./tests/doctests.hs"
6+
component: "pipelined-order-book:doctests"
7+
- path: "./tests"
8+
component: "pipelined-order-book:test-library"
9+
- path: "./bin/Clashi.hs"
10+
component: "pipelined-order-book:exe:clashi"
11+
- path: "./bin/Clash.hs"
12+
component: "pipelined-order-book:exe:clash"

hdl/haskell/src/punt-engine-haskell-cores.cabal cores/pipelined_order_book/pipelined-order-book.cabal

+10-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
cabal-version: 2.4
2-
name: punt-engine-haskell-cores
2+
name: pipelined-order-book
33
version: 0.1
4-
license: MIT
4+
license: GPL-3.0-only
55
author: Race Williams <[email protected]>
66
maintainer: Race Williams <[email protected]>
77

@@ -75,6 +75,7 @@ common common-options
7575
Cabal,
7676

7777
-- clash-prelude will set suitable version bounds for the plugins
78+
-- TODO: get to work with 1.8.2
7879
clash-prelude >= 1.8.1 && < 1.10,
7980
ghc-typelits-natnormalise,
8081
ghc-typelits-extra,
@@ -85,25 +86,20 @@ library
8586
import: common-options
8687
hs-source-dirs: src
8788
exposed-modules:
88-
FixParser.Top
8989
Example.Project
9090
default-language: Haskell2010
9191

92-
-- Builds the executable 'clash', with punt-engine-haskell-cores project in scope
92+
-- Builds the executable 'clash', with pipelined-order-book project in scope
9393
executable clash
9494
main-is: bin/Clash.hs
9595
default-language: Haskell2010
96-
Build-Depends: base, clash-ghc, punt-engine-haskell-cores
97-
if !os(Windows)
98-
ghc-options: -dynamic
96+
Build-Depends: base, clash-ghc, pipelined-order-book
9997

100-
-- Builds the executable 'clashi', with punt-engine-haskell-cores project in scope
98+
-- Builds the executable 'clashi', with pipelined-order-book project in scope
10199
executable clashi
102100
main-is: bin/Clashi.hs
103101
default-language: Haskell2010
104-
if !os(Windows)
105-
ghc-options: -dynamic
106-
build-depends: base, clash-ghc, punt-engine-haskell-cores
102+
build-depends: base, clash-ghc, pipelined-order-book
107103

108104
test-suite doctests
109105
type: exitcode-stdio-1.0
@@ -113,7 +109,7 @@ test-suite doctests
113109
hs-source-dirs: tests
114110
build-depends:
115111
base,
116-
punt-engine-haskell-cores,
112+
pipelined-order-book,
117113
doctest-parallel >= 0.2 && < 0.4,
118114

119115
test-suite test-library
@@ -126,10 +122,10 @@ test-suite test-library
126122
other-modules:
127123
Tests.Example.Project
128124
build-depends:
129-
punt-engine-haskell-cores,
125+
pipelined-order-book,
130126
QuickCheck,
131127
clash-prelude-hedgehog,
132128
hedgehog,
133-
tasty >= 1.2 && < 1.5,
129+
tasty >= 1.2 && < 1.6,
134130
tasty-hedgehog,
135131
tasty-th

hdl/haskell/src/tests/doctests.hs cores/pipelined_order_book/tests/doctests.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import System.Environment (getArgs)
44
import Test.DocTest (mainFromCabal)
55

66
main :: IO ()
7-
main = mainFromCabal "punt-engine-haskell-cores" =<< getArgs
7+
main = mainFromCabal "my-clash-project" =<< getArgs
88

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
create_clock -name {CLK} -period 20.000 -waveform {0.000 10.000} [get_ports {CLK}]
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/* AUTOMATICALLY GENERATED VERILOG-2001 SOURCE CODE.
2+
** GENERATED BY CLASH 1.8.1. DO NOT MODIFY.
3+
*/
4+
`default_nettype none
5+
`timescale 100fs/100fs
6+
module accum
7+
( // Inputs
8+
input wire CLK // clock
9+
, input wire RST // reset
10+
, input wire EN // enable
11+
, input wire [7:0] DIN
12+
13+
// Outputs
14+
, output wire [7:0] DOUT
15+
);
16+
reg [7:0] s = 8'd0;
17+
18+
// register begin
19+
always @(posedge CLK or posedge RST) begin : s_register
20+
if ( RST) begin
21+
s <= 8'd0;
22+
end else if (EN) begin
23+
s <= (s + DIN);
24+
end
25+
end
26+
// register end
27+
28+
assign DOUT = s;
29+
30+
31+
endmodule
32+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#include <cstdlib>
2+
3+
#include <verilated.h>
4+
5+
#include "Vaccum.h"
6+
7+
int main(int argc, char **argv) {
8+
Verilated::commandArgs(argc, argv);
9+
10+
Vaccum *top = new Vaccum;
11+
12+
while(!Verilated::gotFinish()) {
13+
top->eval();
14+
}
15+
16+
top->final();
17+
18+
delete top;
19+
20+
return EXIT_SUCCESS;
21+
}
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"components": [
3+
"accum"
4+
],
5+
"dependencies": {
6+
"transitive": []
7+
},
8+
"domains": {
9+
"Dom50": {
10+
"active_edge": "Rising",
11+
"init_behavior": "Defined",
12+
"period": 20000,
13+
"reset_kind": "Asynchronous",
14+
"reset_polarity": "ActiveHigh"
15+
},
16+
"IntelSystem": {
17+
"active_edge": "Rising",
18+
"init_behavior": "Defined",
19+
"period": 10000,
20+
"reset_kind": "Asynchronous",
21+
"reset_polarity": "ActiveHigh"
22+
},
23+
"System": {
24+
"active_edge": "Rising",
25+
"init_behavior": "Defined",
26+
"period": 10000,
27+
"reset_kind": "Asynchronous",
28+
"reset_polarity": "ActiveHigh"
29+
},
30+
"XilinxSystem": {
31+
"active_edge": "Rising",
32+
"init_behavior": "Defined",
33+
"period": 10000,
34+
"reset_kind": "Synchronous",
35+
"reset_polarity": "ActiveHigh"
36+
}
37+
},
38+
"files": [
39+
{
40+
"name": "accum_shim.cpp",
41+
"sha256": "5abcaca52b57ad0e884cd74d67bf57e5193b1de914e0e8855b122d6c3af5ab12"
42+
},
43+
{
44+
"name": "accum_shim.cpp",
45+
"sha256": "5abcaca52b57ad0e884cd74d67bf57e5193b1de914e0e8855b122d6c3af5ab12"
46+
},
47+
{
48+
"name": "accum.sdc",
49+
"sha256": "872a13ebab22d7d64ce0ca6c4f93a5c1622f788d8269f1451bdba354b37c57a4"
50+
},
51+
{
52+
"name": "accum.v",
53+
"sha256": "289b55da1727d5d617102d84225f8ceba9cad6b7f42542883947b4eef64be0ff"
54+
}
55+
],
56+
"flags": [
57+
20,
58+
20
59+
],
60+
"hash": "b1e53b5786e353c37f9a585beee9d29b8906b6ecbda05e5c89c9ecc4e137fc10",
61+
"top_component": {
62+
"name": "accum",
63+
"ports_flat": [
64+
{
65+
"direction": "in",
66+
"domain": "Dom50",
67+
"is_clock": true,
68+
"name": "CLK",
69+
"type_name": "",
70+
"width": 1
71+
},
72+
{
73+
"direction": "in",
74+
"domain": "Dom50",
75+
"is_clock": false,
76+
"name": "RST",
77+
"type_name": "",
78+
"width": 1
79+
},
80+
{
81+
"direction": "in",
82+
"domain": "Dom50",
83+
"is_clock": false,
84+
"name": "EN",
85+
"type_name": "",
86+
"width": 1
87+
},
88+
{
89+
"direction": "in",
90+
"is_clock": false,
91+
"name": "DIN",
92+
"type_name": "[7:0]",
93+
"width": 8
94+
},
95+
{
96+
"direction": "out",
97+
"is_clock": false,
98+
"name": "DOUT",
99+
"type_name": "[7:0]",
100+
"width": 8
101+
}
102+
]
103+
},
104+
"version": "unstable"
105+
}

flake.lock

+61
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)