Skip to content

Commit 0a24eac

Browse files
committed
Adding an option to print the term representation of store, heap, assumptions and branch conditions
1 parent b20c9a5 commit 0a24eac

File tree

4 files changed

+36
-15
lines changed

4 files changed

+36
-15
lines changed

src/main/scala/debugger/DebugExp.scala

+8-6
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,18 @@ class DebugExp(val id: Int,
138138
}
139139
}
140140

141-
def getTopLevelString(currDepth: Int): String = {
142-
val delimiter = if (finalExp.isDefined && description.isDefined) ": " else ""
143-
"\n\t" + ("\t"*currDepth) + "[" + id + "] " + description.getOrElse("") + delimiter + finalExp.getOrElse("")
141+
def getTopLevelString(currDepth: Int, config: DebugExpPrintConfiguration): String = {
142+
val toDisplay = if (config.printInternalTermRepresentation) term else finalExp
143+
val delimiter = if (toDisplay.isDefined && description.isDefined) ": " else ""
144+
"\n\t" + ("\t"*currDepth) + "[" + id + "] " + description.getOrElse("") + delimiter + toDisplay.getOrElse("")
144145
}
145146

146147

147148
def toString(currDepth: Int, maxDepth: Int, config: DebugExpPrintConfiguration): String = {
148149
if (isInternal_ && !config.isPrintInternalEnabled){
149150
return ""
150151
}
151-
getTopLevelString(currDepth) + childrenToString(currDepth, math.max(maxDepth, config.nodeToHierarchyLevelMap.getOrElse(id, 0)), config)
152+
getTopLevelString(currDepth, config) + childrenToString(currDepth, math.max(maxDepth, config.nodeToHierarchyLevelMap.getOrElse(id, 0)), config)
152153
}
153154

154155
def getExpWithId(id: Int, visited: mutable.HashSet[DebugExp]): Option[DebugExp] = {
@@ -197,7 +198,7 @@ class ImplicationDebugExp(id: Int,
197198
}
198199

199200
if (children.nonEmpty) {
200-
getTopLevelString(currDepth) + " ==> " + childrenToString(currDepth, math.max(maxDepth, config.nodeToHierarchyLevelMap.getOrElse(id, 0)), config)
201+
getTopLevelString(currDepth, config) + " ==> " + childrenToString(currDepth, math.max(maxDepth, config.nodeToHierarchyLevelMap.getOrElse(id, 0)), config)
201202
} else {
202203
"true"
203204
}
@@ -230,7 +231,7 @@ class QuantifiedDebugExp(id: Int,
230231
if (qvars.nonEmpty) {
231232
"\n\t" + ("\t"*currDepth) + "[" + id + "] " + (if (quantifier == "QA") "forall" else "exists") + " " + qvars.mkString(", ") + " :: " + childrenToString(currDepth, math.max(maxDepth, config.nodeToHierarchyLevelMap.getOrElse(id, 0)), config)
232233
} else {
233-
getTopLevelString(currDepth)
234+
getTopLevelString(currDepth, config)
234235
}
235236
}
236237
}
@@ -242,6 +243,7 @@ class DebugExpPrintConfiguration {
242243
var printHierarchyLevel: Int = 2
243244
var nodeToHierarchyLevelMap: Map[Int, Int] = Map.empty
244245
var isPrintAxiomsEnabled: Boolean = false
246+
var printInternalTermRepresentation: Boolean = false
245247

246248
def setPrintHierarchyLevel(level: String): Unit ={
247249
printHierarchyLevel = level match {

src/main/scala/debugger/SiliconDebugger.scala

+25-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import viper.silicon.interfaces.state.Chunk
66
import viper.silicon.interfaces.{Failure, SiliconDebuggingFailureContext, Success, VerificationResult}
77
import viper.silicon.resources.{FieldID, PredicateID}
88
import viper.silicon.rules.evaluator
9-
import viper.silicon.state.terms.Term
9+
import viper.silicon.state.terms.{Term, True}
1010
import viper.silicon.state.{BasicChunk, IdentifierFactory, MagicWandChunk, QuantifiedFieldChunk, QuantifiedMagicWandChunk, QuantifiedPredicateChunk, State}
1111
import viper.silicon.utils.ast.simplifyVariableName
1212
import viper.silicon.verifier.{MainVerifier, Verifier, WorkerVerifier}
@@ -26,7 +26,8 @@ case class ProofObligation(s: State,
2626
v: Verifier,
2727
proverEmits: Seq[String],
2828
preambleAssumptions: Seq[DebugAxiom],
29-
branchConditions: Seq[(ast.Exp, ast.Exp)],
29+
branchConditions: Seq[Term],
30+
branchConditionExps: Seq[(ast.Exp, ast.Exp)],
3031
assumptionsExp: InsertionOrderedSet[DebugExp],
3132
assertion: Term,
3233
eAssertion: DebugExp,
@@ -52,13 +53,23 @@ case class ProofObligation(s: State,
5253
}) +
5354
s"\n\t\t${originalErrorReason.readableMessage}\n\n"
5455

55-
private lazy val stateString: String =
56-
s"Store:\n\t\t${s.g.values.map(v => s"${v._1} -> ${v._2._2.get}").mkString("\n\t\t")}\n\nHeap:\n\t\t${s.h.values.map(chunkString).mkString("\n\t\t")}\n\n"
56+
private lazy val stateString: String = {
57+
if (printConfig.printInternalTermRepresentation)
58+
s"Store:\n\t\t${s.g.values.map(v => s"${v._1} -> ${v._2._1}").mkString("\n\t\t")}\n\nHeap:\n\t\t${s.h.values.map(chunkString).mkString("\n\t\t")}\n\n"
59+
else
60+
s"Store:\n\t\t${s.g.values.map(v => s"${v._1} -> ${v._2._2.get}").mkString("\n\t\t")}\n\nHeap:\n\t\t${s.h.values.map(chunkString).mkString("\n\t\t")}\n\n"
61+
}
5762

58-
private lazy val branchConditionString: String =
59-
s"Branch Conditions:\n\t\t${branchConditions.map(bc => Simplifier.simplify(bc._2, true)).filter(bc => bc != ast.TrueLit()()).mkString("\n\t\t")}\n\n"
63+
private lazy val branchConditionString: String = {
64+
if (printConfig.printInternalTermRepresentation)
65+
s"Branch Conditions:\n\t\t${branchConditions.filter(bc => bc != True).mkString("\n\t\t")}\n\n"
66+
else
67+
s"Branch Conditions:\n\t\t${branchConditionExps.map(bc => Simplifier.simplify(bc._2, true)).filter(bc => bc != ast.TrueLit()()).mkString("\n\t\t")}\n\n"
68+
}
6069

6170
private def chunkString(c: Chunk): String = {
71+
if (printConfig.printInternalTermRepresentation)
72+
return c.toString
6273
val res = c match {
6374
case bc: BasicChunk =>
6475
val snapExpString = bc.snapExp match {
@@ -219,7 +230,7 @@ class SiliconDebugger(verificationResults: List[VerificationResult],
219230
}
220231

221232
val obl = Some(ProofObligation(failureContext.state.get, failureContext.verifier.get, failureContext.proverDecls, failureContext.preambleAssumptions,
222-
failureContext.branchConditions, failureContext.assumptions,
233+
failureContext.branchConditions, failureContext.branchConditionExps, failureContext.assumptions,
223234
failureContext.failedAssertion, failureContext.failedAssertionExp, None,
224235
new DebugExpPrintConfiguration, currResult.message.reason,
225236
new DebugResolver(this.pprogram, this.resolver.names), new DebugTranslator(this.pprogram, translator.getMembers())))
@@ -537,6 +548,13 @@ class SiliconDebugger(verificationResults: List[VerificationResult],
537548
case _ =>
538549
}
539550

551+
println(s"Enter the new value for printInternalTermRepresentation:")
552+
readLine().toLowerCase match {
553+
case "true" | "1" | "t" => obl.printConfig.printInternalTermRepresentation = true
554+
case "false" | "0" | "f" => obl.printConfig.printInternalTermRepresentation = false
555+
case _ =>
556+
}
557+
540558
//println(s"Enter the new value for nodeToHierarchyLevelMap:")
541559
//obl.printConfig.addHierarchyLevelForId(readLine())
542560
}

src/main/scala/interfaces/Verification.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ case class SiliconFailureContext(branchConditions: Seq[ast.Exp],
135135
override lazy val toString: String = branchConditionString + counterExampleString + reasonUnknownString
136136
}
137137

138-
case class SiliconDebuggingFailureContext(branchConditions: Seq[(ast.Exp, ast.Exp)],
138+
case class SiliconDebuggingFailureContext(branchConditions: Seq[Term],
139+
branchConditionExps: Seq[(ast.Exp, ast.Exp)],
139140
counterExample: Option[Counterexample],
140141
reasonUnknown: Option[String],
141142
state: Option[State],

src/main/scala/rules/SymbolicExecutionRules.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ trait SymbolicExecutionRules {
9696

9797
if (Verifier.config.enableDebugging()){
9898
val assumptions = v.decider.pcs.assumptionExps
99-
res.failureContexts = Seq(SiliconDebuggingFailureContext(v.decider.pcs.branchConditionExps.map(bce => bce._1 -> bce._2.get),
99+
res.failureContexts = Seq(SiliconDebuggingFailureContext(v.decider.pcs.branchConditions, v.decider.pcs.branchConditionExps.map(bce => bce._1 -> bce._2.get),
100100
counterexample, reasonUnknown, Some(s), Some(v), v.decider.prover.getAllEmits(), v.decider.prover.preambleAssumptions,
101101
v.decider.macroDecls, v.decider.functionDecls, assumptions, failedAssert, failedAssertExp.get))
102102
} else {

0 commit comments

Comments
 (0)