Skip to content

Commit

Permalink
fix #100
Browse files Browse the repository at this point in the history
  • Loading branch information
l-kent committed Oct 13, 2023
1 parent 96bc93f commit dc64d3f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main/scala/ir/Program.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,10 @@ class Procedure(
}

// update stack references
val rhsStackRefs = l.rhs.variables.intersect(stackRefs)
val variableVisitor = VariablesWithoutStoresLoads()
variableVisitor.visitExpr(l.rhs)

val rhsStackRefs = variableVisitor.variables.toSet.intersect(stackRefs)
if (rhsStackRefs.nonEmpty) {
stackRefs.add(l.lhs)
} else if (stackRefs.contains(l.lhs) && l.lhs != stackPointer) {
Expand All @@ -160,7 +163,8 @@ class Procedure(
for (j <- b.jumps) {
j match {
case g: GoTo => visitBlock(g.target)
case _ =>
case d: DirectCall => d.returnTarget.foreach(visitBlock)
case i: IndirectCall => i.returnTarget.foreach(visitBlock)
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/main/scala/ir/Visitor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,27 @@ class ExternalRemover(external: Set[String]) extends Visitor {
super.visitProcedure(node)
}
}

/** Gives variables that are not contained within a MemoryStore or MemoryLoad
* */
class VariablesWithoutStoresLoads extends ReadOnlyVisitor {
val variables: mutable.Set[Variable] = mutable.Set()

override def visitRegister(node: Register): Register = {
variables.add(node)
node
}
override def visitLocalVar(node: LocalVar): LocalVar = {
variables.add(node)
node
}

override def visitMemoryStore(node: MemoryStore): MemoryStore = {
node
}

override def visitMemoryLoad(node: MemoryLoad): MemoryLoad = {
node
}

}

0 comments on commit dc64d3f

Please sign in to comment.