1 module Pretty (prettyShow) where
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)
10 import TranslatorTypes
12 instance Pretty HsFunction where
13 pPrint (HsFunction name args res) =
14 text name <> char ' ' <> parens (hsep $ punctuate comma args') <> text " -> " <> res'
16 args' = map pPrint args
19 instance Pretty x => Pretty (HsValueMap x) where
20 pPrint (Tuple maps) = parens (hsep $ punctuate comma (map pPrint maps))
21 pPrint (Single s) = pPrint s
23 instance Pretty HsValueUse where
24 pPrint Port = char 'P'
25 pPrint (State n) = char 'C' <> int n
26 pPrint (HighOrder _ _) = text "Higher Order"
28 instance Pretty FlatFunction where
29 pPrint (FlatFunction args res apps conds) =
30 (text "Args: ") $$ nest 10 (pPrint args)
31 $+$ (text "Result: ") $$ nest 10 (pPrint res)
32 $+$ (text "Apps: ") $$ nest 10 (vcat (map pPrint apps))
33 $+$ (text "Conds: ") $$ nest 10 (pPrint conds)
35 instance Pretty FApp where
36 pPrint (FApp func args res) =
37 pPrint func <> text " : " <> pPrint args <> text " -> " <> pPrint res
39 instance Pretty SignalDef where
40 pPrint (SignalDef id) = pPrint id
42 instance Pretty SignalUse where
43 pPrint (SignalUse id) = pPrint id
45 instance Pretty CondDef where
46 pPrint _ = text "TODO"
48 instance Pretty VHDLSession where
49 pPrint (VHDLSession mod nameCount funcs) =
50 text "Module: " $$ nest 15 (text modname)
51 $+$ text "NameCount: " $$ nest 15 (int nameCount)
52 $+$ text "Functions: " $$ nest 15 (vcat (map ppfunc (Map.toList funcs)))
54 ppfunc (hsfunc, (flatfunc)) =
55 pPrint hsfunc $+$ (text "Flattened: " $$ nest 15 (pPrint flatfunc))
56 modname = showSDoc $ Module.pprModule (HscTypes.cm_module mod)
58 instance (OutputableBndr b) => Pretty (CoreSyn.Bind b) where
59 pPrint (CoreSyn.NonRec b expr) =
60 text "NonRec: " $$ nest 10 (prettyBind (b, expr))
61 pPrint (CoreSyn.Rec binds) =
62 text "Rec: " $$ nest 10 (vcat $ map (prettyBind) binds)
64 prettyBind :: (Outputable b, Outputable e) => (b, e) -> Doc
65 prettyBind (b, expr) =
66 text b' <> text " = " <> text expr'
69 expr' = showSDoc $ ppr expr