compat: provide verilog.convert shim.
This commit is contained in:
parent
fc7da1be2d
commit
00ef7a78d3
35
nmigen/compat/fhdl/conv_output.py
Normal file
35
nmigen/compat/fhdl/conv_output.py
Normal file
|
@ -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)
|
26
nmigen/compat/fhdl/verilog.py
Normal file
26
nmigen/compat/fhdl/verilog.py
Normal file
|
@ -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
|
Loading…
Reference in a new issue