diff --git a/files/mockup_prelude.cc b/files/mockup_prelude.cc index 5a865c00d21149f8b9dc36be34e8d6cbeb0c2251..b8fe886a3a876c0efad95a36604c26f3a1d64647 100644 --- a/files/mockup_prelude.cc +++ b/files/mockup_prelude.cc @@ -118,9 +118,3 @@ int _decisionMaker(int i) { return res; } - -void PreIdleHook() { - _print_os_state("PreIdleHook", __LINE__); - ShutdownMachine(); -} - diff --git a/src/CFG/C.hs b/src/CFG/C.hs index 3e4b9813abc9d2ae34306977178db839069836b1..5b5d6f975a1b82d87d809b84463e4715719e24b0 100644 --- a/src/CFG/C.hs +++ b/src/CFG/C.hs @@ -6,6 +6,7 @@ module CFG.C , generateDecl , compileToCAll , declareExtern + , preIdleHook ) where import Control.Comonad @@ -26,6 +27,7 @@ compileToCAll funs = include <> generateDecls funs <> "\n" <> T.unlines (map compileToC funs) + <> preIdleHook include :: Text include = "#include <mockup_prelude.cc>\n\n" @@ -66,6 +68,12 @@ declareExtern funs = mconcat $ callName (Call name _) = Just name callName _ = Nothing +preIdleHook :: Text +preIdleHook = "void PreIdleHook() {\n" + <> " _print_os_state(\"PreIdleHook\", __LINE__);\n" + <> " ShutdownMachine();\n" + <> "}\n" + instrsToC :: [Instr] -> Text instrsToC = (<> "\n") . mconcat . intersperse "\n" . map instrToC diff --git a/test/CFG/CSpec.hs b/test/CFG/CSpec.hs index faa57bda69214fb00d893e26e047c20fca93aef9..047fa1c05d0fc692a0db04ef5fa8c3f3deb67aba 100644 --- a/test/CFG/CSpec.hs +++ b/test/CFG/CSpec.hs @@ -141,6 +141,7 @@ compileToCAllTest = describe "compileToCAll" $ do <> example1FunctionCDecl <> example2FunctionCDecl <> "\n" <> example1FunctionC <> "\n" <> example2FunctionC <> "\n" + <> preIdleHook ) it "compiles two tasks" $ @@ -151,6 +152,7 @@ compileToCAllTest = describe "compileToCAll" $ do <> example1TaskCDecl <> example2TaskCDecl <> "\n" <> example1TaskC <> "\n" <> example2TaskC <> "\n" + <> preIdleHook ) it "compiles one task and one function" $ @@ -161,6 +163,7 @@ compileToCAllTest = describe "compileToCAll" $ do <> example1TaskCDecl <> example2FunctionCDecl <> "\n" <> example1TaskC <> "\n" <> example2FunctionC <> "\n" + <> preIdleHook ) it "compiles one tasks and one ISR" $ @@ -171,6 +174,7 @@ compileToCAllTest = describe "compileToCAll" $ do <> example1TaskCDecl <> "\n" <> example1TaskC <> "\n" <> example2ISRC <> "\n" + <> preIdleHook )