Clash is a functional hardware description language that borrows both its syntax and semantics from the functional programming language Haskell. The Clash compiler transforms these high-level descriptions to low-level synthesizable VHDL, Verilog, or SystemVerilog. Features of Clash: Strongly typed, but with a very high degree of type inference, enabling both safe and fast prototyping using concise descriptions. Interactive REPL: load your designs in an interpreter and easily test all your component without needing to setup a test bench. Higher-order functions, with type inference, result in designs that are fully parametric by default. Synchronous sequential circuit design based on streams of values, called Signals, lead to natural descriptions of feedback loops. Support for multiple clock domains, with type safe clock domain crossing. This package provides: The CoreHW internal language: SystemF + Letrec + Case-decomposition The normalisation process that brings CoreHW in a normal form that can be converted to a netlist Blackbox/Primitive Handling Front-ends (for: parsing, typecheck, etc.) are provided by separate packages: GHC/Haskell Frontend Idris Frontend Prelude library: https://hackage.haskell.org/package/clash-prelude


Keywords
hardware, library, program, Propose Tags, GHC/Haskell Frontend, Idris Frontend, https://hackage.haskell.org/package/clash-prelude, Skip to Readme, Index, Quick Jump, Clash.Annotations.BitRepresentation.ClashLib, Clash.Backend, Clash.Backend.SystemVerilog, Clash.Backend.VHDL, Clash.Backend.Verilog, Clash.Backend.Verilog.Time, Clash.Core.DataCon, Clash.Core.EqSolver, Clash.Core.Evaluator.Types, Clash.Core.FreeVars, Clash.Core.HasFreeVars, Clash.Core.HasType, Clash.Core.Literal, Clash.Core.Name, Clash.Core.PartialEval, Clash.Core.PartialEval.AsTerm, Clash.Core.PartialEval.Monad, Clash.Core.PartialEval.NormalForm, Clash.Core.Pretty, Clash.Core.Subst, Clash.Core.Term, Clash.Core.TermInfo, Clash.Core.TermLiteral, Clash.Core.TermLiteral.TH, Clash.Core.TyCon, Clash.Core.Type, Clash.Core.TysPrim, Clash.Core.Util, Clash.Core.Var, Clash.Core.VarEnv, Clash.Data.UniqMap, Clash.DataFiles, Clash.Debug, Clash.Driver, Clash.Driver.Manifest, Clash.Driver.Types, Clash.Edalize.Edam, Clash.Netlist, Clash.Netlist.BlackBox, Clash.Netlist.BlackBox.Parser, Clash.Netlist.BlackBox.Types, Clash.Netlist.BlackBox.Util, Clash.Netlist.Expr, Clash.Netlist.Id, Clash.Netlist.Id.Common, Clash.Netlist.Id.Internal, Clash.Netlist.Id.SystemVerilog, Clash.Netlist.Id.VHDL, Clash.Netlist.Id.Verilog, Clash.Netlist.Types, Clash.Netlist.Util, Clash.Normalize, Clash.Normalize.PrimitiveReductions, Clash.Normalize.Primitives, Clash.Normalize.Strategy, Clash.Normalize.Transformations, Clash.Normalize.Transformations.ANF, Clash.Normalize.Transformations.Case, Clash.Normalize.Transformations.Cast, Clash.Normalize.Transformations.DEC, Clash.Normalize.Transformations.EtaExpand, Clash.Normalize.Transformations.Inline, Clash.Normalize.Transformations.Letrec, Clash.Normalize.Transformations.MultiPrim, Clash.Normalize.Transformations.Reduce, Clash.Normalize.Transformations.SeparateArgs, Clash.Normalize.Transformations.Specialize, Clash.Normalize.Transformations.XOptimize, Clash.Normalize.Types, Clash.Normalize.Util, Clash.Pretty, Clash.Primitives.Annotations.SynthesisAttributes, Clash.Primitives.DSL, Clash.Primitives.GHC.Int, Clash.Primitives.GHC.Literal, Clash.Primitives.GHC.Word, Clash.Primitives.Intel.ClockGen, Clash.Primitives.Magic, Clash.Primitives.Sized.Signed, Clash.Primitives.Sized.ToInteger, Clash.Primitives.Sized.Vector, Clash.Primitives.Types, Clash.Primitives.Util, Clash.Primitives.Verification, Clash.Primitives.Xilinx.ClockGen, Clash.Rewrite.Combinators, Clash.Rewrite.Types, Clash.Rewrite.Util, Clash.Rewrite.WorkFree, Clash.Unique, Clash.Util, Clash.Util.Eq, Clash.Util.Graph, Clash.Util.Interpolate, Clash.Verification.Pretty, Data.Text.Prettyprint.Doc.Extra, GHC.BasicTypes.Extra, More info, clash-lib-1.8.1.tar.gz, browse, Package description, Package maintainers, ChristiaanBaaij, QBayLogic, edit package information , 0.2.0.1, 0.99.1, 0.99.2, 0.99.3, 0.9999, 1.0.0, 1.0.1, 1.1.0, 1.2.0, 1.2.1, 1.2.2, 1.2.3, 1.2.4, 1.2.5, 1.3.0, 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.4, 1.4.5, 1.4.6, 1.4.7, 1.5.0, 1.6.3, 1.6.4, 1.6.5, 1.6.6, 1.7.0, 1.8.0, 1.8.1, 1.9.0, clash-language+subscribe@googlegroups.com, forum, asic, fpga, hardware-description-language, haskell, systemverilog, verilog, vhdl
License
BSD-2-Clause
Install
cabal install clash-lib-1.8.1

Documentation

Clash - A functional hardware description language

Pipeline status Hackage Hackage Dependencies Documentation Status

Clash is a functional hardware description language that borrows both its syntax and semantics from the functional programming language Haskell. The Clash compiler transforms these high-level descriptions to low-level synthesizable VHDL, Verilog, or SystemVerilog.

Features of Clash:

  • Strongly typed, but with a very high degree of type inference, enabling both safe and fast prototyping using concise descriptions.

  • Interactive REPL: load your designs in an interpreter and easily test all your component without needing to setup a test bench.

  • Higher-order functions, with type inference, result in designs that are fully parametric by default.

  • Synchronous sequential circuit design based on streams of values, called Signals, lead to natural descriptions of feedback loops.

  • Support for multiple clock domains, with type safe clock domain crossing.

Community

Mailing list: for updates and questions join the mailing list clash-language+subscribe@googlegroups.com or read the forum

Slack: functionalprogramming.slack.com#clash (Invite yourself at fpslack.com/).

IRC: libera.chat#clash (webchat access) (or ircs://irc.libera.chat:6697/clash if you want to use a regular IRC client)

Get Clash

Check out clash-lang.org/install to install the latest stable release of Clash, or to setup a Clash project.

Get Clash from source

Get the source code using Git and enter the cloned directory:

git clone git@github.com:clash-lang/clash-compiler.git

# Alternatively, if you haven't setup SSH keys with GitHub:
# git clone https://github.com/clash-lang/clash-compiler.git

cd clash-compiler

To check out a released version, use:

git checkout v1.2.3

To checkout a release branch use:

git checkout 1.2

Note that release branches might contain non-released patches.

GHC compatibility

Linux Windows macOS Clash (released) Clash (development version)
8.6 ✔️ ✔️ ✔️ 1.0 - 1.6 ✔️
8.8 ✔️ ✔️ 1.0 - 1.6 ✔️
8.10 ✔️ ✔️ 1.2 - 1.6 ✔️
9.0 ✔️ ✔️² ✔️ 1.4 - 1.6 ✔️
9.2 ⚠️¹ ⚠️¹ ⚠️¹ ⚠️¹️
9.4 ✔️ ✔️ ✔️ ✔️
9.6 ✔️ ❔³ ❔³ ✔️

¹ GHC 9.2 contains a regression, rendering Clash error messages indecipherable. This change was reverted in 9.4.

² GHC 9.0.2 on Windows fails to compile clash-cores. We therefore don't run the Clash testsuite on CI for this combination.

³ We use Stack to test on Windows/macOS. There is no resolver yet that uses GHC 9.6, so this remains untested.

Cabal

To use Cabal you need both Cabal and GHC installed on your system. We recommend using ghcup. For more information, see https://www.haskell.org/downloads/.

To run clash use:

cabal v2-run -- clash

If this fails, make sure you've got an up-to-date package index:

cabal update

Stack

Install Stack and run:

stack run -- clash

Nix

Or use Nix to get a shell with the clash and clashi binaries on your PATH:

# Start the default dev shell
nix develop .

# Start a dev shell with a specific GHC version
nix develop .#ghc961

You will need a modern version of nix with support for the new-style nix command and flakes (2.4 or newer). Support for these must still be manually enabled, this can be done by setting

experimental-features = nix-command flakes

in your nix.conf.

To automatically enter and exit the nix environment on directory change, you can install direnv and nix-direnv and write the following to a .envrc file in the root of this repository:

use flake

watch_file nix/*

Upon adding or changing this file you must direnv allow in order for the file to be automatically loaded / reloaded on project changes.

Individual packages / applications can also be built or run using the nix build and nix run commands, i.e.

nix build .#clash-ghc
nix run .#clashi

Related libraries and initiatives

  • Clashilator: tooling to integrate Clash with Verilator. Enables fast, multithreaded simulation by compiling Clash designs to C++.
  • Clash Protocols: experimental library for writing Clash circuits with bidirectional communication - such as AXI or Avalon.
  • Clash Starters: starter projects to quickly get you up and running.
  • Clash WaveDrom: generate wave diagrams from Clash using WaveDrom

Projects built with Clash