mirror of
https://github.com/irmen/prog8.git
synced 2024-12-25 23:29:55 +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()
|
||||
}
|
||||
|
||||
internal fun Program.inlineSubroutines() {
|
||||
internal fun Program.inlineSubroutines(): Int {
|
||||
val reorder = SubroutineInliner(this)
|
||||
reorder.visit(this)
|
||||
reorder.applyModifications()
|
||||
return reorder.applyModifications()
|
||||
}
|
||||
|
||||
internal fun Program.addTypecasts(errors: ErrorReporter) {
|
||||
|
@ -150,7 +150,6 @@ private fun processAst(programAst: Program, errors: ErrorReporter, compilerOptio
|
||||
programAst.reorderStatements()
|
||||
programAst.addTypecasts(errors)
|
||||
errors.handle()
|
||||
programAst.inlineSubroutines()
|
||||
programAst.checkValid(compilerOptions, errors)
|
||||
errors.handle()
|
||||
programAst.checkIdentifiers(errors)
|
||||
@ -164,9 +163,10 @@ private fun optimizeAst(programAst: Program, errors: ErrorReporter) {
|
||||
// keep optimizing expressions and statements until no more steps remain
|
||||
val optsDone1 = programAst.simplifyExpressions()
|
||||
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:
|
||||
errors.handle()
|
||||
if (optsDone1 + optsDone2 == 0)
|
||||
if (optsDone1 + optsDone2 + optsDone3 == 0)
|
||||
break
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user