-
Notifications
You must be signed in to change notification settings - Fork 1
/
Main.hs
107 lines (99 loc) · 3.11 KB
/
Main.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
{-# LANGUAGE CPP #-}
module Main where
import System.FilePath
import System.Process
import Control.Monad (when)
import System.Exit
import System.Directory
import System.IO.Error
import Control.Exception (catch)
import Control.Monad.Error (ErrorT(..))
import Language.GTL.Parser.Monad as GTL
import Language.GTL.Parser as GTL
import Language.Scade.Lexer as Sc
import Language.Scade.Parser as Sc
import Language.Promela.Pretty
import Language.Scade.Pretty
import Language.UPPAAL.PrettyPrinter
import Language.GTL.Target.PromelaKCG
import Language.GTL.Target.Local
import Language.GTL.Translation
import Language.GTL.Model
--import Language.GTL.Target.PromelaCUDD as PrBd
--import Language.GTL.Target.PrettyPrinter as PrPr
import Language.GTL.Target.Promela as PrNat
import Language.GTL.Target.UPPAAL as UPP
import Language.GTL.Target.Printer
import Language.GTL.Target.SMT as SMT
import Misc.ProgramOptions
versionString :: String
versionString = "This is the GALS Translation Language of version "++version++".\nBuilt on "++date++"."
++(case tag of
Nothing -> ""
Just rtag -> "\nBuilt from git tag: "++rtag++".")
++(case branch of
Nothing -> ""
Just rbranch -> "\nBuilt from git branch: "++rbranch++".")
++smtExts
where
#ifdef BUILD_VERSION
version = BUILD_VERSION
#else
version = "unknown"
#endif
#ifdef BUILD_DATE
date = BUILD_DATE
#else
date = "unknown date"
#endif
#ifdef BUILD_TAG
tag = Just BUILD_TAG
#else
tag = Nothing
#endif
#ifdef BUILD_BRANCH
branch = Just BUILD_BRANCH
#else
branch = Nothing
#endif
#ifdef SMTExts
smtExts = ""
#else
smtExts = "\nWARNING: Built with Z3 specific SMT output."
#endif
main = do
opts <- getOptions
when (showHelp opts) $ do
putStr usage
exitSuccess
when (showVersion opts) $ do
putStrLn versionString
exitSuccess
let gtl_file = gtlFile opts
when (gtl_file == "") $ do
ioError $ userError "No GTL file given"
exists <- doesFileExist gtl_file
when (not exists) $ do
ioError . userError $ (gtl_file ++ " does not exist.")
(createDirectoryIfMissing True $ outputPath opts)
`catch` (\e -> putStrLn $ "Could not create build dir: " ++ (ioeGetErrorString e))
gtl_str <- readFile gtl_file
mgtl <- case runGTLParser gtl gtl_str of
Left (err,pos) -> return (Left $ "At "++show pos++": "++err)
Right defs -> runErrorT $ gtlParseSpec opts defs
rgtl <- case mgtl of
Left err -> error err
Right x -> return x
case mode opts of
NativeC -> translateGTL (traceFile opts) rgtl >>= putStrLn
Local -> verifyLocal opts (dropExtension gtl_file) rgtl
--PromelaBuddy -> PrBd.verifyModel opts (dropExtension gtl_file) rgtl
{-Tikz -> do
str <- PrPr.gtlToTikz rgtl
putStrLn str-}
Pretty -> putStrLn (simplePrettyPrint rgtl)
Native -> PrNat.verifyModel opts (dropExtension gtl_file) rgtl
UPPAAL -> putStr (prettySpecification $ UPP.translateSpec rgtl)
SMTBMC -> SMT.verifyModelBMC opts rgtl
--SMTInduction -> SMT.verifyModelKInduction (smtBinary opts) rgtl
return ()