diff options
author | jjsuperpower <jjs29356@gmail.com> | 2022-09-24 15:04:21 -0500 |
---|---|---|
committer | jjsuperpower <jjs29356@gmail.com> | 2022-09-24 15:04:21 -0500 |
commit | f2fa10954b481315e749ccb2da8ceb9bcce91723 (patch) | |
tree | a66220594c58582f36abf6980fc8da49b506c972 /hdl/utils.py | |
parent | 5653b767f0dd94cb0441dd326c4c2fb795b996c8 (diff) |
fixed some ugly code
Diffstat (limited to 'hdl/utils.py')
-rw-r--r-- | hdl/utils.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/hdl/utils.py b/hdl/utils.py index a6e8de4..a2f788e 100644 --- a/hdl/utils.py +++ b/hdl/utils.py @@ -2,6 +2,8 @@ import sys from inspect import stack # get name of caller function from typing import Callable +from math import log2, ceil +from enum import Enum import random #hdl specific imports @@ -16,6 +18,8 @@ from hdl.config import * # configuration random.seed(5498) +__all__ = ['cmd', 'e2s', 'sim', 'step', 'eval', 'rand_bits', 'rand_bits_extremes', 'rand_bits_mix'] + def cmd(hdl): ''' @@ -42,7 +46,11 @@ def cmd(hdl): with open(os.path.join(CXXRTL_DIR, os.path.basename(sys.argv[0]).replace('.py', '.cc')), 'w') as f: f.write(out) - +def e2s(e: Enum): + ''' + Get signal length from enum, returns ceil(log2(len(e)))) + ''' + return ceil(log2(len(e))) def sim(dut:Elaboratable, proc: Callable): sim = Simulator(dut) |