small refactor

This commit is contained in:
Irmen de Jong 2022-01-08 18:02:38 +01:00
parent 9e5e3d1559
commit 6fa3f0b6cd
4 changed files with 13 additions and 29 deletions

View File

@ -9,8 +9,6 @@ import prog8.ast.expressions.NumericLiteralValue
import prog8.ast.statements.Directive
import prog8.ast.walk.AstWalker
import prog8.ast.walk.IAstModification
import prog8.compiler.BeforeAsmGenerationAstChanger
import prog8.compiler.BeforeAsmTypecastCleaner
import prog8.compilerinterface.CompilationOptions
import prog8.compilerinterface.IErrorReporter
import prog8.compilerinterface.IStringEncoding
@ -24,7 +22,7 @@ internal fun Program.checkValid(errors: IErrorReporter, compilerOptions: Compila
}
internal fun Program.processAstBeforeAsmGeneration(compilerOptions: CompilationOptions, errors: IErrorReporter) {
val fixer = BeforeAsmGenerationAstChanger(this, compilerOptions, errors)
val fixer = BeforeAsmAstChanger(this, compilerOptions, errors)
fixer.visit(this)
while(errors.noErrors() && fixer.applyModifications()>0) {
fixer.visit(this)

View File

@ -1,4 +1,4 @@
package prog8.compiler
package prog8.compiler.astprocessing
import prog8.ast.IFunctionCall
import prog8.ast.IStatementContainer
@ -16,8 +16,8 @@ import prog8.compilerinterface.IErrorReporter
import prog8.compilerinterface.isIOAddress
import prog8.optimizer.getTempVarName
internal class BeforeAsmGenerationAstChanger(val program: Program, private val options: CompilationOptions,
private val errors: IErrorReporter
internal class BeforeAsmAstChanger(val program: Program, private val options: CompilationOptions,
private val errors: IErrorReporter
) : AstWalker() {
private val subroutineVariables = mutableMapOf<Subroutine, MutableList<Pair<String, VarDecl>>>()

View File

@ -1,4 +1,4 @@
package prog8.compiler
package prog8.compiler.astprocessing
import prog8.ast.IFunctionCall
import prog8.ast.Node
@ -13,7 +13,6 @@ import prog8.ast.expressions.IdentifierReference
import prog8.ast.expressions.TypecastExpression
import prog8.ast.walk.AstWalker
import prog8.ast.walk.IAstModification
import prog8.compiler.astprocessing.isSubroutineParameter
import prog8.compilerinterface.IErrorReporter
internal class BeforeAsmTypecastCleaner(val program: Program,

View File

@ -14,19 +14,14 @@ import prog8.ast.base.ParentSentinel
import prog8.ast.base.Position
import prog8.ast.expressions.*
import prog8.ast.statements.*
import prog8.compiler.printProgram
import prog8.codegen.target.C64Target
import prog8.compiler.BeforeAsmGenerationAstChanger
import prog8.compiler.BeforeAsmTypecastCleaner
import prog8.compilerinterface.*
import prog8.compiler.astprocessing.processAstBeforeAsmGeneration
import prog8.compiler.printProgram
import prog8.compilerinterface.CompilationOptions
import prog8.compilerinterface.LauncherType
import prog8.compilerinterface.OutputType
import prog8.compilerinterface.ZeropageType
import prog8tests.helpers.*
import prog8tests.helpers.DummyFunctions
import prog8tests.helpers.DummyMemsizer
import prog8tests.helpers.DummyStringEncoder
import prog8tests.helpers.ErrorReporterForTests
import prog8tests.helpers.assertSuccess
import prog8tests.helpers.compileText
import prog8tests.helpers.generateAssembly
class TestOptimization: FunSpec({
test("remove empty subroutine except start") {
@ -305,16 +300,8 @@ class TestOptimization: FunSpec({
expr.inferType(result.program).getOrElse { fail("dt") } shouldBe DataType.UBYTE
val options = CompilationOptions(OutputType.RAW, LauncherType.NONE, ZeropageType.DONTUSE, emptyList(), false, true, C64Target)
val changer = BeforeAsmGenerationAstChanger(result.program, options, ErrorReporterForTests())
changer.visit(result.program)
while(changer.applyModifications()>0) {
changer.visit(result.program)
}
val cleaner = BeforeAsmTypecastCleaner(result.program, ErrorReporterForTests())
cleaner.visit(result.program)
while(cleaner.applyModifications()>0) {
cleaner.visit(result.program)
}
result.program.processAstBeforeAsmGeneration(options, ErrorReporterForTests())
// assignment is now split into:
// bb = not bb
// bb = (bb or not ww)