-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
359e5b6
commit 619034e
Showing
11 changed files
with
267 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
subprojects/xcfa/xcfa-cli/src/test/resources/c/litmustest/singlethread/16loop.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
void reach_error(){} | ||
|
||
int main() { | ||
for(int i = 0; i < 30; i++) { | ||
if(i == 19) reach_error(); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/model/XcfaPath.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package hu.bme.mit.theta.xcfa.model; | ||
|
||
import hu.bme.mit.theta.core.decl.ConstDecl; | ||
import hu.bme.mit.theta.core.decl.VarDecl; | ||
import hu.bme.mit.theta.core.stmt.AssignStmt; | ||
import hu.bme.mit.theta.core.stmt.AssumeStmt; | ||
import hu.bme.mit.theta.core.stmt.HavocStmt; | ||
import hu.bme.mit.theta.core.stmt.Stmt; | ||
import hu.bme.mit.theta.core.type.Expr; | ||
import hu.bme.mit.theta.core.type.booltype.BoolType; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static hu.bme.mit.theta.core.decl.Decls.Const; | ||
import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Eq; | ||
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And; | ||
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True; | ||
|
||
public class XcfaPath { | ||
private final List<XcfaEdge> edges; | ||
|
||
public XcfaPath(List<XcfaEdge> edges) { | ||
this.edges = edges; | ||
} | ||
|
||
public Expr<BoolType> getExpression() { | ||
Map<VarDecl<?>, ConstDecl<?>> varToLastConstMap = new LinkedHashMap<>(); | ||
Expr<BoolType> ret = True(); | ||
|
||
for (XcfaEdge edge : edges) { | ||
for (Stmt stmt : edge.getStmts()) { | ||
if (stmt instanceof HavocStmt) { | ||
VarDecl<?> var = ((HavocStmt<?>) stmt).getVarDecl(); | ||
varToLastConstMap.put(var, Const(var.getName(), var.getType())); | ||
} else if (stmt instanceof AssumeStmt) { | ||
Expr<BoolType> expr = XcfaStmtVarReplacer.replaceVars(((AssumeStmt) stmt).getCond(), varToLastConstMap); | ||
ret = And(ret, expr); | ||
} else if (stmt instanceof AssignStmt) { | ||
VarDecl<?> var = ((AssignStmt<?>) stmt).getVarDecl(); | ||
ConstDecl<?> cnst = Const(var.getName(), var.getType()); | ||
Expr<?> expr = XcfaStmtVarReplacer.replaceVars(((AssignStmt<?>) stmt).getExpr(), varToLastConstMap); | ||
ret = And(ret, Eq(cnst.getRef(), expr)); | ||
varToLastConstMap.put(var, cnst); | ||
} else throw new UnsupportedOperationException("Not yet implemented!"); | ||
} | ||
} | ||
return ret; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
subprojects/xcfa/xcfa/src/main/java/hu/bme/mit/theta/xcfa/passes/procedurepass/BMC.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package hu.bme.mit.theta.xcfa.passes.procedurepass; | ||
|
||
import hu.bme.mit.theta.xcfa.model.XcfaEdge; | ||
import hu.bme.mit.theta.xcfa.model.XcfaLocation; | ||
import hu.bme.mit.theta.xcfa.model.XcfaProcedure; | ||
|
||
import java.util.List; | ||
|
||
import static hu.bme.mit.theta.xcfa.passes.procedurepass.Utils.collectPaths; | ||
import static hu.bme.mit.theta.xcfa.passes.procedurepass.Utils.createBuilder; | ||
|
||
public class BMC{ | ||
private static final int MAX_K = 100; | ||
|
||
public List<XcfaEdge> getCex(XcfaProcedure builder) { | ||
if(builder.getErrorLoc() == null) return null; | ||
|
||
XcfaProcedure.Builder workingCopy = createBuilder(builder); | ||
UnrollLoopsPass unrollLoopsPass = new UnrollLoopsPass(); | ||
|
||
for(int i = 0; i < MAX_K; ++i) { | ||
List<XcfaEdge> cex; | ||
if((cex = getCex(workingCopy)) != null) { | ||
return cex; | ||
// XcfaProcedure.Builder retBuilder = XcfaProcedure.builder(); | ||
// retBuilder.setName(builder.getName()); | ||
// Map<XcfaLocation, XcfaLocation> locLut = new LinkedHashMap<>(); | ||
// for (XcfaEdge edge : cex) { | ||
// XcfaLocation source = edge.getSource(); | ||
// XcfaLocation target = edge.getTarget(); | ||
// XcfaLocation newSource = XcfaLocation.copyOf(source); | ||
// XcfaLocation newTarget = XcfaLocation.copyOf(target); | ||
// locLut.putIfAbsent(source, newSource); | ||
// locLut.putIfAbsent(target, newTarget); | ||
// newSource = locLut.get(source); | ||
// newTarget = locLut.get(target); | ||
// retBuilder.addLoc(newSource); | ||
// retBuilder.addLoc(newTarget); | ||
// retBuilder.addEdge(new XcfaEdge(newSource, newTarget, edge.getStmts())); | ||
// } | ||
// retBuilder.setInitLoc(locLut.get(workingCopy.getInitLoc())); | ||
// XcfaLocation location = new XcfaLocation("final", Map.of()); // Final location never contained in CEX but still necesaary | ||
// retBuilder.addLoc(location); | ||
// retBuilder.setFinalLoc(location); | ||
// retBuilder.setErrorLoc(locLut.get(workingCopy.getErrorLoc())); | ||
// System.err.println("BMC saves the day!"); | ||
// return retBuilder.build(); | ||
} | ||
System.out.println("BMC has not found a violation in iteration " + i + " with " + workingCopy.getEdges().size() + " edges."); | ||
workingCopy = unrollLoopsPass.run(workingCopy); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private List<XcfaEdge> getCex(XcfaProcedure.Builder builder) { | ||
XcfaLocation initLoc = builder.getInitLoc(); | ||
XcfaLocation errorLoc = builder.getErrorLoc(); | ||
return collectPaths(initLoc, errorLoc); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.