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])
$$ 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
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
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
_ <- 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
module TargetMapping where
data TargetType =
- FortranParameter [FortranParameterProperties] |
- PPDFunctionSet [PPDFunctionSetProperties]
+ FortranParameter [FortranParameterProperty] |
+ PPDFunctionSet [PPDFunctionSetProperty]
deriving Show
data FortranType =
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