remove unused interned strings in the resulting code (for example from removed if/else blocks)

This commit is contained in:
Irmen de Jong 2023-11-11 21:59:12 +01:00
parent 405926e811
commit d73709653d
8 changed files with 26 additions and 20 deletions

View File

@ -627,7 +627,7 @@ gfx2 {
; Non-recursive scanline flood fill. ; Non-recursive scanline flood fill.
; based loosely on code found here https://www.codeproject.com/Articles/6017/QuickFill-An-efficient-flood-fill-algorithm ; based loosely on code found here https://www.codeproject.com/Articles/6017/QuickFill-An-efficient-flood-fill-algorithm
; with the fixes applied to the seedfill_4 routine as mentioned in the comments. ; with the fixes applied to the seedfill_4 routine as mentioned in the comments.
const ubyte MAXDEPTH = 48 const ubyte MAXDEPTH = 64
word @zp xx = x as word word @zp xx = x as word
word @zp yy = y as word word @zp yy = y as word
word[MAXDEPTH] @split @shared stack_xl word[MAXDEPTH] @split @shared stack_xl

View File

@ -638,7 +638,7 @@ _done
; Non-recursive scanline flood fill. ; Non-recursive scanline flood fill.
; based loosely on code found here https://www.codeproject.com/Articles/6017/QuickFill-An-efficient-flood-fill-algorithm ; based loosely on code found here https://www.codeproject.com/Articles/6017/QuickFill-An-efficient-flood-fill-algorithm
; with the fixes applied to the seedfill_4 routine as mentioned in the comments. ; with the fixes applied to the seedfill_4 routine as mentioned in the comments.
const ubyte MAXDEPTH = 48 const ubyte MAXDEPTH = 64
word @zp xx = x as word word @zp xx = x as word
word @zp yy = y as word word @zp yy = y as word
word[MAXDEPTH] @split @shared stack_xl word[MAXDEPTH] @split @shared stack_xl

View File

@ -373,7 +373,7 @@ monogfx {
; Non-recursive scanline flood fill. ; Non-recursive scanline flood fill.
; based loosely on code found here https://www.codeproject.com/Articles/6017/QuickFill-An-efficient-flood-fill-algorithm ; based loosely on code found here https://www.codeproject.com/Articles/6017/QuickFill-An-efficient-flood-fill-algorithm
; with the fixes applied to the seedfill_4 routine as mentioned in the comments. ; with the fixes applied to the seedfill_4 routine as mentioned in the comments.
const ubyte MAXDEPTH = 48 const ubyte MAXDEPTH = 64
word @zp xx = x as word word @zp xx = x as word
word @zp yy = y as word word @zp yy = y as word
word[MAXDEPTH] @split @shared stack_xl word[MAXDEPTH] @split @shared stack_xl

View File

@ -19,7 +19,23 @@ internal class VerifyFunctionArgTypes(val program: Program, val errors: IErrorRe
errors.err("memory block '${slab.name}' already exists with a different size and/or alignment at ${other.position}", slab.position) errors.err("memory block '${slab.name}' already exists with a different size and/or alignment at ${other.position}", slab.position)
} }
} }
// remove unused strings from interned strings block
val internedBlock = program.allBlocks.singleOrNull { it.name== internedStringsModuleName }
internedBlock?.statements?.withIndex()?.reversed()?.forEach { (index, st) ->
if(st is VarDecl && st.scopedName !in allStringRefs) {
internedBlock.statements.removeAt(index)
} }
}
}
override fun visit(identifier: IdentifierReference) {
if(identifier.wasStringLiteral(program)) {
allStringRefs.add(identifier.nameInSource)
}
}
private val allStringRefs = mutableListOf<List<String>>()
private class Slab(val name: String, val size: Int, val align: Int, val position: Position) private class Slab(val name: String, val size: Int, val align: Int, val position: Position)
private val memorySlabs = mutableListOf<Slab>() private val memorySlabs = mutableListOf<Slab>()

View File

@ -1,7 +1,7 @@
TODO TODO
==== ====
- remove unused interned strings in the resulting code (for example from removed if/else blocks)
- [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 .... - [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 ....
- [on branch: ir-less-branch-opcodes] IR: reduce the number of branch instructions such as BEQ, BEQR, etc (gradually), replace with CMP(I) + status branch instruction - [on branch: ir-less-branch-opcodes] IR: reduce the number of branch instructions such as BEQ, BEQR, etc (gradually), replace with CMP(I) + status branch instruction
- IR: reduce amount of CMP/CMPI after instructions that set the status bits correctly (LOADs? INC? Bitwise operations, etc), but only after setting the status bits is verified! - IR: reduce amount of CMP/CMPI after instructions that set the status bits correctly (LOADs? INC? Bitwise operations, etc), but only after setting the status bits is verified!

View File

@ -1,21 +1,12 @@
%import textio %import textio
%import string
%zeropage basicsafe %zeropage basicsafe
main { main {
sub start() { sub start() {
str name = "irmen????????????" if true {
name[5] = 0 txt.print("true")
} else {
txt.print(name) txt.print("false")
txt.nl() }
ubyte length = string.append(name, ".prg")
txt.print_ub(length)
txt.chrout('[')
for cx16.r0L in 0 to length-1 {
txt.chrout(name[cx16.r0L])
}
txt.chrout(']')
} }
} }

View File

@ -5,4 +5,4 @@ org.gradle.daemon=true
kotlin.code.style=official kotlin.code.style=official
javaVersion=11 javaVersion=11
kotlinVersion=1.9.20 kotlinVersion=1.9.20
version=9.6-SNAPSHOT version=9.6

View File

@ -188,8 +188,7 @@ expression :
arrayindexed: arrayindexed:
scoped_identifier arrayindex scoped_identifier arrayindex
// TODO to allow chained array indexing: | arrayindexed arrayindex // TODO to allow chained/multidimensional array indexing: | arrayindexed arrayindex
// TODO or even to allow array indexing on any uword address value: | expression arrayindex
; ;