diff --git a/src/CFG/C.hs b/src/CFG/C.hs index 5b5d6f975a1b82d87d809b84463e4715719e24b0..6b057d9881c952dd1bb23babbcb2bd856513ac7f 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 084f60626de3a9075f5fdb37e14f49f4720012d0..e9ba0e10400b8b35424d6c0ffd0cd2e4cc1dea9d 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 047fa1c05d0fc692a0db04ef5fa8c3f3deb67aba..777e619de1952778e3f414d71628feca2f7ceccb 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"