@@ -18,14 +18,21 @@ package hu.bme.mit.theta.xcfa.cli.checkers
18
18
import hu.bme.mit.theta.analysis.Trace
19
19
import hu.bme.mit.theta.analysis.algorithm.SafetyChecker
20
20
import hu.bme.mit.theta.analysis.algorithm.SafetyResult
21
+ import hu.bme.mit.theta.analysis.algorithm.bounded.MonolithicExpr
22
+ import hu.bme.mit.theta.analysis.algorithm.bounded.MonolithicExprCegarChecker
21
23
import hu.bme.mit.theta.analysis.algorithm.bounded.createMonolithicL2S
22
24
import hu.bme.mit.theta.analysis.algorithm.bounded.createReversed
23
25
import hu.bme.mit.theta.analysis.algorithm.mdd.MddChecker
26
+ import hu.bme.mit.theta.analysis.algorithm.mdd.MddProof
24
27
import hu.bme.mit.theta.analysis.algorithm.mdd.MddValuationCollector
25
28
import hu.bme.mit.theta.analysis.algorithm.mdd.varordering.orderVarsFromRandomStartingPoints
26
29
import hu.bme.mit.theta.analysis.expl.ExplState
27
30
import hu.bme.mit.theta.analysis.expr.ExprAction
28
31
import hu.bme.mit.theta.analysis.expr.ExprState
32
+ import hu.bme.mit.theta.analysis.pred.PredPrec
33
+ import hu.bme.mit.theta.analysis.pred.PredState
34
+ import hu.bme.mit.theta.analysis.ptr.PtrPrec
35
+ import hu.bme.mit.theta.analysis.ptr.PtrState
29
36
import hu.bme.mit.theta.analysis.unit.UnitPrec
30
37
import hu.bme.mit.theta.common.logging.Logger
31
38
import hu.bme.mit.theta.core.decl.IndexedConstDecl
@@ -68,33 +75,71 @@ fun getMddChecker(
68
75
it.copy(propExpr = True ()).createMonolithicL2S()
69
76
else it
70
77
}
71
- .let {
72
- if (mddConfig.cegar) {
73
- TODO (" MDD cannot return traces, and thus, --cegar won't work yet." )
74
- } else it
75
- }
76
78
.let { if (mddConfig.reversed) it.createReversed() else it }
77
79
78
80
val stmts =
79
81
xcfa.procedures
80
82
.flatMap { it.edges.flatMap { xcfaEdge -> xcfaEdge.getFlatLabels().map { it.toStmt() } } }
81
83
.toSet()
82
- val variableOrder = orderVarsFromRandomStartingPoints(monolithicExpr.vars, stmts, 20 )
83
84
val solverPool = SolverPool (refinementSolverFactory)
84
85
val iterationStrategy = mddConfig.iterationStrategy
85
86
86
- val checker =
87
- MddChecker .create< ExprState , ExprAction > (
88
- monolithicExpr ,
89
- variableOrder ,
87
+ val baseChecker = { abstractME : MonolithicExpr ->
88
+ MddChecker .create(
89
+ abstractME ,
90
+ orderVarsFromRandomStartingPoints(abstractME.vars, stmts, 20 ) ,
90
91
solverPool,
91
92
logger,
92
93
iterationStrategy,
93
- monolithicExpr .valToState,
94
- monolithicExpr .biValToAction,
94
+ abstractME .valToState,
95
+ abstractME .biValToAction,
95
96
)
96
- return SafetyChecker <LocationInvariants , Trace <ExprState , ExprAction >, UnitPrec > { input ->
97
- val result = checker.check(input)
97
+ }
98
+
99
+ val checker: SafetyChecker <MddProof , Trace <ExprState , ExprAction >, UnitPrec > =
100
+ (if (mddConfig.cegar) {
101
+ val cegarChecker =
102
+ MonolithicExprCegarChecker (
103
+ monolithicExpr,
104
+ baseChecker,
105
+ logger,
106
+ getSolver(mddConfig.solver, false ),
107
+ )
108
+ object :
109
+ SafetyChecker <
110
+ MddProof ,
111
+ Trace <XcfaState <PtrState <PredState >>, XcfaAction > ,
112
+ XcfaPrec <PtrPrec <PredPrec >>,
113
+ > {
114
+ override fun check (
115
+ initPrec : XcfaPrec <PtrPrec <PredPrec >>
116
+ ): SafetyResult <MddProof , Trace <XcfaState <PtrState <PredState >>, XcfaAction>> {
117
+ val result =
118
+ cegarChecker.check(initPrec.p.innerPrec) // states are PredState, actions are XcfaAction
119
+ if (result.isUnsafe) {
120
+ val cex = result.asUnsafe().cex as Trace <PredState , XcfaAction >
121
+ val locs =
122
+ (0 until cex.length()).map { i -> cex.actions[i].source } +
123
+ cex.actions[cex.length() - 1 ].target
124
+ val states = locs.mapIndexed { i, it -> XcfaState (xcfa, it, PtrState (cex.states[i])) }
125
+ return SafetyResult .unsafe(Trace .of(states, cex.actions), result.proof)
126
+ } else
127
+ return result
128
+ as SafetyResult <MddProof , Trace <XcfaState <PtrState <PredState >>, XcfaAction >>
129
+ }
130
+
131
+ override fun check ():
132
+ SafetyResult <MddProof , Trace <XcfaState <PtrState <PredState >>, XcfaAction >> {
133
+ return check(mddConfig.initPrec.predPrec(xcfa))
134
+ }
135
+ }
136
+ } else {
137
+ baseChecker(monolithicExpr)
138
+ })
139
+ as SafetyChecker <MddProof , Trace <ExprState , ExprAction >, UnitPrec >
140
+
141
+ return SafetyChecker <LocationInvariants , Trace <ExprState , ExprAction >, UnitPrec > {
142
+ val result = checker.check()
98
143
if (result.isUnsafe) {
99
144
SafetyResult .unsafe(result.asUnsafe().cex, LocationInvariants ())
100
145
} else {
0 commit comments