Skip to content

Commit

Permalink
only do the intersection of read/write vars
Browse files Browse the repository at this point in the history
  • Loading branch information
polgreen committed May 9, 2024
1 parent 099cd72 commit a194f26
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/main/scala/uclid/lang/BlockFlattener.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ package uclid
package lang

import com.typesafe.scalalogging.Logger
import java.util.jar.Attributes.Name


class BlockVariableRenamerPass extends RewritePass {
def renameVarList (vars : List[(Identifier, Type)], context : Scope) : List[(Identifier, Identifier, Type)] = {
Expand Down Expand Up @@ -140,7 +142,6 @@ class BlockFlattenerPass extends RewritePass {
}

def addConcurrentVars (blkStmt : BlockStmt, context: Scope) : BlockStmt = {

val filteredStmts = blkStmt.stmts.filter(_.isInstanceOf[BlockStmt])

if(filteredStmts.size != blkStmt.stmts.size)
Expand All @@ -157,13 +158,21 @@ class BlockFlattenerPass extends RewritePass {
acc ++ readSet
}
}.filter(id => context.map.contains(id) && context.map(id).isInstanceOf[Scope.StateVar]
&& (!id.name.startsWith("__ucld") || id.name.endsWith("_var")))
&& (!id.name.startsWith("__ucld")))

val writes = filteredStmts.foldLeft(Set.empty[Identifier]) {
(acc, blk) => {
val writeSet = StatementScheduler.writeSets(blk.asInstanceOf[BlockStmt].stmts, context)
acc ++ writeSet
}
}.filter(id => context.map.contains(id) && context.map(id).isInstanceOf[Scope.StateVar])

// create new vars. We only need new variables for the reads because there should only be
// create new vars. We only need new variables for the reads that are also written to
// because there should only be
// one write to a variable in a concurrent block. Blocks with more than one write will have been
// caught earlier
val varPairs: Map[Expr, Expr] =
reads.map(
reads.intersect(writes).map(
id => (id.asInstanceOf[Expr] -> NameProvider.get("block_" + id.toString()).asInstanceOf[Expr])).toMap
logger.debug("New vars: " + varPairs.toString())

Expand Down

0 comments on commit a194f26

Please sign in to comment.