Skip to content

Commit 00f2193

Browse files
major update:
-using z3 smt solver -added simple assertion propagation algorithm (propagate conditions and statement predicates until a statement that effects then or a call state) -pruning DEA transitions that are not viable -removing DEA guards that do not need to be checked
1 parent 7567c1b commit 00f2193

27 files changed

+2043
-1329
lines changed

src/CFA.hs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--
2+
-- Licensed under the Apache License, Version 2.0 (the "License");
3+
-- you may not use this file except in compliance with the License.
4+
-- You may obtain a copy of the License at
5+
--
6+
-- http://www.apache.org/licenses/LICENSE-2.0
7+
--
8+
-- Unless required by applicable law or agreed to in writing, software
9+
-- distributed under the License is distributed on an "AS IS" BASIS,
10+
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
-- See the License for the specific language governing permissions and
12+
-- limitations under the License.
13+
14+
module CFA (module CFA.CFA, module CFA.CFGtoCFA) where
15+
16+
import CFA.CFA
17+
import CFA.CFGtoCFA
18+
import SMT
19+
import Parseable

src/CFA/CFA.hs

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
module CFA.CFA where
2+
3+
import Data.List
4+
import qualified DEA.DEA as DEA
5+
import DEA.Parsing
6+
import SMT.SMTLib2
7+
import Data.List
8+
import Control.Monad hiding (guard)
9+
import Text.Parsec hiding (State, label)
10+
import Text.Parsec.String
11+
12+
import Parseable
13+
14+
data Event = Epsilon | DEAEvent DEA.Event deriving (Eq, Ord, Show)
15+
---------
16+
instance Parseable Event where
17+
display Epsilon = ""
18+
display (DEAEvent ev) = display ev
19+
{-parser = do char 'ϵ'
20+
return Epsilon
21+
<||> do ev <- parser
22+
return DEAEvent ev-}
23+
---------------
24+
---------------
25+
-- --the Z3Asserts here represent the value associated with the parameters of the called CFA
26+
--data Call = Call State CFA [Z3Assert] | DelegateCall State CFA [Z3Assert] | DynamicCall State [Z3Assert]
27+
28+
--TODO need to model input parameters for more precise model checking
29+
data Call = Call State CFAReference | DelegateCall State | DynamicCall State deriving (Eq, Ord, Show)
30+
31+
32+
data State = State String deriving (Eq, Ord, Show)
33+
--------
34+
instance Parseable State where
35+
display (State s) = s
36+
{- parser = do s <- many alphaNum
37+
return State s-}
38+
-----------------
39+
-----------------
40+
type CFAReference = String
41+
-----------------
42+
-----------------
43+
type Z3Condition = [Z3Construct]
44+
type Z3Statement = [Z3Construct]
45+
46+
data Transition =
47+
Transition {
48+
src, dst :: State,
49+
condition :: Z3Condition,
50+
stmt :: Z3Statement,
51+
event :: Event
52+
} deriving (Eq, Ord, Show)
53+
--------
54+
instance Parseable Transition where
55+
{- parser = do src <- parser
56+
spaces
57+
string "->"
58+
dst <- parser
59+
spaces
60+
char '['
61+
spaces
62+
string "label"
63+
spaces
64+
char '='
65+
spaces
66+
char '"'
67+
cond <- parser
68+
spaces
69+
string ">>"
70+
spaces
71+
act <- parser
72+
spaces
73+
string ">>"
74+
spaces
75+
event <- parser
76+
char '"'
77+
spaces
78+
char ']'
79+
spaces
80+
char ';'
81+
spaces
82+
return (Transition (src) (dst) (cond) (act) (event))-}
83+
display (Transition src dst cond act event) = (display src) ++ " -> " ++ (display dst) ++ " [label = \"" ++ (foldr (++) "" $ map display cond) ++ " >> " ++ (foldr (++) "" $ map display act) ++ " >> " ++ (display event) ++ "\"];\n"
84+
-----------------
85+
-----------------
86+
87+
data CFA = CFA{
88+
name :: String,
89+
sortDecs :: [SortDeclaration],
90+
varDecs :: [VarDeclaration],
91+
transitions :: [Transition],
92+
states :: [State],
93+
initial :: State,
94+
end :: [State],
95+
calls :: [Call]
96+
} deriving (Eq, Ord, Show)
97+
--------
98+
instance Parseable CFA where
99+
{- parser = do sortDecss <- many parser
100+
varDecss <- many parser
101+
string "digraph"
102+
spaces
103+
char '"'
104+
spaces
105+
cfaName <- many alphaNum
106+
char '"'
107+
spaces
108+
char '{'
109+
spaces
110+
string "initial"
111+
spaces
112+
string "->"
113+
spaces
114+
initialState <- parser
115+
spaces
116+
char ';'
117+
spaces
118+
endStates <- many (parser <* spaces <* string "->" <* spaces <* string "end" <* spaces <* char ';')
119+
transitionList <- many parser
120+
spaces
121+
-- try string "labelloc=\"t\";"
122+
-- string "label=\""
123+
-- spaces
124+
-- signat <- parser
125+
-- spaces
126+
-- string "\";"
127+
-- spaces
128+
char '}'
129+
eof
130+
return CFA{name = cfaName, sortDecs = sortDecss, varDecs = varDecss, transitions = transitionList, states = statesFromTransitions transitionList [], initial = initialState, end = endStates}-}
131+
132+
display cfa = foldr (++) "" (map display (sortDecs cfa)) ++
133+
foldr (++) "" (map display (varDecs cfa)) ++ "\n\n" ++
134+
"digraph \"" ++ display (name cfa) ++ "\"{\n" ++
135+
foldr (++) "" (map display (transitions cfa)) ++
136+
foldr (++) "" (nub [display s ++ "[style=filled, color=gray, label=\"call: " ++ name ++ "\"]" ++ ";\n" | (Call s name) <- calls cfa]) ++
137+
foldr (++) "" (nub [display s ++ "[style=filled, color=gray, label=\"delegate call\"]" ++ ";\n" | (DelegateCall s) <- calls cfa]) ++
138+
foldr (++) "" (nub [display s ++ "[style=filled, color=gray, label=\"dynamic call\"]" ++ ";\n" | (DynamicCall s) <- calls cfa]) ++
139+
foldr (++) "" (nub [display (s) ++ "[style=filled, color=lightgreen]" ++ ";\n" | s <- (end cfa)])
140+
++ "\n}\n"
141+
-----------------
142+
-----------------
143+
144+
emptyCFA :: CFA
145+
emptyCFA = CFA "" [] [] [] [State "0"] (State "0") [State "0"] []

0 commit comments

Comments
 (0)