mirror of
https://github.com/irmen/prog8.git
synced 2025-02-16 22:30:46 +00:00
reinitGlobals option is clearer than the inverse
This commit is contained in:
parent
adc15c24ef
commit
c3c82282ba
@ -16,7 +16,7 @@ class CompilationOptions(val output: OutputType,
|
||||
var slowCodegenWarnings: Boolean = false,
|
||||
var optimize: Boolean = false,
|
||||
var optimizeFloatExpressions: Boolean = false,
|
||||
var dontReinitGlobals: Boolean = false,
|
||||
var reinitGlobals: Boolean = true,
|
||||
var asmQuiet: Boolean = false,
|
||||
var asmListfile: Boolean = false,
|
||||
var experimentalCodegen: Boolean = false,
|
||||
|
@ -201,7 +201,7 @@ internal class ProgramAndVarsGen(
|
||||
val notInitializers = block.children.filterNot { it in initializers }
|
||||
notInitializers.forEach { asmgen.translate(it) }
|
||||
|
||||
if(!options.dontReinitGlobals) {
|
||||
if(options.reinitGlobals) {
|
||||
// generate subroutine to initialize block-level (global) variables
|
||||
if (initializers.isNotEmpty()) {
|
||||
asmgen.out("prog8_init_vars\t.block")
|
||||
@ -364,7 +364,7 @@ internal class ProgramAndVarsGen(
|
||||
private fun entrypointInitialization() {
|
||||
asmgen.out("; program startup initialization")
|
||||
asmgen.out(" cld")
|
||||
if(!options.dontReinitGlobals) {
|
||||
if(options.reinitGlobals) {
|
||||
blockVariableInitializers.forEach {
|
||||
if (it.value.isNotEmpty())
|
||||
asmgen.out(" jsr ${it.key.name}.prog8_init_vars")
|
||||
|
@ -33,7 +33,7 @@ class IRCodeGen(
|
||||
if(options.evalStackBaseAddress!=null)
|
||||
throw AssemblyError("IR doesn't use eval-stack")
|
||||
|
||||
if(!options.dontReinitGlobals) {
|
||||
if(options.reinitGlobals) {
|
||||
// collect global variables initializers
|
||||
program.allBlocks().forEach {
|
||||
val result = mutableListOf<IRCodeChunkBase>()
|
||||
|
@ -120,7 +120,7 @@ private fun compileMain(args: Array<String>): Boolean {
|
||||
filepath,
|
||||
dontOptimize != true,
|
||||
optimizeFloatExpressions == true,
|
||||
dontReinitGlobals == true,
|
||||
dontReinitGlobals != true,
|
||||
dontWriteAssembly != true,
|
||||
slowCodegenWarnings == true,
|
||||
quietAssembler == true,
|
||||
@ -184,7 +184,7 @@ private fun compileMain(args: Array<String>): Boolean {
|
||||
filepath,
|
||||
dontOptimize != true,
|
||||
optimizeFloatExpressions == true,
|
||||
dontReinitGlobals == true,
|
||||
dontReinitGlobals != true,
|
||||
dontWriteAssembly != true,
|
||||
slowCodegenWarnings == true,
|
||||
quietAssembler == true,
|
||||
|
@ -6,11 +6,9 @@ import prog8.ast.Program
|
||||
import prog8.ast.base.AstException
|
||||
import prog8.ast.expressions.Expression
|
||||
import prog8.ast.expressions.NumericLiteral
|
||||
import prog8.ast.printProgram
|
||||
import prog8.ast.statements.Directive
|
||||
import prog8.code.SymbolTableMaker
|
||||
import prog8.code.ast.PtProgram
|
||||
import prog8.code.ast.printAst
|
||||
import prog8.code.core.*
|
||||
import prog8.code.target.*
|
||||
import prog8.codegen.vm.VmCodeGen
|
||||
@ -32,7 +30,7 @@ class CompilationResult(val compilerAst: Program, // deprecated, use codegenAs
|
||||
class CompilerArguments(val filepath: Path,
|
||||
val optimize: Boolean,
|
||||
val optimizeFloatExpressions: Boolean,
|
||||
val dontReinitGlobals: Boolean,
|
||||
val reinitGlobals: Boolean,
|
||||
val writeAssembly: Boolean,
|
||||
val slowCodegenWarnings: Boolean,
|
||||
val quietAssembler: Boolean,
|
||||
@ -77,7 +75,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult? {
|
||||
slowCodegenWarnings = args.slowCodegenWarnings
|
||||
optimize = args.optimize
|
||||
optimizeFloatExpressions = optimizeFloatExpr
|
||||
dontReinitGlobals = args.dontReinitGlobals
|
||||
reinitGlobals = args.reinitGlobals
|
||||
asmQuiet = args.quietAssembler
|
||||
asmListfile = args.asmListfile
|
||||
experimentalCodegen = args.experimentalCodegen
|
||||
|
@ -38,7 +38,7 @@ internal class BeforeAsmAstChanger(val program: Program,
|
||||
|
||||
override fun before(block: Block, parent: Node): Iterable<IAstModification> {
|
||||
// adjust global variables initialization
|
||||
if(options.dontReinitGlobals) {
|
||||
if(!options.reinitGlobals) {
|
||||
block.statements.asSequence().filterIsInstance<VarDecl>().forEach {
|
||||
if(it.type==VarDeclType.VAR) {
|
||||
it.zeropage = ZeropageWish.NOT_IN_ZEROPAGE
|
||||
@ -53,7 +53,7 @@ internal class BeforeAsmAstChanger(val program: Program,
|
||||
}
|
||||
|
||||
override fun after(decl: VarDecl, parent: Node): Iterable<IAstModification> {
|
||||
if(!options.dontReinitGlobals) {
|
||||
if(options.reinitGlobals) {
|
||||
if (decl.type == VarDeclType.VAR && decl.value != null && decl.datatype in NumericDatatypes)
|
||||
throw InternalCompilerException("vardecls for variables, with initial numerical value, should have been rewritten as plain vardecl + assignment $decl")
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ private fun compileTheThing(filepath: Path, optimize: Boolean, target: ICompilat
|
||||
filepath,
|
||||
optimize,
|
||||
optimizeFloatExpressions = true,
|
||||
dontReinitGlobals = false,
|
||||
reinitGlobals = true,
|
||||
writeAssembly = true,
|
||||
slowCodegenWarnings = false,
|
||||
quietAssembler = true,
|
||||
|
@ -44,7 +44,7 @@ class TestCompilerOptionSourcedirs: FunSpec({
|
||||
filepath = filePath,
|
||||
optimize = false,
|
||||
optimizeFloatExpressions = false,
|
||||
dontReinitGlobals = false,
|
||||
reinitGlobals = true,
|
||||
writeAssembly = true,
|
||||
slowCodegenWarnings = false,
|
||||
quietAssembler = true,
|
||||
|
@ -25,7 +25,7 @@ internal fun compileFile(
|
||||
filepath,
|
||||
optimize,
|
||||
optimizeFloatExpressions = optFloatExpr,
|
||||
dontReinitGlobals = false,
|
||||
reinitGlobals = true,
|
||||
writeAssembly = writeAssembly,
|
||||
slowCodegenWarnings = false,
|
||||
quietAssembler = true,
|
||||
|
@ -3,10 +3,12 @@ TODO
|
||||
|
||||
For next minor release
|
||||
^^^^^^^^^^^^^^^^^^^^^^
|
||||
- cleanup handling of noreinit
|
||||
- cleanup handling of noreinit / fix compilation crash of petaxian with this option enabled
|
||||
- BSS: initialize BSS block (without slabs!) to zeros on start, using 1 loop instead of all those initialization assignments
|
||||
- BSS subroutine parameters don't have to be set to 0. But meh, the loop should be super fast anyway.
|
||||
- allow putting BSS in specific upper memory block ($a000-$bfff, $c000-$cfff on C64) add a .cerror check for overflow!
|
||||
- option to put BSS in specific upper memory block ($a000-$bfff, $c000-$cfff on C64) add a .cerror check for overflow!
|
||||
- document bss stuff in the manual
|
||||
|
||||
|
||||
...
|
||||
|
||||
|
@ -34,7 +34,7 @@ class RequestParser : Take {
|
||||
Path(a),
|
||||
optimize = true,
|
||||
optimizeFloatExpressions = false,
|
||||
dontReinitGlobals = false,
|
||||
reinitGlobals = true,
|
||||
writeAssembly = true,
|
||||
slowCodegenWarnings = true,
|
||||
compilationTarget = "c64",
|
||||
|
@ -46,7 +46,7 @@ class IRFileReader {
|
||||
val options = parseOptions(reader)
|
||||
val asmsymbols = parseAsmSymbols(reader)
|
||||
val varsWithoutInit = parseVarsWithoutInit(reader)
|
||||
val variables = parseVariables(reader, options.dontReinitGlobals)
|
||||
val variables = parseVariables(reader)
|
||||
val memorymapped = parseMemMapped(reader)
|
||||
val slabs = parseSlabs(reader)
|
||||
val initGlobals = parseInitGlobals(reader)
|
||||
@ -82,7 +82,7 @@ class IRFileReader {
|
||||
var zeropage = ZeropageType.FULL
|
||||
val zpReserved = mutableListOf<UIntRange>()
|
||||
var loadAddress = target.machine.PROGRAM_LOAD_ADDRESS
|
||||
var dontReinitGlobals = false
|
||||
var reInitGlobals = true
|
||||
var optimize = true
|
||||
var evalStackBaseAddress: UInt? = null
|
||||
var outputDir = Path("")
|
||||
@ -105,7 +105,7 @@ class IRFileReader {
|
||||
"launcher" -> launcher = CbmPrgLauncherType.valueOf(value)
|
||||
"zeropage" -> zeropage = ZeropageType.valueOf(value)
|
||||
"loadAddress" -> loadAddress = value.toUInt()
|
||||
"dontReinitGlobals" -> dontReinitGlobals = value.toBoolean()
|
||||
"reinitGlobals" -> reInitGlobals = value.toBoolean()
|
||||
"evalStackBaseAddress" -> evalStackBaseAddress = if(value=="null") null else parseIRValue(value).toUInt()
|
||||
"zpReserved" -> {
|
||||
val (zpstart, zpend) = value.split(',')
|
||||
@ -127,10 +127,10 @@ class IRFileReader {
|
||||
false,
|
||||
target,
|
||||
loadAddress,
|
||||
dontReinitGlobals = dontReinitGlobals,
|
||||
evalStackBaseAddress = evalStackBaseAddress,
|
||||
outputDir = outputDir,
|
||||
optimize = optimize
|
||||
optimize = optimize,
|
||||
reinitGlobals = reInitGlobals
|
||||
)
|
||||
}
|
||||
|
||||
@ -179,7 +179,7 @@ class IRFileReader {
|
||||
}
|
||||
}
|
||||
|
||||
private fun parseVariables(reader: XMLEventReader, dontReinitGlobals: Boolean): List<StStaticVariable> {
|
||||
private fun parseVariables(reader: XMLEventReader): List<StStaticVariable> {
|
||||
skipText(reader)
|
||||
val start = reader.nextEvent().asStartElement()
|
||||
require(start.name.localPart=="VARIABLESWITHINIT") { "missing VARIABLESWITHINIT" }
|
||||
|
@ -22,7 +22,7 @@ class IRFileWriter(private val irProgram: IRProgram, outfileOverride: Path?) {
|
||||
writeVariables()
|
||||
|
||||
out.write("\n<INITGLOBALS>\n")
|
||||
if(!irProgram.options.dontReinitGlobals) {
|
||||
if(irProgram.options.reinitGlobals) {
|
||||
// note: this a block of code that loads values and stores them into the global variables to reset their values.
|
||||
writeCodeChunk(irProgram.globalInits)
|
||||
}
|
||||
@ -130,7 +130,7 @@ class IRFileWriter(private val irProgram: IRProgram, outfileOverride: Path?) {
|
||||
}
|
||||
out.write("loadAddress=${irProgram.options.loadAddress.toHex()}\n")
|
||||
out.write("optimize=${irProgram.options.optimize}\n")
|
||||
out.write("dontReinitGlobals=${irProgram.options.dontReinitGlobals}\n")
|
||||
out.write("reinitGlobals=${irProgram.options.reinitGlobals}\n")
|
||||
out.write("evalStackBaseAddress=${irProgram.options.evalStackBaseAddress?.toHex()}\n")
|
||||
out.write("outputDir=${irProgram.options.outputDir.toAbsolutePath()}\n")
|
||||
// other options not yet useful here?
|
||||
|
@ -48,7 +48,7 @@ output=PRG
|
||||
launcher=BASIC
|
||||
zeropage=KERNALSAFE
|
||||
loadAddress=0
|
||||
dontReinitGlobals=true
|
||||
reinitGlobals=false
|
||||
evalStackBaseAddress=null
|
||||
</OPTIONS>
|
||||
|
||||
|
@ -15,7 +15,7 @@ class VmProgramLoader {
|
||||
|
||||
varsToMemory(irProgram, allocations, variableAddresses, memory)
|
||||
|
||||
if(!irProgram.options.dontReinitGlobals) {
|
||||
if(irProgram.options.reinitGlobals) {
|
||||
if(irProgram.globalInits.isNotEmpty())
|
||||
programChunks += irProgram.globalInits
|
||||
}
|
||||
@ -197,7 +197,8 @@ class VmProgramLoader {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(program.options.dontReinitGlobals) {
|
||||
if(!program.options.reinitGlobals) {
|
||||
// variable is not initialized as part of a global reinitialization, so we clear it here
|
||||
when(variable.dt) {
|
||||
in ByteDatatypes -> memory.setUB(addr, 0u)
|
||||
in WordDatatypes -> memory.setUW(addr, 0u)
|
||||
|
Loading…
x
Reference in New Issue
Block a user