From 969a5f13ae15701326d7a8af62afe41911192217 Mon Sep 17 00:00:00 2001 From: Alistair Michael Date: Fri, 13 Oct 2023 16:07:50 +1000 Subject: [PATCH 1/5] remove returns --- src/main/scala/analysis/MemoryModelMap.scala | 37 ++++++------------- .../scala/analysis/SteensgaardAnalysis.scala | 4 +- 2 files changed, 14 insertions(+), 27 deletions(-) diff --git a/src/main/scala/analysis/MemoryModelMap.scala b/src/main/scala/analysis/MemoryModelMap.scala index 70fee4e09..766f1c647 100644 --- a/src/main/scala/analysis/MemoryModelMap.scala +++ b/src/main/scala/analysis/MemoryModelMap.scala @@ -1,5 +1,6 @@ package analysis +import scala.util.boundary import analysis.* import ir.BitVecLiteral @@ -77,13 +78,12 @@ class MemoryModelMap { } def popContext(): Unit = { - if (contextStack.size <= 1) { - return - } - contextStack.pop() - rangeMap.stackMap.clear() - for (stackRgn <- contextStack.top) { - add(stackRgn.start.asInstanceOf[BitVecLiteral].value, stackRgn) + if (contextStack.size > 1) { + contextStack.pop() + rangeMap.stackMap.clear() + for (stackRgn <- contextStack.top) { + add(stackRgn.start.asInstanceOf[BitVecLiteral].value, stackRgn) + } } } @@ -98,25 +98,12 @@ class MemoryModelMap { // Find an object for a given value within a range - def findStackObject(value: BigInt): Option[StackRegion] = { - for ((range, obj: StackRegion) <- rangeMap.stackMap) { - if (range.start <= value && value <= range.end) { - obj.extent = Some(range); - return Some(obj) - } - } - None - } - def findDataObject(value: BigInt): Option[DataRegion] = { - for ((range, obj) <- rangeMap.dataMap) { - if (range.start <= value && value <= range.end) { - obj.extent = Some(range); - return Some(obj) - } - } - None - } + def findStackObject(value: BigInt): Option[StackRegion] = + rangeMap.stackMap.find((range, _) => (range.start <= value && value <= range.end)).map((range, obj) => {obj.extent = Some(range); obj}); + + def findDataObject(value: BigInt): Option[DataRegion] = + rangeMap.dataMap.find((range, _) => (range.start <= value && value <= range.end)).map((range, obj) => {obj.extent = Some(range); obj}); override def toString: String = s"Stack: ${rangeMap.stackMap}\n Heap: ${rangeMap.heapMap}\n Data: ${rangeMap.dataMap}\n" diff --git a/src/main/scala/analysis/SteensgaardAnalysis.scala b/src/main/scala/analysis/SteensgaardAnalysis.scala index 15a9799ed..9b7e4f9a3 100644 --- a/src/main/scala/analysis/SteensgaardAnalysis.scala +++ b/src/main/scala/analysis/SteensgaardAnalysis.scala @@ -138,7 +138,7 @@ class SteensgaardAnalysis(program: Program, constantPropResult: Map[CfgNode, Map /** @inheritdoc */ - def pointsTo(): Map[Object, Set[Object]] = { + def pointsTo(): Map[Object, Set[Variable | AAlloc]] = { val solution = solver.solution() val unifications = solver.unifications() Logger.debug(s"Solution: \n${solution.mkString(",\n")}\n") @@ -149,7 +149,7 @@ class SteensgaardAnalysis(program: Program, constantPropResult: Map[CfgNode, Map .mkString(", ")}") val vars = solution.keys.collect { case id: IdentifierVariable => id } - val pointsto = vars.foldLeft(Map[Object, Set[Object]]()) { case (a, v: IdentifierVariable) => + val pointsto = vars.foldLeft(Map[Object, Set[Variable | AAlloc]]()) { case (a, v: IdentifierVariable) => val pt = unifications(solution(v)) .collect({ case PointerRef(IdentifierVariable(id)) => id From a8316dc810b0cd730b8ea25ecc58aa09f7c7d54e Mon Sep 17 00:00:00 2001 From: Alistair Michael Date: Fri, 13 Oct 2023 16:31:15 +1000 Subject: [PATCH 2/5] fix warnings --- src/main/scala/analysis/Lattice.scala | 10 ---------- src/main/scala/analysis/VSA.scala | 4 ++-- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/main/scala/analysis/Lattice.scala b/src/main/scala/analysis/Lattice.scala index 6cd0b3f1c..ad2182f70 100644 --- a/src/main/scala/analysis/Lattice.scala +++ b/src/main/scala/analysis/Lattice.scala @@ -101,16 +101,6 @@ class FlatLattice[X] extends Lattice: type Element = FlatElement - /** Wrap an element of `X` into an element of the flat lattice. - */ - implicit def wrap(a: X): Element = FlatElement.FlatEl(a) - - /** Unwrap an element of the lattice to an element of `X`. If the element is Top or Bot then IllegalArgumentException - * is thrown. Note that this method is declared as implicit, so the conversion can be done automatically. - */ - implicit def unwrap(a: Element): X = a match - case FlatElement.FlatEl(n) => n - case _ => throw new IllegalArgumentException(s"Cannot unlift $a") val bottom: Element = FlatElement.Bot diff --git a/src/main/scala/analysis/VSA.scala b/src/main/scala/analysis/VSA.scala index 000eec891..dfae2a804 100644 --- a/src/main/scala/analysis/VSA.scala +++ b/src/main/scala/analysis/VSA.scala @@ -13,11 +13,11 @@ import util.Logger trait Value trait AddressValue(val expr: Expr, val name: String) extends Value -case class GlobalAddress(override val expr: Expr, override val name: String) extends AddressValue(expr, name) { +case class GlobalAddress(val e: Expr, val n: String) extends AddressValue(e, n) { override def toString: String = "GlobalAddress(" + expr + ", " + name + ")" } -case class LocalAddress(override val expr: Expr, override val name: String) extends AddressValue(expr, name) { +case class LocalAddress(val e: Expr, val n: String) extends AddressValue(e, n) { override def toString: String = "LocalAddress(" + expr + ", " + name + ")" } From 66fa0c34a3a5a37fb45ac7b34942b25e9dafe9ad Mon Sep 17 00:00:00 2001 From: Alistair Michael Date: Fri, 13 Oct 2023 16:31:32 +1000 Subject: [PATCH 3/5] show warnings and deprecations --- build.sbt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index a331e7743..15052da58 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,6 @@ import scala.io.Source -ThisBuild / scalaVersion := "3.1.0" +ThisBuild / scalaVersion := "3.3.0" ThisBuild / version := "0.0.1" ThisBuild / organization := "uq.pac" @@ -28,6 +28,8 @@ lazy val root = project libraryDependencies += mainArgs ) +scalacOptions ++= Seq("-deprecation", "-feature") + lazy val updateExpected = taskKey[Unit]("updates .expected for test cases") updateExpected := { From 0b5d7dc49127275ccb0291cfc38b3623df1692ef Mon Sep 17 00:00:00 2001 From: Alistair Michael Date: Fri, 13 Oct 2023 16:49:55 +1000 Subject: [PATCH 4/5] fix deprecations --- src/main/scala/Main.scala | 2 +- src/main/scala/analysis/Cfg.scala | 2 +- src/main/scala/analysis/MemoryModelMap.scala | 1 - src/main/scala/ir/Visitor.scala | 10 +++++----- src/main/scala/translating/ILtoIL.scala | 9 ++++----- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main/scala/Main.scala b/src/main/scala/Main.scala index f64f60cff..c7184fa7f 100644 --- a/src/main/scala/Main.scala +++ b/src/main/scala/Main.scala @@ -38,7 +38,7 @@ object Main { def main(args: Array[String]): Unit = { val parser = ParserForClass[Config] - val parsed = parser.constructEither(args) + val parsed = parser.constructEither(args.toSeq) val conf = parsed match { case Right(r) => r diff --git a/src/main/scala/analysis/Cfg.scala b/src/main/scala/analysis/Cfg.scala index 02df9bc1a..c382c1dc3 100644 --- a/src/main/scala/analysis/Cfg.scala +++ b/src/main/scala/analysis/Cfg.scala @@ -537,7 +537,7 @@ class ProgramCfg: } } dotArrows = dotArrows.sortBy(arr => arr.fromNode.id + "-" + arr.toNode.id) - val allNodes = dotNodes.values.seq.toList.sortBy(n => n.id) + val allNodes = dotNodes.values.toList.sortBy(n => n.id) new DotGraph("CFG", allNodes, dotArrows).toDotString } diff --git a/src/main/scala/analysis/MemoryModelMap.scala b/src/main/scala/analysis/MemoryModelMap.scala index 766f1c647..f5d3c5f55 100644 --- a/src/main/scala/analysis/MemoryModelMap.scala +++ b/src/main/scala/analysis/MemoryModelMap.scala @@ -1,6 +1,5 @@ package analysis -import scala.util.boundary import analysis.* import ir.BitVecLiteral diff --git a/src/main/scala/ir/Visitor.scala b/src/main/scala/ir/Visitor.scala index 140670228..6fd3a2339 100644 --- a/src/main/scala/ir/Visitor.scala +++ b/src/main/scala/ir/Visitor.scala @@ -274,7 +274,7 @@ class Substituter(variables: Map[Variable, Variable] = Map(), memories: Map[Memo class Renamer(reserved: Set[String]) extends Visitor { override def visitLocalVar(node: LocalVar): LocalVar = { if (reserved.contains(node.name)) { - node.copy(name = '#' + node.name) + node.copy(name = s"#${node.name}") } else { node } @@ -282,7 +282,7 @@ class Renamer(reserved: Set[String]) extends Visitor { override def visitMemory(node: Memory): Memory = { if (reserved.contains(node.name)) { - node.copy(name = '#' + node.name) + node.copy(name = s"#${node.name}") } else { node } @@ -290,14 +290,14 @@ class Renamer(reserved: Set[String]) extends Visitor { override def visitParameter(node: Parameter): Parameter = { if (reserved.contains(node.name)) { - node.name = '#' + node.name + node.name = s"#${node.name}" } super.visitParameter(node) } override def visitProcedure(node: Procedure): Procedure = { if (reserved.contains(node.name)) { - node.name = '#' + node.name + node.name = s"#${node.name}" } super.visitProcedure(node) } @@ -337,4 +337,4 @@ class VariablesWithoutStoresLoads extends ReadOnlyVisitor { node } -} \ No newline at end of file +} diff --git a/src/main/scala/translating/ILtoIL.scala b/src/main/scala/translating/ILtoIL.scala index 9befdef74..d0aad93f5 100644 --- a/src/main/scala/translating/ILtoIL.scala +++ b/src/main/scala/translating/ILtoIL.scala @@ -15,7 +15,7 @@ private class ILSerialiser extends ReadOnlyVisitor { case Some(addr) => f"${addr}:${block.label}" case None => f"?:${block.label}" } - '"' + i + '"' + s"\"$i\"" } def procedureIdentifier(proc: Procedure): String = { @@ -23,7 +23,7 @@ private class ILSerialiser extends ReadOnlyVisitor { case Some(addr) => f"${addr}:${proc.name}" case None => f"?:${proc.name}" } - '"' + i + '"' + s"\"$i\"" } override def visitExpr(node: Expr): Expr = { @@ -200,7 +200,7 @@ private class ILSerialiser extends ReadOnlyVisitor { override def visitUnaryExpr(node: UnaryExpr): Expr = { program ++= "UnaryExpr(" - program ++= '"' + f"${node.op}" + '"' + ", " + program ++= "\"" + f"${node.op}" + "\"" + ", " visitExpr(node.arg) program ++= ")" node @@ -238,8 +238,7 @@ private class ILSerialiser extends ReadOnlyVisitor { override def visitMemory(node: Memory): Memory = { program ++= "Memory(" - program ++= '"' + node.name + '"' - program ++= f", ${node.addressSize}, ${node.valueSize})" + program ++= s"\"${node.name}\", ${node.addressSize}, ${node.valueSize})" node } From 3b31c5a31555db81a3bdb09e8c773c1c6f034ab4 Mon Sep 17 00:00:00 2001 From: Alistair Michael Date: Fri, 13 Oct 2023 17:16:30 +1000 Subject: [PATCH 5/5] bump scala version to 3.3.1 --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 15052da58..a196b3a09 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,6 @@ import scala.io.Source -ThisBuild / scalaVersion := "3.3.0" +ThisBuild / scalaVersion := "3.3.1" ThisBuild / version := "0.0.1" ThisBuild / organization := "uq.pac"