Skip to content

Commit 444e213

Browse files
committed
Preevaluate cpustate
This emulates all the instructions in the basic block to get the cpu state (regs, mem) at the end of the block.
1 parent 15445ef commit 444e213

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

arch/zx48k/optimizer/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,9 @@ def optimize(initial_memory):
208208
basic_blocks[0].prev = LABELS['*START*'].basic_block
209209
LABELS[END_PROGRAM_LABEL].basic_block.add_goes_to(LABELS['*__END_PROGRAM*'].basic_block)
210210

211+
for x in basic_blocks:
212+
x.compute_cpu_state()
213+
211214
for x in basic_blocks:
212215
x.optimize()
213216

arch/zx48k/optimizer/basicblock.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,16 @@ def guesses_initial_state_from_origin_blocks(self):
518518

519519
return regs, mems
520520

521+
def compute_cpu_state(self):
522+
""" Resets and updates internal cpu state of this block
523+
executing the instructions of the block. The block must be a basic block
524+
(i.e. already partitioned)
525+
"""
526+
self.cpu.reset()
527+
528+
for asm_line in self.code:
529+
self.cpu.execute(asm_line)
530+
521531
def optimize(self):
522532
""" Tries to detect peep-hole patterns in this basic block
523533
and remove them.

0 commit comments

Comments
 (0)