]> git.unchartedbackwaters.co.uk Git - francis/ofc.git/commitdiff
Parse output function specification.
authorFrancis Russell <francis@unchartedbackwaters.co.uk>
Sun, 16 Sep 2012 20:29:04 +0000 (21:29 +0100)
committerFrancis Russell <francis@unchartedbackwaters.co.uk>
Sun, 16 Sep 2012 20:29:04 +0000 (21:29 +0100)
src/HighLevel.hs
src/Parser.hs
src/TargetMapping.hs

index a1bbd00f9aba298f456a9de7a197306552be18bf..5f462809cdb0b844b8b1e432711a4f7de30d0cf7 100644 (file)
@@ -40,11 +40,12 @@ type MappingTable = Map String TargetType
 data OFL = OFL {
   symbols :: SymbolTable,
   assignments :: [Assignment],
-  targetMappings :: MappingTable
+  targetMappings :: MappingTable,
+  outputFunction :: FortranFunction
 }
 
 toDoc :: OFL -> Doc
-toDoc ofl = symbolDoc $$ assignmentsDoc $$ targetMappingsDoc
+toDoc ofl = symbolDoc $$ assignmentsDoc $$ targetMappingsDoc $$ outputFunctionDoc
   where
   symbolDoc = text "Symbol table:"
     $$ nest 1 (foldl' ($$) Text.PrettyPrint.empty [text $ show x | x <- assocs $ symbols ofl])
@@ -52,6 +53,8 @@ toDoc ofl = symbolDoc $$ assignmentsDoc $$ targetMappingsDoc
     $$ 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])
+  outputFunctionDoc = text "OutputFunction:"
+    $$ nest 1 (text $ show $ outputFunction ofl)
 
 instance Show OFL where
   show ofl = renderStyle Style {mode = PageMode, lineLength=10, ribbonsPerLine=1.5 } $ toDoc ofl
@@ -76,6 +79,9 @@ addAssignment ofl lhs rhs =
     Right () -> ofl { assignments = (Assign lhs rhs):(assignments ofl) } 
     Left reason -> error $ show reason
 
+setOutputFunction :: OFL -> FortranFunction -> OFL
+setOutputFunction ofl function = ofl { outputFunction = function }
+
 errorOnDuplicate :: Show k => k -> a -> a -> a
 errorOnDuplicate key _ _ = error $ "Attempted redefinition of symbol " ++ show key
 
@@ -128,7 +134,7 @@ getType ofl (Power a b) = promoteType (getType ofl a) (getType ofl b)
 getType ofl (Derivative e _) = getType ofl e
 
 emptyOFL :: OFL
-emptyOFL = OFL { assignments = [], symbols = Map.empty, targetMappings = Map.empty }
+emptyOFL = OFL { assignments = [], symbols = Map.empty, targetMappings = Map.empty, outputFunction = undefined}
 
 -- Validation
 data ValidationError = Message String deriving Show
index 68937ed6652195cb24e0c1ad8024ad38028a1c6e..4ca63d35a1028d0789259d2853a7c46844fd7008 100644 (file)
@@ -129,10 +129,32 @@ parseOFL = do
   _ <- many1 parseAssignment
   _ <- parseTarget
   _ <- many parseBinding
-  _ <- many anyChar
+  _ <- parseOutputFunction
   eof
   getState
 
+parseOutputFunction = do
+  _ <- lSymbol "OutputFunction"
+  ident <- parseIdentifier
+  _ <- lSymbol "="
+  _ <- lSymbol "fortran_function"
+  _ <- lSymbol "with"
+  properties <- lCommaSep parseFortranFunctionProperty
+  modifyState(\x -> setOutputFunction x $ FortranFunction ident properties)
+  <?> "output function specification"
+
+parseFortranFunctionProperty = do
+  parseFortranFunctionNameProperty <|> parseFortranFunctionParamsProperty
+  where
+  parseFortranFunctionNameProperty = do 
+    _ <- lSymbol "name"
+    name <- lParens lStringLiteral
+    return $ FortranFunctionName name
+  parseFortranFunctionParamsProperty = do 
+    _ <- lSymbol "params"
+    idents <- lParens $ lCommaSep lIdentifier
+    return $ FortranFunctionParams idents
+
 parseBinding = do
   _ <- lSymbol "Variable" <|> lSymbol "Parameter"
   ident <- parseIdentifier
index 56692834809df84fecad2fbabf6adb9bde3e12f2..6fc4b0357b09ff0f0890df84141a06338ad183fe 100644 (file)
@@ -1,8 +1,8 @@
 module TargetMapping where
 
 data TargetType = 
-  FortranParameter [FortranParameterProperties] |
-  PPDFunctionSet [PPDFunctionSetProperties]
+  FortranParameter [FortranParameterProperty] |
+  PPDFunctionSet [PPDFunctionSetProperty]
   deriving Show
 
 data FortranType = 
@@ -23,14 +23,23 @@ data SpaceInfo =
   FinePsinc [String]
   deriving Show
 
-data FortranParameterProperties =
+data FortranParameterProperty =
   ParamName String |
   ParamType FortranType |
   Space SpaceInfo |
   Indexed [String]
   deriving Show
 
-data PPDFunctionSetProperties =
+data PPDFunctionSetProperty =
   PPDData String |
   PPDBasis String
   deriving Show
+
+data FortranFunction =
+  FortranFunction String [FortranFunctionProperty]
+  deriving Show
+
+data FortranFunctionProperty =
+  FortranFunctionName String |
+  FortranFunctionParams [String]
+  deriving Show