]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Add pretty printing for parsed representation.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Sun, 16 Sep 2012 10:54:02 +0000 (11:54 +0100)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Sun, 16 Sep 2012 10:54:02 +0000 (11:54 +0100)
ofc.cabal
src/HighLevel.hs

index b7d21606be1d3c8420b3544e90b9175466e47dab..c2fa95d79ad49d96f96d5a20711c27179364319c 100644 (file)
--- a/ofc.cabal
+++ b/ofc.cabal
@@ -10,4 +10,4 @@ Executable ofc
   Main-is:           Main.hs
   Hs-Source-Dirs:    src
   GHC-Options:       -Wall -fno-warn-missing-signatures
-  Build-Depends:     base, containers, parsec >= 3
+  Build-Depends:     base, containers, parsec >= 3, pretty
index e00f5b0ba54c12ecb456e59a6554a3828110c76d..a1bbd00f9aba298f456a9de7a197306552be18bf 100644 (file)
@@ -1,6 +1,7 @@
 module HighLevel where
 import TargetMapping
-import Data.Map as Map (Map, lookup, insertWithKey, empty)
+import Text.PrettyPrint
+import Data.Map as Map (Map, lookup, insertWithKey, assocs, empty)
 import Data.List (foldl')
 
 -- The top-level types
@@ -40,7 +41,20 @@ data OFL = OFL {
   symbols :: SymbolTable,
   assignments :: [Assignment],
   targetMappings :: MappingTable
-} deriving Show
+}
+
+toDoc :: OFL -> Doc
+toDoc ofl = symbolDoc $$ assignmentsDoc $$ targetMappingsDoc
+  where
+  symbolDoc = text "Symbol table:"
+    $$ nest 1 (foldl' ($$) Text.PrettyPrint.empty [text $ show x | x <- assocs $ symbols ofl])
+  assignmentsDoc = text "Assignments: "
+    $$ nest 1 (foldl' ($$) Text.PrettyPrint.empty [text $ show x | x <- assignments ofl])
+  targetMappingsDoc = text "Target properties: "
+    $$ nest 1 (foldl' ($$) Text.PrettyPrint.empty [text $ show x | x <- assocs $ targetMappings ofl])
+
+instance Show OFL where
+  show ofl = renderStyle Style {mode = PageMode, lineLength=10, ribbonsPerLine=1.5 } $ toDoc ofl
 
 -- Symbol table manipulators
 addValueDeclaration :: OFL -> String -> BaseType -> [IndexType] -> OFL