mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-01 23:58:20 +00:00
Remove jumps that just go to the next statement
This might help a bit with switch().
This commit is contained in:
parent
285c7172fd
commit
89c627b0c0
1 changed files with 41 additions and 5 deletions
|
@ -1562,18 +1562,54 @@ class foldconst(object):
|
||||||
if nt == '{}':
|
if nt == '{}':
|
||||||
# Remove SEF statements, and mark as SEF if it ends up empty
|
# Remove SEF statements, and mark as SEF if it ends up empty
|
||||||
idx = 0
|
idx = 0
|
||||||
issef = True
|
nchild = len(child)
|
||||||
while idx < len(child):
|
while idx < nchild:
|
||||||
self.FoldTree(child, idx)
|
self.FoldTree(child, idx)
|
||||||
self.FoldStmt(child, idx)
|
self.FoldStmt(child, idx)
|
||||||
if child[idx].SEF:
|
if child[idx].SEF:
|
||||||
# SEF statements can be removed
|
# SEF statements can be removed
|
||||||
del child[idx]
|
del child[idx]
|
||||||
|
nchild -= 1
|
||||||
else:
|
else:
|
||||||
idx += 1
|
idx += 1
|
||||||
issef = False
|
# Make another pass to remove JUMPs to the next statement
|
||||||
if issef:
|
changed = True # Allow entering the loop
|
||||||
node.SEF = True
|
while changed:
|
||||||
|
changed = False
|
||||||
|
idx = 0
|
||||||
|
while idx < nchild:
|
||||||
|
advance = 1
|
||||||
|
if child[idx].nt == 'JUMP':
|
||||||
|
idx2 = idx + 1
|
||||||
|
while idx2 < nchild:
|
||||||
|
# Search for a label that is the destination of this
|
||||||
|
# JUMP, skipping other labels
|
||||||
|
if child[idx2].nt != '@':
|
||||||
|
break
|
||||||
|
if (child[idx].scope == child[idx2].scope
|
||||||
|
and child[idx].name == child[idx2].name
|
||||||
|
):
|
||||||
|
sym = self.symtab[child[idx].scope][child[idx].name]
|
||||||
|
# remove the JUMP
|
||||||
|
del child[idx]
|
||||||
|
advance = 0
|
||||||
|
changed = True
|
||||||
|
idx2 -= 1 # it has scrolled
|
||||||
|
nchild -= 1
|
||||||
|
# remove reference to label
|
||||||
|
assert(sym['ref'])
|
||||||
|
sym['ref'] -= 1
|
||||||
|
if sym['ref'] == 0:
|
||||||
|
# No longer referenced - delete label too
|
||||||
|
del child[idx2]
|
||||||
|
nchild -= 1
|
||||||
|
break
|
||||||
|
idx2 += 1
|
||||||
|
del idx2
|
||||||
|
idx += advance
|
||||||
|
|
||||||
|
# We're SEF if we're empty, as we've removed all SEF statements
|
||||||
|
node.SEF = nchild == 0
|
||||||
return
|
return
|
||||||
|
|
||||||
if nt == 'IF':
|
if nt == 'IF':
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue