Implement API change of shiftl and shiftr, limit Prelude import of HardwareTypes
[matthijs/master-project/cλash.git] / clash / CLasH / HardwareTypes.hs
1 {-# LANGUAGE TemplateHaskell, DeriveDataTypeable #-}
2
3 module CLasH.HardwareTypes
4   ( module Types
5   , module Data.Param.Vector
6   , module Data.Param.Index
7   , module Data.Param.Signed
8   , module Data.Param.Unsigned
9   , module Prelude
10   , Bit(..)
11   , State(..)
12   , hwand
13   , hwor
14   , hwxor
15   , hwnot
16   , RAM
17   , MemState
18   , blockRAM
19   ) where
20
21 import qualified Prelude as P
22 import Prelude (Bool(..),Num(..),Eq(..),Ord(..),snd,fst,otherwise,(&&),(||),not)
23 import Types
24 import Data.Param.Vector
25 import Data.Param.Index
26 import Data.Param.Signed
27 import Data.Param.Unsigned 
28
29 import Language.Haskell.TH.Lift
30 import Data.Typeable
31
32 newtype State s = State s deriving (P.Show)
33
34 -- The plain Bit type
35 data Bit = High | Low
36   deriving (P.Show, Eq, P.Read, Typeable)
37
38 deriveLift ''Bit
39
40 hwand :: Bit -> Bit -> Bit
41 hwor  :: Bit -> Bit -> Bit
42 hwxor :: Bit -> Bit -> Bit
43 hwnot :: Bit -> Bit
44
45 High `hwand` High = High
46 _ `hwand` _ = Low
47
48 High `hwor` _  = High
49 _ `hwor` High  = High
50 Low `hwor` Low = Low
51
52 High `hwxor` Low = High
53 Low `hwxor` High = High
54 _ `hwxor` _      = Low
55
56 hwnot High = Low
57 hwnot Low  = High
58
59 type RAM s a          = Vector s a
60 type MemState s a     = State (RAM s a)
61
62 blockRAM :: 
63   PositiveT s  =>
64   MemState s a -> 
65   a ->
66   Index s ->
67   Index s ->
68   Bool -> 
69   (MemState s a, a )
70 blockRAM (State mem) data_in rdaddr wraddr wrenable = 
71   ((State mem'), data_out)
72   where
73     data_out  = mem!rdaddr
74     -- Only write data_in to memory if write is enabled
75     mem' =  if wrenable then
76               replace mem wraddr data_in
77             else
78               mem