[project @ 1996-07-25 20:43:49 by partain]
[ghc-hetmet.git] / ghc / compiler / utils / OrdList.lhs
1 %
2 % (c) The AQUA Project, Glasgow University, 1993-1996
3 %
4
5 This is useful, general stuff for the Native Code Generator.
6
7 \begin{code}
8 module OrdList (
9         OrdList,
10
11         mkParList, mkSeqList, mkEmptyList, mkUnitList,
12
13         flattenOrdList
14     ) where
15
16 import Util     ( mapAccumB, mapAccumL, mapAccumR )
17 \end{code}
18
19 This section provides an ordering list that allows fine grain
20 parallelism to be expressed.  This is used (ultimately) for scheduling
21 of assembly language instructions.
22
23 \begin{code}
24 data OrdList a
25   = SeqList (OrdList a) (OrdList a)
26   | ParList (OrdList a) (OrdList a)
27   | OrdObj a
28   | NoObj
29   deriving ()
30
31 mkSeqList a b = SeqList a b
32 mkParList a b = ParList a b
33 mkEmptyList   = NoObj
34 mkUnitList    = OrdObj
35 \end{code}
36
37 %------------------------------------------------------------------------
38
39 Notice this this throws away all potential expression of parallelism.
40
41 \begin{code}
42 flattenOrdList :: OrdList a -> [a]
43
44 flattenOrdList ol
45   = flat ol []
46   where
47     flat NoObj         rest = rest
48     flat (OrdObj x)    rest = x:rest
49     flat (ParList a b) rest = flat a (flat b rest)
50     flat (SeqList a b) rest = flat a (flat b rest)
51
52 {- DEBUGGING ONLY:
53 instance Text (OrdList a) where
54     showsPrec _ NoObj   = showString "_N_"
55     showsPrec _ (OrdObj _) = showString "_O_"
56     showsPrec _ (ParList a b) = showString "(PAR " . shows a . showChar ')'
57     showsPrec _ (SeqList a b) = showString "(SEQ " . shows a . showChar ')'
58 -}
59 \end{code}