Skip to content

Commit

Permalink
add bigendian support for lambda stores
Browse files Browse the repository at this point in the history
  • Loading branch information
ailrst committed Oct 24, 2023
1 parent ff0049a commit 55b1911
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
11 changes: 7 additions & 4 deletions src/main/scala/boogie/BExpr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,14 @@ case class BByteExtract(value: BExpr, offset: BExpr) extends BExpr {
*
* Assumes all inputs are of the same bitvector width.
*/
case class InBounds(bits: Int) extends FunctionOp {
val fnName: String = s"in_bounds$bits"
case class InBounds(bits: Int, endian: Endian) extends FunctionOp {
val fnName: String = endian match {
case Endian.LittleEndian => s"in_bounds${bits}_le"
case Endian.BigEndian=> s"in_bounds${bits}_be"
}
}

case class BInBounds(base: BExpr, len: BExpr, i: BExpr) extends BExpr {
case class BInBounds(base: BExpr, len: BExpr, endian: Endian, i: BExpr) extends BExpr {
override def toString: String = s"$fnName($base, $len, $i)"

val baseSize: Int = base.getType match {
Expand All @@ -524,7 +527,7 @@ case class BInBounds(base: BExpr, len: BExpr, i: BExpr) extends BExpr {

override val getType: BType = BoolBType
override def functionOps: Set[FunctionOp] =
base.functionOps ++ len.functionOps ++ i.functionOps + InBounds(baseSize)
base.functionOps ++ len.functionOps ++ i.functionOps + InBounds(baseSize, endian)
override def locals: Set[BVar] = base.locals ++ len.locals ++ i.locals
override def globals: Set[BVar] = base.globals ++ len.globals ++ i.globals
override def loads: Set[BExpr] = base.loads ++ len.loads ++ i.loads
Expand Down
17 changes: 12 additions & 5 deletions src/main/scala/translating/IRToBoogie.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class IRToBoogie(var program: Program, var spec: Specification) {

val rgProcs = genRely(relies, readOnlyMemory) :+ guaranteeReflexive

// TODO: Fixed point
val functionsUsed1 =
procedures.flatMap(p => p.functionOps).toSet ++
rgProcs.flatMap(p => p.functionOps).toSet ++
Expand Down Expand Up @@ -176,7 +175,7 @@ class IRToBoogie(var program: Program, var spec: Specification) {
else {
val i = BVariable("i", BitVecBType(m.addressSize), Scope.Local)
Lambda(List(i), IfThenElse(
BInBounds(indexVar, BitVecBLiteral(m.accesses, m.addressSize), i),
BInBounds(indexVar, BitVecBLiteral(m.accesses, m.addressSize), m.endian, i),
BByteExtract(valueVar, BinaryBExpr(BVSUB, i, indexVar)),
MapAccess(memVar, i)))
}
Expand All @@ -199,7 +198,7 @@ class IRToBoogie(var program: Program, var spec: Specification) {
else {
val i = BVariable("i", BitVecBType(g.addressSize), Scope.Local)
Lambda(List(i), IfThenElse(
BInBounds(indexVar, BitVecBLiteral(g.accesses, g.addressSize), i),
BInBounds(indexVar, BitVecBLiteral(g.accesses, g.addressSize), Endian.LittleEndian, i),
valueVar,
MapAccess(gammaMapVar, i)))
}
Expand Down Expand Up @@ -270,8 +269,16 @@ class IRToBoogie(var program: Program, var spec: Specification) {
val iVar = BParam("i", BitVecBType(b.bits))
val in = List(baseVar, lenVar, iVar)
val out = BParam(BoolBType)
val end = BinaryBExpr(BVADD, baseVar, lenVar)
val above = BinaryBExpr(BVULE, baseVar, iVar)
val begin = b.endian match {
case Endian.LittleEndian => baseVar
case Endian.BigEndian => BinaryBExpr(BVSUB, baseVar, lenVar)
}
val end = b.endian match {
case Endian.LittleEndian => BinaryBExpr(BVADD, baseVar, lenVar)
case Endian.BigEndian => baseVar
}

val above = BinaryBExpr(BVULE, begin, iVar)
val below = BinaryBExpr(BVULT, iVar, end)
val wrap = BinaryBExpr(BVULE, baseVar, end)
val body = IfThenElse(wrap, BinaryBExpr(BoolAND, above, below), BinaryBExpr(BoolOR, above, below))
Expand Down
5 changes: 0 additions & 5 deletions src/main/scala/util/BASILConfig.scala
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package util

/**
* We use 'quirks' to manage the operation mode of the tool e.g. for a-b testing or compiler options.
*/


case class ILLoadingConfig(adtFile: String, relfFile: String, specFile: Option[String], dumpIL: Option[String])
case class BoogieGeneratorConfig(memoryFunctionType: BoogieMemoryAccessMode = BoogieMemoryAccessMode.SuccessiveStoreSelect)
case class StaticAnalysisConfig(dumpILToPath: Option[String] = None)
Expand Down

0 comments on commit 55b1911

Please sign in to comment.