19 -- Begin Signature -------------------------------------------------------
22 In practice it is nice to be able to place a probe on a signal.
23 Suppose that "s" is a signal. 'probe "s.output" s' has the
24 same meaning as 's' --- but s's contents have been written to
25 the file "s.output". This function has turned out to be
26 critical in the development of the Visio Hawk interface.
28 Some issues to consider:
29 * probe is a hack --- and it messes with referential
30 trancparency. Some Haskell compilers may wreak havoc with
32 * probe is pretty careful not to change the strictness
34 * Avoid using probes within unit definitions. If you duplicate
35 the use of the unit, the output file will be written to
36 simultaniously by both units instantiations. Try using probe
37 only at the top-level of your microarchitecture.
38 * Probes are typically stored in a subdirectory "Probes/"
42 class Show a => Probe a where
43 probe :: String -> Signal a -> Signal a
45 probe n (List vals) = List (zipWith (dataOut n) [1..] vals)
48 -- clear the probes subdirectory in UNIX
49 clearProbes_UNIX :: IO ()
51 -- clear the probes subdirectory in Microsoft
52 clearProbes_MS :: IO ()
54 instance (Show a,Show b) => Probe (a,b)
55 instance (Show a,Show b,Show c) => Probe (a,b,c)
61 instance Probe a => Probe (Maybe a)
62 {-instance (Probe a, Probe b) => Probe (Virtual a b )-}
63 {-instance Probe PipeRegCmd-}
64 {-instance Probe AluOp-}
65 {-instance Probe a => Probe [a]-}
67 -- End Signature --------------------------------------------------------
70 = do { system "rm -f Probes/*"
75 = do { system "del \\Q Probes\\*.*"
79 dataOut :: Probe a => String -> Int -> a -> a
80 dataOut fileName clock val = unsafePerformIO $
82 {h <- openFile ("Probes/" ++ fileName) AppendMode;
83 hPutStrLn h (rjustify 3 (show clock) ++ ": " ++ outp val);
89 instance (Probe a, Probe b) => Probe (Virtual a b ) where
90 outp (Virtual n (Just r)) = "V"++show n ++ "{" ++ outp r ++"}"
91 outp (Virtual n Nothing) = "V"++show n
92 outp (Real r) = outp r
95 instance Probe PipeRegCmd where
100 instance Probe AluOp where
115 instance Probe a => Probe [a] where
117 outp l = "[\t" ++ foldr1 (\x y -> x ++ "\n\t" ++ y) (map outp l) ++ "]"
121 rjustify n s = reverse (take (max n (length s))
122 (reverse s ++ repeat ' '))