diff --git a/scripts/build_env.py b/scripts/build_env.py index 688041f..4adefce 100644 --- a/scripts/build_env.py +++ b/scripts/build_env.py @@ -2,7 +2,10 @@ import os from re import split import subprocess -def ghdlEnvExists(relativePath="work"): +def getCfFileId(std: str): + return "08" if std == "08" else "93" ## Weird behaviour from GHDL, but all vhdl versions besides 08 have [...]93.cf + +def ghdlEnvExists(std, relativePath="work"): ## Check if work exists try: os.lstat(relativePath) @@ -14,34 +17,36 @@ def ghdlEnvExists(relativePath="work"): return False cfFileExists = False filesInWork = os.listdir(relativePath) + cfFileId = getCfFileId(std) for file in filesInWork: - if ".cf" in file: + if ".cf" in file and cfFileId in file: cfFileExists = True if not cfFileExists: return False ## Nothing bad, continue return True -def createBuildEnv(): - if ghdlEnvExists(): +def createBuildEnv(std: str): + if ghdlEnvExists(std=std): print("Build environment already exists, exiting...") return -1 ## Create build env print("Initializing GHDL project in current directory...") os.makedirs("work",exist_ok=True) - addAllVHDLFiles(init=True) + addAllVHDLFiles(std=std, init=True) return 0 -def addAllVHDLFiles(init=False): +def addAllVHDLFiles(std: str, init=False): ## Ensure everything is ready for adding files ## (init exception to avoid one if-case in ghdlEnvExists) - if not ghdlEnvExists() and not init: + if not ghdlEnvExists(std=std) and not init: return -1 vhdlFiles = [] currentlyAdded = [] + cfFileId = getCfFileId(std) ## Find already present files if not init: - cfFileName = list(filter(lambda x: ".cf" in x, os.listdir("work")))[0] + cfFileName = list(filter(lambda x: ".cf" in x and cfFileId in x, os.listdir("work")))[0] cfFilePath = os.path.join(os.getcwd(),f"work/{cfFileName}") currentlyAdded = getCurrentlyAddedFiles(cfFilePath) ## Add files not added @@ -50,7 +55,7 @@ def addAllVHDLFiles(init=False): vhdlFiles.append(file) if len(vhdlFiles) > 0: print(f"Detected new files. Adding {vhdlFiles}") - command = ["ghdl", "-i", "--workdir=work"] + vhdlFiles + command = ["ghdl", "-i", "--workdir=work", "--work=work", f"--std={std}"] + vhdlFiles subprocess.run(command) return 0 @@ -61,7 +66,3 @@ def getCurrentlyAddedFiles(cfFilePath:str): fileLines = filter(lambda x: "file" in x, lines) files = map(lambda x: split("\" \"",x)[1], fileLines) return list(files) - - -if __name__ == "__main__": - getCurrentlyAddedFiles("work/work-obj93.cf") diff --git a/scripts/elab.py b/scripts/elab.py index 79b1441..39b0029 100644 --- a/scripts/elab.py +++ b/scripts/elab.py @@ -4,7 +4,7 @@ import build_env def elabDesign(topDef: str, arch: str, lib: str, std: str): ## Add all source files present in pwd - if build_env.addAllVHDLFiles() == -1: + if build_env.addAllVHDLFiles(std) == -1: print("Adding files failed. GHDL Build environment may be broken...") return -1 command = [ @@ -18,7 +18,6 @@ def runDesign(topDef: str, arch: str, lib: str, std: str): print("Elaboration 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", "--elab-run", f"--workdir={lib}", f"--work={lib}", f"--std={std}", diff --git a/scripts/gantry.py b/scripts/gantry.py index 514eca8..84c3603 100644 --- a/scripts/gantry.py +++ b/scripts/gantry.py @@ -11,15 +11,17 @@ 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") - -@software.command(help="Initializes the GHDL build environment in a library named \"work\". Adds all files ending in \".vhd\" to the project") -def init(): - return build_env.createBuildEnv() - - 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" + ): + return build_env.createBuildEnv(std) + + @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")] = "",