This commit is contained in:
Irmen de Jong 2022-02-10 22:16:09 +01:00
parent c13b7fd883
commit bd0dee5db5
6 changed files with 12 additions and 23 deletions

View File

@ -1,10 +1,13 @@
package prog8.codegen.cpu6502
import com.github.michaelbull.result.fold
import prog8.ast.*
import prog8.ast.IFunctionCall
import prog8.ast.Node
import prog8.ast.Program
import prog8.ast.base.*
import prog8.ast.expressions.*
import prog8.ast.statements.*
import prog8.ast.toHex
import prog8.codegen.cpu6502.assignment.*
import prog8.compilerinterface.*
import prog8.parser.SourceCode

View File

@ -1,10 +1,12 @@
package prog8.codegen.cpu6502
import prog8.ast.*
import prog8.ast.INameScope
import prog8.ast.Program
import prog8.ast.antlr.escape
import prog8.ast.base.*
import prog8.ast.expressions.*
import prog8.ast.statements.*
import prog8.ast.toHex
import prog8.codegen.cpu6502.assignment.AsmAssignTarget
import prog8.codegen.cpu6502.assignment.TargetStorageKind
import prog8.compilerinterface.*

View File

@ -2,7 +2,9 @@ package prog8.codegen.cpu6502
import com.github.michaelbull.result.fold
import com.github.michaelbull.result.onSuccess
import prog8.ast.base.*
import prog8.ast.base.ArrayDatatypes
import prog8.ast.base.DataType
import prog8.ast.base.IntegerDatatypes
import prog8.ast.expressions.StringLiteralValue
import prog8.ast.statements.Subroutine
import prog8.ast.statements.ZeropageWish
@ -41,8 +43,6 @@ internal class VariableAllocator(private val vars: IVariablesAndConsts,
).toList()
val numberOfAllocatableVariables = allVariables.size
val totalAllocatedMemorySize = allVariables.sumOf { memsize(it) }
val varsRequiringZp = allVariables.filter { it.zp == ZeropageWish.REQUIRE_ZEROPAGE }
val varsPreferringZp = allVariables.filter { it.zp == ZeropageWish.PREFER_ZEROPAGE }
val varsDontCare = allVariables.filter { it.zp == ZeropageWish.DONTCARE }
@ -115,21 +115,11 @@ internal class VariableAllocator(private val vars: IVariablesAndConsts,
}
}
println(" number of allocated vars: $numberOfAllocatableVariables total size: $totalAllocatedMemorySize")
println(" number of allocated vars: $numberOfAllocatableVariables")
println(" put into zeropage: $numVariablesAllocatedInZP, non-zp allocatable: ${numberOfNonIntegerVariables+numberOfExplicitNonZpVariables}")
println(" zeropage free space: ${zeropage.free.size} bytes")
}
private fun memsize(variable: IVariablesAndConsts.StaticVariable): Int {
return when(variable.type) {
in NumericDatatypes ->
options.compTarget.memorySize(variable.type)
in ArrayDatatypes -> variable.arraysize!! * options.compTarget.memorySize(ArrayToElementTypes.getValue(variable.type))
DataType.STR -> (variable.initialValue as StringLiteralValue).value.length + 1
else -> 0
}
}
internal fun isZpVar(scopedName: List<String>) = scopedName in zeropage.variables
private fun numArrayElements(variable: IVariablesAndConsts.StaticVariable) =

View File

@ -4,12 +4,7 @@ import prog8.ast.IBuiltinFunctions
import prog8.ast.Program
import prog8.ast.base.DataType
import prog8.ast.base.FatalAstException
import prog8.ast.base.Position
import prog8.ast.base.VarDeclType
import prog8.ast.expressions.InferredTypes
import prog8.ast.statements.VarDecl
import prog8.ast.statements.VarDeclOrigin
import prog8.ast.statements.ZeropageWish
import prog8.compilerinterface.CompilationOptions
import prog8.compilerinterface.ICompilationTarget
import prog8.compilerinterface.IErrorReporter

View File

@ -56,6 +56,7 @@ internal class BeforeAsmAstChanger(val program: Program,
}
// TODO get rid of the vardecl inside the ast - codegen should depend on the IVariableAllocation object
// but if we do this now, all variable name lookups break because these are still done on the Ast directly rather than on a separate symbol table
// return listOf(IAstModification.Remove(decl, parent as IStatementContainer))
return noModifications
}

View File

@ -4,9 +4,7 @@ import java.io.File
import java.io.IOException
import java.nio.file.Path
import kotlin.io.path.Path
import kotlin.io.path.name
import kotlin.io.path.readText
import kotlin.io.path.toPath
/**
* Encapsulates - and ties together - actual source code (=text) and its [origin].