mirror of
https://github.com/irmen/prog8.git
synced 2024-09-09 17:55:07 +00:00
added 'slowwarn' cli option
This commit is contained in:
parent
30da26b9a9
commit
3eaf111e7d
@ -38,6 +38,7 @@ private fun compileMain(args: Array<String>) {
|
|||||||
val dontWriteAssembly by cli.flagArgument("-noasm", "don't create assembly code")
|
val dontWriteAssembly by cli.flagArgument("-noasm", "don't create assembly code")
|
||||||
val dontOptimize by cli.flagArgument("-noopt", "don't perform any optimizations")
|
val dontOptimize by cli.flagArgument("-noopt", "don't perform any optimizations")
|
||||||
val watchMode by cli.flagArgument("-watch", "continuous compilation mode (watches for file changes), greatly increases compilation speed")
|
val watchMode by cli.flagArgument("-watch", "continuous compilation mode (watches for file changes), greatly increases compilation speed")
|
||||||
|
val slowCodegenWarnings by cli.flagArgument("-slowwarn", "show debug warnings about slow/problematic assembly code generation")
|
||||||
val compilationTarget by cli.flagValueArgument("-target", "compilertarget",
|
val compilationTarget by cli.flagValueArgument("-target", "compilertarget",
|
||||||
"target output of the compiler, currently '${C64Target.name}' and '${Cx16Target.name}' available", C64Target.name)
|
"target output of the compiler, currently '${C64Target.name}' and '${Cx16Target.name}' available", C64Target.name)
|
||||||
val moduleFiles by cli.positionalArgumentsList("modules", "main module file(s) to compile", minArgs = 1)
|
val moduleFiles by cli.positionalArgumentsList("modules", "main module file(s) to compile", minArgs = 1)
|
||||||
@ -62,7 +63,7 @@ private fun compileMain(args: Array<String>) {
|
|||||||
println("Continuous watch mode active. Main module: $filepath")
|
println("Continuous watch mode active. Main module: $filepath")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
val compilationResult = compileProgram(filepath, !dontOptimize, !dontWriteAssembly, compilationTarget, outputPath)
|
val compilationResult = compileProgram(filepath, !dontOptimize, !dontWriteAssembly, slowCodegenWarnings, compilationTarget, outputPath)
|
||||||
println("Imported files (now watching:)")
|
println("Imported files (now watching:)")
|
||||||
for (importedFile in compilationResult.importedFiles) {
|
for (importedFile in compilationResult.importedFiles) {
|
||||||
print(" ")
|
print(" ")
|
||||||
@ -87,7 +88,7 @@ private fun compileMain(args: Array<String>) {
|
|||||||
val filepath = pathFrom(filepathRaw).normalize()
|
val filepath = pathFrom(filepathRaw).normalize()
|
||||||
val compilationResult: CompilationResult
|
val compilationResult: CompilationResult
|
||||||
try {
|
try {
|
||||||
compilationResult = compileProgram(filepath, !dontOptimize, !dontWriteAssembly, compilationTarget, outputPath)
|
compilationResult = compileProgram(filepath, !dontOptimize, !dontWriteAssembly, slowCodegenWarnings, compilationTarget, outputPath)
|
||||||
if(!compilationResult.success)
|
if(!compilationResult.success)
|
||||||
exitProcess(1)
|
exitProcess(1)
|
||||||
} catch (x: ParsingFailedError) {
|
} catch (x: ParsingFailedError) {
|
||||||
|
@ -28,7 +28,9 @@ data class CompilationOptions(val output: OutputType,
|
|||||||
val zeropage: ZeropageType,
|
val zeropage: ZeropageType,
|
||||||
val zpReserved: List<IntRange>,
|
val zpReserved: List<IntRange>,
|
||||||
val floats: Boolean,
|
val floats: Boolean,
|
||||||
val noSysInit: Boolean)
|
val noSysInit: Boolean) {
|
||||||
|
var slowCodegenWarnings = false
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class CompilerException(message: String?) : Exception(message)
|
class CompilerException(message: String?) : Exception(message)
|
||||||
|
@ -29,6 +29,7 @@ class CompilationResult(val success: Boolean,
|
|||||||
fun compileProgram(filepath: Path,
|
fun compileProgram(filepath: Path,
|
||||||
optimize: Boolean,
|
optimize: Boolean,
|
||||||
writeAssembly: Boolean,
|
writeAssembly: Boolean,
|
||||||
|
slowCodegenWarnings: Boolean,
|
||||||
compilationTarget: String,
|
compilationTarget: String,
|
||||||
outputDir: Path): CompilationResult {
|
outputDir: Path): CompilationResult {
|
||||||
var programName = ""
|
var programName = ""
|
||||||
@ -49,6 +50,7 @@ fun compileProgram(filepath: Path,
|
|||||||
val totalTime = measureTimeMillis {
|
val totalTime = measureTimeMillis {
|
||||||
// import main module and everything it needs
|
// import main module and everything it needs
|
||||||
val (ast, compilationOptions, imported) = parseImports(filepath, errors)
|
val (ast, compilationOptions, imported) = parseImports(filepath, errors)
|
||||||
|
compilationOptions.slowCodegenWarnings = slowCodegenWarnings
|
||||||
programAst = ast
|
programAst = ast
|
||||||
importedFiles = imported
|
importedFiles = imported
|
||||||
processAst(programAst, errors, compilationOptions)
|
processAst(programAst, errors, compilationOptions)
|
||||||
|
@ -207,7 +207,8 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
|||||||
is FunctionCall -> {}
|
is FunctionCall -> {}
|
||||||
else -> {
|
else -> {
|
||||||
// TODO optimize the others further?
|
// TODO optimize the others further?
|
||||||
println("warning: slow stack evaluation used for typecast: into $targetDt at ${value.position}")
|
if(this.asmgen.options.slowCodegenWarnings)
|
||||||
|
println("warning: slow stack evaluation used for typecast: into $targetDt at ${value.position}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,7 +608,8 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen
|
|||||||
}
|
}
|
||||||
TargetStorageKind.ARRAY -> {
|
TargetStorageKind.ARRAY -> {
|
||||||
// TODO optimize slow stack evaluation for this case, see assignVariableUByteIntoWord
|
// TODO optimize slow stack evaluation for this case, see assignVariableUByteIntoWord
|
||||||
println("warning: slow stack evaluation used for sign-extend byte typecast at ${bytevar.position}")
|
if(this.asmgen.options.slowCodegenWarnings)
|
||||||
|
println("warning: slow stack evaluation used for sign-extend byte typecast at ${bytevar.position}")
|
||||||
asmgen.translateExpression(wordtarget.origAssign.source.expression!!)
|
asmgen.translateExpression(wordtarget.origAssign.source.expression!!)
|
||||||
assignStackValue(wordtarget)
|
assignStackValue(wordtarget)
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,8 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
println("warning: slow stack evaluation used (1): ${memory.addressExpression::class.simpleName} at ${memory.addressExpression.position}") // TODO optimize...
|
if(asmgen.options.slowCodegenWarnings)
|
||||||
|
println("warning: slow stack evaluation used (1): ${memory.addressExpression::class.simpleName} at ${memory.addressExpression.position}") // TODO optimize...
|
||||||
asmgen.translateExpression(memory.addressExpression)
|
asmgen.translateExpression(memory.addressExpression)
|
||||||
asmgen.out(" jsr prog8_lib.read_byte_from_address_on_stack | sta P8ZP_SCRATCH_B1")
|
asmgen.out(" jsr prog8_lib.read_byte_from_address_on_stack | sta P8ZP_SCRATCH_B1")
|
||||||
val zp = CompilationTarget.instance.machine.zeropage
|
val zp = CompilationTarget.instance.machine.zeropage
|
||||||
@ -198,7 +199,8 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
TargetStorageKind.ARRAY -> {
|
TargetStorageKind.ARRAY -> {
|
||||||
println("*** TODO optimize simple inplace array assignment ${target.array} $operator= $value")
|
if(asmgen.options.slowCodegenWarnings)
|
||||||
|
println("*** TODO optimize simple inplace array assignment ${target.array} $operator= $value")
|
||||||
assignmentAsmGen.translateNormalAssignment(target.origAssign) // TODO get rid of this fallback for the most common cases here
|
assignmentAsmGen.translateNormalAssignment(target.origAssign) // TODO get rid of this fallback for the most common cases here
|
||||||
}
|
}
|
||||||
TargetStorageKind.REGISTER -> TODO("reg in-place modification")
|
TargetStorageKind.REGISTER -> TODO("reg in-place modification")
|
||||||
@ -219,7 +221,8 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun inplaceModification_byte_value_to_memory(pointervar: IdentifierReference, operator: String, value: Expression) {
|
private fun inplaceModification_byte_value_to_memory(pointervar: IdentifierReference, operator: String, value: Expression) {
|
||||||
println("warning: slow stack evaluation used (3): @(${pointervar.nameInSource.last()}) $operator= ${value::class.simpleName} at ${value.position}") // TODO
|
if(asmgen.options.slowCodegenWarnings)
|
||||||
|
println("warning: slow stack evaluation used (3): @(${pointervar.nameInSource.last()}) $operator= ${value::class.simpleName} at ${value.position}") // TODO
|
||||||
asmgen.translateExpression(value)
|
asmgen.translateExpression(value)
|
||||||
val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar)
|
val (ptrOnZp, sourceName) = asmgen.loadByteFromPointerIntoA(pointervar)
|
||||||
when (operator) {
|
when (operator) {
|
||||||
@ -410,7 +413,8 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
|
|||||||
private fun inplaceModification_byte_value_to_variable(name: String, dt: DataType, operator: String, value: Expression) {
|
private fun inplaceModification_byte_value_to_variable(name: String, dt: DataType, operator: String, value: Expression) {
|
||||||
// this should be the last resort for code generation for this,
|
// this should be the last resort for code generation for this,
|
||||||
// because the value is evaluated onto the eval stack (=slow).
|
// because the value is evaluated onto the eval stack (=slow).
|
||||||
println("warning: slow stack evaluation used (5): $name $operator= ${value::class.simpleName} at ${value.position}") // TODO
|
if(asmgen.options.slowCodegenWarnings)
|
||||||
|
println("warning: slow stack evaluation used (5): $name $operator= ${value::class.simpleName} at ${value.position}") // TODO
|
||||||
asmgen.translateExpression(value)
|
asmgen.translateExpression(value)
|
||||||
when (operator) {
|
when (operator) {
|
||||||
// note: ** (power) operator requires floats.
|
// note: ** (power) operator requires floats.
|
||||||
@ -1089,7 +1093,8 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
|
|||||||
private fun inplaceModification_word_value_to_variable(name: String, dt: DataType, operator: String, value: Expression) {
|
private fun inplaceModification_word_value_to_variable(name: String, dt: DataType, operator: String, value: Expression) {
|
||||||
// this should be the last resort for code generation for this,
|
// this should be the last resort for code generation for this,
|
||||||
// because the value is evaluated onto the eval stack (=slow).
|
// because the value is evaluated onto the eval stack (=slow).
|
||||||
println("warning: slow stack evaluation used (4): $name $operator= ${value::class.simpleName} at ${value.position}") // TODO
|
if(asmgen.options.slowCodegenWarnings)
|
||||||
|
println("warning: slow stack evaluation used (4): $name $operator= ${value::class.simpleName} at ${value.position}") // TODO
|
||||||
asmgen.translateExpression(value)
|
asmgen.translateExpression(value)
|
||||||
val valueDt = value.inferType(program).typeOrElse(DataType.STRUCT)
|
val valueDt = value.inferType(program).typeOrElse(DataType.STRUCT)
|
||||||
|
|
||||||
@ -1293,7 +1298,8 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
|
|||||||
private fun inplaceModification_float_value_to_variable(name: String, operator: String, value: Expression, scope: Subroutine?) {
|
private fun inplaceModification_float_value_to_variable(name: String, operator: String, value: Expression, scope: Subroutine?) {
|
||||||
// this should be the last resort for code generation for this,
|
// this should be the last resort for code generation for this,
|
||||||
// because the value is evaluated onto the eval stack (=slow).
|
// because the value is evaluated onto the eval stack (=slow).
|
||||||
println("warning: slow stack evaluation used (2): $name $operator= ${value::class.simpleName} at ${value.position}") // TODO
|
if(asmgen.options.slowCodegenWarnings)
|
||||||
|
println("warning: slow stack evaluation used (2): $name $operator= ${value::class.simpleName} at ${value.position}") // TODO
|
||||||
asmgen.translateExpression(value)
|
asmgen.translateExpression(value)
|
||||||
asmgen.out(" jsr floats.pop_float_fac1")
|
asmgen.out(" jsr floats.pop_float_fac1")
|
||||||
asmgen.saveRegister(CpuRegister.X, false, scope)
|
asmgen.saveRegister(CpuRegister.X, false, scope)
|
||||||
@ -1575,7 +1581,8 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
|
|||||||
asmgen.out(" sta (P8ZP_SCRATCH_W1),y")
|
asmgen.out(" sta (P8ZP_SCRATCH_W1),y")
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
println("warning: slow stack evaluation used (6): ${mem.addressExpression::class.simpleName} at ${mem.addressExpression.position}") // TODO
|
if(asmgen.options.slowCodegenWarnings)
|
||||||
|
println("warning: slow stack evaluation used (6): ${mem.addressExpression::class.simpleName} at ${mem.addressExpression.position}") // TODO
|
||||||
asmgen.translateExpression(mem.addressExpression)
|
asmgen.translateExpression(mem.addressExpression)
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
jsr prog8_lib.read_byte_from_address_on_stack
|
jsr prog8_lib.read_byte_from_address_on_stack
|
||||||
@ -1644,7 +1651,8 @@ internal class AugmentableAssignmentAsmGen(private val program: Program,
|
|||||||
asmgen.out(" sta (P8ZP_SCRATCH_W1),y")
|
asmgen.out(" sta (P8ZP_SCRATCH_W1),y")
|
||||||
}
|
}
|
||||||
else -> {
|
else -> {
|
||||||
println("warning: slow stack evaluation used (7): ${memory.addressExpression::class.simpleName} at ${memory.addressExpression.position}") // TODO
|
if(asmgen.options.slowCodegenWarnings)
|
||||||
|
println("warning: slow stack evaluation used (7): ${memory.addressExpression::class.simpleName} at ${memory.addressExpression.position}") // TODO
|
||||||
asmgen.translateExpression(memory.addressExpression)
|
asmgen.translateExpression(memory.addressExpression)
|
||||||
asmgen.out("""
|
asmgen.out("""
|
||||||
jsr prog8_lib.read_byte_from_address_on_stack
|
jsr prog8_lib.read_byte_from_address_on_stack
|
||||||
|
Loading…
Reference in New Issue
Block a user