From a4b2c146327ce024612ad91c83d5cf907fbe5a36 Mon Sep 17 00:00:00 2001 From: Francis Russell Date: Wed, 10 Oct 2012 16:36:59 +0100 Subject: [PATCH] Add pretty printing of symbol tables. --- OFC/SecondLevel.hs | 10 ++++++++-- OFC/TopLevel.hs | 9 +++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/OFC/SecondLevel.hs b/OFC/SecondLevel.hs index c011993..a40c7f2 100644 --- a/OFC/SecondLevel.hs +++ b/OFC/SecondLevel.hs @@ -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 { diff --git a/OFC/TopLevel.hs b/OFC/TopLevel.hs index 1239152..a7711fa 100644 --- a/OFC/TopLevel.hs +++ b/OFC/TopLevel.hs @@ -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 -- 2.47.3