Move around a bunch of types.
[matthijs/master-project/cλash.git] / Pretty.hs
1 module Pretty (prettyShow) where
2
3 import qualified Data.Map as Map
4 import qualified CoreSyn
5 import qualified Module
6 import qualified HscTypes
7 import Text.PrettyPrint.HughesPJClass
8 import Outputable ( showSDoc, ppr, Outputable, OutputableBndr)
9
10 import HsValueMap
11 import FlattenTypes
12 import TranslatorTypes
13
14 instance Pretty HsFunction where
15   pPrint (HsFunction name args res) =
16     text name <> char ' ' <> parens (hsep $ punctuate comma args') <> text " -> " <> res'
17     where
18       args' = map pPrint args
19       res'  = pPrint res
20
21 instance Pretty x => Pretty (HsValueMap x) where
22   pPrint (Tuple maps) = parens (hsep $ punctuate comma (map pPrint maps))
23   pPrint (Single s)   = pPrint s
24
25 instance Pretty HsValueUse where
26   pPrint Port            = char 'P'
27   pPrint (State n)       = char 'C' <> int n
28   pPrint (HighOrder _ _) = text "Higher Order"
29
30 instance Pretty FlatFunction where
31   pPrint (FlatFunction args res apps conds) =
32     (text "Args: ") $$ nest 10 (pPrint args)
33     $+$ (text "Result: ") $$ nest 10 (pPrint res)
34     $+$ (text "Apps: ") $$ nest 10 (vcat (map pPrint apps))
35     $+$ (text "Conds: ") $$ nest 10 (pPrint conds)
36
37 instance Pretty FApp where
38   pPrint (FApp func args res) =
39     pPrint func <> text " : " <> pPrint args <> text " -> " <> pPrint res
40
41 instance Pretty SignalDef where
42   pPrint (SignalDef id) = pPrint id
43
44 instance Pretty SignalUse where
45   pPrint (SignalUse id) = pPrint id
46
47 instance Pretty CondDef where
48   pPrint _ = text "TODO"
49
50 instance Pretty VHDLSession where
51   pPrint (VHDLSession mod nameCount funcs) =
52     text "Module: " $$ nest 15 (text modname)
53     $+$ text "NameCount: " $$ nest 15 (int nameCount)
54     $+$ text "Functions: " $$ nest 15 (vcat (map ppfunc (Map.toList funcs)))
55     where
56       ppfunc (hsfunc, (FuncData flatfunc)) =
57         pPrint hsfunc $+$ (text "Flattened: " $$ nest 15 (pPrint flatfunc))
58       modname = showSDoc $ Module.pprModule (HscTypes.cm_module mod)
59
60 instance (OutputableBndr b) => Pretty (CoreSyn.Bind b) where
61   pPrint (CoreSyn.NonRec b expr) =
62     text "NonRec: " $$ nest 10 (prettyBind (b, expr))
63   pPrint (CoreSyn.Rec binds) =
64     text "Rec: " $$ nest 10 (vcat $ map (prettyBind) binds)
65
66 prettyBind :: (Outputable b, Outputable e) => (b, e) -> Doc
67 prettyBind (b, expr) =
68   text b' <> text " = " <> text expr'
69   where
70     b' = showSDoc $ ppr b
71     expr' = showSDoc $ ppr expr