Skip to content

Commit

Permalink
Merge pull request #6 from akukulanski/include-platform-files
Browse files Browse the repository at this point in the history
files added to platform included in the simulation
  • Loading branch information
ydnatag authored Jun 4, 2021
2 parents be53a70 + 4dcc25c commit 989ee13
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions nmigen_cocotb.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,21 @@ def copy_extra_files(extra_files, path):
for f in extra_files:
shutil.copy(f, path)

def dump_file(filename, content, d):
file_path = d + '/' + filename
if isinstance(content, bytes):
content = content.decode('utf-8')
if os.path.exists(file_path):
with open(file_path, 'r') as f:
c = f.read()
if c != content:
raise ValueError("File {!r} already exists"
.format(filename))
else:
with open(file_path, 'w') as f:
f.write(content)
return file_path

def run(design, module, platform=None, ports=(), name='top', verilog_sources=None, extra_files=None, vcd_file=None, extra_args=None):
with tempfile.TemporaryDirectory() as d:
verilog_file = d + '/nmigen_output.v'
Expand All @@ -85,6 +100,11 @@ def run(design, module, platform=None, ports=(), name='top', verilog_sources=Non
sources.extend(verilog_sources)
if extra_files:
copy_extra_files(extra_files, d)
if platform:
for filename, content in platform.extra_files.items():
filepath = dump_file(filename, content, d)
if filename.endswith('.v') or filename.endswith('.sv'):
sources.append(filepath)
compile_args = []
if vcd_file:
compile_args += compile_args_waveforms
Expand Down

0 comments on commit 989ee13

Please sign in to comment.