PyHCL/pyhcl/tester/tester.py

24 lines
723 B
Python
Raw Permalink Normal View History

2022-05-15 18:14:49 +08:00
from pyhcl.tester.executer import TesterExecuter
from pyhcl.ir.low_ir import *
from pyhcl.dsl.emitter import Emitter
class Tester:
2022-06-21 10:45:11 +08:00
def __init__(self, m: Module):
circuit = Emitter.elaborate(m)
self.main = circuit.main
self.executer = TesterExecuter(circuit)
2022-05-15 18:14:49 +08:00
self.executer.init_executer()
2022-05-28 09:03:57 +08:00
2022-05-15 18:14:49 +08:00
2022-05-28 09:03:57 +08:00
def poke(self, name: str, value: int):
2022-05-15 18:14:49 +08:00
self.executer.set_value(self.main, name, value)
2022-05-28 09:03:57 +08:00
def peek(self, name: str) -> int:
res = self.executer.get_value(self.main, name)
return int(res, 2) if isinstance(res, str) else res
def expect(self, a, b) -> bool:
return a == b
2022-05-15 18:14:49 +08:00
2022-05-28 09:03:57 +08:00
def step(self, n):
self.executer.step(n, self.main)