diff --git a/src/CFG/Parser.hs b/src/CFG/Parser.hs index 901368ec3ac4f92655fde5250fddaba1cf86e692..62145cd9b763c38755123447d2ce7605891494a0 100644 --- a/src/CFG/Parser.hs +++ b/src/CFG/Parser.hs @@ -26,6 +26,7 @@ instance FromJSON (Function ()) where instance FromJSON FunctionKind where parseJSON (String "subtask") = pure KindSubtask parseJSON (String "function") = pure KindFunction + parseJSON (String "isr") = pure KindISR instance FromJSON Block where parseJSON (Object v) = Block diff --git a/src/CFG/Types.hs b/src/CFG/Types.hs index 1414bc27ec0d709b8bfc8caa5b92f7e7777b08f5..85c35e90a6241bbda5748c227b0e79c8e04adba9 100644 --- a/src/CFG/Types.hs +++ b/src/CFG/Types.hs @@ -21,7 +21,7 @@ instance Comonad Function where extract = funAnnotation extend f x = let newAnno = f x in x { funAnnotation = newAnno } -data FunctionKind = KindFunction | KindSubtask +data FunctionKind = KindFunction | KindSubtask | KindISR deriving (Show, Eq) data Block = Block diff --git a/test/CFG/ParserSpec.hs b/test/CFG/ParserSpec.hs index f2a727d7effa82593f33eead5d40c4fbfe3e1171..f0fca647504422513b89b4297b1c308445068cb6 100644 --- a/test/CFG/ParserSpec.hs +++ b/test/CFG/ParserSpec.hs @@ -17,6 +17,7 @@ spec = do example1 example2 both + isrExample example1Input :: BS.ByteString example1Input = [here| @@ -177,3 +178,84 @@ both :: Spec both = it "parses both functions" $ parseFile ("[" <> example1Input <> ", " <> example2Input <> "]") `shouldBe` Right (example1Output <> example2Output) + +isrExampleInput :: BS.ByteString +isrExampleInput = [here| +{ + "kind": "isr", + "entry": "ABB197/kickoff", + "abbs": [ + { + "isKickoff": false, + "call": null, + "successors": [ + "ABB5/ActivateTask" + ], + "name": "ABB4" + }, + { + "isKickoff": false, + "call": { + "type": "syscall", + "name": "OSEKOS_ActivateTask_BB35" + }, + "successors": [ + "ABB6" + ], + "name": "ABB5/ActivateTask" + }, + { + "isKickoff": false, + "call": null, + "successors": [ + "ABB195/iret" + ], + "name": "ABB6" + }, + { + "isKickoff": false, + "call": { + "type": "syscall", + "name": "OSEKOS_iret__ABB195" + }, + "successors": [], + "name": "ABB195/iret" + }, + { + "isKickoff": true, + "call": { + "type": "syscall", + "name": "OSEKOS_kickoff__ABB197" + }, + "successors": [ + "ABB4" + ], + "name": "ABB197/kickoff" + } + ], + "subtask": "ISR1", + "name": "ISR1" +} +|] + +isrExampleOutput :: [Function ()] +isrExampleOutput = [ + Function + { funKind = KindISR + , funName = "ISR1" + , funSubtask = "ISR1" + , funEntryNode = "ABB197/kickoff" + , funBlocks = + [ Block "ABB4" ["ABB5/ActivateTask"] Nothing False + , Block "ABB5/ActivateTask" ["ABB6"] (Just $ SystemCall "OSEKOS_ActivateTask_BB35") False + , Block "ABB6" ["ABB195/iret"] Nothing False + , Block "ABB195/iret" [] (Just $ SystemCall "OSEKOS_iret__ABB195") False + , Block "ABB197/kickoff" ["ABB4"] (Just $ SystemCall "OSEKOS_kickoff__ABB197") True + ] + , funAnnotation = () + } + ] + +isrExample :: Spec +isrExample = it "parses an ISR" $ + parseFile ("[" <> isrExampleInput <> "]") `shouldBe` Right isrExampleOutput