Skip to content

Commit

Permalink
Merge pull request #104 from UQ-PAC/update-scala
Browse files Browse the repository at this point in the history
Update scala to 3.3.1
  • Loading branch information
l-kent authored Oct 16, 2023
2 parents 8929c41 + 7f1dd63 commit 024d25c
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 52 deletions.
4 changes: 3 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import scala.io.Source

ThisBuild / scalaVersion := "3.1.0"
ThisBuild / scalaVersion := "3.3.1"
ThisBuild / version := "0.0.1"
ThisBuild / organization := "uq.pac"

Expand Down Expand Up @@ -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 := {
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/analysis/Cfg.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
10 changes: 0 additions & 10 deletions src/main/scala/analysis/Lattice.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 11 additions & 25 deletions src/main/scala/analysis/MemoryModelMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,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)
}
}
}

Expand All @@ -98,25 +97,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"
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/analysis/SteensgaardAnalysis.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/analysis/VSA.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ")"
}

Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/ir/Visitor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -274,30 +274,30 @@ 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
}
}

override def visitMemory(node: Memory): Memory = {
if (reserved.contains(node.name)) {
node.copy(name = '#' + node.name)
node.copy(name = s"#${node.name}")
} else {
node
}
}

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)
}
Expand Down Expand Up @@ -337,4 +337,4 @@ class VariablesWithoutStoresLoads extends ReadOnlyVisitor {
node
}

}
}
9 changes: 4 additions & 5 deletions src/main/scala/translating/ILtoIL.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ 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 = {
val i = proc.address match {
case Some(addr) => f"${addr}:${proc.name}"
case None => f"?:${proc.name}"
}
'"' + i + '"'
s"\"$i\""
}

override def visitExpr(node: Expr): Expr = {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 024d25c

Please sign in to comment.