[project @ 1999-04-29 11:53:12 by simonpj]
[ghc-hetmet.git] / ghc / tests / programs / jeff-bug / PipeReg.hs
1 module PipeReg where
2
3
4 import Trans
5 import Signal 
6 import Register
7 import Instruction
8
9 -- Begin Signature ----------------------------------------------------------
10
11 {- 
12   pipeReg is helpful for constructing in pipelines 
13 -}
14
15 data PipeRegCmd = Input | Stall | Kill
16                   deriving (Eq,Ord,Enum,Bounded,Show)
17
18
19 -- pipeReg t cmd ts , on the first cycle return "t", in later cycles,
20 -- if cmd=Input then return ts, if cmd=Stall then return the previous
21 -- value and store the input, if cmd=Kill then return a nop
22
23 pipeReg :: (Instruction a, Register b) => 
24            Trans a (c b d) -> Signal PipeRegCmd -> 
25            Signal (Trans a (c b d)) -> Signal (Trans a (c b d))
26
27 input           :: Signal PipeRegCmd
28 stall           :: Signal PipeRegCmd
29 kill            :: Signal PipeRegCmd
30
31 -- End Signature ----------------------------------------------------------
32
33 pipeReg init cmd incoming = out
34   where out = delay init (if' (cmd*==input) then' incoming
35                           else' (if' (cmd*==stall) then' out 
36                           else' (lift0 nop))
37                          )
38
39 input = lift0 Input
40 stall = lift0 Stall
41 kill = lift0 Kill
42