Skip to content

Commit

Permalink
Added HDL generation test
Browse files Browse the repository at this point in the history
Tests the bare minimum: whether HDL can be generated using Clash
  • Loading branch information
martijnbastiaan committed Mar 7, 2024
1 parent 58568da commit 088bf7d
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 40 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,7 @@ jobs:
- name: Run `clash-vexriscv-sim` unittests
run: |
cabal run clash-vexriscv-sim:unittests
- name: Run `clash-vexriscv-sim` HDL test
run: |
cabal run clash-vexriscv-sim:hdl-test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,6 @@ tight_setup_hold_pins.txt

# Verilator debug output
simulation_dump.vcd

# Clash output
verilog
10 changes: 0 additions & 10 deletions clash-vexriscv-sim/app/Clash.hs

This file was deleted.

22 changes: 4 additions & 18 deletions clash-vexriscv-sim/app/HdlTest.hs
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
-- SPDX-FileCopyrightText: 2023 Google LLC
-- SPDX-FileCopyrightText: 2023-2024 Google LLC
--
-- SPDX-License-Identifier: Apache-2.0

import Clash.Prelude
import Clash.Annotations.TH
import Prelude

import VexRiscv

circuit ::
"CLK" ::: Clock System ->
"RST" ::: Reset System ->
"CPU_COMB_INPUT" ::: Signal System CpuIn ->
"JTAG_IN_" ::: Signal System JtagIn ->
"" :::
( "CPU_OUTPUT" ::: Signal System CpuOut
, "JTAG_OUT_" ::: Signal System JtagOut)
circuit clk rst input jtagIn =
vexRiscv clk rst input jtagIn

makeTopEntity 'circuit
import qualified Clash.Main as Clash

main :: IO ()
main = pure ()
main = Clash.defaultMain ["Utils.Instance", "-main-is", "circuit", "--verilog"]
18 changes: 10 additions & 8 deletions clash-vexriscv-sim/clash-vexriscv-sim.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ common common-options

-- Prelude isn't imported by default as Clash offers Clash.Prelude
NoImplicitPrelude

-- See https://github.com/clash-lang/clash-compiler/pull/2511
if impl(ghc >= 9.4)
CPP-Options: -DCLASH_OPAQUE=OPAQUE
else
CPP-Options: -DCLASH_OPAQUE=NOINLINE

ghc-options:
-Wall -Wcompat

Expand Down Expand Up @@ -76,6 +83,7 @@ library
default-language: Haskell2010
exposed-modules:
Utils.Cpu
Utils.Instance
Utils.Interconnect
Utils.ProgramLoad
Utils.ReadElf
Expand All @@ -88,19 +96,13 @@ library
clash-vexriscv,
elf >= 0.31 && < 0.32,

executable clash
import: common-options
main-is: app/Clash.hs
build-Depends: base, clash-ghc

-- XXX: Doesn't really belong in clash-vexriscv-SIM
executable hdl-test
import: common-options
main-is: app/HdlTest.hs
build-Depends:
base,
clash-prelude,
clash-protocols,
clash-vexriscv,
clash-ghc,
clash-vexriscv-sim,

executable clash-vexriscv-bin
Expand Down
25 changes: 25 additions & 0 deletions clash-vexriscv-sim/src/Utils/Instance.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- SPDX-FileCopyrightText: 2024 Google LLC
--
-- SPDX-License-Identifier: Apache-2.0
{-# LANGUAGE CPP #-}

-- | A dummy instance to test whether Clash can generate HDL for the VexRiscv
module Utils.Instance where

import Clash.Prelude
import Clash.Annotations.TH

import VexRiscv

circuit ::
"CLK" ::: Clock System ->
"RST" ::: Reset System ->
"CPU_IN" ::: Signal System CpuIn ->
"JTAG_IN" ::: Signal System JtagIn ->
"" :::
( "CPU_OUTPUT" ::: Signal System CpuOut
, "JTAG_OUT" ::: Signal System JtagOut )
circuit clk rst input jtagIn =
vexRiscv clk rst input jtagIn
{-# CLASH_OPAQUE circuit #-}
makeTopEntity 'circuit
7 changes: 7 additions & 0 deletions clash-vexriscv/clash-vexriscv.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ common common-options

-- Prelude isn't imported by default as Clash offers Clash.Prelude
NoImplicitPrelude

-- See https://github.com/clash-lang/clash-compiler/pull/2511
if impl(ghc >= 9.4)
CPP-Options: -DCLASH_OPAQUE=OPAQUE
else
CPP-Options: -DCLASH_OPAQUE=NOINLINE

ghc-options:
-Wall -Wcompat

Expand Down
8 changes: 4 additions & 4 deletions clash-vexriscv/src/VexRiscv.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
--
-- SPDX-License-Identifier: Apache-2.0

{-# LANGUAGE CPP #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE TemplateHaskellQuotes #-}
{-# LANGUAGE QuasiQuotes #-}
-- {-# LANGUAGE AllowAmbiguousTypes #-}

{-# OPTIONS_GHC -fconstraint-solver-iterations=10 #-}

Expand Down Expand Up @@ -356,7 +356,7 @@ vexRiscv# !_sourcePath clk rst0
, FFI.jtag_debug_resetOut <$> output
, FFI.jtag_TDO <$> output
)
{-# NOINLINE vexRiscv# #-}
{-# CLASH_OPAQUE vexRiscv# #-}
{-# ANN vexRiscv# (
let
primName = 'vexRiscv#
Expand Down

0 comments on commit 088bf7d

Please sign in to comment.