]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Add pretty printing of symbol tables.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Wed, 10 Oct 2012 15:36:59 +0000 (16:36 +0100)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Wed, 10 Oct 2012 15:36:59 +0000 (16:36 +0100)
OFC/SecondLevel.hs
OFC/TopLevel.hs

index c011993319f9c78626574f209db3bd35f4d074d0..a40c7f2a39dba70b9c41776b2b8676b0d320eb1c 100644 (file)
@@ -16,7 +16,7 @@ import qualified OFC.TopLevel as TopLevel
 import Data.Complex
 import Text.PrettyPrint
 import Data.Map (Map)
-import Data.List (foldl', intersperse)
+import Data.List (foldl', intersperse, intercalate)
 import qualified Data.Map as Map
 
 type SymbolTable = Map String SymbolType
@@ -104,9 +104,15 @@ instance PrettyPrintable OFL2 where
   toDoc ofl2 = vcat [symbolDoc, assignmentsDoc]
     where
     symbolDoc = text "Symbol table:"
-      $$ nest 1 (vcat [text $ show x | x <- Map.assocs $ symbols ofl2])
+      $$ nest 1 (vcat [symAssocToDoc x | x <- Map.assocs $ symbols ofl2])
     assignmentsDoc = text "Assignments: "
       $$ nest 1 (vcat $ map toDoc $ assignments ofl2)
+    symAssocToDoc (name, ValueTag baseType indexTypes) = text $
+      (show baseType) ++ " " ++ name ++ case indexTypes of
+        [] -> ""
+        nonNil -> "[" ++ (intercalate ", " (map TopLevel.toOFLString nonNil)) ++ "]"
+    symAssocToDoc (name, IndexTag indexType quant) = 
+      text $ TopLevel.toOFLString indexType ++ " " ++ name ++ " (" ++ show quant ++ ")"
   
 emptyOFL2 :: OFL2
 emptyOFL2 = OFL2 { 
index 1239152145b300067d9298946a4bda159b4fa607..a7711fa130f9b1ad7d6bae037f084460c49113b2 100644 (file)
@@ -35,7 +35,7 @@ module OFC.TopLevel
 import OFC.TargetMapping
 import OFC.Common
 import Text.PrettyPrint
-import Data.List (foldl', intersperse)
+import Data.List (foldl', intersperse, intercalate)
 import Data.Map (Map)
 import qualified Data.Map as Map
 import Data.Set (Set)
@@ -124,13 +124,18 @@ instance PrettyPrintable OFL where
   toDoc ofl = vcat [symbolDoc, assignmentsDoc, targetMappingsDoc, outputFunctionDoc]
     where
     symbolDoc = text "Symbol table:"
-      $$ nest 1 (vcat [text $ show x | x <- Map.assocs $ symbols ofl])
+      $$ nest 1 (vcat [symAssocToDoc x | x <- Map.assocs $ symbols ofl])
     assignmentsDoc = text "Assignments: "
       $$ nest 1 (vcat $ map toDoc $ assignments ofl)
     targetMappingsDoc = text "Target properties: "
       $$ nest 1 (vcat [text $ show x | x <- Map.assocs $ targetMappings ofl])
     outputFunctionDoc = text "OutputFunction:"
       $$ nest 1 (text $ show $ outputFunction ofl)
+    symAssocToDoc (name, ValueTag baseType indexTypes) = text $
+      (toOFLString baseType) ++ " " ++ name ++ case indexTypes of 
+        [] -> ""
+        nonNil -> "[" ++ (intercalate ", " (map toOFLString nonNil)) ++ "]"
+    symAssocToDoc (name, IndexTag indexType) = text $ toOFLString indexType ++ " " ++ name
   
 -- Symbol table manipulators
 addValueDeclaration :: OFL -> String -> BaseType -> [IndexType] -> OFL