Skip to content

Commit 7603ae6

Browse files
authored
Merge pull request #407 from UQ-PAC/collapsed-interval
DSA Clean Up
2 parents f8f4b86 + 4443f16 commit 7603ae6

File tree

17 files changed

+1004
-857
lines changed

17 files changed

+1004
-857
lines changed
483 KB
Binary file not shown.

src/main/scala/Main.scala

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ import bap.*
44
import boogie.*
55
import translating.*
66
import util.RunUtils
7-
import scala.sys.process.*
87

8+
import scala.sys.process.*
99
import java.io.File
1010
import scala.collection.mutable.{ArrayBuffer, Set}
1111
import scala.collection.{immutable, mutable}
1212
import scala.language.postfixOps
1313
import scala.sys.process.*
1414
import util.*
15-
import mainargs.{main, arg, ParserForClass, Flag}
15+
import mainargs.{Flag, ParserForClass, arg, main}
16+
import util.DSAConfig.{Checks, Prereq, Standard}
1617
import util.boogie_interaction.BoogieResultKind
1718

1819
object Main {
@@ -241,14 +242,12 @@ object Main {
241242

242243
val dsa: Option[DSAConfig] = if (conf.simplify.value) {
243244
conf.dsaType match
244-
case Some("set") => Some(DSAConfig(immutable.Set(DSAAnalysis.Set)))
245-
case Some("field") => Some(DSAConfig(immutable.Set(DSAAnalysis.Field)))
246-
case Some("norm") => Some(DSAConfig(immutable.Set(DSAAnalysis.Norm)))
247-
case Some("all") => Some(DSAConfig(immutable.Set(DSAAnalysis.Set, DSAAnalysis.Field, DSAAnalysis.Norm)))
248-
case Some("none") => Some(DSAConfig(immutable.Set.empty))
249-
case None => None
245+
case Some("prereq") => Some(Prereq)
246+
case Some("checks") => Some(Checks)
247+
case Some("standard") => Some(Standard)
248+
case None => Some(Standard)
250249
case Some(_) =>
251-
throw new IllegalArgumentException("Illegal option to dsa, allowed are: (none|set|field|norm|all)")
250+
throw new IllegalArgumentException("Illegal option to dsa, allowed are: (prereq|standard|checks)")
252251
} else {
253252
None
254253
}

src/main/scala/analysis/data_structure_analysis/DSA.scala

Lines changed: 0 additions & 176 deletions
This file was deleted.
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package analysis.data_structure_analysis
2+
3+
import analysis.solvers.{DSAUnionFindSolver, OffsetUnionFindSolver, UnionFindSolver}
4+
import ir.eval.BitVectorEval.{bv2SignedInt, isNegative}
5+
import ir.{BVADD, BinaryExpr, BitVecLiteral, Expr, LocalAssign, Procedure, Program, Register}
6+
import specification.{ExternalFunction, SymbolTableEntry}
7+
import util.{DSALogger, IRContext}
8+
9+
import java.io.File
10+
import scala.collection.{SortedSet, mutable}
11+
12+
/**
13+
* Integer Interval with top and bottom
14+
* start (s) <= end (e)
15+
* For purposes of overlapping and size the interval is inclusive of s and exclusive of e
16+
*/
17+
enum DSInterval extends Offsets {
18+
case Top
19+
case Bot
20+
case Value(s: Int, e: Int)
21+
22+
this match
23+
case DSInterval.Value(s, e) => assert(s <= e, "start of interval should be less than its end")
24+
case _ =>
25+
26+
override def toString: String =
27+
this match
28+
case DSInterval.Top => "Top"
29+
case DSInterval.Bot => "Bot"
30+
case DSInterval.Value(start, end) => s"${start}_$end"
31+
32+
def start: Option[Int] =
33+
this match
34+
case DSInterval.Value(s, e) => Some(s)
35+
case _ => None
36+
37+
def end: Option[Int] =
38+
this match
39+
case DSInterval.Value(s, e) => Some(e)
40+
case _ => None
41+
42+
def size: Option[Int] =
43+
this match
44+
case DSInterval.Value(start, end) => Some(end - start)
45+
case _ => None
46+
47+
def move(func: Int => Int): DSInterval =
48+
this match
49+
case DSInterval.Value(start, end) => Value(func(start), func(end))
50+
case x => x
51+
52+
def isEmpty: Boolean = this.size.contains(0)
53+
54+
def growTo(size: Int): DSInterval =
55+
this match
56+
case DSInterval.Top => DSInterval.Top
57+
case DSInterval.Value(start, end) => DSInterval(start, math.max(end, start + size))
58+
case _ => this
59+
60+
def contains(offset: Int): Boolean =
61+
this match
62+
case DSInterval.Top => true
63+
case DSInterval.Value(start, end) => start <= offset && (end > offset || end == start)
64+
case _ => false
65+
66+
def contains(interval: DSInterval): Boolean =
67+
(this, interval) match
68+
case (DSInterval.Top, _) => true
69+
case (_, DSInterval.Top) => false // this is not top
70+
case (a, b) if a == b => true
71+
case (DSInterval.Value(s, e), _) if s == e => false
72+
case (DSInterval.Value(start1, end1), DSInterval.Value(start2, end2)) =>
73+
start1 <= start2 && (end1 > end2 || (start2 < end2 && end1 >= end2))
74+
case _ => false
75+
76+
def isOverlapping(other: DSInterval): Boolean =
77+
(this, other) match
78+
case (DSInterval.Top, _) => true
79+
case (_, DSInterval.Top) => true
80+
case (a, b) if a == b => true
81+
case (DSInterval.Value(s1, e1), DSInterval.Value(s2, e2)) =>
82+
(s2 < e1 && s2 >= s1) || (s1 < e2 && s1 >= s2)
83+
case _ => false
84+
85+
def join(other: DSInterval): DSInterval = {
86+
(this, other) match
87+
case (DSInterval.Top, _) => DSInterval.Top
88+
case (_, DSInterval.Top) => DSInterval.Top
89+
case (DSInterval.Bot, x) => x
90+
case (x, DSInterval.Bot) => x
91+
case (DSInterval.Value(start1, end1), DSInterval.Value(start2, end2)) =>
92+
DSInterval(math.min(start1, start2), math.max(end1, end2))
93+
}
94+
95+
override def toOffsets: Set[Int] = {
96+
this match
97+
case DSInterval.Value(s, e) => Set(s to e: _*)
98+
case _ => throw Exception("Attempted to retrieve offsets from top/bot")
99+
}
100+
101+
override def toIntervals: Set[DSInterval] = {
102+
this match
103+
case DSInterval.Bot => Set.empty
104+
case x => Set(x)
105+
}
106+
107+
}
108+
109+
object DSInterval {
110+
def apply(start: Int, end: Int) = {
111+
require(start <= end, "start of interval should be less than it's end")
112+
DSInterval.Value(start, end)
113+
}
114+
def join(interval1: DSInterval, interval2: DSInterval): DSInterval = interval1.join(interval2)
115+
implicit def orderingByTuple[T <: DSInterval]: Ordering[T] =
116+
Ordering.by {
117+
case DSInterval.Value(start, end) =>
118+
(start, end)
119+
case _ => (Int.MinValue, Int.MinValue)
120+
}
121+
}

0 commit comments

Comments
 (0)