From 20061080ce82479722e70a54d18048be1d0036e8 Mon Sep 17 00:00:00 2001
From: Hans-Peter Deifel <hpd@hpdeifel.de>
Date: Wed, 19 Oct 2016 01:19:40 +0200
Subject: [PATCH] Add --interrupts flag to mockup generator

Will be used to enable interrupt triggering, but has not implementation
right now
---
 src/CFG/C.hs      |  4 ++--
 src/main/Main.hs  | 18 ++++++++++++++----
 test/CFG/CSpec.hs |  8 ++++----
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/src/CFG/C.hs b/src/CFG/C.hs
index 5b5d6f9..6b057d9 100644
--- a/src/CFG/C.hs
+++ b/src/CFG/C.hs
@@ -20,8 +20,8 @@ import           CFG.IR
 import           CFG.Types
 
 -- | Compile multiple functions to C, inckluding declarations
-compileToCAll :: [Function [Instr]] -> Text
-compileToCAll funs = include
+compileToCAll :: Bool -> [Function [Instr]] -> Text
+compileToCAll _ funs = include
                   <> declareExtern funs
                   <> "\n"
                   <> generateDecls funs
diff --git a/src/main/Main.hs b/src/main/Main.hs
index 084f606..e9ba0e1 100644
--- a/src/main/Main.hs
+++ b/src/main/Main.hs
@@ -14,11 +14,11 @@ import CFG.C
 import CFG.Sanitize
 import Search.Search
 
-data Command = Mockup | Search SearchOpts
+data Command = Mockup MockupOpts | Search SearchOpts
 
 optParser :: Parser Command
 optParser = subparser
-  (  command "mockup" (info (helper <*> pure Mockup) (progDesc "Generate mockup"))
+  (  command "mockup" (info (helper <*> (Mockup <$> mockupOptParser)) (progDesc "Generate mockup"))
   <> command "search" (info (helper <*> (Search <$> searchOptParser))
                        (progDesc "Extract CFG by running EXECUTABLE"))
   )
@@ -35,16 +35,26 @@ searchOptParser = SearchOpts
             <> help "Identify equal states at different source locations"
              )
 
+data MockupOpts = MockupOpts
+  { triggerSyscalls :: Bool
+  }
+
+mockupOptParser :: Parser MockupOpts
+mockupOptParser = MockupOpts
+  <$> switch ( long "interrupts"
+            <> help "Genenrate code to trigger interrupts"
+             )
+
 main :: IO ()
 main = do
   cmd <- execParser $ info (helper <*> optParser)
             ( fullDesc <> progDesc "dOSEK verification tool" )
   case cmd of
     (Search opts) -> driver (mockupExecutable opts) (identifyStates opts)
-    Mockup        -> do
+    Mockup opts   -> do
       cntnt <- BS.getContents
       case P.parseFile cntnt of
         Left err -> putStrLn err
         Right res -> do
           let funs = compileToIRAll $ map (cfg . sanitizeNames) $ appFunctions res
-          T.putStrLn $ compileToCAll $ map (fmap snd) funs
+          T.putStrLn $ compileToCAll (triggerSyscalls opts) $ map (fmap snd) funs
diff --git a/test/CFG/CSpec.hs b/test/CFG/CSpec.hs
index 047fa1c..777e619 100644
--- a/test/CFG/CSpec.hs
+++ b/test/CFG/CSpec.hs
@@ -136,7 +136,7 @@ include = "#include <mockup_prelude.cc>"
 compileToCAllTest :: Spec
 compileToCAllTest = describe "compileToCAll" $ do
   it "compiles two functions" $
-    compileToCAll [example1Function, example2Function]
+    compileToCAll False [example1Function, example2Function]
       `shouldBe` ( include <> "\n\n" <> exampleExternDecls <> "\n"
                  <> example1FunctionCDecl <> example2FunctionCDecl <> "\n"
                  <> example1FunctionC <> "\n"
@@ -145,7 +145,7 @@ compileToCAllTest = describe "compileToCAll" $ do
                  )
 
   it "compiles two tasks" $
-    compileToCAll [example1Function { funKind = KindSubtask },
+    compileToCAll False [example1Function { funKind = KindSubtask },
                    example2Function { funKind = KindSubtask }
                   ]
       `shouldBe` (  include <> "\n\n" <> exampleExternDecls <> "\n"
@@ -156,7 +156,7 @@ compileToCAllTest = describe "compileToCAll" $ do
                  )
 
   it "compiles one task and one function" $
-    compileToCAll [example1Function { funKind = KindSubtask },
+    compileToCAll False [example1Function { funKind = KindSubtask },
                    example2Function
                   ]
       `shouldBe` (  include <> "\n\n" <> exampleExternDecls <> "\n"
@@ -167,7 +167,7 @@ compileToCAllTest = describe "compileToCAll" $ do
                  )
 
   it "compiles one tasks and one ISR" $
-    compileToCAll [example1Function { funKind = KindSubtask },
+    compileToCAll True [example1Function { funKind = KindSubtask },
                    example2Function { funKind = KindISR }
                   ]
       `shouldBe` (  include <> "\n\n" <> exampleExternDecls <> "\n"
-- 
GitLab