Compiling python code while using PyGears framework

Viewed 41

At the moment I'm writing my first code in PyGears and I'm stuck with part how to compile the code. Do I compile it like normal python code or I need some fancy tools?

1 Answers

Yes, you should be able to compile it like a normal Python code. If you are using python3 it should look something like this.

Let's say we have module darken.py

from pygears import gear
from pygears.typing import Ufixp, Uint
from pygears.lib import drv, collect
from pygears.sim import sim, cosim


@gear
def darken(din, *, gain):
    return din * Ufixp[0, 8](gain)


res = []

drv(t=Uint[8], seq=[12, 23, 255]) \
    | darken(gain=0.5) \
    | float \
    | collect(result=res)

cosim('/darken', 'verilator', outdir='./home/stefan/test/output')
sim()

print(res)

We can run a command inside a terminal

python3 darken.py

And output should be

-          /darken/mul [INFO]: Running sim with seed: 167830386130148172
0                      [INFO]: -------------- Simulation start --------------
103                      [INFO]: ----------- Simulation done ---------------
103                      [INFO]: Elapsed: 0.01
[6.0, 11.5, 127.5]
Related