-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1825 from enjoy-digital/verilog_improvements
Verilog improvements
- Loading branch information
Showing
16 changed files
with
267 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# | ||
# This file is part of LiteX (Adapted from Migen for LiteX usage). | ||
# | ||
# This file is Copyright (c) 2013-2014 Sebastien Bourdeauducq <[email protected]> | ||
# This file is Copyright (c) 2023 Florent Kermarrec <[email protected]> | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
|
||
from migen.fhdl.structure import * | ||
from migen.fhdl.verilog import _printexpr as verilog_printexpr | ||
from migen.fhdl.specials import * | ||
|
||
# Helpers ------------------------------------------------------------------------------------------ | ||
|
||
def get_max_name_length(ios): | ||
r = 0 | ||
for io in ios: | ||
if len(io.name) > r: | ||
r = len(io.name) | ||
return r | ||
|
||
# LiteX Instance Verilog Generation ---------------------------------------------------------------- | ||
|
||
def _instance_generate_verilog(instance, ns, add_data_file): | ||
r = "" | ||
|
||
# Instance Description. | ||
# --------------------- | ||
r += "//" + "-"*78 + "\n" | ||
r += f"// Instance {ns.get_name(instance)} of {instance.of} Module.\n" | ||
r += "//" + "-"*78 + "\n" | ||
|
||
# Instance Name. | ||
# -------------- | ||
r += instance.of + " " | ||
|
||
# Instance Parameters. | ||
# -------------------- | ||
parameters = list(filter(lambda i: isinstance(i, Instance.Parameter), instance.items)) | ||
ident = get_max_name_length(parameters) | ||
if parameters: | ||
r += "#(\n" | ||
first = True | ||
r += "\t// Parameters.\n" | ||
for p in parameters: | ||
if not first: | ||
r += ",\n" | ||
first = False | ||
r += f"\t.{p.name}{' '*(ident-len(p.name))} (" | ||
# Constant. | ||
if isinstance(p.value, Constant): | ||
r += verilog_printexpr(ns, p.value)[0] | ||
# Float. | ||
elif isinstance(p.value, float): | ||
r += str(p.value) | ||
# Preformatted. | ||
elif isinstance(p.value, Instance.PreformattedParam): | ||
r += p.value | ||
# String. | ||
elif isinstance(p.value, str): | ||
r += f"\"{p.value}\"" | ||
else: | ||
raise TypeError | ||
r += ")" | ||
r += "\n) " | ||
|
||
# Instance IOs. | ||
# ------------- | ||
r += ns.get_name(instance) | ||
if parameters: | ||
r += " " | ||
r += "(" | ||
inputs = list(filter(lambda i: isinstance(i, Instance.Input), instance.items)) | ||
outputs = list(filter(lambda i: isinstance(i, Instance.Output), instance.items)) | ||
inouts = list(filter(lambda i: isinstance(i, Instance.InOut), instance.items)) | ||
first = True | ||
ident = get_max_name_length(inputs + outputs + inouts) | ||
for io in (inputs + outputs + inouts): | ||
if not first: | ||
r += ",\n" | ||
if len(inputs) and (io is inputs[0]): | ||
r += "\n\t// Inputs.\n" | ||
if len(outputs) and (io is outputs[0]): | ||
r += "\n\t// Outputs.\n" | ||
if len(inouts) and (io is inouts[0]): | ||
r += "\n\t// InOuts.\n" | ||
name_inst = io.name | ||
name_design = verilog_printexpr(ns, io.expr)[0] | ||
first = False | ||
r += f"\t.{name_inst}{' '*(ident-len(name_inst))} ({name_design})" | ||
if not first: | ||
r += "\n" | ||
|
||
# Instance Synthesis Directive. | ||
# ----------------------------- | ||
if instance.synthesis_directive is not None: | ||
synthesis_directive = f"/* synthesis {instance.synthesis_directive} */" | ||
r += f"){synthesis_directive};\n" | ||
else: | ||
r += ");\n" | ||
|
||
r += "\n" | ||
|
||
return r |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,19 @@ | |
# This file is part of LiteX (Adapted from Migen for LiteX usage). | ||
# | ||
# This file is Copyright (c) 2013-2014 Sebastien Bourdeauducq <[email protected]> | ||
# This file is Copyright (c) 2021 Florent Kermarrec <[email protected]> | ||
# This file is Copyright (c) 2021-2023 Florent Kermarrec <[email protected]> | ||
# SPDX-License-Identifier: BSD-2-Clause | ||
|
||
from migen.fhdl.structure import * | ||
from migen.fhdl.module import * | ||
from migen.fhdl.structure import * | ||
from migen.fhdl.module import * | ||
from migen.fhdl.bitcontainer import bits_for | ||
from migen.fhdl.tools import * | ||
from migen.fhdl.verilog import _printexpr as verilog_printexpr | ||
from migen.fhdl.specials import * | ||
from migen.fhdl.tools import * | ||
from migen.fhdl.verilog import _printexpr as verilog_printexpr | ||
from migen.fhdl.specials import * | ||
|
||
# LiteX Memory Verilog Generation ------------------------------------------------------------------ | ||
|
||
def memory_emit_verilog(name, memory, namespace, add_data_file): | ||
def _memory_generate_verilog(name, memory, namespace, add_data_file): | ||
# Helpers. | ||
# -------- | ||
|
||
|
Oops, something went wrong.