re-enabled unused variable removal from library modules (+fixed some @shared vars in libraries)

This commit is contained in:
Irmen de Jong 2022-02-10 03:10:47 +01:00
parent 08bacdd090
commit 343f01d5e1
5 changed files with 8 additions and 9 deletions

View File

@ -106,10 +106,10 @@ class UnusedCodeRemover(private val program: Program,
if(decl.type==VarDeclType.VAR) { if(decl.type==VarDeclType.VAR) {
val block = decl.definingBlock val block = decl.definingBlock
val forceOutput = "force_output" in block.options() val forceOutput = "force_output" in block.options()
if (!forceOutput && decl.origin==VarDeclOrigin.USERCODE && !decl.sharedWithAsm && !block.isInLibrary) { // TODO remove check on block.isInLibrary, but this now breaks some programs if (!forceOutput && decl.origin==VarDeclOrigin.USERCODE && !decl.sharedWithAsm) {
val usages = callgraph.usages(decl) val usages = callgraph.usages(decl)
if (usages.isEmpty()) { if (usages.isEmpty()) {
if(!decl.definingModule.isLibrary) // if(!decl.definingModule.isLibrary)
errors.warn("removing unused variable '${decl.name}'", decl.position) errors.warn("removing unused variable '${decl.name}'", decl.position)
return listOf(IAstModification.Remove(decl, parent as IStatementContainer)) return listOf(IAstModification.Remove(decl, parent as IStatementContainer))
} }

View File

@ -7,7 +7,7 @@ conv {
; ----- number conversions to decimal strings ---- ; ----- number conversions to decimal strings ----
str string_out = "????????????????" ; result buffer for the string conversion routines str @shared string_out = "????????????????" ; result buffer for the string conversion routines
asmsub str_ub0 (ubyte value @ A) clobbers(A,Y) { asmsub str_ub0 (ubyte value @ A) clobbers(A,Y) {
; ---- convert the ubyte in A in decimal string form, with left padding 0s (3 positions total) ; ---- convert the ubyte in A in decimal string form, with left padding 0s (3 positions total)

View File

@ -369,7 +369,7 @@ _done
set_both_strides(13) ; 160 increment = 1 line in 640 px 4c mode set_both_strides(13) ; 160 increment = 1 line in 640 px 4c mode
color &= 3 color &= 3
color <<= gfx2.plot.shift4c[lsb(x) & 3] color <<= gfx2.plot.shift4c[lsb(x) & 3]
ubyte mask = gfx2.plot.mask4c[lsb(x) & 3] ubyte @shared mask = gfx2.plot.mask4c[lsb(x) & 3]
repeat height { repeat height {
%asm {{ %asm {{
lda cx16.VERA_DATA0 lda cx16.VERA_DATA0
@ -545,9 +545,9 @@ _done
} }
sub plot(uword @zp x, uword y, ubyte color) { sub plot(uword @zp x, uword y, ubyte color) {
ubyte[8] bits = [128, 64, 32, 16, 8, 4, 2, 1] ubyte[8] @shared bits = [128, 64, 32, 16, 8, 4, 2, 1]
ubyte[4] mask4c = [%00111111, %11001111, %11110011, %11111100] ubyte[4] @shared mask4c = [%00111111, %11001111, %11110011, %11111100]
ubyte[4] shift4c = [6,4,2,0] ubyte[4] @shared shift4c = [6,4,2,0]
when active_mode { when active_mode {
1 -> { 1 -> {

View File

@ -407,7 +407,7 @@ io_error:
sub save(ubyte drivenumber, uword filenameptr, uword address, uword size) -> ubyte { sub save(ubyte drivenumber, uword filenameptr, uword address, uword size) -> ubyte {
c64.SETNAM(string.length(filenameptr), filenameptr) c64.SETNAM(string.length(filenameptr), filenameptr)
c64.SETLFS(1, drivenumber, 0) c64.SETLFS(1, drivenumber, 0)
uword end_address = address + size uword @shared end_address = address + size
first_byte = 0 ; result var reuse first_byte = 0 ; result var reuse
%asm {{ %asm {{

View File

@ -3,7 +3,6 @@ TODO
For next release For next release
^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^
- (newvaralloc) UnusedCodeRemover after(decl: VarDecl): fix that vars defined in a library can also safely be removed if unused. Currently this breaks programs such as textelite (due to diskio.save().end_address ?)
- make it so that subroutine parameters as variables can again be allocated in ZP, if there's still space - make it so that subroutine parameters as variables can again be allocated in ZP, if there's still space