mirror of
https://github.com/irmen/prog8.git
synced 2025-01-13 10:29:52 +00:00
subroutine inlining is an optimizer step
This commit is contained in:
parent
307558a7e7
commit
ec7b9f54c2
@ -26,10 +26,10 @@ internal fun Program.reorderStatements() {
|
|||||||
reorder.applyModifications()
|
reorder.applyModifications()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun Program.inlineSubroutines() {
|
internal fun Program.inlineSubroutines(): Int {
|
||||||
val reorder = SubroutineInliner(this)
|
val reorder = SubroutineInliner(this)
|
||||||
reorder.visit(this)
|
reorder.visit(this)
|
||||||
reorder.applyModifications()
|
return reorder.applyModifications()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun Program.addTypecasts(errors: ErrorReporter) {
|
internal fun Program.addTypecasts(errors: ErrorReporter) {
|
||||||
|
@ -150,7 +150,6 @@ private fun processAst(programAst: Program, errors: ErrorReporter, compilerOptio
|
|||||||
programAst.reorderStatements()
|
programAst.reorderStatements()
|
||||||
programAst.addTypecasts(errors)
|
programAst.addTypecasts(errors)
|
||||||
errors.handle()
|
errors.handle()
|
||||||
programAst.inlineSubroutines()
|
|
||||||
programAst.checkValid(compilerOptions, errors)
|
programAst.checkValid(compilerOptions, errors)
|
||||||
errors.handle()
|
errors.handle()
|
||||||
programAst.checkIdentifiers(errors)
|
programAst.checkIdentifiers(errors)
|
||||||
@ -164,9 +163,10 @@ private fun optimizeAst(programAst: Program, errors: ErrorReporter) {
|
|||||||
// keep optimizing expressions and statements until no more steps remain
|
// keep optimizing expressions and statements until no more steps remain
|
||||||
val optsDone1 = programAst.simplifyExpressions()
|
val optsDone1 = programAst.simplifyExpressions()
|
||||||
val optsDone2 = programAst.optimizeStatements(errors)
|
val optsDone2 = programAst.optimizeStatements(errors)
|
||||||
|
val optsDone3 = programAst.inlineSubroutines()
|
||||||
programAst.constantFold(errors) // because simplified statements and expressions could give rise to more constants that can be folded away:
|
programAst.constantFold(errors) // because simplified statements and expressions could give rise to more constants that can be folded away:
|
||||||
errors.handle()
|
errors.handle()
|
||||||
if (optsDone1 + optsDone2 == 0)
|
if (optsDone1 + optsDone2 + optsDone3 == 0)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user