From f2fa10954b481315e749ccb2da8ceb9bcce91723 Mon Sep 17 00:00:00 2001 From: jjsuperpower Date: Sat, 24 Sep 2022 15:04:21 -0500 Subject: fixed some ugly code --- hdl/utils.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'hdl/utils.py') 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) -- cgit v1.2.3