[project @ 1999-04-29 11:53:12 by simonpj]
[ghc-hetmet.git] / ghc / tests / programs / jeff-bug / Main.hs
1 module Main where
2
3 import System
4 import Hawk--(hawkMain)
5 import DLX
6 import DLX_Cell
7 import DLX_Reg
8 import DLX_Op
9 import Processor
10 import Signal
11 import Trans
12 import LazyST
13
14 import Probe
15
16 main =
17  do { clearProbes_UNIX
18     ; args <- getArgs
19     ; case args of
20         [file]           -> run file
21         ["-count", file] -> count file    
22         ["-sample",n,file] -> sample (read n) file    
23         otherwise        -> error "Usage: pgm [-count] file\n"
24     ; return ()
25     }
26
27 p :: ((ArrayDesc Int (Instr DLXReg Int), a), Int) -> Signal [Trans DLX_Op (DLX_Cell DLXReg Int)]
28 --p :: ((ArrayDesc Int (Instr DLXReg Int), a), Int) -> Signal [Trans DLX_Op (DLX_Cell (Virtual DLXReg Int) Int)]
29 p = processor
30
31 run file =
32      hawkMain file (mapM_ (putStrLn . show) . (view . p))
33 count file = 
34      hawkMain file (mapM_ (putStrLn . show) . (cnt. view . p))
35
36 sample n file =
37      hawkMain file (mapM_ (putStrLn . pretty) . (take n . view . p))
38
39 pretty tss =
40     foldr (\x y -> show x ++ "\n" ++ y) "\n" tss
41
42 cnt l = runST (
43   do n <- newSTRef 0
44      mapM (\l -> n+=(length l)) l
45   )
46
47 n += v = 
48   do n' <- readSTRef n
49      let v' = v+n'
50      writeSTRef n v'
51      return v'
52