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