1 module Pretty (prettyShow) where
3 import qualified CoreSyn
4 import qualified Module
5 import qualified HscTypes
6 import Text.PrettyPrint.HughesPJClass
7 import Outputable ( showSDoc, ppr, Outputable, OutputableBndr)
11 instance Pretty HsFunction where
12 pPrint (HsFunction name args res) =
13 text name <> char ' ' <> parens (hsep $ punctuate comma args') <> text " -> " <> res'
15 args' = map pPrint args
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
22 instance Pretty HsValueUse where
23 pPrint Port = char 'P'
24 pPrint (State n) = char 'C' <> int n
25 pPrint (HighOrder _ _) = text "Higher Order"
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)
34 instance Pretty FApp where
35 pPrint (FApp func args res) =
36 pPrint func <> text " : " <> pPrint args <> text " -> " <> pPrint res
38 instance Pretty SignalDef where
39 pPrint (SignalDef id) = pPrint id
41 instance Pretty SignalUse where
42 pPrint (SignalUse id) = pPrint id
44 instance Pretty CondDef where
45 pPrint _ = text "TODO"
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))
53 ppfunc (hsfunc, (flatfunc)) =
54 pPrint hsfunc $+$ (text "Flattened: " $$ nest 15 (pPrint flatfunc))
55 modname = showSDoc $ Module.pprModule (HscTypes.cm_module mod)
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)
63 prettyBind :: (Outputable b, Outputable e) => (b, e) -> Doc
64 prettyBind (b, expr) =
65 text b' <> text " = " <> text expr'
68 expr' = showSDoc $ ppr expr