Skip to content

Instantly share code, notes, and snippets.

View christiaanb's full-sized avatar

Christiaan Baaij christiaanb

  • QBayLogic
  • Enschede, The Netherlands
View GitHub Profile
{-# LANGUAGE PatternSynonyms, ViewPatterns, TypeFamilies #-}
module Pat1 (Vec(Nil,(:>)), pattern (:>)) where
import qualified Control.Lens as Lens hiding (pattern (:>))
newtype Vec a = Vec {unvec :: [a]}
pattern Nil :: Vec a
pattern Nil = Vec []
~/devel/clash-compiler-ghc8 (ghc8)$ stack --stack-yaml=stack-ghc801.yaml build
clash-lib-0.7: build
Progre
-- While building package clash-lib-0.7 using:
/home/baaijcpr/.stack/setup-exe-cache/x86_64-linux/setup-Simple-Cabal-1.24.0.0-ghc-8.0.0.20160411 --builddir=.stack-work/dist/x86_64-linux/Cabal-1.24.0.0 build lib:clash-lib --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
Logs have been written to: /home/baaijcpr/devel/clash-compiler-ghc8/.stack-work/logs/clash-lib-0.7.log
Preprocessing library clash-lib-0.7...
[ 8 of 44] Compiling CLaSH.Core.TyCon[boot] ( src/CLaSH/Core/TyCon.hs-boot, .stack-work/dist/x86_64-linux/Cabal-1.24.0.0/build/CLaSH/Core/TyCon.o-boot )
{-# LANGUAGE RankNTypes, DataKinds, PolyKinds, GADTs, TypeFamilies,
FlexibleContexts, TemplateHaskell, ScopedTypeVariables,
UndecidableInstances, TypeOperators, FlexibleInstances #-}
import Data.Proxy
import GHC.Types
type KindOf (a :: k) = ('KProxy :: KProxy k)
data TyFun :: * -> * -> *
type family Apply (f :: TyFun k1 k2 -> *) (x :: k1) :: k2
module TestDF where
import CLaSH.Prelude
testDF :: (Eq b, Show b, KnownNat n, KnownNat m)
=> DataFlow Bool Bool a b
-> Vec n a -- ^ Inputs
-> Vec m b -- ^ Expected outputs
-> Signal Bool -- ^ 'True' indicates we're done with testing
testDF f testIn expOut =
{-# LANGUAGE MultiParamTypeClasses, UndecidableInstances, FlexibleInstances #-}
module DF where
import CLaSH.Prelude hiding (parNDF, LockStep (..))
import CLaSH.Prelude.Explicit
import qualified Data.List as DL
-- The workaround begins here
parNDF :: (KnownSymbol nm, KnownNat rate, KnownNat n)
=> Vec n (DataFlow' ('Clk nm rate) aEn bEn a b)
{-# LANGUAGE PartialTypeSignatures #-}
{-# OPTIONS_GHC -fno-warn-partial-type-signatures #-}
module MultiClockFifo where
import CLaSH.Prelude
import CLaSH.Prelude.Explicit
fifoMem wclk rclk addrSize waddr raddr winc wfull wdata =
asyncRam' wclk rclk
(d2 `powSNat` addrSize)
{-# LANGUAGE GADTs, KindSignatures, ScopedTypeVariables, Rank2Types,
UndecidableInstances, MultiParamTypeClasses #-}
module PopCount2 where
import CLaSH.Prelude
import CLaSH.Sized.Internal.Index
import Data.Proxy (Proxy (..))
import Data.Singletons.Prelude
import qualified Data.List as L
module BitPalindrome3 where
import CLaSH.Prelude
-- evenPalindrome :: (Eq a, KnownNat m) => Vec (m + m) a -> Bool
evenPalindrome v = l == reverse r
where
(l,r) = splitAtI v
-- unevenPalindrome :: (Eq a, KnownNat m) => Vec (m + (m + 1)) a -> Bool
module BitPalindrome2 where
-- import Control.Arrow (second)
import CLaSH.Prelude
-- This function will be in `clash-prelude-0.10.1`
bv2v :: KnownNat n => BitVector n -> Vec n Bit
bv2v = unpack
evenPalindrome :: (Eq a,KnownNat m)
{-# LANGUAGE ScopedTypeVariables #-}
module PopulationCount where
import CLaSH.Prelude
popCnt :: forall n . (KnownNat (n+1), KnownNat (n + 2))
=> BitVector (n+1)
-> Index (n+2)
popCnt bv = sum (map fromIntegral v)
where