summaryrefslogtreecommitdiff
path: root/hdl/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'hdl/utils.py')
-rw-r--r--hdl/utils.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/hdl/utils.py b/hdl/utils.py
new file mode 100644
index 0000000..6aad95f
--- /dev/null
+++ b/hdl/utils.py
@@ -0,0 +1,22 @@
+import sys
+from typing import Callable
+from amaranth import Elaboratable
+from amaranth.back import verilog, cxxrtl
+
+def cmd(hdl, tb:Callable):
+ if len(sys.argv) <= 1:
+ exit()
+
+ if sys.argv[1] == "sim":
+ tb(sys.argv[0].replace('.py', '.vcd'))
+ exit()
+
+ if sys.argv[1] == "v":
+ out = verilog.convert(hdl, ports=hdl.ports)
+ with open(sys.argv[0].replace('.py', '.v'), 'w') as f:
+ f.write(out)
+
+ elif sys.argv[1] == "cc":
+ out = cxxrtl.convert(hdl, ports=hdl.ports)
+ with open(sys.argv[0].replace('.py', '.cc'), 'w') as f:
+ f.write(out) \ No newline at end of file