fixed callgraph issue that allocated ALL variables in a (library) module even though some clearly weren't used at all. Variables declared in block level scope in a library are still all allocated / defined due to the nature of a library module with lists of definitions

This commit is contained in:
Irmen de Jong 2020-12-27 01:02:36 +01:00
parent 4c03950c28
commit 3b8e18004c
6 changed files with 15 additions and 16 deletions

View File

@ -204,8 +204,6 @@ gfx2 {
; You must also have called text_charset() first to select and prepare the character set to use. ; You must also have called text_charset() first to select and prepare the character set to use.
; NOTE: in monochrome (1bpp) screen modes, x position is currently constrained to mulitples of 8 ! ; NOTE: in monochrome (1bpp) screen modes, x position is currently constrained to mulitples of 8 !
uword chardataptr uword chardataptr
ubyte cy222 ; TODO why not removed by compiler???
ubyte cb222 ; TODO why not removed by compiler???
when active_mode { when active_mode {
0, 128 -> { 0, 128 -> {
; 1-bitplane modes ; 1-bitplane modes

View File

@ -75,7 +75,9 @@ io_error:
; -- fill the array 'name_ptrs' with (pointers to) the names of the files requested. ; -- fill the array 'name_ptrs' with (pointers to) the names of the files requested.
ubyte[256] names_buffer ubyte[256] names_buffer
ubyte[256] names_buffer1 ; to store a bit more names ubyte[256] names_buffer1 ; to store a bit more names
; TODO names_buffer = memory("filenames", 512)
uword buf_ptr = &names_buffer uword buf_ptr = &names_buffer
names_buffer1[0] = 0 ; TODO force array to exist
ubyte files_found = 0 ubyte files_found = 0
if lf_start_list(drivenumber, pattern, suffixmatch) { if lf_start_list(drivenumber, pattern, suffixmatch) {
while lf_next_entry() { while lf_next_entry() {

View File

@ -117,12 +117,9 @@ class CallGraph(private val program: Program) : IAstVisitor {
} }
override fun visit(decl: VarDecl) { override fun visit(decl: VarDecl) {
if (decl.autogeneratedDontRemove || decl.definingModule().isLibraryModule) { if (decl.autogeneratedDontRemove || decl.datatype==DataType.STRUCT)
// make sure autogenerated vardecls are in the used symbols and are never removed as 'unused'
addNodeAndParentScopes(decl) addNodeAndParentScopes(decl)
} else if(decl.parent is Block && decl.definingModule().isLibraryModule)
if (decl.datatype == DataType.STRUCT)
addNodeAndParentScopes(decl) addNodeAndParentScopes(decl)
super.visit(decl) super.visit(decl)

View File

@ -2,7 +2,6 @@
TODO TODO
==== ====
- why are unused vars not removed in gfx2 module
- hoist all variable declarations up to the subroutine scope *before* even the constant folding takes place (to avoid undefined symbol errors when referring to a variable from another nested scope in the subroutine) - hoist all variable declarations up to the subroutine scope *before* even the constant folding takes place (to avoid undefined symbol errors when referring to a variable from another nested scope in the subroutine)
- make it possible to use cpu opcodes such as 'nop' as variable names by prefixing all asm vars with something such as '_' - make it possible to use cpu opcodes such as 'nop' as variable names by prefixing all asm vars with something such as '_'
- option to load the built-in library files from a directory instead of the embedded ones (for easier library development/debugging) - option to load the built-in library files from a directory instead of the embedded ones (for easier library development/debugging)

View File

@ -4,6 +4,7 @@
%import diskio %import diskio
iff_module { iff_module {
; TODO uword cmap = memory("palette", 768)
ubyte[256] cmap ubyte[256] cmap
ubyte[256] cmap1 ubyte[256] cmap1
ubyte[256] cmap2 ubyte[256] cmap2

View File

@ -1,17 +1,19 @@
%import test_stack ;%import test_stack
%import textio ;%import textio
%import gfx2
%zeropage basicsafe %zeropage basicsafe
%option no_sysinit %option no_sysinit
main { main {
sub start () { sub start () {
txt.lowercase() ; txt.lowercase()
txt.print_ub(txt.width()) ; txt.print_ub(txt.width())
txt.chrout('\n') ; txt.chrout('\n')
txt.print_ub(txt.height()) ; txt.print_ub(txt.height())
txt.chrout('\n') ; txt.chrout('\n')
test_stack.test() gfx2.text(0,0,2, "sdafsdf")
; test_stack.test()
} }
} }