1
0
mirror of https://github.com/KarolS/millfork.git synced 2024-07-05 09:28:54 +00:00

Fix deduplication

This commit is contained in:
Karol Stasiak 2018-12-26 15:28:57 +01:00
parent 0bb662183c
commit b77f9dd5f8
3 changed files with 12 additions and 2 deletions

View File

@ -144,7 +144,8 @@ abstract class Deduplicate[T <: AbstractCode](env: Environment, options: Compila
def deduplicateIdenticalFunctions(segmentName: String, segContents: Map[String, Either[String, CodeAndAlignment[T]]]): Seq[(String, CompiledFunction[T])] = {
var result = ListBuffer[(String, CompiledFunction[T])]()
val identicalFunctions = segContents.flatMap{
case (name, code) => code.toOption.map(c => name -> actualCode(name, c.code))
case (name, code) =>
code.toOption.map(c => name -> removePositionInfo(actualCode(name, c.code)))
}.filter{
case (_, code) => checkIfLabelsAreInternal(code, code)
}.groupBy{
@ -294,6 +295,10 @@ abstract class Deduplicate[T <: AbstractCode](env: Environment, options: Compila
def renumerateLabels(code: List[T], temporary: Boolean): List[T]
def removePositionInfo(line: T): T
def removePositionInfo(code: List[T]): List[T] = code.map((t:T) => removePositionInfo(t))
def checkIfLabelsAreInternal(snippet: List[T], code: List[T]): Boolean
def bySegment(compiledFunctions: mutable.Map[String, CompiledFunction[T]]): Map[String, Map[String, Either[String, CodeAndAlignment[T]]]] = {
@ -319,7 +324,7 @@ abstract class Deduplicate[T <: AbstractCode](env: Environment, options: Compila
val (good, rest2) = mutCode.span(l => isExtractable(l))
mutCode = rest2
if (good.nonEmpty) {
result += CodeChunk(functionName, cursor, cursor + good.length)(good)
result += CodeChunk(functionName, cursor, cursor + good.length)(removePositionInfo(good))
cursor += good.length
} else {
//println(s"Snippets in $functionName: $result")

View File

@ -112,4 +112,6 @@ class MosDeduplicate(env: Environment, options: CompilationOptions) extends Dedu
useCount.values.forall(_ == 0)
}
override def removePositionInfo(line: AssemblyLine): AssemblyLine = line.copy(source = None)
}

View File

@ -120,4 +120,7 @@ class Z80Deduplicate(env: Environment, options: CompilationOptions) extends Dedu
}
useCount.values.forall(_ == 0)
}
override def removePositionInfo(line: ZLine): ZLine = line.copy(source = None)
}