@@ -280,8 +280,8 @@ class SiliconDebugger(verificationResults: List[VerificationResult],
280
280
while (true ) {
281
281
println(s " \n Enter 'q' to quit, 'z' to zoom in on (i.e., show all children of) an assumption, " +
282
282
s " 'r' to reset the proof obligation, 'ra' to remove assumptions, 'af' to add free assumptions, " +
283
- s " 'ap' prove additional assumptions, 'p ' to execute proof , 'c ' to change print configuration , " +
284
- s " 's' to change the SMT solver, 't' to change the timeout " )
283
+ s " 'ap' prove additional assumptions, 'e ' to evaluate an expression , 'p ' to execute proof , " +
284
+ s " 'c' to change print configuration, ' s' to change the SMT solver, 't' to change the timeout " )
285
285
try {
286
286
val userInput = readLine()
287
287
userInput.toLowerCase match {
@@ -306,6 +306,8 @@ class SiliconDebugger(verificationResults: List[VerificationResult],
306
306
// obl = chooseAssertion(obl)
307
307
// println(s"Current obligation:\n$obl")
308
308
// assertProofObligation(obl)
309
+ case " e" | " eval" =>
310
+ obl = evalExpr(obl)
309
311
case " p" | " prove" =>
310
312
assertProofObligation(obl)
311
313
case " c" | " config" =>
@@ -399,8 +401,8 @@ class SiliconDebugger(verificationResults: List[VerificationResult],
399
401
if (userInput.isEmpty || userInput.equalsIgnoreCase(" s" ) || userInput.equalsIgnoreCase(" skip" )) {
400
402
obl
401
403
} else {
402
- val assumptionE = translateStringToExp(userInput, obl)
403
- evalAssumption(assumptionE, obl, free, obl.v) match {
404
+ val assumptionE = translateStringToExp(userInput, obl, true )
405
+ evalAssumption(assumptionE, obl, true , free, obl.v) match {
404
406
case Some ((resS, resT, resE, evalAssumptions)) =>
405
407
val allAssumptions = obl.assumptionsExp ++ evalAssumptions + DebugExp .createInstance(assumptionE, resE).withTerm(resT)
406
408
obl.copy(s = resS, assumptionsExp = allAssumptions)
@@ -410,13 +412,32 @@ class SiliconDebugger(verificationResults: List[VerificationResult],
410
412
}
411
413
}
412
414
415
+ private def evalExpr (obl : ProofObligation ): ProofObligation = {
416
+ println(s " Enter the expression you want to evaluate: " )
417
+ val userInput = readLine()
418
+ if (userInput.isEmpty || userInput.equalsIgnoreCase(" s" ) || userInput.equalsIgnoreCase(" skip" )) {
419
+ obl
420
+ } else {
421
+ val assumptionE = translateStringToExp(userInput, obl, false )
422
+ evalAssumption(assumptionE, obl, false , false , obl.v) match {
423
+ case Some ((resS, resT, resE, evalAssumptions)) =>
424
+ println(" Evaluation successful!" )
425
+ println(" Result: " + resE.toString)
426
+ println(" Internal result term:" + resT.toString)
427
+ obl.copy(s = resS)
428
+ case None =>
429
+ obl
430
+ }
431
+ }
432
+ }
433
+
413
434
private def chooseAssertion (obl : ProofObligation ): ProofObligation = {
414
435
println(s " Enter the assertion or s(skip) to assert the previous assertion again: " )
415
436
val userInput = readLine()
416
437
if (userInput.equalsIgnoreCase(" s" ) || userInput.equalsIgnoreCase(" skip" )) {
417
438
obl
418
439
} else {
419
- val assertionE = translateStringToExp(userInput, obl)
440
+ val assertionE = translateStringToExp(userInput, obl, true )
420
441
var resT : Term = null
421
442
var resE : ast.Exp = null
422
443
var resV : Verifier = null
@@ -436,7 +457,7 @@ class SiliconDebugger(verificationResults: List[VerificationResult],
436
457
}
437
458
}
438
459
439
- private def translateStringToExp (str : String , obl : ProofObligation ): ast.Exp = {
460
+ private def translateStringToExp (str : String , obl : ProofObligation , expectBool : Boolean ): ast.Exp = {
440
461
def parseToPExp (): PExp = {
441
462
try {
442
463
val fp = new DebugParser ()
@@ -453,7 +474,10 @@ class SiliconDebugger(verificationResults: List[VerificationResult],
453
474
def typecheckPExp (pexp : PExp ): Unit = {
454
475
try {
455
476
obl.resolver.typechecker.names.check(pexp, None , obl.resolver.typechecker.curMember)
456
- obl.resolver.typechecker.check(pexp, PPrimitiv (PReserved (PKw .Bool )((NoPosition , NoPosition )))())
477
+ if (expectBool)
478
+ obl.resolver.typechecker.check(pexp, PPrimitiv (PReserved (PKw .Bool )((NoPosition , NoPosition )))())
479
+ else
480
+ obl.resolver.typechecker.checkTopTyped(pexp, None )
457
481
} catch {
458
482
case e : Throwable => println(s " Error while typechecking $str: ${e.getMessage}" )
459
483
throw e
@@ -480,7 +504,7 @@ class SiliconDebugger(verificationResults: List[VerificationResult],
480
504
translatePExp(pexp)
481
505
}
482
506
483
- private def evalAssumption (e : ast.Exp , obl : ProofObligation , isFree : Boolean , v : Verifier ): Option [(State , Term , ast.Exp , InsertionOrderedSet [DebugExp ])] = {
507
+ private def evalAssumption (e : ast.Exp , obl : ProofObligation , assume : Boolean , isFree : Boolean , v : Verifier ): Option [(State , Term , ast.Exp , InsertionOrderedSet [DebugExp ])] = {
484
508
var resT : Term = null
485
509
var resS : State = null
486
510
var resE : ast.Exp = null
@@ -499,10 +523,12 @@ class SiliconDebugger(verificationResults: List[VerificationResult],
499
523
500
524
verificationResult match {
501
525
case Success () =>
502
- val proved = isFree || resV.decider.prover.assert(resT, None )
526
+ val proved = ! assume || isFree || resV.decider.prover.assert(resT, None )
503
527
if (proved) {
504
- println(" Assumption was added successfully!" )
505
- resV.asInstanceOf [WorkerVerifier ].decider.debuggerAssume(Seq (resT), null )
528
+ if (assume) {
529
+ println(" Assumption was added successfully!" )
530
+ resV.asInstanceOf [WorkerVerifier ].decider.debuggerAssume(Seq (resT), null )
531
+ }
506
532
Some ((resS, resT, resE, evalPcs.assumptionExps))
507
533
} else {
508
534
println(" Fail! Could not prove assumption. Skipping" )
0 commit comments