Skip to content

Commit

Permalink
Don't start writing to the file until it's generated
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekPikula committed Nov 29, 2022
1 parent ba02663 commit 78638f0
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/peakrdl_markdown/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,18 @@ def export(
raise ValueError("The output file is not Markdown file.")
Path(output_path).parent.mkdir(parents=True, exist_ok=True)

# Generate the file.
# Run generation.
gen = self._add_addrmap_regfile(top, node.env.msg).generated

# Write to the file.
with open(output_path, "w", encoding="UTF-8") as output:
output.write(
(
"<!---\n"
"Markdown description for SystemRDL register map.\n\n"
f"Don't override. Generated from: {generated_from}\n"
"-->\n"
)
+ self._add_addrmap_regfile(top, node.env.msg).generated
"<!---\n"
"Markdown description for SystemRDL register map.\n\n"
f"Don't override. Generated from: {generated_from}\n"
"-->\n"
)
output.write(gen)

def _add_addrmap_regfile(
self,
Expand Down

0 comments on commit 78638f0

Please sign in to comment.