mirror of
https://github.com/irmen/prog8.git
synced 2025-02-27 03:29:22 +00:00
don't write the asm file twice
This commit is contained in:
parent
a67a82c921
commit
df997e5d3b
@ -23,6 +23,7 @@ import java.time.LocalDate
|
|||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.io.path.Path
|
import kotlin.io.path.Path
|
||||||
|
import kotlin.io.path.writeLines
|
||||||
import kotlin.math.absoluteValue
|
import kotlin.math.absoluteValue
|
||||||
|
|
||||||
|
|
||||||
@ -77,23 +78,15 @@ class AsmGen(private val program: Program,
|
|||||||
slaballocations()
|
slaballocations()
|
||||||
footer()
|
footer()
|
||||||
|
|
||||||
val outputFile = outputDir.resolve("${program.name}.asm").toFile()
|
|
||||||
outputFile.printWriter().use {
|
|
||||||
for (line in assemblyLines) { it.println(line) }
|
|
||||||
}
|
|
||||||
|
|
||||||
if(options.optimize) {
|
if(options.optimize) {
|
||||||
assemblyLines.clear()
|
|
||||||
assemblyLines.addAll(outputFile.readLines())
|
|
||||||
var optimizationsDone = 1
|
var optimizationsDone = 1
|
||||||
while (optimizationsDone > 0) {
|
while (optimizationsDone > 0) {
|
||||||
optimizationsDone = optimizeAssembly(assemblyLines, options.compTarget.machine, program)
|
optimizationsDone = optimizeAssembly(assemblyLines, options.compTarget.machine, program)
|
||||||
}
|
}
|
||||||
outputFile.printWriter().use {
|
|
||||||
for (line in assemblyLines) { it.println(line) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
outputDir.resolve("${program.name}.asm").writeLines(assemblyLines)
|
||||||
|
|
||||||
return if(errors.noErrors())
|
return if(errors.noErrors())
|
||||||
AssemblyProgram(true, program.name, outputDir, compTarget.name)
|
AssemblyProgram(true, program.name, outputDir, compTarget.name)
|
||||||
else {
|
else {
|
||||||
@ -253,10 +246,9 @@ class AsmGen(private val program: Program,
|
|||||||
|
|
||||||
internal fun out(str: String, splitlines: Boolean = true) {
|
internal fun out(str: String, splitlines: Boolean = true) {
|
||||||
val fragment = (if(" | " in str) str.replace("|", "\n") else str).trim('\n')
|
val fragment = (if(" | " in str) str.replace("|", "\n") else str).trim('\n')
|
||||||
|
|
||||||
if (splitlines) {
|
if (splitlines) {
|
||||||
for (line in fragment.split('\n')) {
|
for (line in fragment.splitToSequence('\n')) {
|
||||||
val trimmed = if (line.startsWith(' ')) "\t" + line.trim() else line.trim()
|
val trimmed = if (line.startsWith(' ')) "\t" + line.trim() else line
|
||||||
// trimmed = trimmed.replace(Regex("^\\+\\s+"), "+\t") // sanitize local label indentation
|
// trimmed = trimmed.replace(Regex("^\\+\\s+"), "+\t") // sanitize local label indentation
|
||||||
assemblyLines.add(trimmed)
|
assemblyLines.add(trimmed)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user