summaryrefslogtreecommitdiff
path: root/hdl/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'hdl/utils.py')
-rw-r--r--hdl/utils.py10
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)