import os import subprocess import build_env from typing import List from project_man import getLibrariesPresent, getLibrariesInProject def generateIncludesForGHDL(includes: List[str]): cmd = [] [exists, projectLibs] = getLibrariesInProject() if not exists: return [] for lib in projectLibs.keys(): includeString = f"{projectLibs[lib]['path']}/work" cmd.append(f"-P{includeString}") for inc in includes: includeString = f"{inc}/work" cmd.append(f"-P{includeString}") return cmd def elabDesign(topDef: str, arch: str, lib: str, std: str, includes: List[str]): if not build_env.ghdlEnvExists(std, lib): print("No GHDL environment present. Add all needed files before elaborating") incs = generateIncludesForGHDL(includes) command = [ "ghdl", "-m", "--workdir=work", f"--work={lib}", f"--std={std}"] + incs + ["-o", f"work/{topDef}-{arch}", f"work.{topDef}", f"{arch}"] subprocess.run(command) def runDesign(topDef: str, arch: str, lib: str, std: str, includes): if not build_env.ghdlEnvExists(std, lib): print("No GHDL environment present. Add all needed files before elaborating") os.makedirs("wave",exist_ok=True) wavePath = os.path.join(os.getcwd(), "wave") incs = generateIncludesForGHDL(includes) command = [ ## may add -v for verbose "ghdl", "--elab-run", f"--workdir=work", f"--work={lib}", f"--std={std}"] + incs + ["-o", f"work/{topDef}-{arch}", f"{topDef}", f"{arch}", f"--wave=wave/{topDef}-{arch}.ghw" ##, "--read-wave-opt=