PyHCL/example/half_adder.py

40 lines
897 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from pyhcl import *
from pyhcl.simulator import Simlite
class HalfAdder(Module):
io = IO(
a=Input(U.w(1)),
b=Input(U.w(1)),
s=Output(U.w(1)),
cout=Output(U.w(1))
)
# 填充完整输出端口s以及cout的逻辑例如
io.s @= io.a ^ io.b
io.cout @= io.a & io.b
def main():
Emitter.dumpVerilog(Emitter.dump(Emitter.emit(HalfAdder()), "HalfAdder.fir"))
# cfg = DpiConfig()
s = Simlite(HalfAdder())
# s.start()
# s.step([20, 20])
# s.step([15, 10])
# s.step([1000, 1])
# s.step([999, 201])
# s.close()
# 生成Verilog文件
if __name__ == '__main__':
Emitter.dumpVerilog(Emitter.dump(Emitter.emit(HalfAdder()), "HalfAdder.fir"))
# cfg = DpiConfig()
s = Simlite(HalfAdder())
s.start()
s.step([20, 20])
s.step([15, 10])
s.step([1000, 1])
s.step([999, 201])
s.close()