mirror of
https://github.com/KarolS/millfork.git
synced 2025-02-04 18:32:38 +00:00
Fix deduplication
This commit is contained in:
parent
0bb662183c
commit
b77f9dd5f8
@ -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")
|
||||
|
@ -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)
|
||||
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user