Enable the DontCare value for Bit again.
[matthijs/master-project/cλash.git] / Bits.hs
1 module Bits where
2
3 --class Signal a where
4 --      hwand :: a -> a -> a
5 --      hwor  :: a -> a -> a
6 --      hwxor :: a -> a -> a
7 --      hwnot :: a -> a
8 --
9 --      -- Prettyprint a signal. We're not extending Show here, since show must
10 --      -- return a valid haskell syntax
11 --      displaysig :: a -> String
12
13 hwand :: Bit -> Bit -> Bit
14 hwor  :: Bit -> Bit -> Bit
15 hwxor :: Bit -> Bit -> Bit
16 hwnot :: Bit -> Bit
17
18 -- Prettyprint Bit signal. We're not extending Show here, since show must
19 -- return Bit valid haskell syntax
20 displaysig :: Bit -> String
21
22 --instance Signal Bit where
23 High `hwand` High = High
24 _ `hwand` _ = Low
25
26 High `hwor` _  = High
27 _ `hwor` High  = High
28 Low `hwor` Low = Low
29
30 High `hwxor` Low = High
31 Low `hwxor` High = High
32 _ `hwxor` _      = Low
33
34 hwnot High = Low
35 hwnot Low  = High
36
37 displaysig High = "1" 
38 displaysig Low  = "0"
39
40 -- The plain Bit type
41 data Bit = High | Low | DontCare
42   deriving (Show, Eq, Read)
43
44 -- A function to prettyprint a bitvector
45
46 --displaysigs :: (Signal s) => [s] -> String
47 displaysigs :: [Bit] -> String
48 displaysigs = (foldl (++) "") . (map displaysig)
49
50 type Stream a = [a]
51
52 -- An infinite streams of highs or lows
53 lows  = Low : lows
54 highs = High : highs
55
56 -- vim: set ts=8 sw=2 sts=2 expandtab: