Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve GHDL Tool #412

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions edalize/flows/sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def configure_tools(self, flow):
'-LDFLAGS "-Wl,-rpath,`cocotb-config --lib-dir` -L`cocotb-config --lib-dir` -lcocotbvpi_verilator -lgpi -lcocotb -lgpilog -lcocotbutils"',
],
),
"ghdl": (
"sim_options",
["--vpi=`cocotb-config --lib-name-path vpi ghdl`"],
),
}
(opt, val) = cocotb_options[tool]
self.edam["tool_options"][tool][opt] = (
Expand Down
77 changes: 53 additions & 24 deletions edalize/tools/ghdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class Ghdl(Edatool):
def setup(self, edam):
super().setup(edam)
analyze_options = self.tool_options.get("analyze_options", [])
run_options = self.tool_options.get("run_options", [])
sim_options = self.tool_options.get("sim_options", [])

# Check of std=xx analyze option, this overyides the dynamic determination of vhdl standard
import re
Expand Down Expand Up @@ -77,16 +79,12 @@ def setup(self, edam):

standard = rx.match(stdarg[0]).group(1)

run_options = self.tool_options.get("run_options", [])

analyze_options = " ".join(analyze_options)

_vhdltypes = ("vhdlSource", "vhdlSource-87", "vhdlSource-93", "vhdlSource-2008")

libraries = {}
library_options = "--work={lib} --workdir=./{lib}"
ghdlimport = ""
vhdl_sources = ""

# GHDL versions older than 849a25e0 don't support the dot notation (e.g.
# my_lib.top_design) for the top level.
Expand All @@ -111,43 +109,74 @@ def setup(self, edam):
# Files without a specified library will by added to
# libraries[None] which is perhaps poor form but avoids
# conflicts with user generated names
libraries[f["logical_name"]] = libraries.get(f["logical_name"], []) + [
f["name"]
]
vhdl_sources += " {file}".format(file=f["name"])
depfiles.append(f)
logical_name = f.get("logical_name", None)
libraries[logical_name] = libraries.get(logical_name, []) + [f["name"]]
else:
unused_files.append(f)

self.edam = edam.copy()
self.edam["files"] = unused_files

ghdlimport = ""
make_libraries_directories = ""
commands = EdaCommands()

make_lib_dirs = []
libs = []
for lib, files in libraries.items():
lib_opts = ""
if lib:
if make_lib_dirs == []:
make_lib_dirs = ["mkdir -p "]
analyze_options += " -P./{}".format(lib)
make_libraries_directories += "\tmkdir -p {}\n".format(lib)
make_lib_dirs.append(format(lib))
lib_opts = library_options.format(lib=lib)
ghdlimport += "\tghdl -i $(STD) $(ANALYZE_OPTIONS) {} {}\n".format(
lib_opts, " ".join(files)
)

commands = EdaCommands()
libs.append(format(lib))
commands.add(
["ghdl", "-i"]
+ stdarg
+ [" -P./{}".format(lib)]
+ [lib_opts, " ".join(files)],
[format(lib)],
["make_lib_dirs"],
)

commands.add(
make_lib_dirs,
["make_lib_dirs"],
[],
)
commands.add(
["ghdl", "-m"]
+ stdarg
+ [analyze_options]
+ [lib_opts]
+ [top_libraries, top_unit],
["analyze"],
libs,
)
if self.tool_options.get("mode") == "verilog":
commands.add(
["ghdl", "-a"] + stdarg + analyze_options + [top_libraries, top_unit],
["ghdl", "--synth", "--out=verilog"]
+ stdarg
+ [top_libraries, top_unit],
["run"],
["analyze", f"work-obj{standard}.cf"],
)
else:
commands.add(
["ghdl", "-r"]
+ stdarg
+ run_options
+ [top_libraries, top_unit]
+ sim_options,
# FIXME: Get names of object files here
[f"work-obj{stdarg[0]}.cf"],
depfiles,
["run"],
["analyze", f"work-obj{standard}.cf"],
)
commands.set_default_target(f"work-obj{stdarg[0]}.cf")

commands.set_default_target("make_lib_dirs")
self.commands = commands

def run_main(self):
cmd = "make"
def run(self):
args = ["run"]

# GHDL doesn't support Verilog, but the backend used vlogparam since
Expand All @@ -169,4 +198,4 @@ def run_main(self):
k, self._param_value_str(v, '"', bool_is_str=True)
)
args.append(extra_options)
self._run_tool(cmd, args)
return ("make", args, self.work_root)