Skip to content

Commit

Permalink
Move plugin and internal definitions to local package
Browse files Browse the repository at this point in the history
  • Loading branch information
t-wallet committed Aug 15, 2024
1 parent 623ecd9 commit 6d5e076
Show file tree
Hide file tree
Showing 21 changed files with 183 additions and 40 deletions.
12 changes: 11 additions & 1 deletion cabal.project
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
packages:
clash-protocols.cabal
./clash-protocols-base, .

tests: True

Expand All @@ -15,6 +15,16 @@ source-repository-package
location: https://github.com/cchalmers/circuit-notation.git
tag: 19b386c4aa3ff690758ae089c7754303f3500cc9

package clash-protocols-base
-- Reduces compile times by ~20%
ghc-options: +RTS -qn4 -A128M -RTS -j4

-- Workaround for Haddock/CPP #if issues https://github.com/haskell/haddock/issues/1382
haddock-options: --optghc="-optP -P"

-- Don't pollute docs with large tuple instances
haddock-options: --optghc=-DHADDOCK_ONLY

package clash-protocols
-- Reduces compile times by ~20%
ghc-options: +RTS -qn4 -A128M -RTS -j4
Expand Down
23 changes: 23 additions & 0 deletions clash-protocols-base/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright (c) 2024, Martijn Bastiaan
2024, QBayLogic B.V.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
5 changes: 5 additions & 0 deletions clash-protocols-base/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Distribution.Simple
import Prelude

main :: IO ()
main = defaultMain
125 changes: 125 additions & 0 deletions clash-protocols-base/clash-protocols-base.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
cabal-version: 2.4
name: clash-protocols-base
synopsis: a battery-included library for (dataflow) protocols
Homepage: https://gitlab.com/martijnbastiaan/clash-protocols
version: 0.1
category: Hardware
license: BSD-2-Clause
license-file: LICENSE
author: Martijn Bastiaan, QBayLogic B.V.
maintainer: Martijn Bastiaan <[email protected]>

flag ci
Description: Running on CI? Used to set fail-on-warning flag.
Manual: True
Default: False

flag large-tuples
description:
Generate instances for classes such as `Units` and `TaggedBundle` for tuples
up to and including 62 elements - the GHC imposed maximum. Note that this
greatly increases compile times for `clash-protocols-base`.
default: False
manual: True

common common-options
default-extensions:
BangPatterns
BinaryLiterals
ConstraintKinds
CPP
DataKinds
DefaultSignatures
DeriveAnyClass
DeriveDataTypeable
DeriveFoldable
DeriveFunctor
DeriveGeneric
DeriveLift
DeriveTraversable
DerivingStrategies
InstanceSigs
KindSignatures
LambdaCase
NoStarIsType
PolyKinds
RankNTypes
ScopedTypeVariables
StandaloneDeriving
TupleSections
TypeApplications
TypeFamilies
TypeOperators
ViewPatterns

-- TemplateHaskell is used to support convenience functions such as
-- 'listToVecTH' and 'bLit'.
TemplateHaskell
QuasiQuotes

-- Prelude isn't imported by default as Clash offers Clash.Prelude
-- NoImplicitPrelude
ghc-options:
-Wall -Wcompat

-- Plugins to support type-level constraint solving on naturals
-fplugin GHC.TypeLits.Extra.Solver
-fplugin GHC.TypeLits.Normalise
-fplugin GHC.TypeLits.KnownNat.Solver

-- Clash needs access to the source code in compiled modules
-fexpose-all-unfoldings

-- Worker wrappers introduce unstable names for functions that might have
-- blackboxes attached for them. You can disable this, but be sure to add
-- a no-specialize pragma to every function with a blackbox.
-fno-worker-wrapper

if flag(ci)
ghc-options: -Werror

default-language: Haskell2010
build-depends:
base >= 4.15.0.0,
Cabal,

clash-prelude >= 1.8.1 && < 1.10,
ghc-typelits-natnormalise,
ghc-typelits-extra,
ghc-typelits-knownnat

custom-setup
setup-depends:
base >= 4.11 && <5,
Cabal >= 2.4,

library
import: common-options
hs-source-dirs: src

if flag(large-tuples)
CPP-Options: -DLARGE_TUPLES

build-depends:
, circuit-notation
, data-default
, deepseq
, extra
, ghc >= 8.7 && < 9.7
, hashable
, tagged
, template-haskell

exposed-modules:
Protocols.Cpp
Protocols.Internal
Protocols.Internal.Classes
Protocols.Internal.TaggedBundle
Protocols.Internal.TaggedBundle.TH
Protocols.Internal.TH
Protocols.Internal.Units
Protocols.Internal.Units.TH
Protocols.Plugin
Protocols.Plugin.Internal

default-language: Haskell2010
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ module Protocols.Plugin (
import Prelude

-- clash-protocols
import Protocols
import Protocols.Internal
import Protocols.Internal.TaggedBundle
import Protocols.Internal.Units
import Protocols.Plugin.Internal

-- circuit-notation
Expand Down
File renamed without changes.
38 changes: 5 additions & 33 deletions clash-protocols.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,6 @@ custom-setup
Cabal >= 2.4,
cabal-doctest >= 1.0.1 && <1.1

-- library inline-circuit-notation
-- visibility: private
-- hs-source-dirs: deps/circuit-notation/src
-- build-depends:
-- , base
-- , clash-prelude >= 1.0
-- , containers
-- , data-default
-- , ghc >=8.6
-- , syb
-- , lens
-- , mtl
-- , pretty
-- , parsec
-- , pretty-show
-- , template-haskell
-- exposed-modules:
-- CircuitNotation
-- default-language: Haskell2010

library
import: common-options
hs-source-dirs: src
Expand All @@ -134,7 +114,7 @@ library
CPP-Options: -DLARGE_TUPLES

build-depends:
-- inline-circuit-notation
, clash-protocols-base
, circuit-notation
, clash-prelude-hedgehog
, data-default
Expand All @@ -155,7 +135,6 @@ library
, tasty-hedgehog >= 1.2

exposed-modules:
Protocols
Protocols.Avalon.MemMap
Protocols.Avalon.Stream
Protocols.Axi4.Common
Expand All @@ -165,23 +144,15 @@ library
Protocols.Axi4.WriteAddress
Protocols.Axi4.WriteData
Protocols.Axi4.WriteResponse
Protocols.Cpp
Protocols.Df
Protocols.DfConv
Protocols.Hedgehog
Protocols.Hedgehog.Internal
Protocols.Idle
Protocols.Internal
Protocols.Internal.TaggedBundle
Protocols.Internal.TaggedBundle.TH
Protocols.Internal.TH
Protocols.Internal.Units
Protocols.Internal.Units.TH
Protocols.Plugin
Protocols.Plugin.Internal
Protocols.Wishbone
Protocols.Wishbone.Standard
Protocols.Wishbone.Standard.Hedgehog
Protocols

-- 'testProperty' is broken upstream, it reports wrong test names
-- TODO: test / upstream ^
Expand All @@ -190,9 +161,7 @@ library
autogen-modules: Paths_clash_protocols

other-modules:
Data.Bifunctor.Extra
Paths_clash_protocols
Protocols.Internal.Classes

default-language: Haskell2010

Expand All @@ -213,6 +182,7 @@ test-suite unittests

Util
build-depends:
clash-protocols-base,
clash-protocols,
clash-prelude-hedgehog,
data-default,
Expand All @@ -236,6 +206,8 @@ test-suite doctests

build-depends:
base,
clash-protocols-base,
clash-protocols,
process,
doctest

4 changes: 2 additions & 2 deletions format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if [[ "$#" -eq 0 || "$1" == "-h" || "$1" == "--help" ]]; then
fi

exclude_files=(
"src/Protocols/Cpp.hs"
"clash-protocols-base/src/Protocols/Cpp.hs"
)

# Make sure it doesn't matter from where this script is executed
Expand All @@ -34,7 +34,7 @@ cd $DIR
if [ $1 == "diff" ] ; then
src_files=$(git diff --cached --name-only --diff-filter=ACMR -- '*.hs')
else
src_files=$(find Setup.hs src tests -type f -name "*.hs")
src_files=$(find clash-protocols-base/Setup.hs Setup.hs clash-protocols-base/src src tests -type f -name "*.hs")
fi

src_files_str=$(printf "%s\n" "${src_files[@]}" | sed 's| |\\ |g')
Expand Down
4 changes: 4 additions & 0 deletions hie.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
cradle:
multi:
- path: "./clash-protocols-base/src"
config: {cradle: {cabal: {component: "lib:clash-protocols-base"}}}
- path: "./src"
config: {cradle: {cabal: {component: "lib:clash-protocols"}}}
- path: "./tests"
Expand All @@ -8,5 +10,7 @@ cradle:
config: {cradle: {cabal: {component: "clash"}}}
- path: "./bin/Clashi.hs"
config: {cradle: {cabal: {component: "clashi"}}}
- path: "./clash-protocols-base/Setup.hs"
config: {cradle: {none: }}
- path: "./Setup.hs"
config: {cradle: {none: }}
2 changes: 2 additions & 0 deletions nix/nixpkgs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ let
self.callCabal2nix "tasty-hedgehog" sources.tasty-hedgehog {};
hedgehog =
self.callCabal2nix "hedgehog" (sources.haskell-hedgehog + "/hedgehog") {};
clash-protocols-base =
self.callCabal2nix "clash-protocols-base" (../clash-protocols-base) {};
};
};
};
Expand Down
1 change: 0 additions & 1 deletion src/Protocols.hs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,5 @@ module Protocols (
import Data.Default (def)
import Protocols.Df (Df)
import Protocols.Internal

import Protocols.Internal.TaggedBundle
import Protocols.Internal.Units
4 changes: 2 additions & 2 deletions src/Protocols/Hedgehog/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,11 @@ class
-- in order to produce pretty reports.
m (ExpectType a)

instance (TestType a, C.KnownDomain dom) => Test (Df dom a) where
instance (TestType a, C.KnownDomain dom) => Test (Df.Df dom a) where
expectN ::
forall m.
(HasCallStack, H.MonadTest m) =>
Proxy (Df dom a) ->
Proxy (Df.Df dom a) ->
ExpectOptions ->
[Df.Data a] ->
m [a]
Expand Down
1 change: 1 addition & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
resolver: lts-21.25 # ghc-9.4.8

packages:
- clash-protocols-base
- .

extra-deps:
Expand Down

0 comments on commit 6d5e076

Please sign in to comment.