From: whitequark Date: Fri, 21 Dec 2018 13:53:06 +0000 (+0000) Subject: compat: provide verilog.convert shim. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0c985fead287218c5eee2bab97c4bc621cc7210d;p=nmigen.git compat: provide verilog.convert shim. --- diff --git a/nmigen/compat/fhdl/conv_output.py b/nmigen/compat/fhdl/conv_output.py new file mode 100644 index 0000000..793fad2 --- /dev/null +++ b/nmigen/compat/fhdl/conv_output.py @@ -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 index 0000000..eee7ea1 --- /dev/null +++ b/nmigen/compat/fhdl/verilog.py @@ -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