Skip to content

Commit

Permalink
Fixed optimizer
Browse files Browse the repository at this point in the history
  • Loading branch information
leventeBajczi committed Nov 11, 2024
1 parent a9707cf commit b069cba
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,33 @@ fun XCFA.optimizeFurther(passes: List<ProcedurePass>): XCFA {
if (passes.isEmpty()) return this
val passManager = ProcedurePassManager(passes)
val copy: XcfaProcedureBuilder.() -> XcfaProcedureBuilder = {
val newLocs = getLocs().associateWith { it.copy() }
XcfaProcedureBuilder(
name = name,
manager = passManager,
params = getParams().toMutableList(),
vars = getVars().toMutableSet(),
locs = getLocs().toMutableSet(),
edges = getEdges().toMutableSet(),
locs = getLocs().map { newLocs[it]!! }.toMutableSet(),
edges =
getEdges()
.map {
val source = newLocs[it.source]!!
val target = newLocs[it.target]!!
val edge = it.withSource(source).withTarget(target)
source.outgoingEdges.add(edge)
target.incomingEdges.add(edge)
edge
}
.toMutableSet(),
metaData = metaData.toMutableMap(),
)
.also { it.copyMetaLocs(this) }
.also {
it.copyMetaLocs(
newLocs[initLoc]!!,
finalLoc.map { newLocs[it] },
errorLoc.map { newLocs[it] },
)
}
}

val builder = XcfaBuilder(name, globalVars.toMutableSet())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,17 @@ constructor(
}
}

fun copyMetaLocs(from: XcfaProcedureBuilder) {
fun copyMetaLocs(
initLoc: XcfaLocation,
finalLoc: Optional<XcfaLocation>,
errorLoc: Optional<XcfaLocation>,
) {
check(!this::optimized.isInitialized) {
"Cannot add/remove new elements after optimization passes!"
}
initLoc = from.initLoc
finalLoc = from.finalLoc
errorLoc = from.errorLoc
this.initLoc = initLoc
this.finalLoc = finalLoc
this.errorLoc = errorLoc
}

fun addEdge(toAdd: XcfaEdge) {
Expand Down

0 comments on commit b069cba

Please sign in to comment.