88 lines
4.6 KiB
Python
88 lines
4.6 KiB
Python
import typer
|
|
import elab as elaborate
|
|
import build_env
|
|
from typing import List, Optional
|
|
from typing_extensions import Annotated
|
|
import subprocess
|
|
|
|
gantry_install_path = "/home/thesis2/exjobb-public/scripts"
|
|
|
|
app = typer.Typer()
|
|
|
|
software = typer.Typer()
|
|
hardware = typer.Typer()
|
|
|
|
app.add_typer(software, name="sim", help="GHDL simulator command group")
|
|
app.add_typer(hardware, name="syn", help="Synthesis and deployment command group")
|
|
|
|
def complete_vhdl_ver():
|
|
return ["87", "93", "93c", "00", "02", "08"]
|
|
|
|
|
|
@software.command(help="Initializes the GHDL build environment in a library named \"work\". Adds all files ending in \".vhd\" to the project")
|
|
def init(
|
|
std: Annotated[str, typer.Option(help="Which VHDL standard to use. 87, 93, 93c, 00, 02 or 08", autocompletion=complete_vhdl_ver)] = "93c",
|
|
library: Annotated[str, typer.Option("--library", "-l", help="Library to compile from")] = "defaultLib",
|
|
):
|
|
return build_env.createBuildEnv(std, library)
|
|
|
|
|
|
@software.command(help="Runs analysis and elaboration on the provided top definition and architecture using GHDL. Automatically adds new files not present in the project")
|
|
def elab(
|
|
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")] = "defaultLib",
|
|
includes: Annotated[Optional[List[str]], typer.Option("--include", "-i", help="Which libraries to include in compile")] = None,
|
|
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"Elaborating {topdef} with arch {arch} in library {library}. VHDL {std}.")
|
|
if includes is not None:
|
|
print(f"Including libraries: {includes}")
|
|
else:
|
|
includes = []
|
|
return elaborate.elabDesign(topdef, arch, library, std, includes)
|
|
|
|
@software.command(help="Simulates elaborated design in GHDL and views waves in gtkwave. Automatically runs `gantry elab` on the same top def and arch.")
|
|
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")] = "defaultLib",
|
|
includes: Annotated[Optional[List[str]], typer.Option("--include", "-i", help="Which libraries to include in compile")] = None,
|
|
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}")
|
|
if includes is not None:
|
|
print(f"Including libraries: {includes}")
|
|
else:
|
|
includes = []
|
|
return elaborate.runDesign(topdef, arch, library, std, includes)
|
|
|
|
@hardware.command(help="Synthesizes the provided top level design using NXPython. Make sure you run this with NXPython.")
|
|
def synth(
|
|
topdef: Annotated[str, typer.Argument(help="Top Definition entity to synthesize")] = "",
|
|
library: Annotated[str, typer.Option("--library", "-l", help="Library to compile from, defaults to \"work\"")] = "defaultLib"
|
|
):
|
|
proc = subprocess.run(["source_and_run.sh", f"{gantry_install_path}/nxp_script.py", "synthDesign", library, topdef])
|
|
|
|
@hardware.command(help="Places the provided top level design using NXPython. Make sure you run this with NXPython.")
|
|
def place(
|
|
topdef: Annotated[str, typer.Argument(help="Top Definition entity to synthesize")] = "",
|
|
library: Annotated[str, typer.Option("--library", "-l", help="Library to compile from, defaults to \"work\"")] = "defaultLib"
|
|
):
|
|
proc = subprocess.run(["source_and_run.sh", f"{gantry_install_path}/nxp_script.py", "placeDesign", library, topdef])
|
|
|
|
|
|
@hardware.command(help="Routes the provided top level design using NXPython. Make sure you run this with NXPython.")
|
|
def route(
|
|
topdef: Annotated[str, typer.Argument(help="Top Definition entity to synthesize")] = "",
|
|
library: Annotated[str, typer.Option("--library", "-l", help="Library to compile from, defaults to \"work\"")] = "defaultLib"
|
|
):
|
|
proc = subprocess.run(["source_and_run.sh", f"{gantry_install_path}/nxp_script.py", "routeDesign", library, topdef])
|
|
|
|
@hardware.command(help="")
|
|
def build():
|
|
print("Build!")
|
|
|
|
if __name__ == "__main__":
|
|
app()
|