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)
12 import TranslatorTypes
14 instance Pretty HsFunction where
15 pPrint (HsFunction name args res) =
16 text name <> char ' ' <> parens (hsep $ punctuate comma args') <> text " -> " <> res'
18 args' = map pPrint args
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
25 instance Pretty HsValueUse where
26 pPrint Port = char 'P'
27 pPrint (State n) = char 'C' <> int n
28 pPrint (HighOrder _ _) = text "Higher Order"
30 instance Pretty id => Pretty (FlatFunction' id) where
31 pPrint (FlatFunction args res apps conds sigs) =
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 $+$ text "Signals: " $$ nest 10 (pPrint sigs)
38 instance Pretty id => Pretty (FApp id) where
39 pPrint (FApp func args res) =
40 pPrint func <> text " : " <> pPrint args <> text " -> " <> pPrint res
42 instance Pretty id => Pretty (CondDef id) where
43 pPrint _ = text "TODO"
45 instance Pretty id => Pretty (Signal id) where
46 pPrint (Signal id) = pPrint id
48 instance Pretty NamedSignal where
49 pPrint (NamedSignal name) = pPrint name
51 instance Pretty VHDLSession where
52 pPrint (VHDLSession mod nameCount funcs) =
53 text "Module: " $$ nest 15 (text modname)
54 $+$ text "NameCount: " $$ nest 15 (int nameCount)
55 $+$ text "Functions: " $$ nest 15 (vcat (map ppfunc (Map.toList funcs)))
57 ppfunc (hsfunc, (FuncData flatfunc)) =
58 pPrint hsfunc $+$ (text "Flattened: " $$ nest 15 (ppffunc flatfunc))
59 ppffunc (Just (Left f)) = pPrint f
60 ppffunc (Just (Right f)) = pPrint f
61 ppffunc Nothing = text "Nothing"
62 modname = showSDoc $ Module.pprModule (HscTypes.cm_module mod)
64 instance (OutputableBndr b) => Pretty (CoreSyn.Bind b) where
65 pPrint (CoreSyn.NonRec b expr) =
66 text "NonRec: " $$ nest 10 (prettyBind (b, expr))
67 pPrint (CoreSyn.Rec binds) =
68 text "Rec: " $$ nest 10 (vcat $ map (prettyBind) binds)
70 prettyBind :: (Outputable b, Outputable e) => (b, e) -> Doc
71 prettyBind (b, expr) =
72 text b' <> text " = " <> text expr'
75 expr' = showSDoc $ ppr expr