Skip to content
Snippets Groups Projects
Commit 5512bb0a authored by Johannes Kung's avatar Johannes Kung
Browse files

Simplified how execution of the processor is stopped

parent df97cd44
No related branches found
No related tags found
1 merge request!9Tick break points
Pipeline #131510 passed
......@@ -77,6 +77,9 @@ class CLI:
bp = self.processor.last_breakpoint
print(f"Reached breakpoint: {bp}")
if self.processor.should_halt():
print("The processor halted")
case ["r"] | ["resets"]:
# self.processor.load_cycle(0)
......@@ -90,10 +93,13 @@ class CLI:
try:
for _ in range(int(user_input.split()[1])):
self.processor.do_tick()
if self.processor.breakpoint_reached:
bp = self.processor.last_breakpoint
print(f"Reached breakpoint: {bp}")
if self.processor.is_stopped:
break
if self.processor.breakpoint_reached:
bp = self.processor.last_breakpoint
print(f"Reached breakpoint: {bp}")
if self.processor.should_halt():
print("The processor halted")
except ValueError:
print("Invalid value")
......
......@@ -60,6 +60,7 @@ class Processor:
self.module_history = self.module_history[0:self.clock]
self.signal_history = self.signal_history[0:self.clock]
self.unstop()
self.save_cycle()
self.clock += 1
......@@ -73,35 +74,39 @@ class Processor:
module = self.update_queue.pop(0)
module.update_logic()
self.check_breakpoints()
self.stop_at_breakpoints()
if self.should_halt():
self.stop()
def run_continuously(self) -> None:
"""
Run the processor until it halts, is stopped or reaches a breakpoint.
"""
while not self.should_halt() and not self.is_stopped:
self.unstop()
while not self.is_stopped:
self.do_tick()
if self.check_breakpoints():
break
def should_halt(self) -> bool:
return False
def stop(self) -> None:
"""
Signal to stop the execution of the processor until the processor is
instructed to run continuously or do some ticks again.
"""
self.is_stopped = True
def unstop(self) -> None:
"""
Reset the stop execution signal.
"""
self.is_stopped = False
def check_breakpoints(self) -> bool:
def stop_at_breakpoints(self) -> None:
"""
Check and record if a breakpoint has been reached at the current state.
Returns
-------
bool
True if a breakpoint has been reached, False otherwise.
Stop the execution if any breakpoint has been reached during this cycle.
Also record the breakpoint that was reached.
"""
self.breakpoint_reached = False
for _, bp in self.breakpoints.items():
......@@ -110,7 +115,8 @@ class Processor:
self.breakpoint_reached = True
self.last_breakpoint = bp
return self.breakpoint_reached
if self.breakpoint_reached:
self.stop()
def reset(self):
......
......@@ -454,7 +454,6 @@ class GUI(QMainWindow):
steps = self.jump_value_box.value()
self.cpu_running = True
self.setDisabledWhenRunning(True)
self.cpu.unstop()
simulation_thread = RunThread(self.cpu, self.cpu_tick_signal, self.update_delay, False, steps)
self.threadpool.start(simulation_thread)
......@@ -470,7 +469,6 @@ class GUI(QMainWindow):
# Create own thread for cpu simulation so gui dosent freeze
self.cpu_running = True
self.setDisabledWhenRunning(True)
self.cpu.unstop()
simulation_thread = RunThread(self.cpu, self.cpu_tick_signal, self.update_delay)
self.threadpool.start(simulation_thread)
......
......@@ -23,7 +23,8 @@ class RunThread(QRunnable):
def run(self):
if self.run_continuously:
while not self.cpu.should_halt() and not self.cpu.is_stopped:
self.cpu.unstop()
while not self.cpu.is_stopped:
self.cpu.do_tick()
self.signal.emit(1)
time.sleep(self.delay)
......@@ -34,5 +35,8 @@ class RunThread(QRunnable):
self.signal.emit(1)
time.sleep(self.delay)
if self.cpu.is_stopped:
break
# Signal end of execution as having run 0 ticks
self.signal.emit(0)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment