From 4a84220553395e4cf1198c61eef4c10c9960f079 Mon Sep 17 00:00:00 2001
From: Hans-Peter Deifel <hpd@hpdeifel.de>
Date: Tue, 18 Oct 2016 00:49:10 +0200
Subject: [PATCH] Parse new function kind 'isr'

TODO: ISRs are not yet correctly compiled to C
---
 src/CFG/Parser.hs      |  1 +
 src/CFG/Types.hs       |  2 +-
 test/CFG/ParserSpec.hs | 82 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 84 insertions(+), 1 deletion(-)

diff --git a/src/CFG/Parser.hs b/src/CFG/Parser.hs
index 901368e..62145cd 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 1414bc2..85c35e9 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 f2a727d..f0fca64 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
-- 
GitLab