diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0be0f35 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*/wave +*/work diff --git a/scripts/build.py b/scripts/build.py deleted file mode 100644 index a05ef46..0000000 --- a/scripts/build.py +++ /dev/null @@ -1,14 +0,0 @@ -import typer - -app = typer.Typer() - -@app.command() -def synth(): - print("Synth!") - -@app.command() -def build(): - print("Build!") - -if __name__ == "__main__": - app() diff --git a/scripts/build_env.py b/scripts/build_env.py index 571ec7f..7479baa 100644 --- a/scripts/build_env.py +++ b/scripts/build_env.py @@ -26,7 +26,7 @@ def createBuildEnv(): return -1 ## Create build env os.makedirs("work",exist_ok=True) - addAllVHDLFiles(init=False) + addAllVHDLFiles(init=True) return 0 def addAllVHDLFiles(init=False): diff --git a/scripts/gantry.py b/scripts/gantry.py new file mode 100644 index 0000000..0bd06ee --- /dev/null +++ b/scripts/gantry.py @@ -0,0 +1,45 @@ +import typer +import synth as syn +import build_env +from typing_extensions import Annotated + + +app = typer.Typer() + + +@app.command() +def init(): + print("Initializing GHDL project in current directory...") + build_env.createBuildEnv() + + + +def complete_vhdl_ver(): + return ["87", "93", "93c", "00", "02", "08"] + +@app.command() +def synth( + topdef: Annotated[str, typer.Argument(help="Top Definition entity to synthesize")] = "", + arch: Annotated[str, typer.Argument(help="Architecture to synthesize within the top definition provided")] = "", + library: Annotated[str, typer.Option("--library", "-l", help="Library to compile from")] = "work", + std: Annotated[str, typer.Option(help="Which VHDL standard to use. 87, 93, 93c, 00, 02 or 08", autocompletion=complete_vhdl_ver)] = "93c" + ): + print(f"Synthesizing {topdef} with arch {arch} in library {library}. VHDL {std}") + syn.synthDesign(topdef, arch, library, std) + +@app.command() +def run( + topdef: Annotated[str, typer.Argument(help="Top Definition entity to synthesize")] = "", + arch: Annotated[str, typer.Argument(help="Architecture to synthesize within the top definition provided")] = "", + library: Annotated[str, typer.Option("--library", "-l", help="Library to compile from")] = "work", + std: Annotated[str, typer.Option(help="Which VHDL standard to use. 87, 93, 93c, 00, 02 or 08", autocompletion=complete_vhdl_ver)] = "93c" + ): + print(f"Running (and synthesizing if needed) {topdef} with arch {arch} in library {library}. VHDL {std}") + syn.runDesign(topdef, arch, library, std) + +@app.command() +def build(): + print("Build!") + +if __name__ == "__main__": + app() diff --git a/scripts/synth.py b/scripts/synth.py new file mode 100644 index 0000000..85e5a13 --- /dev/null +++ b/scripts/synth.py @@ -0,0 +1,31 @@ +import os +import subprocess +import build_env + +def synthDesign(topDef: str, arch: str, lib: str, std: str): + ## Add all source files present in pwd + if build_env.addAllVHDLFiles() == -1: + print("build env not working") + return -1 + command = [ + "ghdl", "-m", f"--workdir={lib}", f"--work={lib}", f"--std={std}", + "-o", f"{lib}/{topDef}-{arch}", f"{lib}.{topDef}", f"{arch}"] + subprocess.run(command) + +def runDesign(topDef: str, arch: str, lib: str, std: str): + ## synth first, then run + if synthDesign(topDef, arch, lib, std) == -1: + print("synth failed") + return -1 + os.makedirs("wave",exist_ok=True) + libPath = os.path.join(os.getcwd(), lib) + wavePath = os.path.join(os.getcwd(), "wave") + command = [ ## may add -v for verbose + "ghdl", "-r", f"{topDef}", f"{arch}", + f"--wave={os.path.join(libPath, topDef)}-{arch}.ghw" ##, "--read-wave-opt=