1 module Pretty (prettyShow) where
3 import qualified CoreSyn
4 import Text.PrettyPrint.HughesPJClass
5 import Outputable ( showSDoc, ppr, Outputable, OutputableBndr)
9 instance Pretty HsFunction where
10 pPrint (HsFunction name args res) =
11 text name <> char ' ' <> parens (hsep $ punctuate comma args') <> text " -> " <> res'
13 args' = map pPrint args
16 instance Pretty x => Pretty (HsValueMap x) where
17 pPrint (Tuple maps) = parens (hsep $ punctuate comma (map pPrint maps))
18 pPrint (Single s) = pPrint s
20 instance Pretty HsValueUse where
21 pPrint Port = char 'P'
22 pPrint (State n) = char 'C' <> int n
23 pPrint (HighOrder _ _) = text "Higher Order"
25 instance Pretty FlatFunction where
26 pPrint (FlatFunction args res apps conds) =
27 (text "Args: ") $$ nest 10 (pPrint args)
28 $+$ (text "Result: ") $$ nest 10 (pPrint res)
29 $+$ (text "Apps: ") $$ nest 10 (vcat (map pPrint apps))
30 $+$ (text "Conds: ") $$ nest 10 (pPrint conds)
32 instance Pretty FApp where
33 pPrint (FApp func args res) =
34 pPrint func <> text " : " <> pPrint args <> text " -> " <> pPrint res
36 instance Pretty SignalDef where
37 pPrint (SignalDef id) = pPrint id
39 instance Pretty SignalUse where
40 pPrint (SignalUse id) = pPrint id
42 instance Pretty CondDef where
43 pPrint _ = text "TODO"
45 instance Pretty VHDLSession where
46 pPrint (VHDLSession nameCount funcs) =
47 text "NameCount: " $$ nest 15 (int nameCount)
48 $+$ text "Functions: " $$ nest 15 (vcat (map ppfunc funcs))
50 ppfunc (hsfunc, (flatfunc)) =
51 pPrint hsfunc $+$ (text "Flattened: " $$ nest 15 (pPrint flatfunc))
53 instance (OutputableBndr b) => Pretty (CoreSyn.Bind b) where
54 pPrint (CoreSyn.NonRec b expr) =
55 text "NonRec: " $$ nest 10 (prettyBind (b, expr))
56 pPrint (CoreSyn.Rec binds) =
57 text "Rec: " $$ nest 10 (vcat $ map (prettyBind) binds)
59 prettyBind :: (Outputable b, Outputable e) => (b, e) -> Doc
60 prettyBind (b, expr) =
61 text b' <> text " = " <> text expr'
64 expr' = showSDoc $ ppr expr