Skip to content

Commit

Permalink
ACSL parser and translator improvements (#7)
Browse files Browse the repository at this point in the history
ACSL parser and translator improvements.
  • Loading branch information
zafer-esen authored Oct 26, 2023
2 parents 9d3dc96 + 260139a commit d2c36a1
Show file tree
Hide file tree
Showing 16 changed files with 630 additions and 453 deletions.
2 changes: 1 addition & 1 deletion acsl-parser/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


CUP = java_cup.Main
CUPFLAGS = -expect 400 -locations
CUPFLAGS = -expect 7 -locations

JLEX = JLex.Main

Expand Down
Binary file modified acsl-parser/acsl-parser.jar
Binary file not shown.
325 changes: 193 additions & 132 deletions acsl-parser/acsl.cf

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions regression-tests/acsl-contracts/contract11.hcc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*@
requires \valid(p, q);
ensures ((\result == *p) || (\result == *q));
ensures \result >= (*p);
ensures \result == *p || \result == *q;
ensures \result >= *p;
ensures \result >= (*q);
*/
int max(int* p, int* q) {
Expand Down
4 changes: 2 additions & 2 deletions regression-tests/acsl-contracts/contract13.hcc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*@
requires \valid(p, q);
ensures ((\result == *p) || (\result == *q));
ensures \result >= (*p);
ensures \result == *p || \result == *q;
ensures \result >= *p;
ensures \result >= (*q);
*/
int max(int* p, int* q) {
Expand Down
2 changes: 1 addition & 1 deletion regression-tests/acsl-contracts/contract14.hcc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*@
ensures \forall int i; (i >= 0) ==> (i > \result);
ensures \forall int i; i >= 0 ==> i > \result;
*/
int getNeg() {
return -1;
Expand Down
4 changes: 2 additions & 2 deletions regression-tests/acsl-contracts/contract2.hcc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*@
requires (x >= 0) && (x <= 4);
ensures (\result >= 10) && (\result <= 14);
requires x >= 0 && x <= 4;
ensures \result >= 10 && \result <= 14;
*/
int foo(int x) {
return 12;
Expand Down
2 changes: 1 addition & 1 deletion regression-tests/acsl-contracts/contract27.hcc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*@
requires \valid(a) && \valid(b);
assigns *a, *b;
ensures (*a) == \old(*b);
ensures *a == \old(*b);
ensures (*b) == \old(*a);
*/
void swap(int* a, int* b) {
Expand Down
4 changes: 2 additions & 2 deletions regression-tests/acsl-standalone/maxptr_unsafe.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*@
requires \valid(p, q);
ensures ((\result == *p) || (\result == *q));
ensures \result >= (*p);
ensures \result == *p || \result == *q;
ensures \result >= *p;
ensures \result >= (*q);
*/
int foo(int* p, int* q) {
Expand Down
4 changes: 2 additions & 2 deletions regression-tests/acsl-standalone/mc91_safe.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*@
ensures ((n <= 100) ==> (\result == 91));
ensures ((n > 100) ==> (\result == (n-10)));
ensures n <= 100 ==> \result == 91;
ensures n > 100 ==> \result == n-10;
*/
int foo(int n) {
if (n > 100) {
Expand Down
2 changes: 0 additions & 2 deletions regression-tests/runalldirs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#!/bin/sh

set -e

./rundir horn-hcc-heap "" -assertNoVerify -dev -t:60
./rundir horn-hcc-array "" -assertNoVerify -dev -t:60
./rundir horn-bv "" -assert -dev -t:60
Expand Down
17 changes: 14 additions & 3 deletions src/tricera/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,7 @@ class Main (args: Array[String]) {
processor(processedSolution)() // will process all predicates
}

println("\nInferred ACSL annotations")
println("="*80)
var printedACSLHeader = false
// line numbers in contract vars (e.g. x/1) are due to CCVar.toString
for ((fun, ctx) <- contexts
if maybeEnc.isEmpty ||
Expand All @@ -515,6 +514,11 @@ class Main (args: Array[String]) {
val fPostWithArgs =
replaceArgs(fPost, ctx.postPredACSLArgNames)

if (!printedACSLHeader) {
println("\nInferred ACSL annotations")
println("=" * 80)
printedACSLHeader = true
}
println("/* contracts for " + fun + " */")
println("/*@")
print( " requires "); println(fPreWithArgs + ";")
Expand All @@ -528,14 +532,21 @@ class Main (args: Array[String]) {
p._1.name.stripPrefix("inv_") == inv.pred.name).get._2
val fInvWithArgs =
replaceArgs(fInv, inv.argVars.map(_.name))
if (!printedACSLHeader) {
println("\nInferred ACSL annotations")
println("=" * 80)
printedACSLHeader = true
}
println("\n/* loop invariant for the loop at line " +
srcInfo.line + " */")
println("/*@")
print( " loop invariant "); println(fInvWithArgs + ";")
println("*/")
}
}
println("="*80 + "\n")
if (printedACSLHeader) {
println("=" * 80 + "\n")
}
}
case None =>
}
Expand Down
Loading

0 comments on commit d2c36a1

Please sign in to comment.