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