compat: provide verilog.convert shim.
authorwhitequark <whitequark@whitequark.org>
Fri, 21 Dec 2018 13:53:06 +0000 (13:53 +0000)
committerwhitequark <whitequark@whitequark.org>
Fri, 21 Dec 2018 13:53:06 +0000 (13:53 +0000)
nmigen/compat/fhdl/conv_output.py [new file with mode: 0644]
nmigen/compat/fhdl/verilog.py [new file with mode: 0644]

diff --git a/nmigen/compat/fhdl/conv_output.py b/nmigen/compat/fhdl/conv_output.py
new file mode 100644 (file)
index 0000000..793fad2
--- /dev/null
@@ -0,0 +1,35 @@
+from operator import itemgetter
+
+
+class ConvOutput:
+    def __init__(self):
+        self.main_source = ""
+        self.data_files = dict()
+
+    def set_main_source(self, src):
+        self.main_source = src
+
+    def add_data_file(self, filename_base, content):
+        filename = filename_base
+        i = 1
+        while filename in self.data_files:
+            parts = filename_base.split(".", maxsplit=1)
+            parts[0] += "_" + str(i)
+            filename = ".".join(parts)
+            i += 1
+        self.data_files[filename] = content
+        return filename
+
+    def __str__(self):
+        r = self.main_source + "\n"
+        for filename, content in sorted(self.data_files.items(),
+                                        key=itemgetter(0)):
+            r += filename + ":\n" + content
+        return r
+
+    def write(self, main_filename):
+        with open(main_filename, "w") as f:
+            f.write(self.main_source)
+        for filename, content in self.data_files.items():
+            with open(filename, "w") as f:
+                f.write(content)
diff --git a/nmigen/compat/fhdl/verilog.py b/nmigen/compat/fhdl/verilog.py
new file mode 100644 (file)
index 0000000..eee7ea1
--- /dev/null
@@ -0,0 +1,26 @@
+import warnings
+
+from ...back import verilog
+from .conv_output import ConvOutput
+
+
+def convert(fi, ios=None, name="top", special_overrides=dict(),
+            attr_translate=None, create_clock_domains=True,
+            display_run=False):
+    if display_run:
+        warnings.warn("`display_run=True` support has been removed",
+                      DeprecationWarning, stacklevel=1)
+    if special_overrides:
+        warnings.warn("`special_overrides` support as well as `Special` has been removed",
+                      DeprecationWarning, stacklevel=1)
+    # TODO: attr_translate
+
+    v_output = verilog.convert(
+        fragment=fi.get_fragment().get_fragment(platform=None),
+        name=name,
+        ports=ios or (),
+        ensure_sync_exists=create_clock_domains
+    )
+    output = ConvOutput()
+    output.set_main_source(v_output)
+    return output